Repository navigation
Closed
Labels
bugSomething isn't working
Milestone
Description
Describe the bug
seems like it's not applied to quantize_ properly
Reproduction
from collections import OrderedDict
import torch
from diffusers.models.transformers.transformer_flux2 import Flux2Transformer2DModel
from diffusers.quantizers.quantization_config import TorchAoConfig
from torchao.quantization import FqnToConfig, Int8WeightOnlyConfig, PerGroup, PerTensor
with torch.no_grad():
_t = Flux2Transformer2DModel.from_pretrained(
"black-forest-labs/FLUX.2-klein-4B",
subfolder="transformer",
torch_dtype=torch.bfloat16,
device_map="cuda",
low_cpu_mem_usage=True,
quantization_config=TorchAoConfig(
FqnToConfig(
OrderedDict(
[
(
r"re:.*transformer_blocks\.\d+\.ff.*",
Int8WeightOnlyConfig(version=2, granularity=PerTensor()),
),
(
r"re:.*transformer_blocks\.\d+\.attn.*",
Int8WeightOnlyConfig(version=2, granularity=PerGroup(64)),
),
("_default", None),
]
)
)
),
)Logs
Traceback (most recent call last):
File "/tmp/reproduce.py", line 9, in <module>
_t = Flux2Transformer2DModel.from_pretrained(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/repro/.venv/lib/python3.12/site-packages/huggingface_hub/utils/_validators.py", line 88, in _inner_fn
return fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^
File "/tmp/repro/.venv/lib/python3.12/site-packages/diffusers/models/modeling_utils.py", line 1398, in from_pretrained
) = cls._load_pretrained_model(
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/repro/.venv/lib/python3.12/site-packages/diffusers/models/modeling_utils.py", line 1792, in _load_pretrained_model
offload_index, state_dict_index, _mismatched_keys, _error_msgs = load_fn(shard_file)
^^^^^^^^^^^^^^^^^^^
File "/tmp/repro/.venv/lib/python3.12/site-packages/diffusers/models/model_loading_utils.py", line 371, in _load_shard_file
offload_index, state_dict_index = load_model_dict_into_meta(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/repro/.venv/lib/python3.12/site-packages/diffusers/models/model_loading_utils.py", line 303, in load_model_dict_into_meta
hf_quantizer.create_quantized_param(
File "/tmp/repro/.venv/lib/python3.12/site-packages/diffusers/quantizers/torchao/torchao_quantizer.py", line 366, in create_quantized_param
quantize_(module, self.quantization_config.get_apply_tensor_subclass())
File "/tmp/repro/.venv/lib/python3.12/site-packages/torchao/quantization/quant_api.py", line 422, in quantize_
raise ValueError(
ValueError: Custom filter_fn and FqnToConfig were both specified. Only filter_fn=None is supported when FqnToConfig is specified.System Info
Copy-and-paste the text below in your GitHub issue and FILL OUT the two last points.
- 🤗 Diffusers version: 0.40.0.dev0
- Platform: Linux-7.2.2-arch1-1-x86_64-with-glibc2.44
- Running on Google Colab?: No
- Python version: 3.12.13
- PyTorch version (GPU?): 2.13.0+rocm7.2 (True)
- Huggingface_hub version: 1.24.0
- Transformers version: 5.5.4
- Accelerate version: 1.12.0
- PEFT version: 0.18.1
- bitsandbytes version: 0.49.2
- optimum-quanto version: 0.2.7
- torchao version: 0.17.0+rocm7.2
- Safetensors version: 0.8.0
- xFormers version: not installed
- Accelerator: NA
- Using GPU in script?: optional
- Using distributed or parallel set-up in script?: noWho can help?
Metadata
Metadata
Assignees
Labels
bugSomething isn't working
Type
Projects
- StatusShow more project fieldsDone
Activity
DN6 commentedon Sep 1, 2026
@Beinsezii The traceback seems to point to an issue with
TorchAO? Are you able to quantize the model withTorchAOdirectly?Beinsezii commentedon Sep 1, 2026
@DN6, Yes, the issue is diffusers callsite of
quantize_. Transformers already handles this, so passingFqnToConfigtoModularPipeline.load_componentsonly works on text encoders.direct_quantization.py
i made a hacky patch on a fork that just adds a special case for FqnToConfig but the Transformers source code seems to have a more sophisticated solution so I thought it would be better for a HuggingFace maintainer to implement this.
sayakpaul commentedon Sep 2, 2026
Checking.
sayakpaul commentedon Sep 2, 2026
@Beinsezii can you check #14686 and see if that fixes the problem?
modelpath-dev commentedon Sep 4, 2026
I will take this issue. Please assign it to me.
The problem seems to be with how
FqnToConfigis applied withinTorchAoConfig. It looks like the quantization configuration is not being applied correctly to thequantize_function. I will start by checking theFqnToConfigimplementation to ensure it correctly matches and applies configurations based on the provided patterns. I will also verify if theTorchAoConfigis correctly integrating these configurations. A small fix might involve adjusting the regex patterns or the application logic inFqnToConfig.modelpath-dev commentedon Sep 6, 2026
@sayakpaul, I will review the changes in PR #14686 to see if they resolve the issue. If it fixes the problem, I will confirm here. Thank you for the update.
modelpath-dev commentedon Sep 8, 2026
@sayakpaul, I checked the changes in PR #14686. It looks promising. I will test it with the provided reproduction script to confirm if it resolves the issue. I will update here once I have the results. Thank you for addressing this.
install2.11.0.sh : leve la restriction VRAM >=20 Go