Skip to content

fix(strix): compile every Triton kernel copy at start-up, no first-request stalls - #51

Merged
rkinas merged 9 commits into
rkinas:mainfrom
kardysm:strix-warm-shapes
Nov 2, 2026
Merged

rkinas merged 9 commits into
rkinas:mainfrom
kardysm:strix-warm-shapes

Conversation

@kardysm

@kardysm kardysm commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Thanks @piotrkowski for finding this out 🙌
Originally uncovered in #21

--mode strix stalled on the first request whose length needed a Triton kernel copy it had not compiled yet. Triton
compiles a kernel once per tile config and per class of each integer argument (1, a multiple of 16, other), and the row
count picks both. The start-up warm-up ran two lengths only, so a request in a new class waited 0.2–0.3 s per missing
copy. This is the one-off stall in the first timed pass of S with 1 question and M with 2 in the request matrix, on
both Strix Halo machines of #14 and #21. Engine 2.4.1 and earlier still have it.

What changes

StrixHaloFastBackend._warm_shapes() runs at the end of the existing warm-up:

  • Projections (qkv, o, down, FFN input) run on zero rows for every row-count range of LINEAR / FFN and every
    class. warm_rows gives 1, then one count that is not a multiple of 16 and one that is, per range. They are called
    the way the forward calls them (same strides, residual for o / down).
  • Six short forwards (WARM_FORWARDS: lengths 17 / 32 against 1 / 3 / 16 readout rows) compile attention and
    rotary, over the first and the last layer only. The layers between need the copies the first one compiles; running
    all 60 layers of basal-2.0 cost ~0.7 s per start.

Kernels and the request path are unchanged. docs/benchmarks/STRIX_HALO.md explains the stall where the results
report it, and the start-up cost. docs/WHATS_NEW.md has an entry under 2.4.2; rename it to the release this lands in.

Results: basal-2.0-4.5B on the Radeon 8060S

before with this PR
Kernels compiled during 152 requests (empty Triton cache) 13, in 4 requests 0
Extra time in those requests 2.7 s 0 s
Start-up, empty cache: backend load / server to first /health 5.8 s / 8.1 s 10.4 s / 12.7 s
Start-up, filled cache: backend load 3.37 s 3.56 s
  • The 4 stalled requests: 160 tokens (1,304 ms against 146 ms repeated), 720 tokens (1,465 against 287 ms), and
    1,550 and 1,600 tokens (1 kernel each).
  • Probabilities bit-identical between base and branch on all 2,362 prompts.
  • Over HTTP (basal-serve --mode strix, bench_matrix.py, edge_check.py): identical answers on all 20 matrix cases
    and the 12 edge-case requests; throughput the same at 1 and 8 clients (6.6 and 16.1 requests/s).

Tests

  • New test_warmup_compiles_every_kernel_copy (GPU): hooks Triton's jit_cache_hook and checks that after start-up
    no row count of 20–5,000 tokens with 1–528 readout rows compiles a kernel. It uses a 3-layer model, so the warm-up
    skips a layer, and checks that the backend keeps all its layers. It fails without the warm-up, and 8 of 9 deliberate
    breaks of the warm-up make it fail (the 9th, dropping (17, 3), is covered by the older warm-up).
  • tests/test_strix.py: 31 passed with a filled cache, an empty cache, in reverse order, and merged into main.
  • Full suite, this branch merged into 2.4.1: 834 passed, 7 failed, 25 skipped. Every failure also happens without
    this PR and comes from this machine's ROCm build: 4 test_gemma4 cases need ROCm's experimental attention flag,
    test_compact_varlen has an fp16 mismatch, and 2 test_cascade_cuda tests use flash-attention options ROCm lacks.
  • ruff: no new findings in the changed lines.

Full test report: https://gist.github.com/kardysm/7ca58120d7cec18dff5f3f4fa74b4e79. It tested a5a9011 and its
merge into 2.4.1; this PR's head is that same merge (identical tree) plus the WHATS_NEW entry.

Notes for review

  • (17, 3) in WARM_FORWARDS overlaps the older two-length warm-up. I kept it as a guard; it costs one 17-token
    forward over 2 layers.
  • warm_rows assumes each row-count range in LINEAR / FFN is at least 32 rows wide. All current ranges are.
  • Warming the first and the last layer covers the layers between because every layer's weights fall in the same
    Triton pointer class (16-byte aligned, storage under 2 GB). That holds for all 60 layers of basal-2.0; the tiny test
    model cannot show it.
  • basal-1.5 was not run end to end; it has the same architecture as basal-2.0.
  • Setup: AMD Ryzen AI Max+ PRO 395 with Radeon 8060S (gfx1151), 128 GB; PyTorch 2.12.0 for ROCm 7.2, Triton 3.7.0,
    Python 3.12.

🤖 Generated with Claude Code

Summary by Sourcery

Precompile every Triton kernel variant required by Strix requests at startup to remove first-request compilation stalls.

Bug Fixes:

  • Eliminate first-request stalls in Strix mode by compiling all Triton kernel variants needed by supported request shapes during startup.

Enhancements:

  • Expand Strix startup warm-up coverage for projection, attention, and rotary kernel variants while limiting forward warm-ups to representative layers.
  • Document the updated Strix startup behavior, latency trade-off, and benchmark results.

Documentation:

  • Update release notes and Strix Halo benchmark documentation with the startup compilation behavior and performance results.

Tests:

  • Add GPU coverage verifying that requests across representative token and readout-row sizes compile no additional Triton kernels after startup.

kardysm and others added 7 commits October 21, 2026 18:57
Triton compiles a kernel once per tile config and per class of each
integer argument (1, a multiple of 16, other), and the row count picks
both. The start-up warm-up ran two lengths only, so the first request
whose length was a multiple of 16 in a tile-config range waited for new
copies: in the request matrix the first timed pass of S with 1 question
(208 tokens) and of M with 2 (720 tokens), on both machines of rkinas#14 / rkinas#21.

The warm-up now runs the projections on zero rows of every range and
class (one row: the last row chunk of qkv / o, one readout row) and six
short forwards for attention and rotary (lengths other / multiple of 16
against readout rows 1 / other / 16). Kernels are unchanged.

basal-2.0 on the 8060S, request matrix: the old code compiled 18 copies
during the matrix (empty Triton cache: S-q1 pass 1 1.82 s against
0.18 s), now none. Start-up 8.8 s against 7.9 s with a filled Triton
cache, 18.7 against 13.8 s at the first start on a machine.

test_warmup_compiles_every_kernel_copy: no row count (20-5000 rows, 1-528
readout rows) compiles a kernel after the warm-up; it fails without it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
STRIX_HALO.md: the start-up warm-up and why it covers every size class,
and the cause at the three places that report the stall (basal-2.0
matrix vs A/B, the ROG Flow Z13 section, the raw results).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The six short forwards of the start-up warm-up compile the attention and
rotary copies. One inner layer (attention over every row) and the last
(readout rows only) need all of them; the layers between run the copies
the first one compiles. Running all 60 layers of basal-2.0 cost ~0.7 s
per start.

basal-2.0 on the 8060S: start-up with a filled Triton cache 6.0-6.1 s
against 6.7-6.8 s (6.0-6.2 s before the warm-up of every shape); the same
34 kernel copies; none compiled during the request matrix from an empty
cache; answers equal to the all-layer warm-up (460 probabilities).

test_warmup_compiles_every_kernel_copy runs a 3-layer model, so the
warm-up skips a layer, and checks that the backend keeps all its layers.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…m-up

STRIX_HALO.md: upstream 2.4.0 and 2.4.1 still ship the two-length
warm-up, so the stall applies to 2.4.1 and earlier. Start-up remeasured
on the 8060S with the first-and-last-layer warm-up (two runs each):
6.0-6.1 against 6.0-6.2 s with a filled Triton cache, 13.4-13.6 against
8.7-8.8 s at the first start on a machine.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
STRIX_HALO.md lists what tests/test_strix.py covers; it now includes
test_warmup_compiles_every_kernel_copy (after the start-up warm-up, no
row count of 20-5,000 tokens with 1-528 readout rows compiles a kernel).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01HURKBzWocW2YSQkzdGE4N2
The fork point was 2.3.1; upstream main is at 2.4.1. No conflicts: upstream
did not touch basal/strix.py, tests/test_strix.py or STRIX_HALO.md since.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NVMXYt7nYcWrTvYzDsd4kD
The start-up compiles every Triton kernel copy a request can need; the
numbers are basal-2.0-4.5B on the Radeon 8060S (the request matrix in
STRIX_HALO.md and the strix-warm-shapes test report).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NVMXYt7nYcWrTvYzDsd4kD
@sourcery-ai

sourcery-ai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

The PR changes Strix initialization to proactively compile all Triton kernel variants implied by projection, FFN, attention, rotary, and row-count classes, using representative warm-up inputs and only the first and last layers for attention. It adds a JIT-hook GPU regression test and documents the resulting elimination of first-request stalls alongside the increased cold-start cost.

Sequence diagram for Strix startup kernel warm-up

sequenceDiagram
    participant Backend as StrixHaloFastBackend
    participant Projection as Projection and FFN kernels
    participant Attention as Attention and rotary kernels
    participant Triton
    participant Request as Request path

    Backend->>Backend: run_shared(existing warm-up)
    Backend->>Projection: warm_rows(LINEAR and FFN configs)
    Projection->>Triton: compile row-count variants
    Backend->>Attention: forward(WARM_FORWARDS) on first and last layers
    Attention->>Triton: compile attention and rotary variants
    Backend->>Triton: _wait()
    Request->>Backend: forward(request)
    Backend->>Triton: reuse warmed kernel copies
Loading

Flow diagram for Strix row-count coverage

flowchart LR
    Start[Warm-up row counts]
    One[1 row]
    Other[Non-multiple-of-16 row]
    Multiple[Multiple-of-16 row]
    Config[Each LINEAR and FFN configuration range]
    Kernels[All projection and FFN kernel copies]

    Start --> One
    Start --> Config
    Config --> Other
    Config --> Multiple
    One --> Kernels
    Other --> Kernels
    Multiple --> Kernels
Loading

File-Level Changes

Change Details Files
Expand Strix start-up warm-up to cover every Triton kernel specialization needed by request shapes, eliminating first-request compilation stalls.
  • Generate representative row counts for each LINEAR and FFN configuration range, including singleton, non-16-multiple, and 16-multiple classes.
  • Warm projection and FFN kernels using forward-equivalent inputs, strides, and residual paths.
  • Run six short attention/rotary forwards across sequence and readout-row classes, limiting execution to the first and last layer while preserving the full layer list afterward.
  • Synchronize completion and restore the original layer collection even if warm-up fails.
basal/strix.py
Add GPU coverage that verifies startup leaves no uncached Triton kernel copies for representative request shapes and does not lose model layers.
  • Intercept Triton JIT cache events after initialization and exercise varied token and readout-row counts across a three-layer model.
  • Assert no kernels compile during those forwards and that all layers remain available.
  • Make the tiny-model helper configurable by layer count.
tests/test_strix.py
Document the tradeoff and measured impact of comprehensive Strix warm-up.
  • Describe eliminated request stalls, Triton specialization classes, startup overhead, and cache behavior in the 2.4.2 release notes.
  • Update Strix benchmark explanations and results to identify the prior one-off stalls and new warm-up behavior.
  • Record the expanded warm-up test coverage in benchmark documentation.
docs/WHATS_NEW.md
docs/benchmarks/STRIX_HALO.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 4 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="basal/strix.py" line_range="302" />
<code_context>
+    # Start-up forwards for attention and rotary (one tile config each): sequence lengths other and a multiple of 16,
+    # each against readout rows 1, other and a multiple of 16 (the last layer's attention takes both counts). They run
+    # the first layer and the last only: every layer between needs the copies the first one compiles.
+    WARM_FORWARDS = ((17, 1), (32, 1), (17, 3), (32, 3), (17, 16), (32, 16))
+
+    @staticmethod
</code_context>
<issue_to_address>
**One-token requests compile kernels**

When a request packs to one token, the forwards in `_warm_shapes` cover only lengths 17 and 32, leaving the `L=1` specializations of `_rope` and `_attn_fwd` uncompiled; Triton compiles them on the first one-token request and stalls it.

Add an `L=1` forward to the startup warm-ups.
</issue_to_address>

### Comment 2
<location path="tests/test_strix.py" line_range="246" />
<code_context>
+    timed pass of S with 1 question and of M with 2 in the request matrix, before the warmup covered them). Three
+    layers: the warmup forwards skip the middle one, and the forwards below run all three."""
+    from basal import strix
+    if not hasattr(triton, "knobs"):
+        pytest.skip("Triton without knobs.runtime.jit_cache_hook")
+    for k in (strix._attn_fwd, strix._swiglu_mm, strix._linear, strix._rmsnorm, strix._rope):
</code_context>
<issue_to_address>
**Test errors without cache hook**

When triton exposes `knobs` but does not expose `knobs.runtime.jit_cache_hook`, `test_warmup_compiles_every_kernel_copy` later assigns `triton.knobs.runtime.jit_cache_hook` at line 258 and raises `AttributeError` instead of skipping, so the suite fails even when the backend is correct.

Check that the nested hook exists before accessing it, and skip when it does not.
</issue_to_address>

### Comment 3
<location path="tests/test_strix.py" line_range="249" />
<code_context>
+    if not hasattr(triton, "knobs"):
+        pytest.skip("Triton without knobs.runtime.jit_cache_hook")
+    for k in (strix._attn_fwd, strix._swiglu_mm, strix._linear, strix._rmsnorm, strix._rope):
+        k.device_caches.clear()  # the copies other tests compiled in this process
+    be = make(tiny(layers=3), warm=True)
+    assert len(be.layers) == 3
</code_context>
<issue_to_address>
**Disk cache masks missing warm-up**

When the required kernel variants are already present in Triton’s persistent disk cache, triton serves those variants from disk without a compile event, so `built` stays empty and the final assertion passes even if `_warm_shapes()` does not compile them at startup.

Run the test with an isolated empty Triton disk cache, or otherwise ensure missing variants cannot be served from disk.
</issue_to_address>

### Comment 4
<location path="docs/benchmarks/STRIX_HALO.md" line_range="237" />
<code_context>
 biases against separate bf16 forwards of every prompt (1–8 questions over one state, several requests in one sequence
-and the same request alone, several forwards per call with a request bisected, determinism), plus the mode dispatch of
+and the same request alone, several forwards per call with a request bisected, determinism), and the start-up warm-up
+(after it, no row count of 20–5,000 tokens with 1–528 readout rows compiles a kernel), plus the mode dispatch of
 `basal-serve` and `basal-bench`. Full suite on this machine: 76 passed, 3 skipped (MLX / Apple only); on engine 2.0.0,
 511 passed, 19 skipped (MLX and the extras not installed).
</code_context>
<issue_to_address>
**Published test count is stale**

When the listed full-suite total is read as describing the suite after this PR, the coverage paragraph now includes the new GPU warm-up test, but the following full-suite total still says “76 passed.” With that test passing on the documented GPU setup, the reported total undercounts the updated suite.

Update the full-suite totals to reflect the added test, or label them as results from a pre-PR run.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread basal/strix.py Resolved
Comment thread tests/test_strix.py Resolved
Comment thread tests/test_strix.py Resolved
Comment thread docs/benchmarks/STRIX_HALO.md Resolved
claude and others added 2 commits October 24, 2026 19:24
A request that packs to one token needed the L=1 copies of _rope and
_attn_fwd, which the warm-up forwards (lengths 17 and 32) never compiled:
WARM_FORWARDS now starts with (1, 1), and the warm-up test runs L=1 too.

The test skips unless triton.knobs.runtime.jit_cache_hook exists (a Triton
with knobs but no such hook raised AttributeError instead of skipping), and
says why Triton's disk cache cannot hide a missing copy: the hook runs at
every miss of the in-process cache, before the disk cache is read.

STRIX_HALO.md: the warm-up test covers 1-5,000 tokens; the full-suite
totals are labelled as the run from when --mode strix was added.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QxYyiinXyVC9b1Gf1vFgAx
STRIX_HALO.md, Tests: tests/test_strix.py 31 passed with Triton's disk
cache filled and empty; full suite 834 passed, 7 failed, 25 skipped. The
7 also fail on 2.4.1 without the warm-up, in PyTorch's attention on ROCm:
test_gemma4 needs efficient attention (experimental on ROCm, head size up
to 256), test_cascade_cuda needs seqused_k and the packed log-sum-exp
layout, and test_compact_varlen's bottom-right causal case differs.

Start-up remeasured with the one-token warm-up, basal-serve to the first
/health, two runs each: 12.7-12.8 against 7.7-7.8 s at the first start on
a machine, 5.6 against 5.4-5.5 s with a filled Triton cache.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@rkinas

rkinas commented Oct 28, 2026

Copy link
Copy Markdown
Owner

Thank you, Michał! The start-up warm-up for --mode strix is in basal 2.5 with your commits as you wrote them.

We also tested it on a Strix Halo machine of our own (Radeon 8060S): your fix does what it says (no Triton compile during requests). Answers matched --mode eager bf16 on 99.2% of 1,000 prompts, just under our 99.5% bar for marking a path as verified, so the Strix Halo section stays "community-maintained, not yet verified on our hardware". Two additions in 2.5: HARDWARE.md says start-up needs a C compiler (sudo apt install build-essential), and the GPU wait now spins for the first 0.3 s, so a short question takes 161 ms instead of 390 ms. We will look at the remaining flips in 2.5.1. The PR will close when 2.5 is published on main.

@rkinas
rkinas merged commit 3315010 into rkinas:main Nov 2, 2026
1 check passed
rkinas added a commit that referenced this pull request Nov 2, 2026
@kardysm

kardysm commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

@rkinas

Thanks, got it

It took me a while to take a little bit of time to start investigation on the matching.
I'll need more time for a deeper dive and analyzing the report below, but I wanted to drop raw analysis in case you'd like to glance at it.

It seems it might be challenging to achieve 99.5%+ results (and keep the speed) as it seems eager mode might not agree with itself, raw report draft below

https://claude.ai/artifact/593d24ueKo3GFkhYBJ15zb

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.

3 participants