Repository navigation
fix(marlin): size the FP32 bias stage and keep it out of the reduction (#4735) - #4819
Merged
Merged
Conversation
#4735) #4657 widened the Marlin bias epilogue stage to FP32: the kernel now reserves thread_n_blocks * 16 / 4 int4 (tb_n * 4 bytes) instead of / 8, and the wider stage was placed at sh + sh_size_b_red_min, inside the B/reduce union. The host-side shared-memory model was not updated: get_kernel_cache_size() still counted tb_n * 2 bytes for the bias and only reserved max(sh_b, sh_red) for the union. A thread config the host accepts can therefore need more dynamic shared memory than the launch reserves, and the FP32 bias copy shares memory with the split-K reduction. The g_idx stage was also budgeted as tb_k / 4 bytes although the kernel allocates tb_k / 4 int4. Fix the budget model and the layout together: - get_kernel_cache_size(): sh_bias_size = tb_n * 4 bytes and tmp_size = max(sh_b_size, sh_red_size) + sh_bias_size. - get_kernel_cache_size(): sh_g_idx_size = stages * tb_k * 4 bytes. - marlin_template.h: place the bias stage after the union (sh + sh_size_b_red_max), so it can never overlap a reduction write. - marlin_template.h: read the staged FP32 bias from shared memory in the epilogue instead of preloading a Vec<float, 2> fragment array, so a launch without a bias does not reserve the widened registers. Measurement host: 8x NVIDIA PG506 (sm_80, 124 SMs), torch 2.15.0.dev20260928+cu130, Triton 3.8.0. Tests (CUDA_VISIBLE_DEVICES=4, real JIT kernel): - tests/kernels/test_marlin_tile_determinism_4735.py: 12 passed. - Marlin suites (tests/kernels/test_marlin*.py, tests/test_marlin*.py): 396 passed, 2 skipped, 10 failed. The 10 failures are pre-existing on this host and reproduce identically on unmodified main: test_marlin_g_idx.py::test_marlin_decodes_noncontiguous_g_idx, test_marlin_jit.py::test_marlin_cuda_smoke_build_and_forward, and the eight test_marlin_scratch_cuda.py N=200 padded cases (b_bias.size(0) != size_n). - tests/kernels/test_kernel_input_contiguity.py and test_kernel_compile_levels_gptq.py: 10 passed, 3 skipped. The reported wrong/nondeterministic tiles are architecture-specific: on the sm_80 measurement host 6000+ real-kernel launches over the issue shapes were deterministic before and after the change, so the numerical failure could not be reproduced here. The deterministic defects the new test pins on sm_80 are the host/kernel bias-size disagreement and the bias/reduction overlap; the same file also carries the issue's 30-launch bitwise + FP64-oracle determinism sweep for the sm_89/sm_120 GPTQ bf16 and AWQ fp16 cases.
This was referenced Nov 17, 2026
Qubitium
added a commit
that referenced
this pull request
Nov 18, 2026
…ces (#4735) (#5058) #4657 widened the Marlin bias stage to FP32 (thread_n_blocks * 16 / 4 int4) and #4819 fixed the host-side model to match it. The regression test that landed with #4819 only compares source *strings*; it never recomputes the extent the kernel declares, so it cannot show that the host budget covers the whole layout (B/reduce union, FP32 bias, g_idx, zero points, scales, A) for the configs is_valid_config() accepts. Add a derived check that translates the real declarations in marlin_template.h and gptq_marlin.cu into Python, evaluates them over the real thread-config matrix (4 thread configs x thread_m_blocks 1..4 x bits {4,8} x group {128,64,32,-1} x act_order x zero-point modes, 2880 cases), and asserts host dynamic shared memory >= the kernel requirement. It also pins that the FP32 bias sits after the union (span == union + bias) and that the bias and g_idx regions match byte for byte. A second test replays the pre-#4657 tb_n * 2 bias term through the same model and asserts it under-counts, so the invariant cannot be satisfied by two models that agree on the wrong number. On 0d9396e^ (pre-fix) the new invariant test fails with ``assert 512 == 1024`` for the FP32 bias stage; on current main all four static checks pass.
11 tasks done
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.
fix(marlin): size the FP32 bias stage and keep it out of the reduction (#4735)
#4657 widened the Marlin bias epilogue stage to FP32: the kernel now reserves
thread_n_blocks * 16 / 4 int4 (tb_n * 4 bytes) instead of / 8, and the wider
stage was placed at sh + sh_size_b_red_min, inside the B/reduce union. The
host-side shared-memory model was not updated: get_kernel_cache_size() still
counted tb_n * 2 bytes for the bias and only reserved max(sh_b, sh_red) for
the union. A thread config the host accepts can therefore need more dynamic
shared memory than the launch reserves, and the FP32 bias copy shares memory
with the split-K reduction. The g_idx stage was also budgeted as tb_k / 4
bytes although the kernel allocates tb_k / 4 int4.
Fix the budget model and the layout together:
tmp_size = max(sh_b_size, sh_red_size) + sh_bias_size.
(sh + sh_size_b_red_max), so it can never overlap a reduction write.
epilogue instead of preloading a Vec<float, 2> fragment array, so a launch
without a bias does not reserve the widened registers.
Measurement host: 8x NVIDIA PG506 (sm_80, 124 SMs), torch
2.15.0.dev20260928+cu130, Triton 3.8.0.
Tests (CUDA_VISIBLE_DEVICES=4, real JIT kernel):
396 passed, 2 skipped, 10 failed. The 10 failures are pre-existing on this
host and reproduce identically on unmodified main:
test_marlin_g_idx.py::test_marlin_decodes_noncontiguous_g_idx,
test_marlin_jit.py::test_marlin_cuda_smoke_build_and_forward, and the eight
test_marlin_scratch_cuda.py N=200 padded cases (b_bias.size(0) != size_n).
test_kernel_compile_levels_gptq.py: 10 passed, 3 skipped.
The reported wrong/nondeterministic tiles are architecture-specific: on the
sm_80 measurement host 6000+ real-kernel launches over the issue shapes were
deterministic before and after the change, so the numerical failure could not
be reproduced here. The deterministic defects the new test pins on sm_80 are
the host/kernel bias-size disagreement and the bias/reduction overlap; the
same file also carries the issue's 30-launch bitwise + FP64-oracle
determinism sweep for the sm_89/sm_120 GPTQ bf16 and AWQ fp16 cases.