Skip to content

[Frontend] A reduction's blocks fill the tile budget, and its kept axis is read from its strides - #411

Merged
YWHyuk merged 1 commit into
pytorchsim-triton-backendfrom
frontend/reduction-blocks-fill-budget
Oct 22, 2026
Merged

YWHyuk merged 1 commit into
pytorchsim-triton-backendfrom
frontend/reduction-blocks-fill-budget

Conversation

@student-Jungmin

@student-Jungmin student-Jungmin commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

Cause (found by the compiler's validation error loop: PSAL-POSTECH/PyTorchSim-Triton-Backend#269, #270, #271)

  • A reduction along its contiguous axis kept XBLOCK at the lane count (128) and took only R0_BLOCK from the tile budget. With a short reduced axis the tile is a sliver of the budget: Qwen3-8B's q_norm / k_norm (RMSNorm over 128, fused with rope in the layer) run as 128 x 128 tiles, one DMA wait each.
  • Which axis is contiguous came from Inductor's reduction hint. Inductor leaves it DEFAULT for any kernel of at least num_sm * 64 rows, whatever its strides, so gate_up at decode (1 x 4096 @ 4096 x 24576) took the row path: XBLOCK=128, R0_BLOCK=4096, grid=(192), each program reading 256-B runs of the weight at a 48 KiB stride ([TOGSim] Trace-bridge dependency + SRAM version redesign #270), while q_proj (N 4096) took the kept-axis path.

Change

  • kept_axis_rows_block takes as many rows of R0_BLOCK as the budget the other blocks use holds (one lane's, times the lanes), at least the lane cover.
  • _kept_axis_contiguous reads the unit-stride axis of the kernel's largest read (MemoryDep strides, bytes from numbytes_hint) instead of the hint.
  • Default change: short-axis reductions and GEMVs whose hint was DEFAULT get larger blocks, so their kernels in the bundle change.

Tests: tests/system/test_reduction_tiling.py (pass locally).

Numbers (compiler CI, qwen3_8b suite; TOGSim ÷ v6e). The bundle rebuilt with this PR is PSAL-POSTECH/PyTorchSim-Triton-Backend#273 (31 of 116 workloads change). Before: main 4b2b1ad, run 39632293777. After: main 23b108c, run 39686040845; the compiler is the same in both.

group before after within ±20% after
layer prefill 27.247 (5 / 6 timed) 0.980 6 / 6
layer decode 4.657 0.919 6 / 6
op GEMV (T=1) 1.459 1.015 6 / 6
op GEMM 0.848 0.859 16 / 36
op norm 1.501 0.655 2 / 21
  • gate_up at T 1: 9.24 → 1.05. Layer prefill T 4096 is now timed; it was over the 900-s step limit before.
  • Layer per S: prefill 0.96 / 1.00 / 1.05 / 0.98 / 0.96 / 0.93 (T = S 128 … 4096); decode 0.92 → 0.90 over S 128 … 4096.

Open: the norms are now faster than v6e. rmsnorm runs 0.63–0.79 at T ≥ 128 (0.37 at T 1, unchanged), q_norm 0.66–0.83, k_norm 0.53–0.79. Before, they were 0.68–0.90 (rmsnorm), 2.39–5.24 (q_norm) and 0.94–3.51 (k_norm). The geomean moved from slow to fast by about the same distance (1.50 → 0.655), so this group is not better; it needs its own cause (what a large norm tile costs on v6e that TOGSim does not charge).

…is is read from its strides

Two changes to the block a reduction kernel is pinned with.

A reduction along its contiguous axis kept XBLOCK at the lane count (128) and took only R0_BLOCK
from the tile budget. With a short reduced axis the tile was 0.8% of the budget: Qwen3-8B's q_norm
([T, 32, 128], RMSNorm over 128) ran 128 x 128 tiles, 256 of them at T 1024, each waiting on its
DMA. kept_axis_rows_block now takes as many rows of R0_BLOCK as the budget the other blocks use
(one lane's, times the lanes) holds, at least the lane cover: 128 -> 16384 rows for q_norm.

Which axis is contiguous came from Inductor's reduction hint, OUTER meaning the kept axis.
Inductor leaves the hint DEFAULT for any kernel of at least num_sm * 64 rows (ir.py num_splits),
whatever its strides, so the GEMV 1 x 4096 @ 4096 x 24576 (gate_up at decode) took the row path,
192 programs each reading 256-B runs of the weight at a 48 KiB stride, while the same GEMV at
N 4096 (q_proj) took the kept-axis one. _kept_axis_contiguous now reads the unit-stride axis of
the kernel's largest read (MemoryDep strides, bytes from numbytes_hint).
@YWHyuk
YWHyuk merged commit 7f927a2 into pytorchsim-triton-backend Oct 22, 2026
@YWHyuk
YWHyuk deleted the frontend/reduction-blocks-fill-budget branch October 23, 2026 03:05
student-Jungmin added a commit to PSAL-POSTECH/PyTorchSim-Triton-Backend that referenced this pull request Nov 10, 2026
…e tile budget (PyTorchSim #411)

The 31 qwen3_8b workloads whose kernels change when PyTorchSim pins a reduction's blocks to the
tile budget and reads its kept axis from strides (PSAL-POSTECH/PyTorchSim#411, 38bbf999), built
with #409's bundle.py on it: every layer, q_norm, k_norm and rmsnorm at T >= 256, gate_up at T 1
(the GEMV #270 names) and down at T 4096 (a template timed again). The other 85 are byte-equal and
stay. bundle.json is main's.
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.

2 participants