You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Quantizer configs are mutated in place, leaking modules_to_not_convert across loads #15124
BitsAndBytes (4-bit and 8-bit), TorchAO, Quanto, and ModelOpt quantizers each alias a modules_to_not_convert-style list directly from self.quantization_config and then call .extend() on it, instead of copying it first:
ModelOpt: modelopt_quantizer.py (_process_model_before_weight_loading), which also writes module entries into modelopt_config["quant_cfg"]
Reusing the same quantization_config object across two from_pretrained calls leaks state between loads — keep_in_fp32_modules and CPU/disk-offloaded module names accumulate on the shared config object across calls, and in PipelineQuantizationConfig the same quant_kwargs list / quant_mapping object is shared across components (including transformers text encoders), so the leak isn't confined to one component. The accumulated list also gets written into config.json on save.
Reproduction
importtorchfromdiffusersimportBitsAndBytesConfigfromdiffusers.quantizers.bitsandbytes.bnb_quantizerimportBnB8BitDiffusersQuantizerskip_modules= ["proj_out"]
config=BitsAndBytesConfig(load_in_8bit=True, llm_int8_skip_modules=skip_modules)
model=torch.nn.Sequential(torch.nn.Linear(4, 4), torch.nn.Linear(4, 4))
for_inrange(2):
quantizer=BnB8BitDiffusersQuantizer(config)
quantizer._process_model_before_weight_loading(model, device_map=None, keep_in_fp32_modules=["norm_out"])
print(config.llm_int8_skip_modules)
# ['proj_out', 'norm_out', 'norm_out'] after two loads - should stay ['proj_out']
System Info
diffusers @ main, commit aaf57d0
Python 3.12, Linux
Who can help?
(leaving blank — no specific quantization reviewer listed in the template's tag guide)
Activity