Repository navigation
Description
Audit of main @ beb6db8 (first measured at 27c6b7b) on an R9700 (ROCm 10.1, 32 GB), with Llama-3.1-8B-Instruct, OLMoE-1B-7B, Qwen1.5-MoE-A2.7B and Phi-tiny-MoE. Items 1 and 2 are generic (not HIP-specific).
1. Shared-input Hessian adoption keeps three C² per leader/follower pair (−0.96 GiB / −20% peak on Qwen1.5-MoE, output bitwise unchanged) (medium)
adopt_hessian_from (quantization/gptq.py:1394-1441, called from looper/gptq_processor.py:516) makes the leader materialize early, into a new result_accum (materialize_global_hessian, :1335-1391). The leader's fp32 partial is then parked in _deferred_hessian_sources and released only at the leader's own quantize(), and the follower gets a private copy. All pairs adopt at the end of capture, so every pair holds leader H + leader partial + follower copy.
Qwen1.5-MoE-A2.7B (2-layer copy), GPTQ 4-bit, 128 samples; at the MoE subset start: live H 1.906 GiB + deferred partials 0.953 GiB
peak alloc peak reserved ckpt sha
baseline 4.668 GiB 5.514 GiB c32c5fae7e07aca6
release deferred sources after adoption (leader + follower)
3.711 GiB 4.627 GiB c32c5fae7e07aca6 (identical)
Fix:
- Release the leader's reduction sources once adoption is done.
- For a single same-device fp32 partial, adopt the partial as H (scale in place) instead of allocating zeros and adding.
- For another ~C² per pair, give the follower H copy-on-write (clone at its
quantize()).
This scales with expert count × hidden² (Qwen3-MoE, DeepSeek, any :in=-tagged MoE tree); on dense Llama-8B it's ~128 MiB. Untagged gate/up (OLMoE/Phi-MoE, #4041) currently build duplicate Hessians instead; tagging them today would cost more, not less, until this is fixed.
2. Reloading a quantized MoE whose experts defuser splits at runtime (OLMoE, Phi-tiny-MoE) materializes full bf16 per-expert weights on the host: peak RSS 3.3× the checkpoint (medium)
The quantized-load path builds a real CPU shell (models/loader.py:2615, from_config under suspend_hf_weight_init), then calls _convert_model_with_defuser(..., cleanup_original=True) (:2657). defuser's _unfuse_single_projection (moe_experts_interface.py:448-460, same in 0.0.31) runs .cpu().transpose().contiguous() on the uninitialized fused 3-D params, writing bf16 per-expert copies that QuantLinear replaces right afterwards. defuser skips params that are already on meta.
OLMoE-1B-7B RTN 4-bit ckpt (3.656 GiB): reload peak RssAnon 12.17 GiB (VmHWM 16.5) GPU 3.658 GiB
fused expert params moved to meta before defuser, defused linears to_empty(cpu) afterwards:
peak RssAnon 4.19 GiB (VmHWM 8.6) GPU 3.658 GiB, logits identical
Phi-tiny-MoE (ckpt 2.2 GiB): RssAnon 6.08 GiB (VmHWM 9.0); Qwen1.5-MoE (block replaced at construction): 1.51 GiB for 1.71 (clean)
Fix: on the quantized-load path, put fused expert params on meta before defuser (or build the shell on meta), then to_empty the defused linears.
3. #4359 (for #4350) only covers gptq.py: QQQ has no OOM→CPU fallback, and EXL3 block_ldl misses solver allocation failures (low-medium)
- QQQ (
quantization/qqq.py:817-850): any allocation failure in the Cholesky → inverse → Cholesky sequence re-raises unless the sample-count fallback applies. Under a 1.3 GiB per-process cap on Llama-3.2-1B:torch.OutOfMemoryError ... Tried to allocate 256.00 MiBatqqq.py:826(cholesky_inverse), and the run aborts. GPTQ under the same cap falls back to CPU and continues. - EXL3 (
exllamav3/.../exl3_lib/quantize.py:444-447): its handler only matchesOutOfMemoryError/ "CUDA|HIP out of memory". A realRuntimeError: hipsolver error: HIPSOLVER_STATUS_ALLOC_FAILED, when calling hipsolverDnCreate(handle)(injected with anLD_PRELOADhipMalloc-failure shim) propagates, even thoughgptq.py's_is_memory_allocation_failureclassifies it correctly. On a warm handle,potrfdoesn't allocate, so the exposure is the first solver call per worker thread.
Fix: reuse _is_memory_allocation_failure and the CPU retry in qqq.py and block_ldl.
4. GPTQ's CPU fallback stops at the Hessian inverse: the W-sized allocations and block update that follow still abort the run (low-medium)
After the fallback computes the inverse on CPU, gptq.py:2526-2527 (Losses = torch.zeros_like(W), Q = torch.zeros_like(W)) and the block update (W[:, i2:] -= Err1.matmul(Hinv[i1:i2, i2:])) run unprotected:
Llama-3.2-1B gptq4, 1.15 GiB per-process cap: 8x "CUDA OOM during act-group Hessian permutation ... falling back to CPU",
1x "... during Hessian inverse ... falling back to CPU", then
gptq.py:2527 _quantize_impl / W[:, i2:] -= Err1.matmul(Hinv[i1:i2, i2:])
torch.OutOfMemoryError: CUDA out of memory. Tried to allocate 32.00 MiB -> quantize() aborts
Fix: wrap the post-inverse allocations and block update in the same handler (retry the module on CPU), or allocate Q/Losses before the inverse. Otherwise the "finish on CPU instead of aborting" intent doesn't hold on shared GPUs.
Measurements (Llama-3.1-8B-Instruct, 128 C4 samples, bf16, defaults, ROCm)
| method | peak alloc / reserved | per-layer reserved | PPL (40 win) | reload GPU vs ckpt |
|---|---|---|---|---|
| GPTQ 4-bit | 4.17 / 8.10 GiB | flat | 9.69 | 5.339 = 5.339 GiB |
| AWQ 4-bit | 1.95 / 3.63 | flat (#4342 holds) | 9.79 | 5.335 = 5.335 |
| QQQ | 4.58 / 6.21 | flat | 9.96 | 10.565 vs 5.314 (reduce_buffer, #4387) |
The GPTQ peak is dominated by four down_proj C² fp32 buffers (784 MiB each): H after the GAR permutation (gptq.py:2456), L (:1916) and two temporaries in inverse_factor (:1936-1937). QQQ has the same pattern at qqq.py:825-826. Everything fits on 32 GB. Leftover EXL3 allocation after del is #4391.
Checked, clean
- fix(gptq): classify solver allocation failures for CPU fallback (#4350) #4359 on HIP classifies
HIPSOLVER_STATUS_ALLOC_FAILEDcorrectly, and GPTQ'so_projfallback completes. - GPTQ/QQQ/AWQ reserved stays flat per layer on ROCm (the [MEM] CUDA default alloc conf (expandable_segments + max_split_size_mb:256) grows reserved VRAM per layer during GPTQ (1B: 5.4 GiB reserved for 1.23 allocated; 8B: ~45 GiB), AllSpark keeps both weight layouts resident, CPU fp16 TorchLinear ~120x slow GEMM #4389 growth is CUDA-only).
- Reload GPU memory equals the packed checkpoint (±1%) for GPTQ, AWQ, OLMoE, Qwen-MoE and Phi-MoE.
- Routed inputs are not cached per expert; fused 3-D experts are not duplicated during quantize.
🤖 Generated with Claude Code
Activity
Qubitium commentedon Nov 16, 2026
Claimed by an AI agent: items 2-4 (MoE reload host materialization, QQQ/EXL3 OOM fallback, GPTQ post-inverse fallback). Item 1 is already merged via #4430.
fix(loader,gptq,qqq,exl3): complete the #4400 memory fallbacks (#4442)
Qubitium commentedon Nov 16, 2026
Re-checked at 489aed6 on an RTX 4090 with Qwen1.5-MoE-A2.7B (2-layer truncation, GPTQ 4-bit).
verified, and the quantized weights are bit-identical with dedup on or off.HessianConfig(dedup_shared_inputs=True)peaks at 3.452 GiB vs 3.388 GiB with it off; with a dynamic override, 3.462 vs 3.351 GiB.(AI-assisted review, round 13 at
489aed6)fix(qqq): honour damp_auto_increment in Hessian recovery (#5932)
test(moe): ship a tiny tokenizer with the #4400 reload fixture (#6556) (