Repository navigation
[Engine] Inkling 2 on AMD under WSL2: simpler decode graph - #293
Open
okada-shogo wants to merge 2 commits into
Open
okada-shogo wants to merge 2 commits into
okada-shogo wants to merge 2 commits into
Conversation
…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>
This was referenced Nov 24, 2026
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.
Problem and result
On AMD, Inkling 2 decoded slower with CUDA/HIP graphs than without them:
--no-graphsmade 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-graphsis 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:
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.The fix, on HIP only:
card_routes(): every routed expert is in VRAM, orcard_far_is set). The whole pass is then one graph, which is kept.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, onewarm-up request first in each process. Mean of 3 runs, the builds' order rotated each round.
Prompt tok/s, higher is better (same runs):
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:--no-graphsPrompt tok/s on native, higher is better (same runs; "prompt 8K" is the read of the 8K prompt in the decode run):
--no-graphsNative 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)
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:
--no-graphsThe 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):
Kernels per decode token: UD-Q2_K_XL 1,609 → 1,106, IQ4_NL 1,482 → 1,072.
Related discussion
none
Approach
inkling2.cpp:kBranchis false on HIP, as on Metal. The sink's and taps' products then run on the main streamthrough the same
gemv_bf16()launch.Engine::layer_records()(new, default true): Inkling 2 returns false on HIP.run()of one token then captures itslayers in graphs only when
card_routes()holds (all experts cached, orcard_far_, which also has a whole-pass graph).Windows (n > 1) and
step()keep main's graphs. Other families and backends keeptrue.Validation
Passed:
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_teston both cards: 336 checks (RX 9070 XT) and 330 (RX 7800 XT), 0 failed.gfx1100;gfx1101;gfx1201 and CUDA sm_75;sm_86 on our builders.
card_routes()/ one-token rule (review fix) does not change the measured runs:card_far_stays off on HIPwithout the pinned mirror, and the decode tokens above are single-token calls.
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.RX 7800 XT with 12 cores and 23 GB RAM. Measured on main cdfae80 + this PR.
poly_inkling2_test425 checks, 0 failed; frozen identity vs main36e654b (
STRATA_GPU_EXPERTS=900 STRATA_FREEZE_EXPERTS=1, IQ4_NL 302 +64, fp16 KV, graphs on,--top-probs 20, samecache set fnv d399a9b142b98855): SAME.
Failed:
Not run:
Limits
Credits: the
--no-graphsfinding is from our gap profiles against the amd-preview branch.🤖 Generated with Claude Code