Hacktoberfest 2026: as issues que os mantenedores marcaram para outubro, abertas e boas para iniciantes. Ver issues do Hacktoberfest

Quantizer configs are mutated in place, leaking modules_to_not_convert across loads

Aberta
#15,124 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
4/5
Tempo estimado
3-5 dias
Facilidade para iniciantes
54/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
python, pytorch
Domínio
machine-learning

Direção de pesquisa

Start by reading _process_model_before_weight_loading in bnb_quantizer.py, torchao_quantizer.py, quanto_quantizer.py, and modelopt_quantizer.py, then trace how each quantizer handles modules_to_not_convert and modelopt_config["quant_cfg"]. Reproduce the shared-config mutation with the supplied BitsAndBytes example and check for tests covering repeated loads and PipelineQuantizationConfig. Done means repeated loads leave the shared config unchanged and do not accumulate entries in saved config.json.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

Describe the bug

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:

  • BitsAndBytes 4/8-bit: bnb_quantizer.py (_process_model_before_weight_loading)
  • TorchAO: torchao_quantizer.py (_process_model_before_weight_loading)
  • Quanto: quanto_quantizer.py (_process_model_before_weight_loading)
  • 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
import torch
from diffusers import BitsAndBytesConfig
from diffusers.quantizers.bitsandbytes.bnb_quantizer import BnB8BitDiffusersQuantizer

skip_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 _ in range(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)

Linguagem predominante
Python
Estrelas
34.8k
Forks
7.4k
Merge médio
2d 10h
PRs com merge (30d)
56

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de huggingface/diffusers

Todas as issues de huggingface/diffusers

Issues semelhantes

Mais issues de Python

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.