aitune.torch.module.wrapper_module
aitune.torch.module.wrapper_module
AITune wrapper module.
Module Contents
Classes
Functions
Data
API
Bases: CallableObjectProxy
AITune module wrapper.
This class wraps a torch module and provides tuning functionality. The module can be in 3 different states:
passthrough: the module is not tuned, and will behave identically to the original module.recording: the module records samples and detects multi-graphs, this is a necessary step before tuning.tuned: the module is tuned and uses underlying tuned module.
You can go from passthrough and recording with enablePassthrough and enableRecording methods.
You can go from tuned to passthrough/recording only if the force flag is True - then the module will be reset.
This wrapper can be used in place of a torch module, and will behave identically to the original module.
Get the device of the module.
Multi-graphs of the module.
Get the backends of the module.
Get the name of the module.
Get the state of the module.
Delegate getitem calls to the wrapped module.
This allows the proxy to handle indexing operations on the wrapped module, which is particularly useful for Sequential modules and other indexable modules.
Parameters:
The index or key to use for accessing the wrapped module.
Returns: Any
The result of accessing the wrapped module with the given key.
Create a cache directory for the graph.
Calls one of the wrappers depending on the module state.
Before calling a particular wrapper, the forward method is restored so that we avoid infinite recursion. After the implementation handles the call forward is restored back to point to this _forward to intercept subsequent calls.
Parameters:
The wrapped module.
The instance of the module.
The arguments to pass to the module.
The keyword arguments to pass to the module.
Returns: Any
The result of the call.
Returns strategies for given graph specs.
Module level strategies (list/dict) take precedence over provided strategy. The function checks if there is sufficient strategies (list/dict).
Handle new hooks if added by a backend.
Before tuning hooks are cleared (empty OrderedDict). If there are new hooks added by a backend, they should be added to the existing ones but before the original hooks so that application layer hooks (like HF post processing hooks) are called after the backend hooks.
Offload the module to the meta device only if no JIT backends are used.
Proxy the forward calls.
We need to re-enable hooks, so that they will be called before and after proxied forward.
Resets the module to initial state.
Restore the original forward and hooks.
We need to disable hooks, otherwise they will be called twice.
Sets up strategy or strategy_map or strategy_list depending on input args.
Activates the module backends.
Deactivates the module backends.
Enables passthrough mode.
Parameters:
if True, force the module to be in the passthrough mode.
Enables recording mode.
Parameters:
if True, force the module to be in the recording mode.
Create a wrapper module from a state dictionary.
Check if the state dictionary has a wrapper module.
Convert the wrapper module to a state dictionary.
The method follows torch.state_dict format so that it could be called recursively from torch.nn.Module.state_dict. The name of the function follows aitune convention of from/to dict. Special alias is created to match torch convention i.e. state_dict.
Tunes the module.
Parameters:
the device to use for tuning
the tuning strategy to use
if True, only dry run the tuning
Bases: enum.Enum
Possible states of the Module class.
Get the name of an object from its module and class.
Sanitize model name to be used as a module name.