Skip to content

[BUG] Re-saving a loaded quantized model builds the shell with from_config outside _MODEL_LOAD_LOCK, reopening the #4129 default-dtype race #4204

Closed

Description

@Qubitium

Severity: medium
Status: likely. The unlocked call sequence is confirmed; a full save()-vs-load() race did not hit the window in 10 tries on our host.
Version: 7.11.0 @ 9dad249

Summary

The save_quantized → get_model_with_quantize path (models/writer.py:~2148, :2446-2459) runs suspend_hf_weight_init() + self.loader.from_config(config, dtype=model_dtype). transformers wraps that in local_torch_dtype, a process-global torch.set_default_dtype.

Only from_pretrained / from_quantized are serialised by _serialized_model_load (models/loader.py). These are also unlocked:

  • utils/model_dequant.py:~359
  • utils/tt_blockfloat_quant.py:~2155 (_from_config)

Reproduce (the save-path sequence on one thread, GPTQModel.load on another)

import threading, torch
from transformers import AutoConfig, AutoModelForCausalLM
from gptqmodel import GPTQModel, QuantizeConfig
from gptqmodel.utils.hf import suspend_hf_weight_init
P = "Qwen/Qwen3-0.6B"; cfg = AutoConfig.from_pretrained(P); stop = threading.Event()
def saver():   # what BaseQModel.get_model_with_quantize does, without the lock
    while not stop.is_set():
        with suspend_hf_weight_init(): AutoModelForCausalLM.from_config(cfg, dtype=torch.bfloat16)
t = threading.Thread(target=saver); t.start()
for i in range(8):
    try:
        GPTQModel.load(P, quantize_config=QuantizeConfig(bits=4, offload_to_disk=False), dtype=torch.float16, device="cpu")
        print(i, "ok", torch.get_default_dtype())
    except Exception as e: print(i, e)
stop.set(); t.join()

Actual:

  • 5/8 loads raised model load left a corrupted state: floating parameters are not all torch.float16: {'torch.bfloat16': 34} or torch.get_default_dtype() changed.
  • The "ok" loads observed default=torch.bfloat16 mid-run.

Expected: every model-construction site, including the save-side shell build, the dequant path and the TT block-float path, takes _MODEL_LOAD_LOCK.

Related: #4129 (closed) fixed only the load entry points.


Found during an AI-assisted review (Claude Code) of 9dad249; repros were run on RTX 4090/5090 (CUDA 13) and/or Radeon AI PRO R9700 (ROCm) unless marked static/suspected.

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions