Skip to content

[PERF] Regression from #4845 (fix of #4783), also #4832: verify-by-full-rebuild of every CPU int4 qweight makes the AVX512 AUTO first forward 10x slower (8B: 1.97 -> 23.5 s) and every state_dict() 72x slower (0.32 -> 22.9 s) #4884

Closed

Description

@Qubitium

Found on main @ 5cded90, x86-64 AVX512-BF16 host (CPU only, OMP_NUM_THREADS=8, torch 2.15).

What is wrong

#4845 (fix of #4783) drops the checkpoint qweight clone of TorchCpuAvx512Linear, which is CPU AUTO for every bf16 GPTQ model. To do that it now runs finalize_fused_train_state at the end of transform_cpu (torch_cpu_avx512.py:229). That call rebuilds every module's full checkpoint qweight in pure Torch through rebuild_avx512_qweight (_cpu_int4pack_layout.py: unpack_hf_int4, a ret_idx scatter, codes.t().reshape(...), then 8 strided shift/OR passes) and compares it bitwise with the clone. With the clone gone, every state_dict() (save, PEFT checkpoint callbacks, get_peft_model_state_dict) runs the same full rebuild on every module.

The pure-Torch inverse is about 13x slower than the C++ forward pack it verifies. The memory win is real (8B: RSS 15.25 -> 6.66 GB). The cost lands on the cold first request and on every state_dict():

Meta-Llama-3.1-8B-Instruct-GPTQ-INT4, GPTQModel.load(dtype=bf16, device="cpu"), AUTO = TorchCpuAvx512Linear x224
                        load    first forward (32 tok)   2nd forward   model.state_dict()
6fe07cb6d (before)     3.02 s         1.97 s               0.428 s          0.32 s
5cded90c9 (after)      4.46 s        23.49 s               0.486 s         22.95 s

Breakdown of the first forward (timers wrapped around the functions):

Llama-3.2-1B-Instruct-GPTQ-4bits-gp128 (identity order): first fwd 0.257 -> 2.757 s; rebuild_avx512_qweight 2.395 s, unpack_hf_int4 0.413 s, C++ transform itself 0.10 s
Qwen2.5-0.5B-Instruct-gptq-4bit (desc_act):              first fwd 0.236 -> 1.601 s; rebuild_avx512_qweight 1.292 s
synthetic 4096x14336 module:                             rebuild_avx512_qweight 200 ms (desc_act) / 144 ms (identity)

#4832 (fix of #4814) added the same verify step to Paro's CPU layouts (paro.py::_ensure_cpu_layout -> finalize_fused_train_state). Qwen2.5-0.5B Paro 4-bit bf16 first forward: 0.545 -> 2.194 s, of which 1.66 s is finalize_fused_train_state. fp16: 5.53 -> 9.48 s.

Minimal repro

import time, torch
from gptqmodel import GPTQModel
m = GPTQModel.load("Meta-Llama-3.1-8B-Instruct-GPTQ-INT4", dtype=torch.bfloat16, device="cpu")  # AUTO
ids = torch.randint(100, 1000, (1, 32))
with torch.inference_mode():
    t = time.perf_counter(); m.model(ids); print("first fwd", time.perf_counter() - t)   # 23.5 s (1.97 s at 6fe07cb6d)
t = time.perf_counter(); m.model.state_dict(); print("state_dict", time.perf_counter() - t)   # 22.9 s (0.32 s)

Suggested fix

  • The verify step does not need a full-weight rebuild of every module. The inverse is a deterministic pure-Torch function of the layout. Verify it once per process (or once per (bits, group_size, desc_act) layout) on a small tensor, or on a sampled slice of row groups per module, and then drop the clone.
  • Make the inverse itself cheap. Do one contiguous pass instead of codes.t().reshape(...) plus 8 strided passes. Better, add a C++ unpack next to pack_gptq_int4 in the same AVX512 extension, since the forward pack takes 0.10 s for the whole 1B model. That also brings state_dict() on 8B back from 23 s toward the old 0.3 s.

Test that should have caught it

test_cpu_avx512_snapshot_rebuild_4783.py checks only correctness. A CPU perf guard should bound the first forward relative to the second (or relative to the transform), for example at most 3x on a 1B model. It should also bound state_dict() on a transformed module relative to its tensor bytes.

Severity

Medium. CPU AUTO serving of every bf16 GPTQ model is affected: about 10x slower cold start (+21 s TTFT on 8B). Every state_dict()/save after the first forward takes about 23 s on 8B instead of 0.3 s.

🤖 Generated with Claude Code

Activity

  1. Qubitium commented on Nov 17, 2026

    @Qubitium
    CollaboratorAuthor

    Agent claim: agent-root-4884 is working on this issue now.

  2. Qubitium commented on Nov 17, 2026

    @Qubitium
    CollaboratorAuthor

    Agent claim released: agent-root-4884 finished this issue. Fix is #4965, squash-merged to main as c52ae99.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions