llmcompressor.core.session
CompressionSession
A session for compression that holds the lifecycle and state for the current compression session
Source code in llmcompressor/core/session.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 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 252 253 254 255 |
|
lifecycle
property
Lifecycle is used to keep track of where we are in the compression process and what modifiers are active. It also provides the ability to invoke events on the lifecycle.
Returns:
Type | Description |
---|---|
CompressionLifecycle | the lifecycle for the session |
state
property
State of the current compression session. State instance is used to store all information such as the recipe, model optimizer, data, etc. that is needed for compression.
Returns:
Type | Description |
---|---|
State | the current state of the session |
event(event_type, batch_data=None, loss=None, **kwargs)
Invoke an event for current CompressionSession.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
event_type | EventType | the event type to invoke | required |
batch_data | Optional[Any] | the batch data to use for the event | None |
loss | Optional[Any] | the loss to use for the event if any | None |
kwargs | additional kwargs to pass to the lifecycle's event method | {} |
Returns:
Type | Description |
---|---|
ModifiedState | the modified state of the session after invoking the event |
Source code in llmcompressor/core/session.py
finalize(**kwargs)
Finalize the session for compression. This will run the finalize method for each modifier in the session's lifecycle. This will also set the session's state to the finalized state.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kwargs | additional kwargs to pass to the lifecycle's finalize method | {} |
Returns:
Type | Description |
---|---|
ModifiedState | the modified state of the session after finalizing |
Source code in llmcompressor/core/session.py
get_serialized_recipe()
Returns:
Type | Description |
---|---|
Optional[str] | serialized string of the current compiled recipe |
Source code in llmcompressor/core/session.py
initialize(recipe=None, recipe_stage=None, recipe_args=None, model=None, teacher_model=None, optimizer=None, attach_optim_callbacks=True, train_data=None, val_data=None, test_data=None, calib_data=None, copy_data=True, start=None, steps_per_epoch=None, batches_per_step=None, loggers=None, **kwargs)
Initialize the session for compression. This will run the initialize method for each modifier in the session's lifecycle. This will also set the session's state to the initialized state.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
recipe | Union[str, List[str], Recipe, List[Recipe], None] | the recipe to use for the compression, can be a path to a recipe file, a raw recipe string, a recipe object, or a list of recipe objects. | None |
recipe_stage | Union[str, List[str], None] | the stage to target for the compression | None |
recipe_args | Union[Dict[str, Any], None] | the args to use for overriding the recipe defaults | None |
model | Optional[Any] | the model to compress | None |
teacher_model | Optional[Any] | the teacher model to use for knowledge distillation | None |
optimizer | Optional[Any] | the optimizer to use for the compression | None |
attach_optim_callbacks | bool | True to attach the optimizer callbacks to the compression lifecycle, False otherwise | True |
train_data | Optional[Any] | the training data to use for the compression | None |
val_data | Optional[Any] | the validation data to use for the compression | None |
test_data | Optional[Any] | the testing data to use for the compression | None |
calib_data | Optional[Any] | the calibration data to use for the compression | None |
copy_data | bool | True to copy the data, False otherwise | True |
start | Optional[float] | the start epoch to use for the compression | None |
steps_per_epoch | Optional[int] | the number of steps per epoch to use for the compression | None |
batches_per_step | Optional[int] | the number of batches per step to use for compression | None |
loggers | Union[None, LoggerManager, List[BaseLogger]] | the metrics manager to setup logging important info and milestones to, also accepts a list of BaseLogger(s) | None |
kwargs | additional kwargs to pass to the lifecycle's initialize method | {} |
Returns:
Type | Description |
---|---|
ModifiedState | the modified state of the session after initializing |
Source code in llmcompressor/core/session.py
log(event_type, loss=None)
Log model and loss information for the current event type
Parameters:
Name | Type | Description | Default |
---|---|---|---|
event_type | EventType | the event type to log for | required |
loss | Optional[Any] | the loss to log if any | None |
Source code in llmcompressor/core/session.py
reset()
reset_stage()
Reset the session for starting a new stage, recipe and model stays intact