Skip to content

fix(exl3): reconstruct through the portable kernel when the trellis is off CUDA (#4789) - #4835

Merged
Qubitium merged 2 commits into
mainfrom
fix/issue-4789
Nov 17, 2026
Merged

Qubitium merged 2 commits into
mainfrom
fix/issue-4789

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Fixes #4789.

After quantize() the packed layers stay on CPU (default offload_to_disk=True,
and also with it disabled), so the first in-session forward hit
ExllamaV3Linear._ensure_inner -> validate_device(cpu) and raised
NotImplementedError: EXL3_EXLLAMA_V3 inference requires NVIDIA CUDA. Only FP16
failed; BF16 off CUDA already routed to _ensure_torch_inner.

Change

ExllamaV3Linear.forward now reconstructs through the portable kernel whenever
its materialized trellis is not on CUDA (_needs_torch_fallback()), reusing the
existing _ensure_torch_inner path. An absent or meta trellis keeps the native
path and its existing error. CUDA models keep _ensure_inner (including the
BF16 fast path).

The class is deliberately left alone instead of switching to
ExllamaV3TorchLinear in place:

  • ExllamaV3Linear is not a BaseQuantLinear, so rehome_quantized_kernel
    never collects it, and select_quant_linear has no EXL3 entry
    (Unsupported quantization method: METHOD.EXL3), so the suggested selector
    route needs new special cases in three places.
  • the checkpoint writer keys the EXL3 module schema on
    type(module) is ExllamaV3Linear (looper/checkpoint_modules.py), so an
    in-place switch would change what save() writes.
  • ExllamaV3TorchLinear.forward reads _compiled_forward, which only
    __init__ sets, so a raw __class__ swap is not attribute-complete.

validate_device now names the device the module is on and tells the caller to
move the model to CUDA, instead of claiming the host lacks NVIDIA CUDA.

Tests

New tests/test_exl3_in_session_fp16_4789.py (11 tests): fp16 and bf16 module
and two-projection decoder-stack forwards match the reloaded EXL3_TORCH
checkpoint bit-exactly (rtol=0, atol=0); the in-session forward leaves
packed_module_config (the saved EXL3 schema) unchanged; the new device message
and the CUDA/meta paths are pinned.

pytest tests/test_exl3_in_session_fp16_4789.py tests/test_quantize_in_session_4381.py \
       tests/test_rehome_cpu_fallback_pairs.py tests/test_awq_gemv_insession_4554.py \
       tests/test_exllamav3_cpu.py -> 94 passed, 4 skipped

Red on parent: 8 failed, 2 passed — fp16 forward/decoder/schema/message cases
fail with the exact reported NotImplementedError; the bf16 controls pass.

ruff: clean.

…s off CUDA (#4789)

After `quantize()` the packed layers stay on CPU (with the default
`offload_to_disk=True` and with it disabled), so the first in-session forward
hit `ExllamaV3Linear._ensure_inner` -> `validate_device(cpu)` and raised
`NotImplementedError: EXL3_EXLLAMA_V3 inference requires NVIDIA CUDA`. Only
FP16 failed because BF16 off CUDA already routed to `_ensure_torch_inner`.

`ExllamaV3Linear.forward` now reconstructs through the portable kernel whenever
its materialized trellis is not on CUDA, reusing the existing
`_ensure_torch_inner` path. The class is deliberately left alone instead of
switching it to `ExllamaV3TorchLinear` in place:

* `ExllamaV3Linear` is not a `BaseQuantLinear`, so `rehome_quantized_kernel`
  never collects it, and `select_quant_linear` has no EXL3 entry
  (`Unsupported quantization method: METHOD.EXL3`), so the suggested selector
  would need new special cases in the rehome machinery.
* the checkpoint writer keys the EXL3 module schema on
  `type(module) is ExllamaV3Linear` (`looper/checkpoint_modules.py`), so an
  in-place class switch would change what `save()` writes; this fix keeps the
  saved native EXL3 layout byte-identical.
* `ExllamaV3TorchLinear.forward` reads `_compiled_forward`, which only
  `__init__` sets, so a raw `__class__` swap is not attribute-complete.

CUDA models keep `_ensure_inner` (including the BF16 fast path), and an absent
or meta trellis keeps its existing error. `validate_device` now names the
device the module is on and tells the caller to move the model to CUDA instead
of claiming the host lacks NVIDIA CUDA.

Tests: fp16/bf16 module and decoder-stack forwards match the reloaded
EXL3_TORCH checkpoint exactly (atol=0); the in-session forward leaves the
saved EXL3 module schema unchanged; the new device message and the preserved
CUDA/meta paths are pinned.
@Qubitium
Qubitium merged commit fa91047 into main Nov 17, 2026
6 checks passed
@Qubitium
Qubitium deleted the fix/issue-4789 branch November 17, 2026 16:31
sLaffey pushed a commit to sLaffey/GPTQModel that referenced this pull request Nov 18, 2026
… the native stub (ModelCloud#4895) (ModelCloud#4924)

tests/test_exllamav3_inner_handle_4793.py built its trellis on CPU. Since
ModelCloud#4835 (fa91047), forward() sends every non-CUDA trellis to
_ensure_torch_inner(), so the burst never reached _ensure_inner() and the
stubbed native handle was never built. It failed on the fake 2x2x16 trellis
with "storage differs from logical dimensions or 128-channel padding" instead
of guarding the ModelCloud#4793 handle race.

Build the trellis on CUDA, where _needs_torch_fallback() is false, and skip
the file without CUDA so a CPU-only host does not silently test the portable
path. Assert that the stubbed LinearEXL3 served every forward and that no
torch inner was built, so a future routing change fails loudly instead of
quietly losing the ModelCloud#4793 regression guard.

Red on origin/main: 2 failed. Green: 2 passed.
sLaffey pushed a commit to sLaffey/GPTQModel that referenced this pull request Nov 18, 2026
…lCloud#4978)

Seven tests went red because their doubles/oracles predate library changes
that behave as intended. This is test-only; no product code changes.

- test_fusion_kernel_backends: gc.collect() before the weakref check; ModelCloud#4871
  leaves transient Dynamo trace garbage that keeps the pre-fusion weight
  alive. The refs are still asserted dead afterwards.
- test_failed_run_fence_4595: del qmodel + gc.collect() so ModelCloud#4829's finalizer
  runs before the no-leak assertion; a late finalizer must not recreate the
  released run dir.
- test_exl3_projection_resume: add _release_deferred_hessian_sources() to the
  _Capture double (ModelCloud#4837).
- test_kernel_audit_regressions: stub _needs_torch_fallback=lambda: False on
  the SimpleNamespace self (ModelCloud#4835).
- test_moe_resave_preserves_experts_4589: accept the earlier RuntimeError
  "does not provide tensors" refusal (ModelCloud#4810); still assert no safetensors.
- test_positional_mask_capture_4660: build the native oracle with the same
  mask-derived position_ids the capture uses (ModelCloud#4930).
- test_qqq_kernel_memory_4387: snapshot the oracle weight/s_channel before
  the first forward, which may drop the checkpoint layout (ModelCloud#4856).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant