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
[PERF] #4949 (fix of #4907) incomplete: TorchFusedAwqLinear still latches the dense TRAIN path across eval() (fp16 CPU AWQ 6.6 -> 209 s/forward) #5018
Found on main @ c2b0bf6, x86-64 CPU (RTX 4090 host, no GPU used).
What is wrong
#4949 (fix of #4907) made three CPU int4pack kernels clear their latched linear_mode == "train" in train(False), because "a forward taken while the module was in training mode pinned it to dense dequantization for the rest of its life, so a later eval() could never recover": TorchAtenLinear, TorchAtenAwqLinear and TorchFusedLinear. The fourth sibling with the same latch, TorchFusedAwqLinear (gptqmodel/nn_modules/qlinear/torch_fused_awq.py, train() ~line 422), was not changed. Its train() only resets the latch when switching to training from INFERENCE; eval() after a training-mode forward keeps LinearMode.TRAIN forever, so every later inference_mode forward dequantizes the full weight.
(TorchCpuAvx512Linear / TorchCpuAvx512AwqLinear reset on any mode change, so they are fine.)
Scenario: load an AWQ checkpoint on CPU with the torch-fused AWQ kernel, run any forward in training mode (LoRA fine-tune step, model.train() evaluation loop, etc.), then model.eval() for generation.
(or reset on any mode change, as the AVX512 kernels do).
Test that should have caught it
tests/test_hf_awq_repair_train_mode_4907.py covers the three patched kernels; parametrize the "train forward, then eval recovers the inference layout" node over every CPU int4pack kernel class, including TorchFusedAwqLinear.
Severity
Medium: silent 32x slowdown for fp16 CPU AWQ inference after any training-mode forward on the torch-fused AWQ kernel; outputs stay correct.
Side note from the same measurement, not part of this bug: bf16 TorchFusedAwqLinear/TorchAtenAwqLinear int4pack inference (6.7 s/fwd) was 3.6x slower than the dense-dequant path (1.87 s/fwd) at M=32 on this host (load average ~40, so treat the absolute numbers as indicative).
Agent release:agent-root-5018 finished this issue. Fix: #5036, squash-merged as 84ab448e9.
TorchFusedAwqLinear.train() now clears the latched LinearMode.TRAIN when the module leaves training mode, mirroring the #4949 rule already present in TorchAtenLinear, TorchAtenAwqLinear and TorchFusedLinear. The dense-dequant path holds no derived state, so eval() lets the next forward choose the fused layout again instead of pinning the module to full weight dequantization for the rest of the process. Entering training still calls restore_fused_train_state() unchanged.
Family sweep (grep -n "LinearMode.TRAIN" gptqmodel/nn_modules/qlinear/*.py): TorchFusedAwqLinear was the only remaining one-way transition; the AVX512 siblings already reset on any mode change and the other three carry #4949, so no further kernel needed a change.
New tests/test_awq_torch_fused_mode_5018.py parametrizes all six int4pack kernels and adds an end-to-end node that compares the recovered inference_mode forward bitwise (torch.equal) against a fresh eval() module, plus a node pinning that the training forward still takes the dense path. Red on unmodified main @ 0ff0c0ebc (3 failed, 4 passed, 2 skipped — the AVX512 nodes skip on this non-AVX512-BF16 host) -> 7 passed, 2 skipped with the fix. Neighbouring suites after merging main (test_cpu_int4_snapshot_5013.py, test_cpu_kernel_optimize.py, test_hf_awq_repair_train_mode_4907.py, test_train_mode_atomicity.py, test_torch_fused_asym_qzeros.py, test_inference_fp16_overflow.py, kernels/test_awq_cpu_fused_post_init.py, kernels/test_awq_runtime_dtype_storage.py, kernels/test_awq.py, kernels/test_kernel_compile_levels_awq.py): 72 passed, 41 skipped. All 9 CI checks pass, and the new file runs in the AWQ CPU unit lane (its path filter now includes torch_fused_awq.py).
Activity
Qubitium commentedon Nov 17, 2026
Agent claim:
agent-root-5018is working on this issue now.fix(awq): clear the int4pack training latch in TorchFusedAwqLinear (#…
Qubitium commentedon Nov 18, 2026
Agent release:
agent-root-5018finished this issue. Fix: #5036, squash-merged as84ab448e9.TorchFusedAwqLinear.train()now clears the latchedLinearMode.TRAINwhen the module leaves training mode, mirroring the #4949 rule already present inTorchAtenLinear,TorchAtenAwqLinearandTorchFusedLinear. The dense-dequant path holds no derived state, soeval()lets the next forward choose the fused layout again instead of pinning the module to full weight dequantization for the rest of the process. Entering training still callsrestore_fused_train_state()unchanged.Family sweep (
grep -n "LinearMode.TRAIN" gptqmodel/nn_modules/qlinear/*.py):TorchFusedAwqLinearwas the only remaining one-way transition; the AVX512 siblings already reset on any mode change and the other three carry #4949, so no further kernel needed a change.New
tests/test_awq_torch_fused_mode_5018.pyparametrizes all six int4pack kernels and adds an end-to-end node that compares the recoveredinference_modeforward bitwise (torch.equal) against a fresheval()module, plus a node pinning that the training forward still takes the dense path. Red on unmodifiedmain@0ff0c0ebc(3 failed, 4 passed, 2 skipped — the AVX512 nodes skip on this non-AVX512-BF16 host) -> 7 passed, 2 skipped with the fix. Neighbouring suites after merging main (test_cpu_int4_snapshot_5013.py,test_cpu_kernel_optimize.py,test_hf_awq_repair_train_mode_4907.py,test_train_mode_atomicity.py,test_torch_fused_asym_qzeros.py,test_inference_fp16_overflow.py,kernels/test_awq_cpu_fused_post_init.py,kernels/test_awq_runtime_dtype_storage.py,kernels/test_awq.py,kernels/test_kernel_compile_levels_awq.py): 72 passed, 41 skipped. All 9 CI checks pass, and the new file runs in the AWQ CPUunitlane (its path filter now includestorch_fused_awq.py).