Added subfunction fix for gemma 4 with CB - #1245
Open
abhishek-singh591 wants to merge 3 commits into
Open
Conversation
Signed-off-by: Abhishek kumar singh <sabhis@qti.qualcomm.com>
Contributor
|
@abhishek-singh591 Can you run gemma4_diss.py script and ensure that perf for Gemma4-26B-A4B-IT model is not impacted with these changes. |
Signed-off-by: Abhishek kumar singh <sabhis@qti.qualcomm.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
This PR fixes Gemma4 vision continuous-batching compilation with use_onnx_subfunctions=True.
The QAIC compiler was failing on the Gemma4 decoder ONNX with:
The failing Range came from the Gemma4 sliding-window cache update path.
Root Cause
In the Gemma4 sliding cache update, the sliding context length was derived from the KV-cache tensor shape:
layer_ctx_len = self.keys.shape[2]
This value was then used to build cache indices with torch.arange(...).
With ONNX subfunctions enabled, this shape-derived value became a dynamic input inside the decoder-layer subfunction:
Shape(past_key) -> Gather -> Range limit
QAIC requires the Range limit inside subfunctions to be constant, so compilation failed.
Fix
Use the static Gemma4 sliding-window config value instead of deriving it from the runtime KV-cache shape.
For sliding-attention layers, the attention module now passes cache_kwargs["sliding_window"] = self.sliding_window into the cache update path.
The Gemma4 cache layer also stores the sliding-window length from config, so sliding cache indexing can use a compile-time constant instead of self.keys.shape[2].
Additionally, dummy KV cache creation for sliding layers now uses layer_seq_len = config.sliding_window instead of layer_seq_len = min(config.sliding_window, seq_len).
Validation
Validated using:
/home/abhishek/dynamo/bin/python examples/image_text_to_text/models/gemma_vision/gemma4/gemma4_cb.py
The script completed successfully with use_onnx_subfunctions=True.