Repository navigation
Conversation
On SWA visits with loop messages and B <= 12 (every single-token decode
step and every tree verify), the three loop controllers (attn, k, v) all
take the mixed input in0 as their source, and k1_loop_ctrl_up3 got
dst = {in0, in1, in2}. The kernel runs the three channels as separate
blocks of one launch (blockIdx.z) with no ordering between them, so the
channel 0 blocks overwrote in0 while the k and v blocks of the same
launch were still reading it. k and v then saw either the mixed input or
the attn controller's output, depending on block order, and identical
greedy requests gave different tokens from run to run. Prompt reads
(B > 12) were not affected: that path copies in0 to in1 / in2 first, and
the CPU backend gives every channel its own copy as well.
Channel 0 now writes to mx3, which SWA visits do not use (only global
visits mix three attnres queries into it, before the controllers), and
q_in and the 3-channel input RMSNorm follow it. k and v keep reading the
unchanged in0. No extra copy or kernel launch; global visits and the
B > 12 path are unchanged. Both call sites are fixed: the forward pass
and the tree verify.
This changes greedy output on HIP for any prompt that reaches decode.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SG5G8VwxLyU5bwfggEz6AU
This was referenced Nov 23, 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
Fixes #6736. On HIP,
k1_loop_ctrl_up3updatesin0in place for channel 0 while the k and v channels of the same launch still readin0on sliding-window visits. Which value k and v see depends on block timing, so greedy decode withstrata-inklingdoesn't repeat, and some steps compute k and v from the wrong input.With this PR, on a Radeon AI PRO R9700 (gfx1201), greedy output repeats exactly (9/9 prompts, against 1/9 before), with
--draft offand with DSpark, on currentmainand on 0.2.19, also across separately started servers. Decode speed doesn't change.Related discussion
#6736 has the measurements that locate the race (per-step and per-layer state hashes). #6665 depended on this to show that its checkpoint resume is token-exact; the results are below.
Approach
On SWA visits all three loop controllers read
in0(src_p = {in0, in0, in0}), and channel 0 used to write its result back toin0. Now channel 0 writes tomx3, andq_inpoints there, soin0stays unchanged until every channel has read it.mx3holds B × 3 × D floats and is only written on global visits (the attnres mix), so it's free on SWA visits. The q, r, gate and sink projections already readq_in, so the change is the destination pointer and the input of the 3-channel norm. This is done at both call sites: the forward pass and the DSpark tree verify.I chose this over the alternatives:
in0toin1/in2first, as the B > 12 path does. It's correct but adds 2 copies of B × D × 4 bytes on each of the 20 affected visits per token.Visits with B > 12, global visits and the CPU backend don't change. The CUDA, Metal and SYCL backends don't have this kernel.
Validation
Environment: I wrote and tested the change on Strata 0.2.19 (
c6f6427d9). This PR's commit is the same 12 changed lines re-applied on currentmain(73d4f4196); it didn't cherry-pick because the file is now LF instead of CRLF. OnmainI repeated the build and the repeat test (marked "main" below); everything else ran on 0.2.19. Both:strata-inklingbuilt for gfx1201 only, standalone CMake ofengine/src/inkling2with the clang in the Strata venv's ROCm SDK (-DSTRATA_ENABLE_HIP=ON -DSTRATA_HIP_ARCHS=gfx1201), the same flags with and without the commit; Radeon AI PRO R9700 32 GB; Linux x86_64; Inkling-2-Mini SQ-20; served by the 0.2.19 serve in both cases,--parallel 1, BF16 KV. Outputs are compared by token id from the engine's proto log.Passed:
HIP build, gfx1201,
mainand 0.2.19: no new warnings.Repeat, same request twice, 9 prompts (code, SQL, bash, a translation, a word problem, an explanation, 2K- and 8K-token documents), 200 tokens:
--draft off, main--draft off, 0.2.19Same output as copying
in0toin1/in2before the kernel (a debug build): 9/9 token-identical in both modes.State hashes (debug-only build, not part of the PR) after every decode step, covering logits, final hidden row, the SWA and global KV rows written that step, and ShortConv rows: identical over 96 steps on every case. Before, they differed from step 1.
Speed,
--draft off, alternating before/after/after/before, 7 prompts × 400 tokens per run:With DSpark the numbers depend on how many drafts are accepted, which changes with the generated text, so they aren't comparable before and after.
With [Engine] Inkling: resume multi-turn prompts from a prompt checkpoint on HIP (#6627) #6665 on top: its checkpoint resume gives the same tokens as the existing exact-prefix resume at 5,002 and 19,741 prompt tokens, with
--draft offand with DSpark. Its exact-prefix path is also token-identical to this commit alone.Failed: none.
Not run:
--parallelabove 1.hip/ink_hip_backend.hip.cpp.Limits
--draft offstill give different greedy output after about 75 to 280 tokens on this card (at 200 tokens: 5/9 identical onmain, 3/9 on 0.2.19), while each mode repeats exactly. That matches [Engine] Inkling-2-Mini SQ-20: DSpark changes greedy output on long prompts, and is non-deterministic at 41k #6671 on Metal; this PR doesn't change it.🤖 Generated with Claude Code
https://claude.ai/code/session_01SG5G8VwxLyU5bwfggEz6AU