Skip to content

fix(marlin): size the FP32 bias stage and keep it out of the reduction (#4735) - #4819

Merged
Qubitium merged 1 commit into
mainfrom
root/marlin-tiles-4735
Nov 17, 2026
Merged

Qubitium merged 1 commit into
mainfrom
root/marlin-tiles-4735

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

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:

  • 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.

#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.
@Qubitium
Qubitium merged commit 0d9396e into main Nov 17, 2026
6 checks passed
@Qubitium
Qubitium deleted the root/marlin-tiles-4735 branch November 17, 2026 15:52
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.
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