perf(kimi-k2): compact local top-1 readback into one pinned transfer#734
Open
LanluZ wants to merge 2 commits into
Open
perf(kimi-k2): compact local top-1 readback into one pinned transfer#734LanluZ wants to merge 2 commits into
LanluZ wants to merge 2 commits into
Conversation
Pack each active row's top-1 id and value into one compact device packet via a dedicated pack kernel, land it in a persistent pinned host buffer with a single active-prefix D2H, and wait on that transfer's completion event instead of synchronizing the whole compute stream. Refs openinfer-project#716 Signed-off-by: LanluZ <lanluz@users.noreply.github.com>
Signed-off-by: LanluZ <lanluz@users.noreply.github.com>
LanluZ
force-pushed
the
perf-kimi-k2-top1-readback
branch
from
July 21, 2026 09:20
c53ccb7 to
fe565d8
Compare
Collaborator
|
Thanks for working on this. The implementation direction matches #716, and a little runtime evidence would help us validate both correctness and the intended improvement. The current description notes that end-to-end testing was not completed; the generic CI checks also do not exercise the Kimi-K2 runtime path. Could you please add results from the same hardware/software/configuration for:
These results will let us confirm that the runtime behavior is preserved and evaluate the optimization in its intended context. Once they are attached, we can continue with the detailed review. |
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.
Description
Fixes #716
Kimi's batched local top-1 readback synchronized the whole compute stream and then copied the full-capacity ID and value buffers through two pageable D2Hs, although only
active_rowsare consumed. This adds a full-stream barrier and two host transfers to the decode tail.This change:
pack_top1_packets_cudakernel that interleaves each active row's{i32 id, bf16 value}into one compact 8-byte device packet (shared argmax kernels are untouched).CudaSlice<u8>) + pinned host landing buffer (PinnedHostSlice<u8>) inSamplingScratch.active_rows * 8bytes) into the pinned buffer instead of two full-capacity pageable copies.PinnedHostSliceevent) instead ofcudaStreamSynchronize— no full-stream barrier solely for top-1 readback.Token IDs, values, and cross-rank selection semantics are unchanged; the row range checks are preserved verbatim.
I was unable to complete end-to-end testing locally. Requesting the reviewer / maintainer to verify.
Type of Change
Checklist
docs/conventions/coding-style.md).CLAUDE.md).