Repository navigation
perf(marlin): use 128x64 tiles when the output grid is small - #5216
Merged
Merged
Conversation
#4913) For group_blocks > thread_k_blocks (g128 with thread_k = 64) a quantization group spans two pipeline stages. fetch_to_shared() copies the group's scales and zero points only into the slot of the group's first stage. The second stage re-read that slot (`2 * (pipe / 2)`) after the last wait_for_stage() barrier that protects it. In the same window, faster warps refill that slot with stage pipe + stages, which belongs to group g + 2. cp.async latency normally hides the race. When the GPU time-slices to another process, in-flight copies drain before the context is saved, so a lagging warp applies group g+2's scales. One k-warp-group then gets a whole 64-row output block wrong, with no error raised. This affects GPTQ and AWQ in fp16 and bf16 on sm_89 and sm_120. Port vLLM's guard from vllm-project/vllm#24722 (vLLM >= 0.12.0): only the group's first stage reads shared memory for scales and integer or float zero points; the later stages keep frag_s / frag_qzp / frag_zpf. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Port the small-grid tile override from vLLM's Marlin planner (vllm-project/vllm#24722). When the auto-selected thread tile leaves fewer than four output tiles per SM (m_tiles * n_tiles * 4 <= sms), launch the narrow {thread_k=128, thread_n=64, threads=128} tile instead. The wide tile made most SMs split K for the same few output tiles and then queue on their reduction locks. Example: Llama-3-8B k/v projection at M=64 drops from 72.6 us to 16.9 us on an RTX 5090. The override applies only in the auto-config branch. It requires is_valid_config and an instantiated kernel. The full-SM sm_80 tables and Ada's narrow FP32 AWQ schedule keep their own tuned tile. Adds a profiler-based test that pins the launched tile and checks each launch against an FP64 oracle, plus docs/marlin-tile-schedule.md. Depends on #5188 (#4913 scale-slot race fix), which this branch carries. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Qubitium
marked this pull request as ready for review
November 18, 2026 11:26
This was referenced Nov 18, 2026
Qubitium
added a commit
that referenced
this pull request
Nov 18, 2026
#5216 switched to the narrow {thread_k=128, thread_n=64, threads=128} tile whenever the auto-selected tile left fewer than four output tiles per SM. That test counted output tiles only: it ignored K and the 256-thread tile it replaced. On 128-SM Ada parts N=4096 sits exactly on the boundary, so every large-K down projection took the narrow tile even though the wide tile already had enough split-K work per SM (1.07-1.31x slower at M=4/16/128). Keep #5216's tile-count gate, but on parts with at most 128 SMs require the narrow tile to still split K over at least two threadblocks per output tile. A 16-row wide tile is kept for long K unless the narrow tile still splits K at least four ways. The 170-SM RTX 5090 keeps #5216's measured choice; the narrow tile was faster there for every 16-row shape, including large K. Also forward optional thread_k/thread_n/num_threads through the existing manual branch so tests and tuning can compare both tiles on identical operands; the defaults keep the 18-argument ABI (and the 20-argument scratch ABI). Selection is unchanged numerically: both tiles are bitwise deterministic, agree to one output ulp, and auto is bitwise identical to the forced tile the rule selects.
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.
Summary
Port the small-grid thread-tile override from vLLM's Marlin planner
(vllm-project/vllm#24722,
csrc/quantization/marlin/marlin.cu). When theauto-selected tile leaves fewer than four output tiles per SM
(
m_tiles * n_tiles * 4 <= sms),marlin_mmnow launches the narrow{thread_k=128, thread_n=64, threads=128}tile. The old planner kept the widetile. Most SMs then split K for the same few output tiles and queued on their
reduction locks: Llama-3-8B
k_proj/v_projat M=64 took 72.6 us on anRTX 5090, and 16.9 us with this change.
Correctness evidence (summary):
test_marlin_small_grid_tiles.pyis red on baseline (8 tileassertions fail: the wide tile is launched) and green with the fix.
(RTX 5090): 235 passed +
test_marlin_jit.py65 passed per card, with2 arch-gated skips.
error is identical, the mean of per-case max errors is identical, and the
≤2 differing cases per card move by less than half an FP16 ulp.
and AWQ bf16) is green on both cards.
Depends on #5188 (the #4913 scale-slot race fix). This branch carries that
commit (
f66a4fc6c) and should be rebased once #5188 lands. vLLM #24722contains the same guard.
Net diff: one 24-line hunk in
gptq_marlin.cu, plus a test and a docs page.What Changed
gptqmodel_ext/marlin/gptq_marlin.cu: in the auto-config branch ofmarlin_mm, afterdetermine_exec_config, switch to{128, 64, 128}whenceil(prob_m_split / (16 * thread_m_blocks)) * (prob_n / thread_n) * 4 <= sms,is_valid_configaccepts the narrow tile, andget_marlin_kernelhas aninstantiation for it. The kernel itself does not change.
(
marlin_prefers_full_sm80) and Ada's narrow FP32 AWQ schedule(
narrow_splitk_arch/narrow_fp32_awq, includingnarrow_small_m_tiles)keep their tile; the override is skipped for them. Manual
thread_k/thread_n, theforce_exact_splitretry andexec_config_t/blocks_per_smare unchanged.tests/kernels/test_marlin_small_grid_tiles.py(new): reads the launchedkernel's template arguments from the profiler. It asserts that small-grid
shapes launch
{128, 64, 128}and that a large-grid shape does not, andchecks every launch against an FP64 oracle (GPTQ and AWQ, FP16/BF16).
docs/marlin-tile-schedule.md(new, linked fromdocs/README.md):selection flow, before/after table and measurements.
Out of scope: the rest of vllm-project/vllm#24722. The hybrid scheduling /
contiguous-K restructure was evaluated separately and is not part of this PR.
W4A8 and the FP4/FP8 8-bit scale layout are excluded.
Tests
Red (baseline
a706c646e+ #5188, RTX 4090 sm_89, new test copied in):Green, both cards (
TORCH_CUDA_ARCH_LIST=8.9on GPU 0 / RTX 4090,12.0onGPU 2 / RTX 5090,
CUDA_DEVICE_ORDER=PCI_BUS_ID):The #4913 time-slicing soak (
test_group_scales_survive_gpu_time_slicing,gptq-fp16 and awq-zp-bf16, 10,000 launches each against a GPU tenant) passed on
both cards. The source-parsing tests in
test_marlin_tile_determinism_4735.pyand
test_marlin_fp32_schedule.pypass unchanged; this change does not moveany planner constant they pin.
Skips (both cards):
test_awq_machete_marlin.py:290(Machete is SM90-only) and:308(Swordfish needs sm100/103/110). No skip touches the changed path.Not verified: performance on sm_89/sm_80/sm_86/sm_90. GPU 0 (4090) is shared
with outside load, so it was used for correctness only. No other idle card was
available.
Model Support / Module Plan
Not applicable: no model definitions change.
Logic Flow Documentation
The change adds one decision to the tile planner. Diagram (also in
docs/marlin-tile-schedule.md):flowchart TD A["marlin_mm: next M split"] --> B{"narrow_small_m_tiles?"} B -- "yes" --> B1["{128, 128, 256} (unchanged)"] B -- "no" --> C{"manual thread_k/thread_n?"} C -- "yes" --> C1["manual tile (unchanged)"] C -- "no" --> D["determine_exec_config (table tile)"] D --> E{"tile found, !full_sm80, !narrow_fp32_awq?"} E -- "no" --> F["table tile"] E -- "yes" --> G{"m_tiles * n_tiles * 4 <= sms?"} G -- "no" --> F G -- "yes" --> H{"{128,64,128} valid + instantiated?"} H -- "no" --> F H -- "yes" --> I["{128, 64, 128}"] D -- "no valid tile" --> X["retry with fewer thread_m_blocks (unchanged)"] classDef new fill:#e6f4ea,stroke:#137333,color:#111 classDef fail fill:#fce8e6,stroke:#c5221f,color:#111 class G,H,I new class X failgptq_marlin.cu, auto branch:thread_tfg = exec_cfg.tb_cfg)m_tiles*n_tiles*4 <= sms{128, 64, 128}Review Requirements
Kernel Accuracy Requirements
FP64 oracle sweep: GPTQ sym g128 (
desc_actFalse and True) and AWQ zp g128,FP16 and BF16, with and without bias, M in {1, 7, 16, 64, 128, 512, 2048}.
Shapes: Llama-3-8B (4096x6144, 4096x4096, 4096x1024, 4096x28672, 14336x4096)
and Qwen2.5-7B (3584x3584, 3584x512, 18944x3584). That is 672 cases per card.
All outputs are finite, and every case is bitwise identical across repeated
launches. Storage is unchanged: no new buffers or caches, and the narrow tile
uses less shared memory than the wide one.
Performance
RTX 5090 (sm_120, 170 SMs), GPU 2,
CUDA_DEVICE_ORDER=PCI_BUS_ID. Bothsides use the same harness: the raw
apply_{gptq,awq}_marlin_linearcall iscaptured as a CUDA graph of 20 launches; 10 warmup replays, then the median of
60 replays timed with CUDA events. Baseline and change ran from separate
worktrees with separate JIT build roots. Each cell is the GPTQ-FP16 per-call
time in microseconds (before → after), then the range of the change over
{GPTQ, AWQ} × {FP16, BF16}:
Over the 224 cases: 124 improved by more than 2%, 96 are within ±2%, and 4 regressed by more than 2% (listed below).
Unverified outliers. Down projections at M=128: Llama 14336x4096 measured
+0..+3% and Qwen 18944x3584 +1..+4%:
These runs (10:20 to 10:35 UTC+0) finished before I observed any other
process on GPU 2. However, the harness did not yet check for other processes,
and from about 10:45 GPU 2 was continuously shared with other sessions' jobs.
The interleaved re-runs of these cells never got an idle window, so the
outliers are unverified (GPU contended). sm_89/sm_80/sm_86/sm_90
performance is unmeasured.
Commands (per side,
<wt>= baseline or change worktree):The harness is a local script, not part of this PR. It builds modules through
MarlinLinear/AwqMarlinLinear.post_init()and times the raw apply call; theaccuracy mode compares
module(x)withx.double() @ W.double() + bias.Notes
git merge-treemerges this branch cleanly with both heads (
394ec0dbe,76d84a4d9). Thehelper signatures this hunk calls (
is_valid_config,get_marlin_kernel)are identical on both.
n_tiles * m_tiles * 4 <= sms). GPT-QModel adds theget_marlin_kernelinstantiation check and the two tuned-path exclusions.🤖 Generated with Claude Code