Skip to content

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

Reduce VRAM usage of quantizing VLM models (#1777)

Liang Lv64a5817d0c22
diff --git a/auto_round/calibration/llm.py b/auto_round/calibration/llm.py
index 75306c486..b87fd284d 100644
--- a/auto_round/calibration/llm.py
+++ b/auto_round/calibration/llm.py
@@ -72,7 +72,6 @@ class LLMCalibrator(Calibrator):
and len(layer_names) == 0
and not c.quantizer.has_qlayer_outside_block
and (last_cache_name is None or last_cache_name in block_names)
- and not getattr(c, "mllm", False)
):
# low_gpu_mem_usage or calibrate only the embedding layer (also fast on CPU)
calibrate_on_cpu = True
diff --git a/test/test_cuda/models/test_mllm.py b/test/test_cuda/models/test_mllm.py
index ba79f77f8..d2eba8e9c 100644
--- a/test/test_cuda/models/test_mllm.py
+++ b/test/test_cuda/models/test_mllm.py
@@ -238,3 +238,34 @@ class TestAutoRound:
assert len(inputs) >= 3, "Should have cached at least 3 input keys"
finally:
autoround._should_stop_cache_forward = original_should_stop
+
+ def test_mllm_text_dataset_low_vram(self):
+ """Test that MLLM with string/text dataset uses CPU caching to reduce peak VRAM."""
+ from auto_round.utils.device import memory_monitor
+
+ model_name = get_model_path("Qwen/Qwen2-VL-2B-Instruct")
+ dataset = ["a small test sentence", "another test input"]
+
+ memory_monitor.reset()
+ memory_monitor._initialized = True
+
+ autoround = AutoRound(
+ model=model_name,
+ bits=4,
+ group_size=128,
+ nsamples=1,
+ iters=1,
+ dataset=dataset,
+ seqlen=8,
+ )
+ autoround.quantize()
+
+ peak_vram_gb = memory_monitor.peak_vram.get("0", 0) / 1024
+ print(f"peak_vram: {peak_vram_gb:.2f}GB")
+
+ # CPU caching keeps the model off GPU except for individual blocks, so peak VRAM
+ # should be well below the full model size.
+ assert peak_vram_gb < 2, (
+ f"Expected peak_vram < 2GB with CPU caching for MLLM, got {peak_vram_gb:.2f}GB. "
+ "MLLM models with text datasets should use CPU caching to reduce peak VRAM."
+ )