Store MoE routing indices per-block in KVBlockAllocator for prefix caching sharing#2
Open
lmcafee-nvidia wants to merge 6 commits into
Conversation
…ility. Move routing indices from per-request step-by-step accumulation to per-block storage on KVBlockAllocator. At request completion, routing is reconstructed by concatenating per-block routing in block order. Matched (prefix-cached) blocks retain routing from the original request, so reconstruction naturally covers all tokens including skipped prefixes. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Aligns with PR NVIDIA#3925's conversion of routing_indices to np.ndarray. Changes block_routing dict, store/get/reconstruct methods, and _store_routing_per_block to use numpy throughout. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
69a0403 to
2d90296
Compare
store_routing_per_block and reconstruct_routing_from_blocks operate on allocator state and belong alongside the existing store/get primitives. Controller and engine call sites now delegate to the allocator. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
store_routing_per_block expects a dict mapping request_id to routing ndarray, but _router_record_bookkeeping was returning a plain list. This caused "ambiguous truth value" errors when checking membership. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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
request.routing_indices) to per-block inKVBlockAllocator.block_routing, so routing data is shared alongside KV cache blocks when requests share a prefix._store_routing_per_blockscatters routing indices into the allocator using the context's token-to-block mapping. At request completion,_reconstruct_routing_from_blocksconcatenates block routing data back into a contiguous array.torch.Tensortonp.ndarray, aligning with the base branch's conversion ofrouting_indicestonp.ndarray.Test plan
TestPerBlockRoutingtests pass (pytest ... ::TestPerBlockRouting -xvs)🤖 Generated with Claude Code