Skip to content

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

Fix attribute bug for diffusion model (#1338)

Wang, Mengnia4ee3a007f7a
diff --git a/auto_round/utils/model.py b/auto_round/utils/model.py
index b7b98cf1e..cc505e976 100644
--- a/auto_round/utils/model.py
+++ b/auto_round/utils/model.py
@@ -1249,7 +1249,7 @@ def mv_module_from_gpu(module):
def is_moe_model(model: torch.nn.Module) -> bool:
- if hasattr(model, "config"):
+ if hasattr(model, "config") and hasattr(model.config, "to_dict"):
for key in model.config.to_dict().keys():
if "moe" in key or "expert" in key:
return True
diff --git a/test/test_cpu/models/test_diffusion.py b/test/test_cpu/models/test_diffusion.py
new file mode 100644
index 000000000..32848ce85
--- /dev/null
+++ b/test/test_cpu/models/test_diffusion.py
@@ -0,0 +1,33 @@
+import shutil
+
+import pytest
+from diffusers import AutoPipelineForText2Image
+
+from auto_round import AutoRound
+
+from ...helpers import get_model_path
+
+flux_name_or_path = get_model_path("black-forest-labs/FLUX.1-dev")
+
+
+def setup_flux():
+ """Fixture to set up the Flux model and tokenizer."""
+ model_name = flux_name_or_path
+ pipe = AutoPipelineForText2Image.from_pretrained(model_name)
+ output_dir = "./tmp/test_quantized_flux"
+ return pipe, output_dir
+
+
+def test_flux(setup_flux):
+ pipe, output_dir = setup_flux
+ autoround = AutoRound(
+ pipe,
+ tokenizer=None,
+ scheme="MXFP4",
+ iters=0,
+ num_inference_steps=2,
+ )
+ # skip model saving since it takes much time
+ autoround.quantize()
+ shutil.rmtree(output_dir, ignore_errors=True)
diff --git a/test/test_cpu/requirements.txt b/test/test_cpu/requirements.txt
index a54cc4e4e..7f8f469f8 100644
--- a/test/test_cpu/requirements.txt
+++ b/test/test_cpu/requirements.txt
@@ -6,4 +6,6 @@ torchvision
pillow
numba
llmcompressor @ git+https://github.com/vllm-project/llm-compressor.git@main
-lm_eval
\ No newline at end of file
+lm_eval
+diffusers
+protobuf