llmcompressor.core.session_functions
Session management functions for LLM compression workflows.
Provides global session management functionality including session creation, activation, reset operations, and lifecycle callback management.
Classes:
-
LifecycleCallbacks–A class for invoking lifecycle events for the active session
Functions:
-
active_session–:return: the active session for sparsification
-
create_session–Context manager to create and yield a new session for sparsification.
-
reset_session–Reset the currently active session to its initial state
LifecycleCallbacks
A class for invoking lifecycle events for the active session
Methods:
-
batch_end–Invoke a batch end event for the active session
-
batch_start–Invoke a batch start event for the active session
-
calibration_epoch_end–Invoke a epoch end event for the active session during calibration. This event
-
calibration_epoch_start–Invoke a epoch start event for the active session during calibration. This event
-
event–Invoke an event for the active session
-
loss_calculated–Invoke a loss calculated event for the active session
-
optim_post_step–Invoke an optimizer post-step event for the active session
-
optim_pre_step–Invoke an optimizer pre-step event for the active session
-
sequential_epoch_end–Invoke a sequential epoch end event for the active session. This event should be
batch_end classmethod
Invoke a batch end event for the active session
Parameters:
-
–kwargsadditional kwargs to pass to the current session's event method
Returns:
-
ModifiedState–the modified state of the active session after invoking the event
Source code in llmcompressor/core/session_functions.py
batch_start classmethod
Invoke a batch start event for the active session
Parameters:
-
(batch_dataOptional[Any], default:None) –the batch data to use for the event
-
–kwargsadditional kwargs to pass to the current session's event method
Returns:
-
ModifiedState–the modified state of the active session after invoking the event
Source code in llmcompressor/core/session_functions.py
calibration_epoch_end classmethod
Invoke a epoch end event for the active session during calibration. This event should be called after the model has been calibrated for one epoch
see src/llmcompressor/pipelines/basic/pipeline.py for usage example
Source code in llmcompressor/core/session_functions.py
calibration_epoch_start classmethod
Invoke a epoch start event for the active session during calibration. This event should be called before calibration starts for one epoch
see src/llmcompressor/pipelines/basic/pipeline.py for usage example
Source code in llmcompressor/core/session_functions.py
event classmethod
Invoke an event for the active session
Parameters:
-
(event_typeEventType) –the event type to invoke
-
–kwargsadditional kwargs to pass to the current session's event method
Returns:
-
ModifiedState–the modified state of the active session after invoking the event
Source code in llmcompressor/core/session_functions.py
loss_calculated classmethod
Invoke a loss calculated event for the active session
Parameters:
-
(lossOptional[Any], default:None) –the loss to use for the event
-
–kwargsadditional kwargs to pass to the current session's event method
Returns:
-
ModifiedState–the modified state of the active session after invoking the event
Source code in llmcompressor/core/session_functions.py
optim_post_step classmethod
Invoke an optimizer post-step event for the active session
Parameters:
-
–kwargsadditional kwargs to pass to the current session's event method
Returns:
-
ModifiedState–the modified state of the active session after invoking the event
Source code in llmcompressor/core/session_functions.py
optim_pre_step classmethod
Invoke an optimizer pre-step event for the active session
Parameters:
-
–kwargsadditional kwargs to pass to the current session's event method
Returns:
-
ModifiedState–the modified state of the active session after invoking the event
Source code in llmcompressor/core/session_functions.py
sequential_epoch_end classmethod
Invoke a sequential epoch end event for the active session. This event should be called after one sequential layer has been calibrated/trained for one epoch
This is called after a sequential layer has been calibrated with one batch, see src/llmcompressor/pipelines/sequential/pipeline.py for usage example
Source code in llmcompressor/core/session_functions.py
active_session
Returns:
-
CompressionSession–the active session for sparsification
create_session
Context manager to create and yield a new session for sparsification. This will set the active session to the new session for the duration of the context.
Returns:
-
Generator[CompressionSession, None, None]–the new session