llmcompressor.core.events
LLM Compressor Core Events Package
This package provides the core components and lifecycle management for events used in the LLM Compressor framework. It includes definitions for various event types and lifecycles that are critical for managing the state and execution flow of the model compression and training processes.
Event
dataclass
A class for defining an event that can be triggered during sparsification.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
type_ | Optional[EventType] | The type of event. | None |
steps_per_epoch | Optional[int] | The number of steps per epoch. | None |
batches_per_step | Optional[int] | The number of batches per step where step is an optimizer step invocation. For most pathways, these are the same. See the invocations_per_step parameter for more details when they are not. | None |
invocations_per_step | int | The number of invocations of the step wrapper before optimizer.step was called. Generally can be left as 1 (default). For older amp pathways, this is the number of times the scaler wrapper was invoked before the wrapped optimizer step function was called to handle accumulation in fp16. | 1 |
global_step | int | The current global step. | 0 |
global_batch | int | The current global batch. | 0 |
Source code in src/llmcompressor/core/events/event.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
|
current_index
property
writable
Calculates the current index of the event.
Returns:
Type | Description |
---|---|
float | The current index of the event, which is either the global step or the epoch with the fraction of the current step. |
Raises:
Type | Description |
---|---|
ValueError | if the event is not epoch based or if the steps per epoch are too many. |
epoch
property
Calculates the current epoch.
Returns:
Type | Description |
---|---|
int | The current epoch. |
Raises:
Type | Description |
---|---|
ValueError | if the event is not epoch based. |
epoch_based
property
Determines if the event is based on epochs.
Returns:
Type | Description |
---|---|
bool | True if the event is based on epochs, False otherwise. |
epoch_batch
property
Calculates the current batch within the current epoch.
Returns:
Type | Description |
---|---|
int | The current batch within the current epoch. |
Raises:
Type | Description |
---|---|
ValueError | if the event is not epoch based. |
epoch_full
property
Calculates the current epoch with the fraction of the current step.
Returns:
Type | Description |
---|---|
float | The current epoch with the fraction of the current step. |
Raises:
Type | Description |
---|---|
ValueError | if the event is not epoch based. |
epoch_step
property
Calculates the current step within the current epoch.
Returns:
Type | Description |
---|---|
int | The current step within the current epoch. |
Raises:
Type | Description |
---|---|
ValueError | if the event is not epoch based. |
new_instance(**kwargs)
Creates a new instance of the event with the provided keyword arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kwargs | Keyword arguments to set in the new instance. | {} |
Returns:
Type | Description |
---|---|
Event | A new instance of the event with the provided kwargs. |
Source code in src/llmcompressor/core/events/event.py
should_update(start, end, update)
Determines if the event should trigger an update.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start | Optional[float] | The start index to check against, set to None to ignore start. | required |
end | Optional[float] | The end index to check against, set to None to ignore end. | required |
update | Optional[float] | The update interval, set to None or 0.0 to always update, otherwise must be greater than 0.0, defaults to None. | required |
Returns:
Type | Description |
---|---|
bool | True if the event should trigger an update, False otherwise. |
Source code in src/llmcompressor/core/events/event.py
EventType
Bases: Enum
An Enum for defining the different types of events that can be triggered during model compression lifecycles. The purpose of each EventType is to trigger the corresponding modifier callback during training or post training pipelines.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
INITIALIZE | Event type for initialization. | required | |
FINALIZE | Event type for finalization. | required | |
BATCH_START | Event type for the start of a batch. | required | |
LOSS_CALCULATED | Event type for when loss is calculated. | required | |
BATCH_END | Event type for the end of a batch. | required | |
CALIBRATION_EPOCH_START | Event type for the start of a calibration epoch. | required | |
SEQUENTIAL_EPOCH_END | Event type for the end of a layer calibration epoch, specifically used by | required | |
CALIBRATION_EPOCH_END | Event type for the end of a calibration epoch. | required | |
OPTIM_PRE_STEP | Event type for pre-optimization step. | required | |
OPTIM_POST_STEP | Event type for post-optimization step. | required |