llmcompressor.transformers.sparsification.compressed_tensors_utils
get_model_compressor(model, sparsity_config=None, quantization_format=None, save_compressed=True, skip_sparsity_compression_stats=True, state_dict=None, disable_sparse_compression=False)
Obtain the compressor based on the config and the quantization_format
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model | Module | torch model | required |
sparsify_config | Sparsity Compression config | required | |
quantization_format | Optional[str] | Format that the model was quantized to. if not provivided, will be extrapolated from | None |
save_compressed | bool | boolean representing to save in a compressed format | True |
skip_sparsity_compression_stats | bool | bool allowing compression stats on std out | True |
state_dict | Optional[Dict] | state_dict of the model | None |
disable_sparse_compression | bool | bool to skip sparse compression | False |
Source code in src/llmcompressor/transformers/sparsification/compressed_tensors_utils.py
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 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
|
modify_save_pretrained(model)
Overrides a PreTrainedModel's save_pretrained() method with a wrapped version that supports compression. The new save_pretrained function performs the following saving operations:
- Saves the model state, potentially in a compressed format
- Saves the recipe, appending any current recipes to existing recipe files
- Copies any necessary python files from the model cache
Source code in src/llmcompressor/transformers/sparsification/compressed_tensors_utils.py
36 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 |
|
patch_tied_tensors_bug(model)
Patches bug where HF transformers will fail to untie weights under specific circumstances (https://github.com/huggingface/transformers/issues/33689).
This function detects those cases and unties the tensors if applicable
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model | Module | model to fix | required |
Source code in src/llmcompressor/transformers/sparsification/compressed_tensors_utils.py
update_and_save_recipe(model_stub, save_directory)
Save a recipe ontop of any existing recipe files located at model_stub
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_stub | str | path to existing model or model stub which may contain an existing recipe | required |
save_directory | str | path to save combined existing recipe and current recipe | required |