llmcompressor.transformers.compression.compressed_tensors_utils
Functions:
-
modify_save_pretrained–Overrides a PreTrainedModel's save_pretrained() method with a wrapped version that
get_model_compressor
get_model_compressor(
model: Module,
sparsity_config: SparsityCompressionConfig
| None = None,
quantization_format: str | None = None,
save_compressed: bool = True,
skip_sparsity_compression_stats: bool = True,
disable_sparse_compression: bool = False,
)
Obtain the compressor based on the config and the quantization_format
Parameters:
-
(modelModule) –torch model
-
–sparsify_configSparsity Compression config
-
(quantization_formatstr | None, default:None) –Format that the model was quantized to. if not provivided, will be extrapolated from
infer_quantization_format -
(save_compressedbool, default:True) –boolean representing to save in a compressed format
-
(skip_sparsity_compression_statsbool, default:True) –bool allowing compression stats on std out
-
(disable_sparse_compressionbool, default:False) –bool to skip sparse compression
Source code in llmcompressor/transformers/compression/compressed_tensors_utils.py
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 | |
modify_save_pretrained
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 llmcompressor/transformers/compression/compressed_tensors_utils.py
update_and_save_recipe
Save a recipe ontop of any existing recipe files located at model_stub
Parameters:
-
(model_stubstr) –path to existing model or model stub which may contain an existing recipe
-
(save_directorystr) –path to save combined existing recipe and current recipe