aitune.torch.backend.backend
Backend interface.
Module Contents
Classes
API
Backend interface for tuning a module.
Get a logger specific to this backend implementation.
Get the device of the backend.
Returns True if the backend is active.
Returns True if the backend is a JIT backend.
This method ensures that the backend has this property defined.
Name of a backend.
Activates backend.
After activating, the backend should be ready to do inference.
Assert the device of the backend.
Parameters:
The device to assert.
Build the model with the given arguments.
After building, the backend should be activated.
Parameters:
The module to build the backend on.
The name of the backend.
The graph specification of the backend.
The data to build the backend on.
The cache directory to store the backend artifacts.
Clean up memory.
Deactivates backend.
After deactivating, the backend cannot be used to do inference.
Deploys the backend.
After deploying, the backend is ready to do inference. Backend cannot be deactivated anymore.
Run inference with the given arguments.
Parameters:
Variable length argument list.
Arbitrary keyword arguments.
Returns:
The result of the inference.
Set the device of the backend.
Parameters:
The device to set the backend on.
Record a build step result.
Activates backend.
After activating, the backend should be ready to do inference.
Build the model with the given arguments.
Building a backend should be idempotent i.e. do not cause side effects. A model is not necessarily pure functional and can have an internal state (like kv cache for LLMs). That is why build can call a sample of inputs at most once so that subsequent calls have exact same state as the first call for the given sample.
After building, the backend should be activated.
Deactivates backend.
After deactivating, the backend cannot be used to do inference.
Deploys the backend.
After deploying, the backend is ready to do inference. Backend cannot be deactivated anymore.
Parameters:
The device to deploy the backend on.
Returns the description of the backend.
Creates a backend from a module and state_dict.
Run inference with the given arguments.
Parameters:
Variable length argument list.
Arbitrary keyword arguments.
Returns: Any
The result of the inference.
Returns the key of the backend.
Returns the state_dict of the backend.
Note: if there any binary artifacts (files) which should be stored by a backend, they must be passed as Python Path object. Such objects will be bundled with a checkpoint.
Bases: enum.Enum
Base class for backend build step enums.
Configuration for a backend.
Returns the default fields to describe.
Returns the changed fields of the backend configuration.
Describe the backend configuration. Display only changed fields.
Initialise config from a plain dict (e.g. parsed from YAML).
The default implementation passes all keys as keyword arguments. Override in subclasses that need type conversion (e.g. nested dicts, enum values, or pickle-serialised objects).
Returns the keys of the backend configuration.
Returns the state_dict of the backend.
Saves the backend configuration to a file.
Bases: enum.Enum
Enum representing the state of a backend.
State transitions:
Note:
- Changing state to deployed should be done in
ModuleWrapperas it does a proxy offorwardmethod and reverses that in order to deploy/recompile jit backends. - After loading a checkpoint you can still do activation when grokking with the code but bare in mind that jit backends do recompilation.
Bases: Backend
Dummy backend for testing purposes.
Activate the backend.
Build the model with the given arguments.
Deactivate the backend.
Deploy the backend.
Run inference with the given arguments.
Returns the description of the backend.
Creates a backend from a module and state_dict.
Run inference with the given arguments.
Returns the key of the backend.
Returns the state_dict of the backend.