Skip to content

fix(exl3): keep Torch fallback out of checkpoint state - #3738

Merged
Qubitium merged 1 commit into
mainfrom
codex/fix-exl3-torch-state-dict
Nov 9, 2026
Merged

Qubitium merged 1 commit into
mainfrom
codex/fix-exl3-torch-state-dict

Conversation

@Qubitium

@Qubitium Qubitium commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator

Summary

ExllamaV3Linear registered its BF16/FP32 Torch fallback as an nn.Module child. The first wide-input forward added _torch_inner.* packed-buffer keys to state_dict(), so a checkpoint saved before forward failed load_state_dict(..., strict=True) afterward.

_ensure_torch_inner() now stores the helper as an unregistered runtime object with object.__setattr__. It still borrows the parent's packed buffers and is rebuilt when the signature changes. _apply() and clear_weight_cache() discard it before a move or explicit reset. No dense or expanded weight cache is introduced.

Before and after

Mechanism Before After
Helper ownership self._torch_inner = ExllamaV3TorchLinear(...) registered a child (gptqmodel/nn_modules/exllamav3.py:272 before this PR). object.__setattr__ keeps the runtime helper out of _modules (gptqmodel/nn_modules/exllamav3.py:272-285).
Checkpoint First BF16/FP32 forward added _torch_inner.* keys; strict reload of a pre-forward checkpoint failed. Checkpoint keys stay stable before and after forward, including load_state_dict(assign=True).
Moves and cache clearing The fallback appeared in module traversal despite borrowing parent buffers. _apply() and clear_weight_cache() drop it; the next wide-input forward rebuilds from current packed buffers.

Shipped flow

flowchart TD
    A["ExllamaV3Linear.forward"] --> B{"Input dtype is FP16?"}
    B -- Yes --> C["_ensure_inner: native handle"]
    B -- No --> D["_ensure_torch_inner"]
    D --> E["_current_signature"]
    E --> F{"Matches _torch_inner_signature?"}
    F -- Yes --> G["Reuse unregistered ExllamaV3TorchLinear"]
    F -- No --> H["Build helper with parent packed buffers"]
    H --> I["object.__setattr__: keep helper out of _modules"]
    I --> G
    G --> J["ExllamaV3TorchLinear.forward"]
    J --> K["_forward_chunked: decode bounded output tiles"]
    K --> L{"Packed storage valid and materialized?"}
    L -- No --> X["ValueError or RuntimeError"]
    L -- Yes --> M["Return output; state_dict has parent keys only"]
    N["load_state_dict: copy or assign"] --> D
    O["_apply or clear_weight_cache"] --> P["_drop_inner"]
    P --> D
    classDef failure fill:#ffe8e8,stroke:#b30000,color:#111;
    class X failure;
Loading

Reference: EXL3 inference buffer lifecycle, linked from README.

Validation

  • On origin/main at 671ba828, the new CPU regression failed for both BF16 and FP32: a wide forward added _torch_inner.* keys. A separate direct reproduction showed strict reload missing _torch_inner.trellis, _torch_inner.suh, and _torch_inner.svh.
  • EXL3 lifecycle suites: 85 passed, 53 skipped. Broader tests/test_exllamav3.py: 17 passed, 2 skipped. After rebase onto 520809c8, focused lifecycle tests: 4 passed, 1 skipped.
  • The CPU regression uses a 128-input/576-logical-output packed fixture with an independent Torch bitstream/FP32 oracle (rtol=atol=2e-3). Measured maximum absolute error: BF16 6.026e-5, FP32 5.588e-9.
  • Checkpoint storage stays at 23,168 bytes after repeated forwards; an intentional model-wide FP32 bias cast makes it 24,320 bytes. The helper's buffers alias the parent. A decoded FP32 output chunk is bounded by 128 × 512 × 4 = 262,144 bytes for this fixture; overall temporary peak was not measured.
  • CPU single-thread forward latency, 3 warmups then median of 10 runs (no baseline comparison): BF16 1.78 ms, FP32 1.77 ms.
  • Changed-file Ruff and git diff --check passed. CUDA/ROCm execution was unavailable on this host; the native FP16 path is unchanged.

No backward-compatibility shim was added; hf_ APIs are untouched. This is a separate follow-up to #3732.

@Qubitium
Qubitium force-pushed the codex/fix-exl3-torch-state-dict branch from ddc600b to 6078a2c Compare November 9, 2026 19:19
@Qubitium
Qubitium merged commit 65c7d6c into main Nov 9, 2026
6 checks passed
@Qubitium
Qubitium deleted the codex/fix-exl3-torch-state-dict branch November 9, 2026 19:23
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