Feature Dev Tools¶
TODO: Move all state object container basec lasses to feature dev tools to separate application classes from feature development tool classes… just like with framework.
State Objects¶
To implement new modular state objects the metalcass MetaStateObject
is required, to identify instances the base class BaseStateObject
is required.
State Object Metaclass¶
State Object Base Class¶
-
ignite_framework.feature_dev_tools.state_objects.base_state_objects.
BaseStateObject
¶ alias of
ignite_framework.framework.frame_state_objects.FrameStateObject
State Objects¶
-
class
ignite_framework.feature_dev_tools.state_objects.modular_state_objects.
StateObject
(initial_value='', instance_attr__get__='', instance_attr__set__='')[source]¶ StateObject is a data-descriptor that stores any value in state.
Features:
” overloaded suffix: _ref ” state shortcut auto-generation
-
class
ignite_framework.feature_dev_tools.state_objects.modular_state_objects.
StateVariable
(initial_value='', instance_attr__get__='', instance_attr__set__='')[source]¶ StateVariable is the basic state variable without any additional type checking or setting conditions.
Features:
gets/sets/calls a _value and gets/sets/calls a list of callbacks which are callables triggered when _value is set
overloaded suffixes: [‘_callbacks’, _ref’, ‘_every’, ‘_once’]
- _ref: returns StateObjectsReference-instance of itself
- _callbacks: returns list of callbacks (functions called when value is set)
set-value type dependent __set__() overload:
- CALLABLE_TYPES & tuple`([<CALLABLE_TYPES>, <dict>]): appended to its `_callbacks-list
- any other type: sets its _value
state shortcut auto-generation
-
class
ignite_framework.feature_dev_tools.state_objects.modular_state_objects.
StateParameter
(initial_value='', instance_attr__get__='', instance_attr__set__='')[source]¶ StateParameter is the basic state parameter without any additional type checking or setting conditions. StateParameters of any kind should be made available in state.params for e.g. hyper-parameter optimization or Tensorboard tracking.
Features:
- same as StateVariable
- state.params reference auto-generation as state.params.<bso_ctr_name>_<parameter_name>
-
class
ignite_framework.feature_dev_tools.state_objects.modular_state_objects.
StateFunction
(initial_value='', instance_attr__get__='', instance_attr__set__='')[source]¶ StateFunction is the a state object with as function or method as value.
Features:
- same as StateObject
- set-value types restricted to CALLABLE_TYPES
-
class
ignite_framework.feature_dev_tools.state_objects.modular_state_objects.
StateIterationCounter
(initial_value='', instance_attr__get__='', instance_attr__set__='')[source]¶ Iteration counter is a state variable, only allowing ‘’int’’ with increasing values by step size ‘+`1`.
-
class
ignite_framework.feature_dev_tools.state_objects.modular_state_objects.
StateBooleanConfigurationVariable
(initial_value='', instance_attr__get__='', instance_attr__set__='')[source]¶ Type selective configuration variable of type
bool
.
-
class
ignite_framework.feature_dev_tools.state_objects.modular_state_objects.
StateBooleanVariable
(initial_value='', instance_attr__get__='', instance_attr__set__='')[source]¶ Type selective state variable of type
bool
.
-
class
ignite_framework.feature_dev_tools.state_objects.modular_state_objects.
StateConfigurationVariable
(initial_value='', instance_attr__get__='', instance_attr__set__='')[source]¶ Configuration parameter with the features of a StateVariable, e.g. for state.configs.debug_mode=True/False.
Note: In contrast to the StateParameter the StateConfigurationVariable ist not referenced in state.params Normally used for configuration values that change value throughout a state run or/and also require callbacks, e.g. stat.config.debug/run_mode, state.configs.device, …
-
class
ignite_framework.feature_dev_tools.state_objects.modular_state_objects.
StateDevice
(initial_value='', instance_attr__get__='', instance_attr__set__='')[source]¶ StateDevice is the device parameter defining the device the processes of the state object container should run on.
-
class
ignite_framework.feature_dev_tools.state_objects.modular_state_objects.
StateIntCounter
(initial_value='', instance_attr__get__='', instance_attr__set__='')[source]¶ Type and value selective state variable only allowing type
int
and increasing values.
-
class
ignite_framework.feature_dev_tools.state_objects.modular_state_objects.
StateUnresetableIntCounter
(initial_value='', instance_attr__get__='', instance_attr__set__='')[source]¶ State variable which can only be set with monotonically increasing integers and is unresetable.
Utils¶
-
exception
ignite_framework.feature_dev_tools.utils.
FeatureNotImplementedError
(*args, **kwargs)[source]¶ - Raised when during feature development a required implementation (e.g. methods by sub/super classes)
- is missing or abstract method was mot overriden.
-
ignite_framework.feature_dev_tools.utils.
create_bso_ctr_name_prefix_from_input_ref
(input_ref)[source]¶
-
ignite_framework.feature_dev_tools.utils.
extract_successive_bso_ctr_name_from_preceding_path
(path: list)[source]¶ Returns a unique bso ctr name for the successive bso ctr of the data flow path. The return name is representative for the data flow path so the user can easy allocate the bso ctr in the context of the full data flow path.
This functions accounts for the automatic naming of bso-containers and possible interfering user-defined names if bso-ctrs within the data flow path.
Parameters: path (list(str)) – path of preceding frame state object containers, e.g. [‘trainer’, ‘trainer_logits’, ‘training_precision’, ‘trainer_logits_precision_scalar’] Returns: successive bso name (str)
-
ignite_framework.feature_dev_tools.utils.
get_caller_refs
(caller_refs, input_refs)[source]¶ Reformat argument
caller_refs
as list of state objects references.This is no general use function, use only if apppriate for implemented feature.
The list
caller_refs
is then used to add the according feature methods to the caller refs’ callbacks:def __init__(..., input_ref(s), ..., caller_refs,...): ... caller_refs = get_caller_refs(caller_refs, input_refs) # Note: Also a feature `args-list` and `kwargs-dict` (and individual description) could be added. for caller_ref, feature_method in caller_refs, feature_methods: caller_ref.caller_name = feature_method
Parameters: - caller_refs –
list of state objects references or single state objects reference or ‘’ or None:
- ’’: placeholders for setting intput_refs as the default caller_refs
- None: will normally prevent the feature method(s) to be added to a callback, e.g. if supposed to be added later on or in case it’s not required (some metrics have not all methods implemented).
- input_refs – list of state objects references providing input data of the feature, e.g.
- state.trainer.output_ref –
Returns: list of state objects reference(s) (
None
s mau be included) or (reformated) list of argumentinput_ref(s)
- caller_refs –
-
ignite_framework.feature_dev_tools.utils.
get_component_attr
(self, instance, owner)[source]¶ ‘instance_attr__get__` method for state component integrating a simple attribute with name ``self.name`` of a PyTorch class instance (or any external class), e.g. integrating
Module.training
as state parameter in the state component state.modules.model.Parameters: - self – BaseStateObject (e.g. StateVariable())instance or subclass instance that integrates the relevant state component attributes with state.
- instance – BaseStateObject container (e.g. state.engines)
- owner – The owner class holding/owning self
Returns: attribute of state component
-
ignite_framework.feature_dev_tools.utils.
get_module_component_device
(self, instance, owner)[source]¶ The ‘instance_attr__get__` method for the state component integrating the parameter device (self.name)
Parameters: - instance – the state object instance (data descriptor instance attached to the class of self)
- owner – the class of self (
self.__class__
)
Returns: current device of the module instance self.component
-
ignite_framework.feature_dev_tools.utils.
set_component_attr
(self, instance, value)[source]¶ instance_attr__set__ function for BaseStateObject to integrate StateComponent attributes in state.
Parameters: - self – BaseStateObject (e.g.
StateVariable()
) instance or subclass instance that integrates the relevant state compoment attributes with state. - instance – BaseStateObject container (e.g. state.engines)
- value – value to be set
- self – BaseStateObject (e.g.
-
ignite_framework.feature_dev_tools.utils.
set_module_component_device
(self, instance, value)[source]¶ The instance_attr__set__ method for a state component integrating the parameter device of a PyTorch class (
Module
).Actually, the PyTorch class method
\*.to(device=...)
is integrated as there is not direct parameter device in e.g.torch.nn.Module
.Parameters: - instance – the state object instance (data descriptor instance attached to the class of self)
- value – the value to set the instance’s component’s attribute self.name (==device)
-
class
ignite_framework.feature_dev_tools.container_ids.
ContainerID
[source]¶ Baseclass for all state container identification classes for each state container.
Only class instances can only be assigned to specific state containers if their type has been registered before with the state container. There are 2 ways registering a class:
- The class inherits the the required
ContainerID
, e.g.class NewClass(MetricID): pass
to assign tostate.metrics
. - The class instance registers its type with the state container, e.g.
state.metrics.register_user_defined_ctrID_class(type(instance))
.
- The class inherits the the required
-
class
ignite_framework.feature_dev_tools.container_ids.
BaseTransitionsContainerID
[source]¶ ID-class for all transition state containers.
-
class
ignite_framework.feature_dev_tools.container_ids.
ConfigurationsContainerID
[source]¶ ID-class for
state.configs
.
-
class
ignite_framework.feature_dev_tools.container_ids.
ContainerID
[source] Baseclass for all state container identification classes for each state container.
Only class instances can only be assigned to specific state containers if their type has been registered before with the state container. There are 2 ways registering a class:
- The class inherits the the required
ContainerID
, e.g.class NewClass(MetricID): pass
to assign tostate.metrics
. - The class instance registers its type with the state container, e.g.
state.metrics.register_user_defined_ctrID_class(type(instance))
.
- The class inherits the the required
-
class
ignite_framework.feature_dev_tools.container_ids.
DataloadersContainerID
[source]¶ ID-class for
state.dataloaders
.
-
class
ignite_framework.feature_dev_tools.container_ids.
EnginesContainerID
[source]¶ ID-class for
state.engines
.
-
class
ignite_framework.feature_dev_tools.container_ids.
MaintenanceContainerID
[source]¶ ID-class for
state.maintenance
.
-
class
ignite_framework.feature_dev_tools.container_ids.
MetricID
[source]¶ ID-class for infrastructure metrics in
state.maintenance
, e.g. GPU/CPU-resource metrics.
-
class
ignite_framework.feature_dev_tools.container_ids.
MetricsContainerID
[source]¶ ID-class for
state.metrics
.
-
class
ignite_framework.feature_dev_tools.container_ids.
ModulesContainerID
[source]¶ ID-class for
state.modules
.
-
class
ignite_framework.feature_dev_tools.container_ids.
OptimizersContainerID
[source]¶ ID-class for
state.optimizers
.
-
class
ignite_framework.feature_dev_tools.container_ids.
OutputhandlersContainerID
[source]¶ ID-class for
state.output_handlers
.
-
class
ignite_framework.feature_dev_tools.container_ids.
ParametersContainerID
[source]¶ ID-class for
state.params
.
-
class
ignite_framework.feature_dev_tools.container_ids.
PipelinesContainerID
[source]¶ ID-class for
state.pipelines
.
-
class
ignite_framework.feature_dev_tools.container_ids.
StateComponentID
[source]¶ ID-class for all state component containers.