Skip to content

perf: --mode strix, Triton kernels for AMD Strix Halo (gfx1151), on basal 2.0.0 - #2

Merged
kardysm merged 2 commits into
mainfrom
strix-halo-perf
Oct 16, 2026
Merged

kardysm merged 2 commits into
mainfrom
strix-halo-perf

Conversation

@kardysm

@kardysm kardysm commented Oct 15, 2026 •

Copy link
Copy Markdown
Owner

Code and tests only: one commit (b2bc0e4) touching basal/strix.py, basal/server.py, basal/bench.py and tests/test_strix.py. The docs, the benchmark scripts and the raw results are in #3, which is stacked on this branch; merge this PR first.

Rebased onto basal 2.0.0

This is #1 again, rebased onto upstream main at 45cf199 (af1ce43 feat: basal 2.0.0 plus three docs commits). #1 was merged into the fork's 1.5-based main. That main has been reset to upstream, and the old merge stays on the branch strix-1.5-merged (be2e2dc).

What changed against #1:

  • streams, inflight = False, 1 on StrixHaloFastBackend. In 2.0, GraphBackend declares streams = True / inflight = 2, and the server then calls run_shared(..., done=callback) with two calls at once. The strix backend runs its own run_shared (as GGUFBackend and MPSBackend do), so it declares the same values they do. Without this line every request through --mode strix would fail with a TypeError.
  • Docs: upstream shrank the README to an index, so the strix row of the modes table goes to docs/SERVING.md (in docs(strix): --mode strix benchmarks, HARDWARE.md and SERVING.md (stacked on #2) #3). This was the only rebase conflict.
  • Everything else strix.py uses from the engine is the same in 2.0: _units / _readout / _assemble, the five-field packed row, PREFILL, and the readout rows taken from lm_head. The 2.0 option-code readout goes through the same _readout(h, lids).

basal-2.0-4.5B through --mode strix

basal-2.0-4.5B has the architecture of basal-1.5 (Llama, 60 layers, hidden 2048, GQA 16/2, biases) and runs through --mode strix unchanged. Against --mode gguf with basal-2.0-4.5B-Q8_0.gguf, interleaved A/B with both servers up (each shape sent to both engines in alternating order, median of 5 rounds; the script bench_ab.py is in #3), so thermal drift and the power limit hit both alike:

request prompt tokens gguf strix speed-up
S (≈100 tokens), 1 question 201 136 ms 144 ms 0.94×
S, 5 questions 1,508 277 ms 203 ms 1.37×
M (≈570), 1 question 669 397 ms 263 ms 1.51×
M, 10 questions 8,825 816 ms 464 ms 1.76×
L (≈2,000), 1 question 2,109 1.27 s 714 ms 1.77×
L, 5 questions 16,772 1.41 s 788 ms 1.79×
XL (≈6,000), 1 question 6,163 4.16 s 2.41 s 1.73×
XL, 5 questions 49,204 4.37 s 2.52 s 1.73×
XL, 20 questions 141,818 5.25 s 2.90 s 1.81×
single questions, 32 clients – 11.5/s 19.0/s 1.65×
  • Speed: faster than gguf on every shape except one short question at a time. The long-state gain is larger than with basal-1.5 (XL, 1 question: 1.70× in the matrix, 1.52× with 1.5). Each added question costs 12–28 ms (gguf 37–55 ms).
  • Answers: 142/144 decisions equal to the fp32 reference for both engines (strix mean |Δp| 0.0047, max 0.028; gguf 0.0064, 0.068). The two others are one question that fp32 puts at 0.502 / 0.498 and both engines the other way round. All 26 edge-case decisions equal fp32. strix and gguf differ on 4 of 188 matrix decisions, all multi-label yes/no on XL at 0.47–0.54.
  • Costs: start-up 6.2 s, 10.1 GiB GTT (gguf 3.3 s, 5.8 GiB).
  • basal-1.5 → 2.0: prompt format 2 reads one option order by default (1.5 read two), so requests carry about half the prompt tokens. With strix: S with 20 questions 1.08 s → 467 ms, XL with 20 questions 4.57 → 3.00 s, 32 clients 10.9 → 20.3/s.
  • The full request matrix, edge cases, fp32 reference and raw results are in docs(strix): --mode strix benchmarks, HARDWARE.md and SERVING.md (stacked on #2) #3. A one-engine-at-a-time matrix run agrees with the A/B within 5% except S with 1 question (an outlier: strix 231 ms there, 142–148 ms in every A/B round).

The numbers in the sections below were measured with basal-1.5-4.5B on #1 (981b354).

Summary

--mode strix is a basal forward written for AMD Strix Halo (Ryzen AI Max+ 395, Radeon 8060S, gfx1151), on basal-1.5; basal-2.0 runs through it unchanged. It keeps the bf16 weights and replaces the kernels that a profile showed to be slow on this GPU with Triton ones. On a request matrix with basal-1.5 it is 1.12–1.75× faster than --mode gguf and agrees with an fp32 reference on 144 of 144 decisions. With basal-2.0 it is 1.37–1.81× faster except for one short question at a time (0.94×), and agrees with fp32 on 142 of 144 (the other two are a 0.502 / 0.498 tie).

It is opt-in by name (basal-serve --mode strix, basal-bench --modes strix). Every other mode is unchanged: basal/engine.py is not touched, and server.py / bench.py only gain the dispatch for the new mode. The new module is basal/strix.py. It needs no new dependencies (Triton ships with PyTorch on ROCm) and adds no CLI flags.

Why: where --mode gguf spends its time

Every request is at least 98.5% GPU decode, at 16–19 useful TFLOPS whatever the size. GPU time by operation, from llama.cpp's Vulkan performance logger:

operation S, 1 q L, 1 q XL, 1 q XL, 20 q speed
FFN matmuls 69% 60% 51% 47% 21–25 TFLOPS
flash attention 2.5% 10% 23% 28.5% ~11 TFLOPS on long rows
element-wise (bias and residual adds, SwiGLU, norms) 16% 18% 15.5% 14.5% memory-bound, fp32
attention projections 12.5% 12.4% 10.4% 9.7% q / o 18, k / v 8–9 TFLOPS

The model has biases on every linear layer, and llama.cpp adds each one in a separate pass. This GPU sustains ~35–40 TFLOPS on matmuls. The CPU, weight bandwidth, clock ramp-up and llama.cpp's batch size are not limits.

What it does

kernel at ~6k tokens stock
attention over the packed prefix trie, GQA-packed ~20 TFLOPS AOTriton causal ~10
gate + up + biases + SwiGLU in one kernel ~32 TFLOPS F.linear + silu × up ~17
qkv / o / down with bias and residual in the epilogue, tile configs per row count o 2.4 ms / layer F.linear + add 3.7 ms
  • Attention mask. The block mask of a packed request (the state once, then every question and option order) becomes an interval per key. Depth-first packing puts each subtree in one contiguous range, so key k is visible to query q iff k ≤ q < sub_end[k]. Key blocks no query can see are skipped, and fully visible ones run without a mask. A packed row therefore costs what a causal row of the same length costs.
  • One sequence per chunk. Rows of several requests are separate trees in one sequence, so there is no padding, no captured shapes and no graphs. Requests over 16,384 tokens are bisected as in GraphBackend.
  • Smaller pieces: RMSNorm and rotary kernels, the last layer computed only for the readout rows, and the GPU awaited by polling an event (ROCm's synchronize spins a CPU core at 100%).
  • Rounding follows the stock bf16 forward step by step. The Hugging Face modules keep views of the fused q / k / v weights, so the evidence head still runs the stock model.

Results: request matrix over HTTP, p50

state 1 question 5 questions 20 questions
S (≈100 tokens) 178 → 159 ms (1.12×) 573 → 348 ms (1.65×) 1.79 → 1.08 s (1.66×)
M (≈570) 439 → 289 ms (1.52×) 817 → 480 ms (1.70×) 2.12 → 1.25 s (1.70×)
L (≈2,000) 1.28 s → 736 ms (1.74×) 1.73 → 1.09 s (1.59×) 3.22 → 2.12 s (1.52×)
XL (≈6,000) 4.16 → 2.73 s (1.52×) 4.78 → 3.28 s (1.46×) 6.77 → 4.57 s (1.48×)
  • Speed: fastest on all 20 shapes. --mode fast-nocompile as shipped is 2–12× slower than strix here, at 888 s start-up and 32 GiB.
  • Throughput, single questions over short states: 32 clients 7.7 → 10.9/s.
  • Answers: 144/144 decisions equal to fp32 (mean |Δp| 0.0042; gguf 143/144, 0.0067) and 26/26 edge cases.
  • Costs: 10.0 GiB GTT against 5.8 for gguf; start-up 6–7 s.

Full tables, method and raw results: #3 (docs/benchmarks/STRIX_HALO.md).

Limits

  • Long states stay below 2×. Their matmuls are 58 TFLOP at ~35 TFLOPS sustained, and under strix the package runs at its power limit (~160 W, then ~140 W after ~25 s), with the GPU at 2.15–2.33 GHz. A single XL forward on a cool GPU takes 2.37 s (1.76×).
  • One short question at a time is faster with gguf (141 vs 159 ms): the bf16 weights are 9 GB per forward, the Q8_0 file 5 GB.
  • Model shapes: Llama models with silu, a power-of-two hidden size and an FFN size divisible by 64 (checked at start-up); bf16 only.
  • Hardware: tile configs were tuned on the 8060S, and the mode has not been run on other GPUs.

Tests

  • tests/test_strix.py, 18 cases:

    • every Triton kernel against its stock counterpart: attention against a dense masked softmax over rows of several requests (including readout-only queries), rotary (bit-identical), projections for every row-count config, FFN input and RMSNorm;
    • the interval mask against the block mask it replaces;
    • the backend on a tiny random Llama with biases against separate bf16 forwards: questions over one state, several requests in one sequence against the same request alone, chunking and bisection, determinism;
    • the mode dispatch.

    It caught rows of a later request in one sequence turning into NaN, which is fixed.

  • Full suite on the 8060S, rebased onto 2.0.0: 510 passed, 20 skipped (MLX, and the media / mcp extras not installed, training-side code). tests/test_format2_vectors.py passes against the basal-2.0-4.5B tokenizer.

  • Engine 2.0.0 installed into a venv with llama-cpp-python (Vulkan): 511 passed, 19 skipped; tests/test_strix.py 18 passed.

  • Real model: on perf: --mode strix, Triton kernels for AMD Strix Halo (gfx1151) #1, answers equal to the benchmarked basal-1.5 run (max |Δp| 0.000). basal-2.0-4.5B: request matrix, edge cases, fp32 reference and the A/B above.

🤖 Generated with Claude Code

…ls for AMD Strix Halo (gfx1151)

A profile of --mode gguf on the Radeon 8060S: every request is >=98.5% GPU decode at
16-19 useful TFLOPS; FFN matmuls take 47-69% of the GPU time (21-25 TFLOPS), flash
attention up to 28.5% on long states (~11 TFLOPS), unfused bias / residual / SwiGLU
passes ~15% (the model has biases on every linear layer). basal/strix.py
(StrixHaloFastBackend) keeps the bf16 weights and replaces those kernels:

- attention: Triton flash attention over the packed prefix trie, GQA-packed. The block
  mask becomes an interval per key (depth-first packing: key k is visible to query q
  iff k <= q < sub_end[k]); key blocks no query can see are skipped, fully visible ones
  run unmasked. ~20 TFLOPS at 6k tokens (AOTriton ~10)
- FFN input: gate, up, biases and SwiGLU in one kernel, ~32 TFLOPS (F.linear + silu*up ~17)
- qkv / o / down: Triton matmuls with the bias and residual add in the epilogue, tile
  configs per row count
- RMSNorm and rotary kernels, the last layer for the readout rows only, all rows of a
  chunk one sequence (no padding, shapes or graphs), the GPU awaited by polling an event
  (ROCm's synchronize spins a core at 100%); rounding as the stock bf16 forward

Request matrix over HTTP against gguf, basal-1.5-4.5B: 1.12-1.75x (S 1 q 178 -> 159 ms,
L 1 q 1.28 -> 0.74 s, XL 1 q 4.16 -> 2.73 s, XL 20 q 6.77 -> 4.57 s; 32 clients
7.7 -> 10.9/s); 144/144 decisions equal to an fp32 reference, 26/26 edge cases.
basal-2.0-4.5B (same Llama shape) runs through it unchanged: 1.37-1.81x except one
short question at a time (136 -> 144 ms, 0.94x); XL 20 q 5.25 -> 2.90 s, 32 clients
11.5 -> 19.0/s; 142/144 equal to fp32 (the other two are one 0.502 / 0.498 question),
26/26 edge cases. GTT 10.0 GiB, start-up 6-7 s.

Opt-in by name (--mode strix in basal-serve and basal-bench); every other mode and
basal/engine.py are unchanged. Like GGUFBackend it runs its own run_shared, so it
declares streams = False, inflight = 1 (no early readouts, one engine call at a time).
Tests: tests/test_strix.py (kernels against their stock counterparts, the interval mask
against the block mask, the backend against separate forwards).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… --deterministic; safe warmup

From the review of rkinas#14:

- StrixHaloFastBackend.unsupported(cfg) replaces the start-up shape check. Every
  tile config must divide its projection: the matmuls have no column or depth
  masks, so a qkv width that is not a multiple of 128 left its last columns
  unwritten. Head size and query heads per kv head must be powers of two
  (tl.arange; other shapes failed to compile), head size at least 16. RoPE
  types whose frequencies depend on the sequence length (dynamic, longrope)
  are refused, since the tables are computed once. basal-1.5 and basal-2.0
  pass unchanged.
- ROCm only: the kernels take AMD launch options (waves_per_eu). On CUDA the
  mode now refuses at start-up, and the GPU tests skip.
- --deterministic accepts strix. It already runs one request per forward, and
  the Triton kernels have no atomics or split-K, so an answer depends only on
  its own request. Tested under torch.use_deterministic_algorithms: identical
  answers, no refused op.
- Warmup token ids stay within the vocabulary and lengths within the context.
- Docstring: a single prompt over TOKEN_BUDGET runs alone in one forward, as
  in GraphBackend.

Tests: 11 new in tests/test_strix.py; suite 521 passed, 20 skipped.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kardysm
kardysm merged commit 9248c13 into main Oct 16, 2026
kardysm added a commit that referenced this pull request Oct 16, 2026
docs(strix): --mode strix benchmarks, HARDWARE.md and SERVING.md (stacked on #2)
kardysm pushed a commit that referenced this pull request Oct 19, 2026
@lukaspoloki)

Conflicts: the MPS commit of the branch (c531ba3) is not taken, since main has MPS from #4: README.md, basal/engine.py, basal/server.py, basal/bench.py and tests/test_engine.py stay as on 2.2. Kept: basal/viz.py, basal/viz.html, the basal-viz script, viz.html as package data and the segments test. The port to the 2.2 engine follows.
kardysm pushed a commit that referenced this pull request Oct 19, 2026
… option orders, calibration and answer

Port of #2 to the current engine without its MPS backend (main has MPS since #4): the page runs a basal-serve Server in process (--mode mps on Apple Silicon, eager elsewhere) and reads its PyTorch model for the per-layer readout. Prompts, option codes (up to 255, format 2 from basal.json) and option orders (one by default for format-2 models; --orders 1|2) come from Server.jobs_for; temperatures per type and option-count bucket and the per-type certified thresholds from the calibration file basal-serve loads; multi questions are explained per label, act and tool by their base type. The code logits are read in fp32 as the engines read them. Each request is also answered by Server.decide and the page shows the difference. The page handles one or two orders and types without a certified threshold; question types the form does not edit (act, tool, tasks) are sent as JSON. Llama-architecture models only (refused otherwise). Docs: SERVING.md, "See how a decision is made". Checked with basal-2.0-mini on MPS and CPU, bundled examples and a multi / act / 30-option request: equal to the served answer for single questions (0 on MPS), within 0.006 for requests with several questions (one packed row over the state, bf16).
kardysm pushed a commit that referenced this pull request Oct 19, 2026
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