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: TorchLinear/AWQ torch kernels recompute scales_fit_dtype range reductions on every .to()/train()/eval() (slow load, cpu>accel decode) #6605
TorchLinear (and the TORCH-derived TRITON / SINQ kernels) and every AwqDecodeRangeMixin kernel (AWQ_TORCH, fused/aten/AVX512 AWQ) recompute the range-safe decode answers eagerly in clear_weight_cache(). That runs 4 full-tensor scale reductions per module (decode_dtype_for_scales + scales_fit_dtype for FP16/BF16/FP32), each ending in bool(...all()) (a host sync on an accelerator, or a small CPU reduction that oversubscribes OpenMP on a busy host). And clear_weight_cache() runs on every_apply (.to(), .cuda(), .cpu()), every train()/eval(), post_init() and state-dict load.
The scales do not change in any of these steps. A device move keeps their values (the forward-dtype contract K2 allows device moves only for "the same weights"). train()/eval() and post_init() keep the same tensor at the same version. So the answers are recomputed for unchanged inputs.
Where the 16 calls per module come from during load (4 refreshes × 4 calls): create_quant_module.to(), the dispatch .to(cuda), post_init(), and model.eval(). Only the dispatch move sees new values.
Whole-model cpu>accel offload (#6592/#6594) moves every layer to the accelerator and back on each forward, so every decoded token pays 8 reductions per linear plus a sync.
RTN quantize (Qwen2.5-0.5B-Instruct, default disk offload) also pays this on the post-loop moves/eval() (1848 calls), but that is a minor part of its regression versus pre-#6473 (see the note below).
Expected
Compute the range answers once per distinct scale content. A device move or train()/eval() must reuse them, while keeping the selected decode dtype bit-identical. The answers still have to be precomputed eagerly for compiled / CUDA-graph forwards.
Note on RTN
cProfile of RTN quantize on main (16 threads) shows most of the post-#6473 slowdown in mmap.flush inside file_back_module/offload_to_disk (9.0 s of 13.8 s; 168 calls), not in scales_fit_dtype (0.16 s). That is tracked separately.
Correction on the RTN note: no separate issue was filed. The RTN quantize regression versus pre-#6473 (Qwen2.5-0.5B, 16 threads: 3.6 s before #6473, 11.7-29.6 s on main) is mostly synchronous mmap.flush() + fsync in weight_loader/filebacked.pywrite_safetensors, reached from file_back_module(evict=True) during offload_to_disk (9.0 s of 13.8 s in cProfile). Eviction needs clean pages, so this looks like a design trade-off of the disk-offload default rather than this issue. #6607 removes the scales_fit_dtype share (1848 → 168 reductions; 11.1 s → 1.2 s uncapped).
Activity
Qubitium commentedon Dec 1, 2026
Correction on the RTN note: no separate issue was filed. The RTN quantize regression versus pre-#6473 (Qwen2.5-0.5B, 16 threads: 3.6 s before #6473, 11.7-29.6 s on main) is mostly synchronous
mmap.flush()+fsyncinweight_loader/filebacked.pywrite_safetensors, reached fromfile_back_module(evict=True)duringoffload_to_disk(9.0 s of 13.8 s in cProfile). Eviction needs clean pages, so this looks like a design trade-off of the disk-offload default rather than this issue. #6607 removes the scales_fit_dtype share (1848 → 168 reductions; 11.1 s → 1.2 s uncapped).perf(qlinear): compute scale range answers once per scale content (#6605