From 65f6acff019e1cce05511242fe942ee30a111f0a Mon Sep 17 00:00:00 2001 From: George Date: Fri, 22 Nov 2024 13:46:55 +0000 Subject: [PATCH] comment --- src/compressed_tensors/compressors/base.py | 2 -- .../model_compressors/model_compressor.py | 12 +++++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/compressed_tensors/compressors/base.py b/src/compressed_tensors/compressors/base.py index b519382b..ee751053 100644 --- a/src/compressed_tensors/compressors/base.py +++ b/src/compressed_tensors/compressors/base.py @@ -125,8 +125,6 @@ def compress_module(self, module: Module) -> Optional[Dict[str, torch.Tensor]]: return None # module is not quantized quantization_scheme = module.quantization_scheme if not hasattr(quantization_scheme, "weights"): - # models that ran CompressedLinear.from_linear will - # run delattr(module, "weight") return None # weights are not quantized quantization_args = quantization_scheme.weights diff --git a/src/compressed_tensors/compressors/model_compressors/model_compressor.py b/src/compressed_tensors/compressors/model_compressors/model_compressor.py index 466bbc09..5d1030d8 100644 --- a/src/compressed_tensors/compressors/model_compressors/model_compressor.py +++ b/src/compressed_tensors/compressors/model_compressors/model_compressor.py @@ -24,7 +24,6 @@ import torch import transformers from compressed_tensors.base import ( - COMPRESSION_CONFIG_NAME, COMPRESSION_VERSION_NAME, QUANTIZATION_CONFIG_NAME, QUANTIZATION_METHOD_NAME, @@ -103,14 +102,14 @@ def from_pretrained( :return: compressor for the configs, or None if model is not compressed """ config = AutoConfig.from_pretrained(pretrained_model_name_or_path, **kwargs) - compression_config = getattr(config, COMPRESSION_CONFIG_NAME, None) or getattr( - config, QUANTIZATION_CONFIG_NAME, None - ) + compression_config = getattr(config, QUANTIZATION_CONFIG_NAME, None) + return cls.from_compression_config(compression_config) @classmethod def from_compression_config( - cls, compression_config: Union[Dict[str, Any], "CompressedTensorsConfig"] + cls, + compression_config: Union[Dict[str, Any], "CompressedTensorsConfig"], ): """ :param compression_config: @@ -267,7 +266,10 @@ def compress( state_dict = model.state_dict() compressed_state_dict = state_dict + + # submodule name to q_args quantized_modules_to_args = map_modules_to_quant_args(model) + if self.quantization_compressor is not None: compressed_state_dict = self.quantization_compressor.compress( state_dict, names_to_scheme=quantized_modules_to_args