Skip to content

fix(exl3): accept noncontiguous BF16 and FP32 activations - #3740

Merged
Qubitium merged 1 commit into
mainfrom
codex/fix-exl3-wide-noncontiguous
Nov 9, 2026
Merged

Qubitium merged 1 commit into
mainfrom
codex/fix-exl3-wide-noncontiguous

Conversation

@Qubitium

@Qubitium Qubitium commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Merged #3731 already sends BF16/FP32 inputs from ExllamaV3Linear.forward to the bounded Torch FP32 reconstruction path. Both native GEMM branches require FP16 inputs. This follow-up fixes the remaining failure for noncontiguous wide activations: _forward_eager used view to flatten leading dimensions, so transposed batches raised before inference.

  • Use reshape for the wide-input flattening; contiguous inputs still use a view.
  • Test bridge dispatch at 1, 32, 33, and 64 rows; test the native FP16 branch selection at 32 and 33 rows.
  • Test BF16 and FP32 packed EXL3 output against an independent float64 reconstruction oracle on CPU and, when available, NVIDIA CUDA.
  • Document the routing in EXL3 wide activation dispatch, link it from README, and correct the prior statement that EXL3 native kernels accept FP32.

Dispatch flow

flowchart TD
    A["ExllamaV3Linear.forward(x)"] --> B{"x.dtype is float16?"}
    B -->|yes| C["_ensure_inner"]
    C --> D["LinearEXL3.forward"]
    D --> E{"rows greater than 32?"}
    E -->|no| F["bc.run: FP16 native GEMM"]
    E -->|yes| G["ext.hgemm: FP16 native GEMM"]
    B -->|no| H["_ensure_torch_inner"]
    H --> I["ExllamaV3TorchLinear._forward_eager"]
    I --> J["reshape rows; convert to FP32"]
    J --> K["_forward_chunked: packed trellis decode and FP32 matmul"]
    K --> L["add bias; cast to input dtype"]
    P["Direct native call with BF16 or FP32"] --> X["TORCH_CHECK_DTYPE rejects input"]
    classDef failure fill:#fdd,stroke:#b00,color:#700
    class X failure
Loading
Mechanism Before After
Wide-input flattening gptqmodel/nn_modules/exllamav3_torch.py:548 used view, which fails for transposed leading dimensions reshape preserves logical row order
Dtype dispatch gptqmodel/nn_modules/exllamav3.py:294-306 already sends BF16/FP32 to Torch Unchanged, now tested across the 32/33-row boundary
Native input contract gptqmodel_ext/exllamav3/quant/exl3_gemm.cu:52 and gptqmodel_ext/exllamav3/hgemm.cu:32 require FP16 Unchanged; a direct wide call to the lower-level native class still rejects it

Validation

  • Rebased on merged fix(exl3): keep Torch fallback out of checkpoint state #3738. Combined tests/test_exl3_wide_input.py tests/test_exllamav3_cpu.py tests/test_exllamav3_torch_padding.py: 146 passed, 56 skipped on CPU; this includes strict checkpoint reload and noncontiguous wide-input oracles.
  • /root/venv/bin/python -m pytest tests/test_exl3_wide_input.py tests/test_exllamav3_cpu.py -q --disable-warnings --log-cli-level=ERROR: 69 passed, 4 skipped in 22.01 s.
  • /root/venv/bin/python -m ruff check gptqmodel/nn_modules/exllamav3_torch.py tests/test_exl3_wide_input.py tests/test_exllamav3_cpu.py: passed.
  • git diff HEAD^ HEAD --check: passed.
  • CPU independent oracle, packed 128×128 four-bit EXL3, noncontiguous 32/33-row BF16/FP32 inputs with one activation at 131,072: BF16 raw relative L2 0.001501292 max and visible rounded relative L2 0.000009998 max; FP32 raw relative L2 0.000000330 max. Limit: 0.002.
  • After repeated forwards: 8,960 bytes of unique packed weight/scale/bias buffers, 0 bytes of additional dense weight cache. Decoded 128×128 FP32 tile: 65,536 transient bytes; production tile width is bounded to 512 output columns.

Environment and scope

NVIDIA CUDA is unavailable on this runner, so the four CUDA oracle cases skipped; actual native extension execution was not measured. The CPU dispatch tests exercise the 32/33-row native branch logic with mocked extension calls. The old noncontiguous path raised, so there is no comparable pre-fix inference latency. No public compatibility layer or hf_ API was changed. No backward compatibility is retained except for hf_ APIs.

@Qubitium
Qubitium force-pushed the codex/fix-exl3-wide-noncontiguous branch from 5599e36 to b9b2003 Compare November 9, 2026 19:31
@Qubitium
Qubitium merged commit c337ac1 into main Nov 9, 2026
6 checks passed
@Qubitium
Qubitium deleted the codex/fix-exl3-wide-noncontiguous branch November 9, 2026 19:36
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