Repository navigation
fix(exl3): keep Torch fallback out of checkpoint state - #3738
Merged
Merged
Conversation
Qubitium
force-pushed
the
codex/fix-exl3-torch-state-dict
branch
from
November 9, 2026 19:19
ddc600b to
6078a2c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ExllamaV3Linearregistered its BF16/FP32 Torch fallback as annn.Modulechild. The first wide-input forward added_torch_inner.*packed-buffer keys tostate_dict(), so a checkpoint saved before forward failedload_state_dict(..., strict=True)afterward._ensure_torch_inner()now stores the helper as an unregistered runtime object withobject.__setattr__. It still borrows the parent's packed buffers and is rebuilt when the signature changes._apply()andclear_weight_cache()discard it before a move or explicit reset. No dense or expanded weight cache is introduced.Before and after
self._torch_inner = ExllamaV3TorchLinear(...)registered a child (gptqmodel/nn_modules/exllamav3.py:272before this PR).object.__setattr__keeps the runtime helper out of_modules(gptqmodel/nn_modules/exllamav3.py:272-285)._torch_inner.*keys; strict reload of a pre-forward checkpoint failed.load_state_dict(assign=True)._apply()andclear_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;Reference: EXL3 inference buffer lifecycle, linked from README.
Validation
origin/mainat671ba828, 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.tests/test_exllamav3.py: 17 passed, 2 skipped. After rebase onto520809c8, focused lifecycle tests: 4 passed, 1 skipped.rtol=atol=2e-3). Measured maximum absolute error: BF166.026e-5, FP325.588e-9.128 × 512 × 4 = 262,144bytes for this fixture; overall temporary peak was not measured.git diff --checkpassed. 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.