Repository navigation
fix(exl3): skip zero-row hadamard launches (#4550) - #4587
Merged
Merged
Conversation
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.
Fixes #4550
Root cause
cbf5994added contiguity checks and 64-bit row offsets to EXL3'shad_r_128/had_r_128_dualbut not the zero-batch return that the same commit added togptqmodel_ext/hadamard. Withrows == 0, both functions still builtdim3 gridDim(0, cols / 128)and launched; the runtime rejected the zero-sized grid andcuda_check(cudaPeekAtLastError())calledexit().LinearEXL3.forwardreaches that path unconditionally on ROCm (torch_mode = Truewhentorch.version.hipis set) and on CUDA whenreconstructis forced.hgemmhappens to accept M=0, but the Hadamard launches do not.Fix
Two entry-point guards; the M>0 code path is unchanged:
flowchart TD A["EXL3 forward / had_r_128(M)"] --> B{"rows == 0?"} B -- "yes (LinearEXL3.forward)" --> C["return torch.empty(out_shape, dtype, device)"] B -- "yes (had_r_128 / _dual)" --> D["validate output dtype, then return before gridDim/launch"] B -- "no" --> E["existing gridDim(rows, blocks) launch"] classDef fixed fill:#e8f6e8,stroke:#1b7f1b,color:#111; class C,D fixed;had_r_128(rows=0)launchesgridDim(0, blocks)-> invalid launch / process exithad_r_128_dual(rows=0)sameLinearEXL3.forward(M=0)callshad_r_128->hgemm->had_r_128torch_modedispatchThe Python guard uses
bsz = x.numel() // x.shape[-1], so it also covers a leading zero extent such as(2, 0, K). The C++ guard sits afterTORCH_CHECK_SHAPES_FULL/TORCH_CHECK_DIM/TORCH_CHECK_DIV/contiguity and keeps the existing output-dtype validation for empty operands.Docs updated in
docs/kernel-input-contiguity.md(empty-operand flow now includes EXL3had_r_128/had_r_128_dualandLinearEXL3.forward).Before / after evidence
Python entry-point test (
tests/test_hadamard_empty_input.py::test_exl3_forward_guards_empty_batch_before_kernel_launch):rows=0failed withAssertionError: assert ['had_r_128', ..., 'had_r_128'] == [];rows=2passed.["had_r_128", "hgemm", "had_r_128"].Real extension test (
test_exllamav3_had_r_128_accepts_an_empty_batch, CUDA RTX 4090):GPU assert: invalid argument /root/stableabi/gptqmodel-kern2/gptqmodel_ext/exllamav3/quant/hadamard.cu 132(the process exits incuda_check).y.shape == (0, 128), dtype preserved.test_exllamav3_had_r_128_still_launches_for_nonempty_rowspasses too (nonempty output is finite and differs from the input, proving the launch happened).Tests (thread caps
OMP/MKL/OPENBLAS/NUMEXPR_NUM_THREADS=4)CUDA (
/opt/venvs/cu130t,CUDA_VISIBLE_DEVICES=GPU-1892aea4-cc09-827c-b9a5-93d4eef7f5ae):pytest tests/test_hadamard_empty_input.py tests/test_exl3_wide_input.py tests/kernels/test_exllamav3_kernel.py -q -k "not addresses_rows_past_two"->46 passed, 1 deselectedpytest tests/kernels/test_exllamav3_kernel.py -q -k "hadamard_kernel_rejects_strided_operands"->1 passedROCm (
/opt/venvs/rocm101t,HIP_VISIBLE_DEVICES=0only):pytest tests/test_hadamard_empty_input.py -q->13 passed(includes the realhad_r_128M=0 and M>0 extension tests)Lint:
ruff check gptqmodel docs/eora tests setup.py->All checks passed!git fetch origin main && git merge --no-edit origin/main-> mergedc280dfeba; lint and tests re-run after the merge.Hardware
NVIDIA RTX 4090 (
GPU-1892aea4-cc09-827c-b9a5-93d4eef7f5ae), AMD R9700 (HIP_VISIBLE_DEVICES=0); torch2.16.0.dev+cu130and2.16.0.dev+rocm10.1.Limitations
had_r_128_dualis not exposed by the Python bindings, so its guard is compile-validated only; the runtime regression covershad_r_128andLinearEXL3.forward.tests/test_exl3_wide_input.py::test_native_exl3_row_boundary_uses_expected_half_kernel[32-bc]fails on ROCm at unmodifiedHEADbecause HIP forcestorch_mode=Trueand the test expects the NVIDIA-onlybcpath for 32 rows. Verified pre-existing; not caused by this change and not modified here.