Arm backend: Reuse identical CONST_SHAPE nodes#19770
Conversation
Cache CONST_SHAPE nodes created by InsertConstShapesPass and reuse them when a later view/repeat needs the same shape. This removes duplicate shape constants. This improvement is model dependent. Models with few repeated literal shapes will not see any meaningful change, but some models can benefit from it notably. The table below shows the results of a local test lowering DeiT Tiny to TOSA-FP. The lowering time reduced in this run, likely because passes following InsertConstShapesPass had fewer nodes to iterate over. | Metric | Baseline | Optimized | Delta | | -------------- | -------- | --------- | ---------------- | | Total ops | 2106 | 1736 | -370 (-17.6%) | | CONST_SHAPE | 466 | 96 | -370 (-79.4%) | | TOSA size | 23.82 MB | 23.75 MB | -71.6 KB (-0.3%) | | Execution time | 118.7 s | 78.4 s | -40.3 s (-34.0%) | Signed-off-by: Martin Lindström <Martin.Lindstroem@arm.com> Change-Id: I620b04e496996fafebc9c7f7854fd8399b3d6d4b
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/19770
Note: Links to docs will display an error until the docs builds have been completed. ❗ 1 Active SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below: ⏳ 38 Pending, 1 Unrelated FailureAs of commit d06f7fd with merge base 77df9b7 ( BROKEN TRUNK - The following job failed but were present on the merge base:👉 Rebase onto the `viable/strict` branch to avoid these failures
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@pytorchbot label ciflow/trunk |
|
@pytorchbot label "partner: arm" |
|
@pytorchbot label "release notes: none" |
There was a problem hiding this comment.
Pull request overview
This PR optimizes the Arm backend lowering pipeline by reusing identical tosa.CONST_SHAPE nodes emitted by InsertConstShapesPass, reducing duplicate shape constants in generated TOSA graphs.
Changes:
- Adds an instance-level cache keyed by shape tuple.
- Reuses previously created
CONST_SHAPEnodes for laterview_copy/repeatops with the same literal shape.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const_node = self._const_shape_cache.get(shape) | ||
| if const_node is None: |
| const_node = self._const_shape_cache.get(shape) | ||
| if const_node is None: |
Cache CONST_SHAPE nodes created by InsertConstShapesPass and reuse them when a later view/repeat needs the same shape. This removes duplicate shape constants.
This improvement is model dependent. Models with few repeated literal shapes will not see any meaningful change, but some models can benefit from it notably.
The table below shows the results of a local test lowering DeiT Tiny to TOSA-FP. The lowering time reduced in this run, likely because passes following InsertConstShapesPass had fewer nodes to iterate over.
cc @digantdesai @freddan80 @per @zingo @oscarandersson8218 @mansnils @Sebastian-Larsson @robell @rascani