Skip to content

fix(loader,gptq,qqq,exl3): complete the #4400 memory fallbacks - #4442

Merged
Qubitium merged 2 commits into
mainfrom
fix/moe-reload-oom-4400
Nov 16, 2026
Merged

Qubitium merged 2 commits into
mainfrom
fix/moe-reload-oom-4400

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Summary

The remaining three findings of #4400 (item 1, shared-input Hessian adoption release, shipped in #4430):

  1. Reloading a quantized MoE whose experts defuser splits at runtime materialized full bf16 per-expert weights on the host (OLMoE-1B-7B 4-bit: peak RssAnon 12.17 GiB for a 3.66 GiB checkpoint, 3.3x).
  2. QQQ had no OOM->CPU fallback around its Cholesky/inverse sequence, and EXL3 block_ldl missed solver allocation failures (HIPSOLVER_STATUS_ALLOC_FAILED).
  3. GPTQ's CPU fallback stopped at the Hessian inverse: the W-sized allocations (Losses, Q) and the block update still ran on the failed device and aborted the run.

Addresses items 2-4 of #4400.

What Changed

  • models/loader.py: _meta_fused_expert_params() parks the fused 3-D gate_up_proj/gate_proj/up_proj/down_proj (and fused biases) on meta before _convert_model_with_defuser(..., cleanup_original=True) on the quantized-load path; _materialize_meta_expert_linears() then to_emptys fully-meta split linears so make_quant can build kernels. The legacy path is kept for non-quantized loads and for differently-named fused experts.
  • quantization/qqq.py: Hessian inverse factored into _inverse_hessian, wrapped in _is_memory_allocation_failure + CPU retry.
  • exllamav3/.../exl3_lib/quantize.py: block_ldl classifies allocation failures with _is_memory_allocation_failure and retries the diagonal-block inverse on CPU.
  • quantization/gptq.py: the post-inverse block pass (Losses/Q + block update) is wrapped in the same CPU retry; the retry resets partially-appended scale/zero entries and the block index first. git diff -w is 38 lines.
  • Docs: docs/quantized-moe-reload-meta-shell.md (lifecycle + OOM-fallback Mermaid diagrams, README link). New tests: tests/test_moe_reload_meta_4400.py, tests/test_moe_reload_meta_e2e_4400.py, tests/test_qqq_exl3_oom_fallback_4400.py, tests/test_gptq_post_inverse_fallback_4400.py.

Tests

PYTHONPATH=/root/work-4400b /root/venv/bin/python -m pytest \
  tests/test_moe_reload_meta_4400.py tests/test_moe_reload_meta_e2e_4400.py \
  tests/test_qqq_exl3_oom_fallback_4400.py tests/test_gptq_post_inverse_fallback_4400.py -q
9 passed

PYTHONPATH=/root/work-4400b /root/venv/bin/python -m pytest \
  tests/test_gptq_hessian_alloc_fallback_4350.py tests/test_gptq_cuda.py \
  tests/test_qqq_kernel_memory_4387.py tests/test_loader.py \
  tests/test_loader_offload_staging_4385.py -q
46 passed, 148 skipped (fused/JIT kernels unavailable without CUDA_HOME)

PYTHONPATH=/root/work-4400b /root/venv/bin/python -m pytest \
  tests/test_awq_loader_dtype.py tests/test_checkpoint_interop_4053.py -q
36 passed, 1 skipped
/root/venv/bin/python -m ruff check <4 source + 4 test files>
All checks passed!

Measured (synthetic fused-MoE shell, 8 layers x 8 experts, bf16, ~3.2 GB expert weights): peak RssAnon 8830.5 MiB -> 7747.1 MiB (shell baseline 7726.1 MiB), i.e. the fix adds ~21 MiB over the shell instead of 1.1-1.9 GiB; 4-layer variant 5558.7 -> 4264.1 MiB. Tiny real OLMoE 4-bit reload 1138.1 -> 1083.1 MiB with state_dict and logits torch.equal. QQQ retry: packed Q/scale bitwise equal to an unconstrained CPU run. GPTQ block-pass retry: Q bitwise equal. EXL3 block_ldl: L matches the CPU run at rtol/atol 1e-6.

Fail-before on pristine main: all four item-2 tests fail (helpers absent) and the fallback assertions fail while the non-memory guardrails pass.

Not executed: the real allenai/OLMoE-1B-7B-0924 reload (13.9 GB download + 7B quantization) — synthetic shell plus a tiny real OLMoE checkpoint used instead; fused GPTQ CUDA block-update and Marlin/Triton/EXL3 kernels (no CUDA_HOME).

Logic Flow Documentation

docs/quantized-moe-reload-meta-shell.md documents the reload lifecycle (including the legacy and partially-meta fallbacks) and the OOM-fallback decision path with Mermaid diagrams using the real symbol names; linked from README.md.

Review Requirements

  • Reviewed; no env-var behavior switches.
  • The meta shell is only used on the quantized-load path; quantization still needs real fused values.
  • Differently-named fused experts keep the legacy path (no regression).

Item 2: on the quantized-load path, park fused 3-D expert projections on
meta before Defuser's tensor defusion and restore real (uninitialized)
storage on the split linears afterwards. Defuser then never materializes
one dense bf16 Linear per expert just to have make_quant replace it.

Item 3: QQQ and EXL3 block_ldl now classify solver allocation failures
with GPTQ's _is_memory_allocation_failure and finish the Hessian inverse
on the host instead of aborting. EXL3 also retries the diagonal-block
inverse.

Item 4: GPTQ retries the post-inverse block pass (Losses/Q and the
W-sized block update) on CPU when the allocation fails on the device.

Tests cover the meta expert shell (structural + end-to-end bitwise reload),
the QQQ/EXL3 CPU retries (bitwise/close against an unconstrained CPU run),
and the GPTQ block-pass retry (bitwise against a CPU run) plus its
non-memory guardrail.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant