llmcompressor.modifiers.modifier
Classes:
-
Modifier–A base class for all modifiers to inherit from.
Modifier
Bases: ModifierInterface, HooksMixin
A base class for all modifiers to inherit from. Modifiers are used to modify the training process for a model. Defines base attributes and methods available to all modifiers
Lifecycle: 1. initialize 2. on_event -> * on_start if self.start <= event.current_index * on_end if self.end >= event.current_index 5. finalize
Parameters:
-
–indexThe index of the modifier in the list of modifiers for the model
-
–groupThe group name for the modifier
-
–startThe start step for the modifier
-
–endThe end step for the modifier
-
–updateThe update step for the modifier
Methods:
-
finalize–Finalize the modifier for the given model and state.
-
initialize–Initialize the modifier for the given model and state.
-
on_end–on_end is called when the modifier ends and must be implemented
-
on_event–on_event is called whenever an event is triggered
-
on_finalize–on_finalize is called on modifier finalization and
-
on_initialize–on_initialize is called on modifier initialization and
-
on_start–on_start is called when the modifier starts and
-
on_update–on_update is called when the model in question must be
-
should_end–:param event: The event to check if the modifier should end
-
should_start–:param event: The event to check if the modifier should start
-
update_event–Update modifier based on the given event. In turn calls
Attributes:
-
finalized(bool) –:return: True if the modifier has been finalized
-
initialized(bool) –:return: True if the modifier has been initialized
finalize
Finalize the modifier for the given model and state.
Parameters:
-
(stateState) –The current state of the model
-
–kwargsAdditional arguments for finalizing the modifier
Raises:
-
RuntimeError–if the modifier has not been initialized
Source code in llmcompressor/modifiers/modifier.py
initialize
Initialize the modifier for the given model and state.
Parameters:
-
(stateState) –The current state of the model
-
–kwargsAdditional arguments for initializing the modifier
Raises:
-
RuntimeError–if the modifier has already been finalized
Source code in llmcompressor/modifiers/modifier.py
on_end
on_end is called when the modifier ends and must be implemented by the inheriting modifier.
Parameters:
-
(stateState) –The current state of the model
-
(eventEvent) –The event that triggered the end
-
–kwargsAdditional arguments for ending the modifier
Source code in llmcompressor/modifiers/modifier.py
on_event
on_finalize
on_finalize is called on modifier finalization and must be implemented by the inheriting modifier.
Parameters:
-
(stateState) –The current state of the model
-
–kwargsAdditional arguments for finalizing the modifier
Returns:
-
bool–True if the modifier was finalized successfully, False otherwise
Source code in llmcompressor/modifiers/modifier.py
on_initialize abstractmethod
on_initialize is called on modifier initialization and must be implemented by the inheriting modifier.
Parameters:
-
(stateState) –The current state of the model
-
–kwargsAdditional arguments for initializing the modifier
Returns:
-
bool–True if the modifier was initialized successfully, False otherwise
Source code in llmcompressor/modifiers/modifier.py
on_start
on_start is called when the modifier starts and must be implemented by the inheriting modifier.
Parameters:
-
(stateState) –The current state of the model
-
(eventEvent) –The event that triggered the start
-
–kwargsAdditional arguments for starting the modifier
Source code in llmcompressor/modifiers/modifier.py
on_update
on_update is called when the model in question must be updated based on passed in event. Must be implemented by the inheriting modifier.
Parameters:
-
(stateState) –The current state of the model
-
(eventEvent) –The event that triggered the update
-
–kwargsAdditional arguments for updating the model
Source code in llmcompressor/modifiers/modifier.py
should_end
Parameters:
-
(eventEvent) –The event to check if the modifier should end
Returns:
- –
True if the modifier should end based on the given event
Source code in llmcompressor/modifiers/modifier.py
should_start
Parameters:
-
(eventEvent) –The event to check if the modifier should start
Returns:
-
bool–True if the modifier should start based on the given event
Source code in llmcompressor/modifiers/modifier.py
update_event
Update modifier based on the given event. In turn calls on_start, on_update, and on_end based on the event and modifier settings. Returns immediately if the modifier is not initialized
Parameters:
-
(stateState) –The current state of sparsification
-
(eventEvent) –The event to update the modifier with
-
–kwargsAdditional arguments for updating the modifier
Raises:
-
RuntimeError–if the modifier has been finalized