Skip to content

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

fix diffusion model tuning issue (#1617)

Wang, Mengnie56369ca73ab
diff --git a/auto_round/compressors/diffusion/compressor.py b/auto_round/compressors/diffusion/compressor.py
index a1bc795ac..ea7eba39e 100644
--- a/auto_round/compressors/diffusion/compressor.py
+++ b/auto_round/compressors/diffusion/compressor.py
@@ -326,6 +326,7 @@ class DiffusionCompressor(BaseCompressor):
if self.pipe.device != self.model.device:
self.pipe.to(self.model.device)
+ self.pipe.to(self.model.dtype)
with tqdm(range(1, total + 1), desc="cache block inputs") as pbar:
for ids, prompts in self.dataloader:
if isinstance(prompts, tuple):
@@ -374,6 +375,11 @@ class DiffusionCompressor(BaseCompressor):
# torch.cuda.empty_cache()
+ def _should_stop_cache_forward(self, name: str) -> bool:
+ """Determine whether current forward pass can stop after caching `name`."""
+ # diffusion model needs to run all steps to collect input
+ return False
+
def _get_save_folder_name(self, format: OutputFormat) -> str:
"""Generates the save folder name based on the provided format string.
diff --git a/test/test_cpu/models/test_diffusion.py b/test/test_cpu/models/test_diffusion.py
index 6b0dc0f76..dbc88f0e7 100644
--- a/test/test_cpu/models/test_diffusion.py
+++ b/test/test_cpu/models/test_diffusion.py
@@ -52,3 +52,20 @@ def test_flux(setup_flux):
# skip model saving since it takes much time
autoround.quantize()
shutil.rmtree(output_dir, ignore_errors=True)
+
+
+def test_flux_calib(setup_flux):
+ pipe, output_dir = setup_flux
+ autoround = AutoRound(
+ pipe,
+ tokenizer=None,
+ scheme="NVFP4",
+ iters=1,
+ num_inference_steps=2,
+ nsamples=2,
+ dataset="coco2014",
+ )
+ # skip model saving since it takes much time
+ all_inputs = autoround.cache_inter_data(["transformer_blocks.0"], 2)
+ assert len(all_inputs["transformer_blocks.0"]["hidden_states"]) == 4
+ shutil.rmtree(output_dir, ignore_errors=True)