Repository navigation
Conversation
_apply_attn_res_impl copied block_residual to a contiguous tensor before the fused kernel. Mono decode keeps the closed blocks in one bank and hands the seams it runs through the model -- most MLA layers' attention seams, and layer 0's MLP seam -- a slice of it, blocks[:, :n]. On a step of more than one row that slice is not contiguous, so each of those seams first copied [T, n, H]. The kernel already reads T and B by stride, so only the hidden dimension has to be unit-stride; the copy is now made only when it is not. Results are bitwise unchanged. GPU tests run every bank width, on the slice and on its contiguous copy, at 1, 6, 16, 48 and 130 tokens and each output variant (add_hidden, out_norm, the FP8 quant), and slices past block 0 and past token 0 at 1 and 16 tokens, and require byte-identical outputs; another checks that the kernel is handed the slice itself, not a copy. Signed-off-by: Rebecca Lee <rebecca.lee@amd.com>
Contributor
🏷️ CI GuideRuns automatically on every eligible PR before approval:
Heavy model tests:
|
Contributor
|
LGTM |
HaonanWang98
approved these changes
Nov 4, 2026
|
ci triage for db6ae8f:
|
This branch has not been deployed
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.
Summary
_apply_attn_res_implcopiesblock_residualto a contiguous tensor before the fused AttnReskernel. The kernel already reads the block residual by its token and block strides, so only the
hidden dimension has to be unit-stride; this PR copies only when it is not. Outputs are
bit-identical. Production builds its block residual with
torch.cat, which is contiguous, so itnever copied and nothing changes there. Mono decode, which passes slices of one block bank, saves
108 us of GPU time per target forward (0.8%) at the agentic recipe's C1 launch.
Motivation
Mono decode keeps the closed blocks in one bank,
blocks[T, 8, H], and passes a seam the blocksbefore it as
blocks[:, :n]. With more than one row andn < 8that slice has strides(8 H, H, 1), so the call copied it first: 22 copies per multi-row step (the attention seams ofMLA layers 3, 7, ..., 83, and layer 0's MLP seam; layers 87, 91 and 92 take the whole bank,
which is contiguous), 9.7 MB per step at C1.
Changes
br = block_residual if block_residual.stride(-1) == 1 else block_residual.contiguous().Performance
8x MI355X, the agentic recipe's C1 launch (mono decode on, 8-row verify steps), main against main
with this PR. GPU time of the 22 seams that copied, per target forward in rank 0's profile:
_attn_res_fused_kernelThe AttnRes calls at these seams take 0.35 us longer each (+3.4%). A microbenchmark of the seam
traces that to the call losing the copy in front of it (it now starts right after K2, on input
no kernel has just read), not to the strided read. Median ITL, 14.75 ms on main and 14.65 ms with
this PR, is consistent with the net, but one server run per arm cannot resolve 0.1 ms.
Method
rocm/atom-dev:nightly_202611011508-rocm10.0, ATOM main606aceb11mounted over the image's,with and without this commit. Every arm preloads
/usr/lib/x86_64-linux-gnu/libgomp.so.1,without which main's loader (feat(mono): shared DSA indexer mono launch; Kimi-K3 mono to 64 rows, plain decode and ReplaySSM #2871) cannot resolve
omp_set_num_threadsin this image.recipes/Agentic-Kimi-K3.md's C1 launch: TP8, DCP1, DSpark with 7 speculative tokens, syntheticacceptance length 3.84, mono on with main's preconditions (fp32 state, five projections
excluded from
ptpc_fp8).atom.benchmarks.benchmark_serving, random dataset, 8192 in / 1024 out (range ratio 0.8),--ignore-eos, 5 prompts at concurrency 1, seed 0: a warmup wave, then two timed waves. Withspeculative decoding the median ITL is the step period.
the 22 seams are its first 22
_attn_res_fused_kernelcalls. Its last 4 read the whole bankand are within 0.1 us of main's. Each row is the median over replays of a sum over a forward.
264 MB weight-streaming GEMM in K2's place, reproduce the slowdown (+0.52 us a call). A tiny
kernel after the GEMM plus a just-read slice recover all of it; without the GEMM there is none.
Limitations
t * stride_br_toverflows past37,449 rows. Mono decode steps are at most 64 rows; production's
torch.catbank has the samelimit.
stride(0), whicha mono slice now sets to
8 H. That is aligned and its kernel takes the stride as an argument,so nothing breaks, but the check should cover it; and on gfx1250 the in-place test below would
see the TDM launch. Happy to adapt whichever lands second.
Testing
gfx950 (MI355X),
rocm/atom-dev:nightly_202611011508-rocm10.0.tests/model_ops/test_kimi_k3_attn_res_strided.py(new, GPU): 34 passed.past block 0 and past token 0, are byte-identical to
slice.contiguous(), scales included..contiguous()fails thistest and none of the other 33.
a
testspackage in the image's site-packages, which shadows ATOM's, masked).blackandruffclean.