Skip to content

[Engine] Inkling 2 on AMD under WSL2: simpler decode graph - #293

Open
okada-shogo wants to merge 2 commits into
simplexai-labs:mainfrom
okada-shogo:port/hip-no-pass-graph
Open

okada-shogo wants to merge 2 commits into
simplexai-labs:mainfrom
okada-shogo:port/hip-no-pass-graph

Conversation

@okada-shogo

@okada-shogo okada-shogo commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Problem and result

On AMD, Inkling 2 decoded slower with CUDA/HIP graphs than without them: --no-graphs made UD-Q2_K_XL decode 35% faster on an RX 9070 XT. This PR removes the two graph features that cost time on HIP. Under WSL2 (the rented Salad hosts), UD-Q2_K_XL decode becomes 39-40% faster on an RX 9070 XT and 73% faster on an RX 7800 XT; IQ4_NL is 6.5-6.8% faster. On native Linux the gain is gone: the same RX 9070 XT measures -0.9% to +0.5% (see the native table), and --no-graphs is no faster than main there either. The graph cost is a WSL2/dxg cost (host syncs and submissions are 2-3x slower there). The outputs are the same bits, and CUDA and Metal are unchanged.

The two causes:

  1. layer_head() sends the BF16 products of the attention sink and the convolution taps to a side stream and joins it again, inside the graph of the whole decode pass. On HIP that fork and join cost more than they save. UD-Q2_K_XL has these products in BF16.
  2. When some experts are outside VRAM (IQ4_NL on a 16 GB card), each layer is captured and replayed as its own small graph. On HIP those small replays were slower than plain launches.

The fix, on HIP only:

  • No side stream, as on Metal.
  • A single token's layers are captured only when its experts are routed on the card (card_routes(): every routed expert is in VRAM, or card_far_ is set). The whole pass is then one graph, which is kept.
  • Windows of several tokens keep their graphs, and step() (--batch) is not touched: Inkling 2 runs one sequence on AMD.

Decode tok/s, higher is better. 256 tokens written after the prompt, --serve, fp16 KV, 32K context, default flags, one
warm-up request first in each process. Mean of 3 runs, the builds' order rotated each round.

Card Model Measure main this PR alone Change
RX 9070 XT 16 GB UD-Q2_K_XL decode after 302 60.0 83.7 +39.5%
RX 9070 XT 16 GB UD-Q2_K_XL decode after 8K 56.5 78.3 +38.6%
RX 9070 XT 16 GB IQ4_NL decode after 302 41.4 44.2 +6.8%
RX 9070 XT 16 GB IQ4_NL decode after 8K 36.4 38.8 +6.5%
RX 7800 XT 16 GB UD-Q2_K_XL decode after 302 38.0 65.7 +72.7%
RX 7800 XT 16 GB UD-Q2_K_XL decode after 8K 34.9 60.5 +73.4%

Prompt tok/s, higher is better (same runs):

Card Model Measure main this PR alone Change
RX 9070 XT 16 GB UD-Q2_K_XL prompt 2K 1247.2 1281.2 +2.7%
RX 9070 XT 16 GB UD-Q2_K_XL prompt 8K 1285.5 1295.4 +0.8%
RX 9070 XT 16 GB IQ4_NL prompt 2K 1066.3 1080.5 +1.3%
RX 9070 XT 16 GB IQ4_NL prompt 8K 764.0 780.3 +2.1%
RX 7800 XT 16 GB UD-Q2_K_XL prompt 2K 418.6 414.3 −1.0%
RX 7800 XT 16 GB UD-Q2_K_XL prompt 8K 412.1 414.4 +0.5%

Native Linux (Fedora, kernel 7.2, ROCm 7.2.4, RX 9070 XT 16 GB, Ryzen 7 7800X3D, --threads 11), same method as above. Decode tok/s, higher is better, mean of 3 runs:

Card Model Measure main main --no-graphs this PR alone Change (PR vs main)
RX 9070 XT, native UD-Q2_K_XL decode after 302 65.7 65.3 65.1 -0.9%
RX 9070 XT, native UD-Q2_K_XL decode after 8K 61.7 61.2 61.1 -1.0%
RX 9070 XT, native IQ4_NL decode after 302 64.0 64.2 64.3 +0.5%
RX 9070 XT, native IQ4_NL decode after 8K 58.7 58.8 58.7 0.0%

Prompt tok/s on native, higher is better (same runs; "prompt 8K" is the read of the 8K prompt in the decode run):

Card Model Measure main main --no-graphs this PR alone Change (PR vs main)
RX 9070 XT, native UD-Q2_K_XL prompt 2K 1401.4 1403.7 1402.9 +0.1%
RX 9070 XT, native UD-Q2_K_XL prompt 8K 1372.1 1372.6 1373.7 +0.1%
RX 9070 XT, native IQ4_NL prompt 2K 1104.0 1117.1 1117.5 +1.2%
RX 9070 XT, native IQ4_NL prompt 8K 1244.5 1248.6 1244.2 0.0%

Native runs differ by 0.5 tok/s or less inside a build, so the -0.9% on UD-Q2_K_XL is real but small. Experts in VRAM are equal on all three builds (IQ4_NL 2,336 of 3,072; UD-Q2_K_XL 3,058 of 3,072). Native sync costs about 18 us a round trip against 41-51 us on WSL2, so the graphs save little there.

Experts in VRAM are the same on both sides (UD-Q2_K_XL 3072 of 3072; IQ4_NL about 2,376 of 3,072 on the RX 9070 XT).

Each run (tok/s)
Card Model Measure Build Run 1 Run 2 Run 3
RX 9070 XT 16 GB UD-Q2_K_XL decode after 302 main 60.9 59.8 59.3
RX 9070 XT 16 GB UD-Q2_K_XL decode after 302 this PR 83.8 83.8 83.5
RX 9070 XT 16 GB UD-Q2_K_XL decode after 8K main 56.5 56.6 56.4
RX 9070 XT 16 GB UD-Q2_K_XL decode after 8K this PR 78.4 78.5 78.0
RX 9070 XT 16 GB IQ4_NL decode after 302 main 41.4 41.5 41.2
RX 9070 XT 16 GB IQ4_NL decode after 302 this PR 44.2 44.4 44.0
RX 9070 XT 16 GB IQ4_NL decode after 8K main 36.4 36.4 36.4
RX 9070 XT 16 GB IQ4_NL decode after 8K this PR 38.8 38.9 38.6
RX 7800 XT 16 GB UD-Q2_K_XL decode after 302 main 39.4 39.6 35.1
RX 7800 XT 16 GB UD-Q2_K_XL decode after 302 this PR 66.0 65.1 65.9
RX 7800 XT 16 GB UD-Q2_K_XL decode after 8K main 38.1 32.5 34.0
RX 7800 XT 16 GB UD-Q2_K_XL decode after 8K this PR 60.3 60.4 60.7
What each of the two changes does (RX 9070 XT, decode after 302, tok/s)

One test binary with switches, 3 runs each, mean. The "no whole-pass graph" column is from an earlier set of 3 on the same box. "Per-layer graphs only inside a whole-pass graph" is the second change alone:

Model main --no-graphs no side stream no whole-pass graph per-layer graphs only inside a whole-pass graph both (this PR)
UD-Q2_K_XL 59.6 81.0 83.6 72.4 59.3 83.8
IQ4_NL 41.7 43.8 41.4 41.3 44.0 42.9

The side stream causes the UD-Q2_K_XL loss; the per-layer graphs cause the IQ4_NL loss. The IQ4_NL "both" mean holds one
slow run (41.1, the others 44.2 and 43.5); the final build above gives 44.2.

Kernels per decode token (rocprof, 64 tokens after 302, RX 9070 XT): UD-Q2_K_XL 1,706 → 1,609; IQ4_NL 1,584 → 1,482.

Together with #294 and #295 (RX 9070 XT, decode tok/s)

This PR alone vs this PR + #294 (attention projections grouped into one launch per quant type) + #295 (clip and KV-store kernels fused). Same run setup, mean of 3. Identity between the two is SAME (prompts of 302, 2,048 and 8,192 tokens; both files):

Card Model Measure this PR alone + both PRs Change
RX 9070 XT 16 GB UD-Q2_K_XL decode after 302 83.7 91.9 +9.8%
RX 9070 XT 16 GB UD-Q2_K_XL decode after 8K 78.2 85.2 +9.0%
RX 9070 XT 16 GB IQ4_NL decode after 302 44.0 46.8 +6.4%
RX 9070 XT 16 GB IQ4_NL decode after 8K 38.6 40.8 +5.6%

Kernels per decode token: UD-Q2_K_XL 1,609 → 1,106, IQ4_NL 1,482 → 1,072.

Related discussion

none

Approach

  • inkling2.cpp: kBranch is false on HIP, as on Metal. The sink's and taps' products then run on the main stream
    through the same gemv_bf16() launch.
  • Engine::layer_records() (new, default true): Inkling 2 returns false on HIP. run() of one token then captures its
    layers in graphs only when card_routes() holds (all experts cached, or card_far_, which also has a whole-pass graph).
    Windows (n > 1) and step() keep main's graphs. Other families and backends keep true.
  • Same bits: the same kernels in the same order. Only the graph capture and the stream change.

Validation

Passed:

  • HIP identity (end to end on the cards, not a unit test; there is no unit test for graph-capture choices), main vs this PR, RX 9070 XT and RX 7800 XT: STRATA_GPU_EXPERTS=1500 STRATA_FREEZE_EXPERTS=1 strata-poly --tokens <ids> --max-new N --top-probs 20 --kv fp16, prompts of 302 (+64), 2,048 (+16) and 8,192 (+16) tokens:
    SAME (ids and every top-20 line byte for byte). UD-Q2_K_XL on both cards, IQ4_NL on the RX 9070 XT.
  • poly_inkling2_test on both cards: 336 checks (RX 9070 XT) and 330 (RX 7800 XT), 0 failed.
  • Builds: HIP on the boxes (ROCm 7.2.4, gfx1201 and gfx1101); after the rebase onto 36e654b, HIP
    gfx1100;gfx1101;gfx1201 and CUDA sm_75;sm_86 on our builders.
  • The card_routes() / one-token rule (review fix) does not change the measured runs: card_far_ stays off on HIP
    without the pinned mirror, and the decode tokens above are single-token calls.
  • Native Linux: frozen identity main vs this PR on the RX 9070 XT (STRATA_FREEZE_EXPERTS=1, equal placement, --top-probs 20, fp16 KV): SAME for UD-Q2_K_XL and IQ4_NL at prompts of 302 (+64), 2,048 (+16) and 8,192 (+16) tokens.
  • Environment of the first tables: rented Salad containers (WSL2, /dev/dxg, ROCm 7.2.4). RX 9070 XT with a Ryzen 9 9900X3D and 62 GB RAM;
    RX 7800 XT with 12 cores and 23 GB RAM. Measured on main cdfae80 + this PR.
  • CUDA unchanged, RTX 2070 Super (sm_75), rebased branch: poly_inkling2_test 425 checks, 0 failed; frozen identity vs main
    36e654b (STRATA_GPU_EXPERTS=900 STRATA_FREEZE_EXPERTS=1, IQ4_NL 302 +64, fp16 KV, graphs on, --top-probs 20, same
    cache set fnv d399a9b142b98855): SAME.

Failed:

  • none observed

Not run:

  • Native Linux for the RX 7800 XT and for the other PRs on top of this one.
  • IQ4_NL timing on the RX 7800 XT: that host has 23 GB RAM and the 17.6 GB file was read from disk (minutes a run).
  • RX 7900 XT / XTX, native Linux or Windows.

Limits

  • The gain is a WSL2 gain. The first tables are from rented Salad hosts under WSL2; on native Linux (RX 9070 XT) this PR is neutral for IQ4_NL and 1% slower for UD-Q2_K_XL. Users on native Linux get the same bits but no speedup; Windows was not measured.
  • The Salad numbers are from rented consumer hosts, not a controlled timing box. The RX 7800 XT's main runs varied (35 to 40).
  • Prompt speed barely changes; the gain is decode.

Credits: the --no-graphs finding is from our gap profiles against the amd-preview branch.

🤖 Generated with Claude Code

…h layer recordings only for a whole pass

Same bits. On HIP, layer_head() no longer forks the sink's and the convolution taps' BF16 products to the side
stream inside the whole pass's recording (as on Metal): the fork and the join made the replay slower than one
stream. And a single token's layers (run() of one token) are recorded only when its experts are routed on the
card (card_routes(): every routed expert in VRAM, or card_far_), where the whole pass is one recording; otherwise
its launches go one by one, which was faster on AMD than per-layer recordings. Windows (n > 1) keep their
recordings, and step() is not touched (Inkling 2 runs one sequence on AMD). CUDA and Metal unchanged
(Engine::layer_records() defaults to true).

Decode after 302, 256 tokens, 3 rounds: RX 9070 XT UD-Q2_K_XL 60.0 -> 83.7 tok/s, IQ4_NL 41.4 -> 44.2;
RX 7800 XT UD-Q2_K_XL 38.0 -> 65.7. Identity SAME (frozen cache, top-20 lines, 302/2048/8192).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With the HIP doorbell (simplexai-labs#306) a token routes on the card, so the per-layer rule
for partial caches must not turn the token's recording off. bell_on() is false
on HIP without simplexai-labs#306, so this changes nothing on its own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@okada-shogo okada-shogo changed the title [Engine] Inkling 2 on AMD: decode without the BF16 side branch in the recorded pass (+40% to +73% UD-Q2_K_XL decode) [Engine] Inkling 2 on AMD: no side-stream fork inside the decode graph (+40-73% UD-Q2_K_XL decode) Nov 24, 2026
@okada-shogo okada-shogo changed the title [Engine] Inkling 2 on AMD: no side-stream fork inside the decode graph (+40-73% UD-Q2_K_XL decode) [Engine] Inkling 2 on AMD: drop the side stream and per-layer graphs from decode (+39-73% UD-Q2_K_XL decode, same bits) Nov 24, 2026
@okada-shogo okada-shogo changed the title [Engine] Inkling 2 on AMD: drop the side stream and per-layer graphs from decode (+39-73% UD-Q2_K_XL decode, same bits) [Engine] Inkling 2 on AMD: simpler decode graph (+39-73% UD-Q2_K_XL decode) Nov 24, 2026
@okada-shogo okada-shogo changed the title [Engine] Inkling 2 on AMD: simpler decode graph (+39-73% UD-Q2_K_XL decode) [Engine] Inkling 2 on AMD: simpler decode graph (faster decode) Nov 24, 2026
@okada-shogo okada-shogo changed the title [Engine] Inkling 2 on AMD: simpler decode graph (faster decode) [Engine] Inkling 2 on AMD under WSL2: simpler decode graph Nov 24, 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