Repository navigation
Conversation
`gptqmodel/nn_modules/exllamav3.py` receives 37 changed lines in this PR but had no test coverage: `test_exllamav3_torch_padding.py` only exercised `ExllamaV3TorchLinear`. The native module is the one that pads the bias to the stored width and slices `LinearEXL3` output back to `out_features`, so an unchecked regression there is silent wrong-shape/wrong-value output rather than a crash. Add forward coverage for logical widths 128/576/1056 with and without bias against the existing independent oracle, plus a fail-closed check that a bias already widened to the padded width is rejected. Both are verified to fail when the crop is removed. Gate on the module's own `SUPPORTS_DEVICES = [DEVICE.CUDA]` rather than `torch.cuda.is_available()`, which is also true on ROCm where this backend raises `NotImplementedError` by design.
c0daaad to
3c460b7
Compare
Qubitium
left a comment
There was a problem hiding this comment.
Review
Fetched main at eb433e86 (includes #3582) and rebased layer 5 onto it. PR is now
MERGEABLE, changedFiles: 3 (was 9), diff is exactly this layer:
exllamav3.py +37, exllamav3_torch.py +32/-11, test +208. One commit pushed
(3c460b7b) closing a coverage gap.
The fix is real, and worse than the PR describes
I reproduced the pre-PR state by swapping only exllamav3_torch.py back to
c0daaad0~1 and re-running against the PR's own independent oracle:
outputs=128 ok max_abs=2.8e-09
outputs=576 ValueError: EXL3 expects out_features to be divisible by 128, got 576.
outputs=1056 ValueError: EXL3 expects out_features to be divisible by 128, got 1056.
So on the Torch backend this was a hard failure, not a silent drift: any EXL3
linear whose out_features was not already 128-aligned raised on every forward.
The PR body frames this as preserving logical outputs over padded storage; the
practical effect is that 576/1056-wide modules did not run at all on
EXL3_TORCH. Worth stating that plainly in the changelog.
Post-PR, all shapes are correct against the oracle, and the padding model is
sound: _apply_hadamard_right is block-local over 128 columns, so cropping after
the complete block is equivalent to cropping the transform — the padded channels
have to participate in the Hadamard and then be discarded, which is what the code
does.
Verification
The PR reported 63 passed, 36 skipped, with the CUDA cases skipped. That host had
no admitted GPU; this one does, so the skips were not actually a limitation of
the code:
CUDA host: 107 passed (63 CPU + 36 CUDA + 8 new native)
ROCm host: 99 passed, 8 skipped (native EXL3 is CUDA-only by declaration)
ruff check tests/ gptqmodel/... clean
Coverage gap I closed
gptqmodel/nn_modules/exllamav3.py gets 37 changed lines and had no test
coverage — test_exllamav3_torch_padding.py only exercises
ExllamaV3TorchLinear. That module is the one that pads the bias to the stored
width and slices LinearEXL3 output back to out_features; a regression there
returns wrong-shape or wrong-value output rather than raising.
3c460b7b adds:
- forward coverage for logical widths 128/576/1056, bias on/off, against the
existing oracle; - a fail-closed check that a bias already widened to the padded width is rejected.
I verified they are not vacuous: removing the [..., :self.out_features] crop
fails 4 of them.
The native backend declares SUPPORTS_DEVICES = [DEVICE.CUDA], so the gate uses
that declaration rather than torch.cuda.is_available(), which is also true under
ROCm where it raises NotImplementedError by design. Getting this wrong is easy —
my first version of the tests failed 8/8 on ROCm for exactly that reason.
Observations (non-blocking)
_stored_featuresis duplicated with divergent rules. The Torch copy
requirestrellis.dtype == torch.int16, an exact packing width, and rejects
missingsuh/svh; the native copy accepts any dtype, allowsoutputs == out_featuresas well as the padded width, and tolerates missing scales. That is
deliberate-looking (the native path relies onLinearEXL3for its own
validation) but the two will drift. A shared helper with an explicit strictness
flag, or a comment at each explaining why the rule differs, would help._apply(self, fn, recurse=True)is needed fornn.Module._applyin current
Torch and matches other modules in the repo (qlinear/__init__.py,
fp8.py), so no objection — just noting it is an unrelated signature change
riding along in this commit.forward()in the native module always callsx.half(), so FP32/BF16 callers
are downcast before the kernel and upcast after. That is pre-existing and not
touched here, but it interacts with the "preserve the activation dtype"
language in the summary: the dtype is preserved on the output, the
computation is FP16. The Torch backend honours the activation dtype properly
(_forward_eagerkeeps FP32); the two backends therefore differ numerically.
Fine, but the summary reads as though they do the same thing.
The new `_stored_features` guard required the trellis word count to be in `range(16, 129, 16)`, i.e. at most 8 bits. EXL3 packs `bits` 16-bit words, so a 16-bit checkpoint legitimately stores 256 words. Every valid 10/12/16-bit module was rejected with "invalid trellis geometry or dtype", which broke `tests/test_exllamav3_cpu.py` (8 failures) — those tests build 10/12/16-bit modules and passed on `main` before this layer. Validate the actual invariant instead: a positive multiple of 16. The bit depth is already derived from the same dimension by `_bits_per_weight()`. Adds coverage for every supported width (2..16 bits) plus non-word-aligned widths, and the bit-width cases fail against the original guard.
`_ensure_inner` hands `LinearEXL3` a *widened copy* of `bias` whenever `out_features` is padded to a 128 multiple. The copy is frozen when the inner module is built, and `_current_signature` only tracked `_EXL3_BUFFER_NAMES` via `data_ptr`, which an in-place write does not change. So on any non-128-aligned width (576, 1056, ...) a later `bias.add_` — adapter merge, calibration, scale folding — was silently ignored, while 128-aligned widths worked because the kernel aliased the live tensor. Include `Tensor._version` for the bias in the cache signature. It bumps on every in-place mutation, so the padded copy is rebuilt exactly when the source changed and never otherwise (verified: 0 rebuilds across 20 steady-state forwards at both 128 and 576). Adds a regression test across 128/576/1056 that asserts an in-place bias delta reaches the output; it fails on the padded widths before this change.
Full validation: two regressions found and fixedContinuing past the first review, I ran the layer against a broader EXL3 sweep and Regression 1 — every 10/12/16-bit checkpoint was rejected
if (... or trellis.shape[-1] not in range(16, 129, 16)):
raise ValueError(f"EXL3 module `{self.name}` has invalid trellis geometry or dtype")EXL3 packs This is a hard failure, not drift, and it is a regression against Fixed in Regression 2 — padded bias became frozen
So on 576/1056 widths a Fixed in Both have regression tests that fail before the fix. The bias test is Full resultsBroad EXL3 sweep (
Additional coverage added
Still not validatedEnd-to-end EXL3 model quality on a real checkpoint (this is all synthetic fixtures), |
Summary
Validate stored EXL3 geometry separately from logical linear dimensions. Complete each stored Hadamard block before cropping logical outputs, preserve padded bias handling and the activation dtype, and retain upstream chunked Torch decode. Cover output widths 128, 576, and 1056, including a chunk boundary.
Stack
Layer 5/36 of a dependency-ordered fork extraction. Depends on #3582. Review only this layer.
GitHub requires this cross-fork PR to target upstream
main, so its Files changed tab includes earlier stack layers. After the predecessor lands, rebase this branch and retarget the next layer; do not merge later layers out of order. No predecessor is merged automatically.Tests
63 passed, 36 CUDA cases skipped. Used Python 3.12, Torch 2.14.1, Transformers 5.19.0. No model quantization, GPU work, downloads, or heavyweight model validation. Unit fixtures are small and CPU execution is constrained to one math thread.
Review and remaining validation
This layer and its dependency diff were reviewed for scope, existing extension points, and compatibility with the resolved fork snapshot. New focused regression coverage is included. Kept as a draft for maintainer review; hardware paths and end-to-end model behavior have not been revalidated in this session. No speed claim. Original integration/history is preserved in tpurtell#3.
Small CPU oracle matrix: input shape
(1,33,128), logical outputs 128/576/1056, bias on/off; FP16, BF16 and FP32 independently preserve input dtype. Independent packed decode/Hadamard reconstruction supplies the reference. All comparisons usertol=atol=2e-3or tighter.The visible columns include mandatory activation-dtype output rounding. No model-scale or GPU claims. The 36 CUDA cases remain skipped and require admitted hardware before readiness.