Repository navigation
[Perf] Parallelize KDA cache updates across layers - #1092
Merged
Todobe merged 6 commits intoNov 28, 2026
Merged
Conversation
Collaborator
|
/pr-review |
yuejiat0416
reviewed
Nov 26, 2026
yuejiat0416
previously approved these changes
Nov 26, 2026
Todobe
reviewed
Nov 26, 2026
yuejiat0416
reviewed
Nov 27, 2026
yuejiat0416
approved these changes
Nov 27, 2026
Todobe
approved these changes
Nov 28, 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.
Summary
At small batch sizes, the KDA cache update kernels expose only one program per
request while iterating over layers serially. This change launches
conv_state_rollbackandmove_intermediate_cache_kdawith a(requests, layers)grid. Each program usestl.program_id(1)to update onelayer, replacing the serial layer loop.
keep the KDA mover's head/V tiling and tail masks unchanged.
test_mamba_state_update.py, using itsdata generators, public API and comparison helpers. Existing test cases,
shared helpers and accuracy standards are unchanged.
Mamba test file. Public signatures, the legacy module and the generic
non-KDA mover are unchanged.
Validation
cases. Six cover both operators at batch 1, 8 and 32. Shapes use 69 layers,
TP=16 (six local heads), head dimensions 128 and four draft tokens. Move uses
FP32 with transposed destination storage; rollback uses BF16. Each cache pool
has
batch + 3slots. The single-request rollback case uses step zero so itperforms a rollback instead of taking the negative-step skip path.
Six additional Move cases cover mixed valid/negative steps at batch 2/8/32
and all-negative steps at batch 1/8/32. They check skipped destination
slots exactly against their initial values across every layer.
profiling by default. Use
-k kimi_k31for the 12 added cases, or-k skipped_stepsfor the six new skipped-step cases.60b6672, before the standalone test file was removed.This is historical NPU validation, not a fresh run of the consolidated suite.
each machine. These measurements use the separate timing flow described
below; the optimized kernel code is unchanged by this test consolidation.
passed reduced-shape CPU Triton-interpreter checks against
torch_native,preserving batch sizes 1/8/32. The six skipped-step cases also passed
reduced-shape interpreter checks; injected corruption of a skipped slot
in the last layer was detected for both patterns. Hardware initialization
was mocked for these local checks. The full-shape pytest suite has not
been rerun on NPU.
on Ascend950DT_9582 for both implementations, including unchanged skipped
slots across all layers. This is NPU benchmark correctness validation,
not an NPU pytest result; see the second-Move results below.
pre-commit run --all-files --show-diff-on-failurepreviously passedon an isolated Windows checkout, including the same six skipped-step cases
from validation commit
b53dc695. A rerun for this follow-up was blocked byWindows application control (
WinError 4551) while launching a hook; nonew full pre-commit pass is claimed.
git diff --checkpassed.Performance
The baseline is the serial-layer implementation from upstream commit
458e72caf6cdfb5b9c06711e6f84d134d15e3f97. Both machines' recorded source hashesmatch the same measured baseline and optimized source. The final test-file
cleanup does not change the optimized kernels' executable structure.
Kimi K3.1-derived inputs use 69 KDA layers, six local heads, head dimensions 128,
four draft tokens and a pool of 257 slots. TP=16 is a synthetic sharding choice;
each run uses one NPU, logical device 0, without a model server.
[69, 257, 6, 2304][69, B, 4, 6, 128, 128]; destination[69, 257, 6, 128, 128]The original A3/A5 measurements below use step zero for all requests. Timings are median microseconds from three
warmups and 20 alternating-order NPU event samples; speedup is
old/new.Destination resets, compilation and reference checks are outside the measured
interval. A separate A/B timing flow is used because rollback mutates its
input. Event elapsed time can include host enqueue gaps and is not
profiler-summed kernel time or end-to-end serving throughput.
A3
Chip: Ascend910_9362. PyTorch 2.10.0+cpu, torch-npu 2.10.0.post6,
Triton 3.2.0, Triton-Ascend 3.2.2. CANN: 9.1.0.
Recorded at 2026-11-26 02:36:51 UTC.
A5
Chip: Ascend950PR_9589. PyTorch 2.13.0+cpu, torch-npu 2.13.0,
Triton 3.6.0, Triton-Ascend 3.6.0+dev20261105160244.
CANN: 9.2.0. Recorded at 2026-11-26 02:59:04 UTC.
Large-batch behavior
Small batches improve on both machines, but the improvement is not uniform.
A3 move latency increases by 1.70% at batch 16 and 1.14% at batch 64. A5 move
latency increases by 1.30%-1.47% at batches 64-256; A5 conv is approximately
flat at batches 64-256, with a 0.61% increase at batch 128.
This implementation uses layer parallelism at every batch size. These small
regressions are disclosed rather than treated as noise; their repeatability
has not yet been established across independent runs. No batch-dependent
fallback or end-to-end serving speedup is claimed.
Second KDA Move with skipped steps
Device: Ascend950DT_9582, logical NPU 0. This is a separate device from
the Ascend950PR_9589 run above; its software versions were not supplied in
the new log. Run directory:
20261127T063244.613239Z(2026-11-27 UTC).The benchmark on the validation branch
compares the same upstream serial baseline against the unchanged optimized
kernel. It uses 69 layers, six local heads, 128x128 state, four drafts, FP32,
transposed destination storage, and a pool of
2 * batch + 3slots.Current-state and checkpoint destination slots are disjoint. Before each
sample, the destination is reset and the first Move runs outside timing;
only the second Move is timed. Mixed batches alternate a valid step cycling
through 0..3 with
-1; all-skip batches use-1throughout and still launchthe second Move. Batch 1 has only the all-skip scenario.
All 17 scenarios passed correctness checks for both implementations,
including all layers and unchanged skipped/untouched slots. Timings below
are median microseconds after three warmups and 20 alternating-order samples,
with the same NPU-event wrapper-call metric described above. These shapes and
the first-Move setup differ from the original step-zero benchmark, so absolute
latencies should be compared within each A/B pair.
Mixed batches improve by 1.931x-19.039x at batch 2-32. At batch 64-256,
latency increases by approximately 1.1%-1.2%; this regression is disclosed,
and the sampled old/new ranges do not overlap in this run. Repeatability
across independent runs has not yet been established. All-skip medians remain
approximately 52-59 us, with new-minus-old differences from -2.872 to +0.488 us;
there is no clear skip-only latency amplification in this wrapper-call metric.
No kernel implementation or batch-dependent dispatch change is included in
this follow-up. The benchmark stays on the validation branch; only the six
regression cases are added to this PR's existing test file.