Repository navigation
Description
Audit of main @ 5065bf1 (first measured at 27c6b7b), RTX 4090, plus R9700 for item 2. All numbers are per-process.
1. CUDA default allocator config makes reserved VRAM grow per layer during GPTQ: 4.4× the allocated peak, and ~45 GiB reserved for an 8B model (high; CUDA sibling of #4313)
gptqmodel/_alloc_conf.py:35 sets the CUDA default PYTORCH_ALLOC_CONF to expandable_segments:True,max_split_size_mb:256,garbage_collection_threshold:0.7. With max_split_size_mb capping block splitting on top of expandable segments, GPTQ's per-layer Hessian/workspace pattern keeps mapping new pages instead of reusing them. #4313's fix covered only ROCm/AWQ.
Llama-3.2-1B GPTQ 4-bit (same calibration), peak allocated 1.23 GiB in every case:
default conf peak reserved 5.40 GiB (end of quantize: 5.40 GiB still reserved)
expandable_segments:True only peak reserved 1.67 GiB
no expandable segments 2.55 GiB
default conf, cuda_workers=1 2.16 GiB
Llama-3.1-8B bf16, n=32, default conf, 48 GB card:
peak allocated 5.41 GiB, peak reserved 45.46 GiB (reserved per layer 0.39 -> 45 GiB while active stays ~0.12 GiB),
1 alloc retry, 15.6 GiB still reserved after quantize() returns
capped at 14.5 GiB: default conf hits the cap (14.21 GiB), 8 alloc retries, 49.9 s; expandable-only 5.27 GiB, 0 retries, 44.1 s
On a shared or smaller card, this reservation starves other processes and causes alloc retries and slowdowns, even though the real working set is a few GiB. Fix: drop max_split_size_mb from the CUDA default, which is what is fragmenting expandable segments here, and call torch.cuda.empty_cache() when quantize() ends. A test asserting that peak reserved stays within ~1.5× peak allocated on a small model would catch regressions.
2. AllSpark keeps the weight in both checkpoint and kernel layout, so 8-bit W8A16 uses as much VRAM as fp16 (low-medium; dedup)
nn_modules/qlinear/allspark.py:279-280 (_repack) creates qweight_packed/scales_packed as non-persistent buffers, while the checkpoint qweight (int32) and scales stay resident on the GPU, used only as the export source and cache key. The module docstring (lines 14-21) describes this as intentional for export, but the memory cost isn't documented. allspark_awq.py:327-329 follows the same pattern and adds zeros_packed (code read only).
Qwen2.5-0.5B GPTQ 8-bit g=-1, BACKEND.ALLSPARK (R9700, same at 27c6b7b and 5065bf1):
qweight int32 341.25 MiB + qweight_packed uint8 341.25 MiB + scales 0.58 + scales_packed 0.58
quantized modules 683.7 MiB vs dense fp16 weights 682.5 MiB; whole model 944.0 MiB vs 603.5 MiB under AUTO (TorchLinear)
Saving: 341.8 MiB here (50% of the quantized-module memory), about 6.5 GiB on an 8B model. Fix: after the repack, move qweight/scales to CPU (pinned) or drop them. Rebuild them on demand for state_dict()/save (un-repacking is a deterministic inverse), and key the cache on a version counter instead of the GPU tensor. tests/test_allspark_linear.py::test_linear_bias_does_not_expand_persistent_storage checks only persistent buffers, not resident bytes.
3. TorchLinear on CPU with fp16 activations runs an fp16 GEMM that is ~120× slower than computing in fp32 (low-medium; perf)
nn_modules/qlinear/torch.py _forward_eager (the CPU fp16 addmm branch and the matmul_fp32_reduce fallthrough; _numerics.py:18 _WIDE_REDUCE_DEVICES = ("cuda",)). On CPUs without fp16 GEMM hardware (this host has AVX512-BF16 but no AVX512-FP16/AMX-FP16), PyTorch's fp16 matmul/addmm/linear is extremely slow:
(511 x 896) @ (896 x 4864): fp16 matmul 1970 ms | addmm 2004 ms | F.linear 1938 ms | fp32 upcast 16.4 ms
Qwen2.5-0.5B, one 512-token forward, TorchLinear on CPU fp16: 147.3 s, NLL 2.709939
x upcast to fp32 inside _forward_eager: 2.59 s, NLL 2.709915
This path is hit by explicit BACKEND.TORCH on CPU and by in-session use after quantize() (#4380). Fix: on CPU with fp16 inputs, compute x.float() against the dequantized fp32 weight and round once. That is also more accurate. Alternatively, gate the change on cpu_features lacking fp16 GEMM support.
4. Concurrent quantize() runs report each other's peak VRAM (low)
models/base.py:285-316 (_reset_peak_vram_stats / _peak_vram_gib) uses the process-global allocator counters, so two concurrent runs reset each other's peak. Quantizing Qwen2.5-0.5B and Llama-3.2-1B in two threads, both "Quantize summary" lines report 1.57 GiB, while Qwen's real peak is 0.448 GiB. Label the figure as process-wide, or skip the reset while another run is active.
Checked, clean
- [BUG] CUDA OOM during desc_act / act_group_aware Hessian permutation permutes W twice → scrambled weights #4168: desc_act/act_group_aware commit H and W together.
- [BUG] GPTQ Hessian-inverse CPU fallback only triggers on errors whose text contains "out of memory";
HIPSOLVER/CUSOLVER_STATUS_ALLOC_FAILEDaborts the whole run #4350: every GPTQ fallback gate uses_is_memory_allocation_failure. - [PERF] AUTO picks ExllamaV2 for bf16 asym 4-bit GPTQ; its bf16 path rebuilds a dense fp16 weight + fp32 copy on every forward (~10–20× slower, ~266 MiB scratch per 4096×11008 layer) #4213: AUTO picks TritonV2 for bf16 asym.
- [BUG]
GGUFCudaKernelkeeps an extra device copy of the quantized weight for each distinct batch size (up to 8 per layer) #4216: one shared ggml weight. - [BUG]
QQQLinearworkspace is zero-sized for out_features=64 → illegal memory access; undersized whenever N % 128 != 0 #4215: the workspace is correctly sized (~14 KiB per module). - [BUG] LazyTurtle converts
.bin/.ptcheckpoints into a full temp safetensors copy on everyload()and keeps it until interpreter exit #4205/[BUG] LazyTurtle.bin→ safetensors conversion still goes to the system TMPDIR and ignoresoffload_to_disk_path(incomplete fix of #4205) #4319: the conversion is ref-counted and finalized. - Allocation after
quantize(): allocated memory returns to ~0. 4 vs 1 CUDA workers give the same allocated peak; the only per-worker cost is fragmentation (3.42 vs 2.29 GiB reserved).
🤖 Generated with Claude Code
Activity
Qubitium commentedon Nov 16, 2026
Taking this. I'll investigate against current
main, add a targeted regression test, and open a PR. Will report back here if the claim turns out to be invalid or already fixed.Qubitium commentedon Nov 16, 2026
CUDA default now installs
expandable_segments:Trueonly (nomax_split_size_mb; inertgarbage_collection_thresholddropped), ROCm default unchanged for #4313: #4419fix: stop forcing max_split_size_mb on CUDA allocator config (#4389) (#…
fix(rocm): stop pinning max_split_size_mb in the allocator default (#…
Qubitium commentedon Nov 20, 2026
Item 2 here (AllSpark keeps both weight layouts resident) is still present at HEAD
85caf6c. The issue was closed by #4419, which only changed the allocator config.gptqmodel/nn_modules/qlinear/allspark.py:287-288:_repack()registersqweight_packed/scales_packedwhile the checkpointqweight/scalesstay on the GPU.forward()(lines 296-316) reads only the packed copies.gptqmodel/nn_modules/qlinear/allspark_awq.py:339-341: same pattern, pluszeros_packed.CPU validation with the repack op replaced by a stand-in that returns the same shapes as
utils/allspark.py:allspark_repack. Script:allspark_dual_residency.py, which constructsAllSparkLinear(K=4096, N=11008)and callspost_init(). Output:Result: W8A16 under AllSpark still uses the same weight VRAM as FP16, double what the format needs. Marlin's approach would fix this: replace
qweightin place, set a repacked flag, and fail closed in_save_to_state_dict(marlin.py:482,486-497). If export from a live module has to keep working,allspark_repackis a deterministic permutation, so the inverse could be computed on demand in_save_to_state_dict.Found by automated code audit (Claude Code).