llmcompressor.core.state
Module for managing the state of the LLM Compressor.
This module provides classes for holding and updating the state information related to data, hardware, and model compression.
Data
dataclass
A dataclass to hold different data sets for training, validation, testing, and/or calibration. Each data set is a ModifiableData instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
train | Optional[Any] | The training data set | None |
val | Optional[Any] | The validation data set | None |
test | Optional[Any] | The testing data set | None |
calib | Optional[Any] | The calibration data set | None |
Source code in src/llmcompressor/core/state.py
Hardware
dataclass
A dataclass to hold information about the hardware being used.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
device | Optional[str] | The current device being used for training | None |
devices | Optional[List[str]] | List of all devices to be used for training | None |
rank | Optional[int] | The rank of the current device | None |
world_size | Optional[int] | The total number of devices being used | None |
local_rank | Optional[int] | The local rank of the current device | None |
local_world_size | Optional[int] | The total number of devices being used on the local machine | None |
distributed | Optional[bool] | Whether or not distributed training is being used | None |
distributed_strategy | Optional[str] | The distributed strategy being used | None |
Source code in src/llmcompressor/core/state.py
ModifiedState
dataclass
A dataclass to represent a modified model, optimizer, and loss.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model | Optional[Any] | The modified model | required |
optimizer | Optional[Any] | The modified optimizer | required |
loss | Optional[Any] | The modified loss | required |
modifier_data | Optional[List[Dict[str, Any]]] | The modifier data used to modify the model, optimizer, and loss | required |
Source code in src/llmcompressor/core/state.py
__init__(model, optimizer, loss, modifier_data)
Initialize the ModifiedState with the given parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model | Any | The modified model | required |
optimizer | Any | The modified optimizer | required |
loss | Any | The modified loss | required |
modifier_data | List[Dict[str, Any]] | The modifier data used to modify the model, optimizer, and loss | required |
Source code in src/llmcompressor/core/state.py
State
dataclass
State class holds information about the current compression state.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model | Any | The model being used for compression | None |
teacher_model | Any | The teacher model being used for compression | None |
optimizer | Any | The optimizer being used for training | None |
optim_wrapped | bool | Whether or not the optimizer has been wrapped | None |
loss | Any | The loss function being used for training | None |
batch_data | Any | The current batch of data being used for compression | None |
data | Data | The data sets being used for training, validation, testing, and/or calibration, wrapped in a Data instance | Data() |
hardware | Hardware | Hardware instance holding info about the target hardware being used | Hardware() |
loggers | Optional[LoggerManager] | LoggerManager instance holding all the loggers to log | None |
model_log_cadence | Optional[float] | The cadence to log model information w.r.t epochs. If 1, logs every epoch. If 2, logs every other epoch, etc. Default is 1. | None |
Source code in src/llmcompressor/core/state.py
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 |
|
compression_ready
property
Check if the model and optimizer are set for compression.
Returns:
Type | Description |
---|---|
bool | True if model and optimizer are set, False otherwise |
update(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, model_log_cadence=None, **kwargs)
Update the state with the given parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model | Any | The model to update the state with | None |
teacher_model | Any | The teacher model to update the state with | None |
optimizer | Any | The optimizer to update the state with | None |
attach_optim_callbacks | bool | Whether or not to attach optimizer callbacks | True |
train_data | Any | The training data to update the state with | None |
val_data | Any | The validation data to update the state with | None |
test_data | Any | The testing data to update the state with | None |
calib_data | Any | The calibration data to update the state with | None |
copy_data | bool | Whether or not to copy the data | True |
start | float | The start index to update the state with | None |
steps_per_epoch | int | The steps per epoch to update the state with | None |
batches_per_step | int | The batches per step to update the state with | 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 |
model_log_cadence | Optional[float] | The cadence to log model information w.r.t epochs. If 1, logs every epoch. If 2, logs every other epoch, etc. Default is 1. | None |
kwargs | Additional keyword arguments to update the state with | {} |
Returns:
Type | Description |
---|---|
Dict | The updated state as a dictionary |
Source code in src/llmcompressor/core/state.py
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 |
|