Skip prefix block TKG BHSD materialization#155
Open
dario-fumarola wants to merge 1 commit intoaws-neuron:mainfrom
Open
Skip prefix block TKG BHSD materialization#155dario-fumarola wants to merge 1 commit intoaws-neuron:mainfrom
dario-fumarola wants to merge 1 commit intoaws-neuron:mainfrom
Conversation
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
Avoid redundant BHSD materialization for prefix-cached token generation when block KV layout and block TKG attention are enabled.
Today
NeuronBaseModel.get_model_output()callskv_mgr.get_cache()before entering the decoder layers. For prefix caching withBlockKVCacheManager, that gathers block KV and reshapes it into flat BHSD. The block TKG attention path then fetches raw block KV throughkv_mgr._fetch_cache()and usesactive_block_table, so the earlier BHSD materialization is not consumed.This change skips that eager BHSD materialization only for the block-TKG token-generation path. Other paths keep the existing behavior.
Checklist
Core Change
Test Coverage
Testing
How did you test this change?
Validated on
inf2.xlargeusing the Neuron SDK 2.29 inference DLC:pytorch-inference-neuronx:2.9.0-sdk2.29.0-ubuntu24.04torch 2.9.1torch-neuronx 2.9.0.2.13neuronx_distributed 0.18.27753Test Results:
Also confirmed the patched branch is reachable during a real Neuron TKG trace on Inf2.
Compatibility
Tested with:
inf2.xlargeAdditional Information
The skip is gated on:
active_block_tableBlockKVCacheManagerKV quantization remains on the existing path because prefix cache reads dequantize before block selection, while the raw block-TKG path does not currently receive dequant scale parameters.
Related Issues
N/A
By submitting this PR, I confirm that: