fix: Enable RTR rewrite autoconf for QNN 6D Reshape models (Swin, Nougat)#336
Merged
Conversation
Fix two bugs preventing the ReshapeTransposeReshapeOverlyHighDimPattern
rewrite from being auto-triggered during the optimize-analyze loop:
1. pattern_id mismatch: ReshapeTransposeReshapeOverlyHighDimPattern and
LowDimPattern both inherited pattern_id from shared schema, producing
'SUBGRAPH/ReshapeTransposeReshapePattern' instead of the class-specific
IDs expected by information rules. Added property overrides.
2. kebab/snake case mismatch: information rule emits 'highdimRTR-lowdimRTR'
(kebab-case) but RewritePipe.build_config looks up python_name
'highdimRTR_lowdimRTR' (snake_case). Added key.replace('-', '_')
normalization in AnalysisResult.get_optimization_config().
Models affected: Swin, Donut, Nougat (vision-encoder-decoder family)
Root cause: Swin window partition creates 6D Reshape ops (e.g. [1,8,7,8,7,192])
which exceed QNN EP max tensor rank of 5D.
xieofxie
reviewed
Apr 14, 2026
xieofxie
reviewed
Apr 14, 2026
| ) | ||
| assert len(htp_patterns) == 1, f"Expected 1 HTP pattern, got {len(htp_patterns)}" | ||
|
|
||
| # Check pattern IDs (note: multiple Pattern classes can share same pattern_id) |
Contributor
There was a problem hiding this comment.
what does "multiple Pattern classes can share same pattern_id" mean? I am unfaimilar with this..
Contributor
Author
There was a problem hiding this comment.
From copilot:
Multiple Pattern classes can share the same pattern_id when they are semantically equivalent variants of the same subgraph. For example, Gelu1Pattern, Gelu2Pattern, Gelu3Pattern, and Gelu4Pattern all return "SUBGRAPH/GeluPattern"
|
|
||
| if action_item.optimization_options: | ||
| optim_options.update(action_item.optimization_options) | ||
| # Normalize kebab-case keys to snake_case (python_name) |
Collaborator
There was a problem hiding this comment.
Consider to update the original information config? Then we could get rid of this transform
Contributor
Author
There was a problem hiding this comment.
Should we add both config and here? Adding here is to prevent wrong config...
DingmaomaoBJTU
approved these changes
Apr 14, 2026
7dbef95 to
0e90915
Compare
DingmaomaoBJTU
approved these changes
Apr 20, 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.
Problem
Several models fail on QNN EP (NPU) because Swin's window partition creates 6D Reshape operations (e.g.
[1, 8, 7, 8, 7, 192]), exceeding QNN's max tensor rank of 5D.The codebase already has a
ReshapeTransposeReshapeOverlyHighDimPatternrewrite that merges consecutive dimensions to reduce 6D→≤5D, but it was never auto-triggered due to two bugs in the autoconf pipeline.Affected Models
microsoft/swin-large-patch4-window7-224(image-classification)facebook/nougat-base(image-to-text, vision-encoder-decoder)naver-clova-ix/donut-base(image-to-text, vision-encoder-decoder)PekingU/rtdetr_r50vd_coco_o365(object-detection) — already worked, no 6D ReshapesRoot Cause
Bug 1:
pattern_idmismatchReshapeTransposeReshapeOverlyHighDimPatternandLowDimPatternboth inheritpattern_idfrom a sharedPatternSchema(name="ReshapeTransposeReshapePattern"), producingSUBGRAPH/ReshapeTransposeReshapePatterninstead of the class-specific IDs expected by information rules (e.g.SUBGRAPH/ReshapeTransposeReshapeOverlyHighDimPattern).Bug 2: kebab/snake case key mismatch
The information rule emits
"highdimRTR-lowdimRTR": true(kebab-case), butRewritePipe.build_config()looks upkwargs.get("highdimRTR_lowdimRTR")(snake_case viacap.python_name).Fix
Override
pattern_idin bothOverlyHighDimPatternandLowDimPatternto return their class-specific IDs (uses the base class's designed extension point).Normalize keys in
AnalysisResult.get_optimization_config()withkey.replace("-", "_")— no-op for existing snake_case keys.Testing
Unit Tests
Perf Verification (
winml perfon Snapdragon X Elite NPU)PekingU/rtdetr_r50vd_coco_o365microsoft/swin-large-patch4-window7-224ComposeGraph failedfacebook/nougat-baseComposeGraph failednaver-clova-ix/donut-baseComposeGraph failedFinalizeGraphs 6020