GPT-OSS: Hoist Layer-Invariant Attention Mask Preparation Outside Decoder Subfunctions - #1231
Draft
abhishek-singh591 wants to merge 4 commits into
Draft
GPT-OSS: Hoist Layer-Invariant Attention Mask Preparation Outside Decoder Subfunctions#1231abhishek-singh591 wants to merge 4 commits into
abhishek-singh591 wants to merge 4 commits into
Conversation
Signed-off-by: Abhishek kumar singh <sabhis@qti.qualcomm.com>
ochougul
marked this pull request as draft
August 4, 2026 16:39
Signed-off-by: Abhishek kumar singh <sabhis@qti.qualcomm.com>
abhishek-singh591
marked this pull request as ready for review
August 4, 2026 18:26
ochougul
marked this pull request as draft
August 5, 2026 04:33
ochougul
reviewed
Aug 5, 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.
GPT-OSS: Hoist Layer-Invariant Attention Mask Preparation Outside Decoder Loop
Summary
This change hoists GPT-OSS attention-mask preparation out of
QEffGptOssDecoderLayerand out of thedecoder-layer loop. The model now computes the reusable full-attention and sliding-window additive
masks once before iterating over decoder layers, then passes the already-prepared mask matching each
layer’s attention type.
Problem
For GPT-OSS 120B decode, enabling ONNX subfunctions showed an approximately 13% inference performance
drop compared with non-subfunction compilation. Inspection of the exported decoder function showed
redundant, layer-invariant mask work inside
QEffGptOssDecoderLayer; for example, nodes such asGather_604appeared inside the repeated decoder subfunction.GPT-OSS uses both
full_attentionandsliding_attention, but the actual full/sliding masks arelayer-invariant for a given forward call. Only the choice of which mask to pass depends on
config.layer_types[layer_idx]/self_attn.sliding_window.Approach
The model forward now builds the base causal mask and sliding-window causal mask once, before the
decoder-layer loop.
It then prepares reusable additive masks outside the loop:
full_attention_maskfor full-attention layers.sliding_attention_maskfor sliding-attention layers.Inside the decoder-layer loop, the code only selects the already-prepared mask based on the layer’s
attention type.
Old in-layer behavior: