Skip to content

PTQ-Level Efficiency, QAT-Level Accuracy | 训练后量化的效率,量化感知训练的精度

improve "compressed-tensors" import error raise (#2263)

Wang, Chang672eb8e983e0
diff --git a/auto_round/cli/main.py b/auto_round/cli/main.py
index 6eedfe4b6..167a634b2 100644
--- a/auto_round/cli/main.py
+++ b/auto_round/cli/main.py
@@ -278,6 +278,15 @@ def tune(args):
if fmt not in SUPPORTED_FORMATS:
raise ValueError(f"{fmt} is not supported, we only support {SUPPORTED_FORMATS}")
+ if any("llm_compressor" in fmt for fmt in formats):
+ from auto_round.export.export_to_llmcompressor import check_compressed_tensors_supported
+
+ try:
+ check_compressed_tensors_supported(raise_error=True)
+ except ImportError as error:
+ logger.error(str(error))
+ raise SystemExit(1) from None
+
if "auto_gptq" in args.format and args.asym is True:
logger.warning(
"the auto_gptq kernel has issues with asymmetric quantization. "
diff --git a/auto_round/export/export_to_llmcompressor/config.py b/auto_round/export/export_to_llmcompressor/config.py
index 1f5090e6c..9c66c5ffa 100644
--- a/auto_round/export/export_to_llmcompressor/config.py
+++ b/auto_round/export/export_to_llmcompressor/config.py
@@ -25,17 +25,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from auto_round.utils import logger
-
-def check_compressed_tensors_supported(raise_error: bool = False): # pragma: no cover
+def check_compressed_tensors_supported(raise_error: bool = False):
try:
import compressed_tensors # noqa: F401
return True
except ImportError:
- msg = "Please install compressed-tensors via 'pip install compressed-tensors' to save as llm-compressor format"
- logger.error(msg)
+ msg = (
+ "Please `pip install compressed-tensors` since the 'llm_compressor' output format requires "
+ "the optional dependency 'compressed-tensors'."
+ )
if raise_error:
raise ImportError(msg) from None
return False