llmcompressor.metrics.utils.frequency_manager
Frequency management utilities for metrics logging.
Provides classes and functions for managing logging frequencies and determining when metrics should be recorded during training and compression workflows. Supports both epoch-based and step-based logging with configurable modes and intervals.
Classes:
-
FrequencyManager
–Class for managing the frequency of logging and model updates
Functions:
-
log_ready
–Check if we are ready to log again based on the given parameters
FrequencyManager
FrequencyManager(
log_frequency: LogStepType = None,
mode: LoggingModeType = DEFAULT_LOGGING_MODE,
frequency_type: FrequencyType = DEFAULT_FREQUENCY_TYPE,
)
Class for managing the frequency of logging and model updates
Parameters:
-
log_frequency
LogStepType
, default:None
) –The frequency to log at
-
mode
LoggingModeType
, default:DEFAULT_LOGGING_MODE
) –The logging mode to use, either "on_change" or "exact", "on_change" will log when the model has been updated since the last log, "exact" will log at the given frequency regardless of model updates
-
frequency_type
FrequencyType
, default:DEFAULT_FREQUENCY_TYPE
) –The frequency type to use, either "epoch", "step", or "batch" controls what the frequency manager is tracking, e.g. if the frequency type is "epoch", then the frequency manager will track the number of epochs that have passed since the last log, if the frequency type is "step", then the frequency manager will track the number of optimizer steps
Methods:
-
log_ready
–Check if the frequency manager is ready to log
-
log_written
–Sets the last log step to the given step
-
model_updated
–Sets the last model update to the given step
Attributes:
-
is_epoch_frequency_manager
(bool
) –:return: True if the frequency manager is tracking epochs,
-
is_optim_frequency_manager
(bool
) –:return: True if the frequency manager is tracking optimizer steps,
-
log_frequency
(LogStepType
) –:return: The log frequency
Source code in llmcompressor/metrics/utils/frequency_manager.py
is_epoch_frequency_manager property
Returns:
-
bool
–True if the frequency manager is tracking epochs, False otherwise
is_optim_frequency_manager property
Returns:
-
bool
–True if the frequency manager is tracking optimizer steps, False otherwise
log_ready
Check if the frequency manager is ready to log Conditions for readiness: - log frequency is not None - current log step is None - current log step greater than or equal to the last log step plus the log frequency - if check_model_update is True, or self._check_model_update is True, then the last model update step must be greater than or equal to the last log step, and the current log step must be greater than or equal to the last model update step plus the log frequency
Parameters:
-
current_log_step
LogStepType
) –The current log step
-
check_model_update
bool
, default:False
) –If True, will check if the model has been updated since the last log step and if _log_frequency steps have passed since the last model update; Defaults to False.
Returns:
- –
True if the frequency manager is ready to log, False otherwise
Source code in llmcompressor/metrics/utils/frequency_manager.py
log_written
Sets the last log step to the given step
:post-cond: The last log step is set to the given step
Parameters:
-
step
LogStepType
, default:None
) –The step to set the last log step to
Source code in llmcompressor/metrics/utils/frequency_manager.py
model_updated
Sets the last model update to the given step
:post-cond: The last model update step is set to the given step
Parameters:
-
step
LogStepType
, default:None
) –The step to set the last model update to
Source code in llmcompressor/metrics/utils/frequency_manager.py
log_ready
log_ready(
current_log_step: Optional[LogStepType],
last_log_step: Optional[LogStepType],
log_frequency: Optional[LogStepType],
last_model_update_step: Optional[LogStepType] = None,
check_model_update: bool = False,
)
Check if we are ready to log again based on the given parameters (Stateless version of FrequencyManager().log_ready)
Conditions for readiness: - log frequency is not None - current log step is None - current log step greater than or equal to the last log step plus the log frequency - if check_model_update is True, then the last model update step must be greater than or equal to the last log step, and the current log step must be greater than or equal to the last model update step plus the log frequency
Parameters:
-
current_log_step
Optional[LogStepType]
) –The current log step
-
last_log_step
Optional[LogStepType]
) –The last step at which logging occurred
-
log_frequency
Optional[LogStepType]
) –The frequency to log at
-
last_model_update_step
Optional[LogStepType]
, default:None
) –The last step at which the model was updated
-
check_model_update
bool
, default:False
) –If True, will check if the model has been updated since the last log step and if log_frequency steps have passed since the last model update; Defaults to False.
Returns:
- –
True if logging cadence has been reached again False otherwise