Skip to content

Arm backend: Deduplicate constants emitted during TOSA lowering - #22638

Open
YufengShi-dudu wants to merge 2 commits into
pytorch:mainfrom
YufengShi-dudu:deduplicate-consts-emitted-during-tosa-lowering
Open

Arm backend: Deduplicate constants emitted during TOSA lowering#22638
YufengShi-dudu wants to merge 2 commits into
pytorch:mainfrom
YufengShi-dudu:deduplicate-consts-emitted-during-tosa-lowering

Conversation

@YufengShi-dudu

@YufengShi-dudu YufengShi-dudu commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

Pool backend-generated helper constants per TOSA basic block using dtype, shape, and exact serialized bytes as the key. Implement the pool in a TosaSerializer subclass. Helper operands use the tensor returned by addConst, making reuse safe.

Keep graph-owned constants unpooled because later lowering refers to their FX names. This covers model parameters, buffers, lifted constants, and CONST_SHAPE outputs, while preserving packed FP4 serialization.

Deduplicate identical static CONST_SHAPE nodes in FX, where their uses can safely be rewritten to the first occurrence.

Representative TOSA-FP operator comparisons:

Model Before After Reduction Bytes saved
SD3 1,518 1,038 480 (31.6%) 89,068
InceptionV3 673 456 217 (32.2%) 42,092
Conformer 488 365 123 (25.2%) 22,852

This change was authored with assistance from Codex.

Change-Id: I4de44b034aff33cbf2888801238cc48df5a9124d

cc @digantdesai @freddan80 @per @zingo @oscarandersson8218 @mansnils @Sebastian-Larsson @robell @rascani

Pool backend-generated helper constants per TOSA basic block using
dtype, shape, and exact serialized bytes as the key. Implement the
pool in a TosaSerializer subclass. Helper operands use the tensor
returned by addConst, making reuse safe.

Keep graph-owned constants unpooled because later lowering refers to
their FX names. This covers model parameters, buffers, lifted
constants, and CONST_SHAPE outputs, while preserving packed FP4
serialization.

Deduplicate identical static CONST_SHAPE nodes in FX, where their uses
can safely be rewritten to the first occurrence.

Representative TOSA-FP operator comparisons:

| Model       | Before | After | Reduction   | Bytes saved |
|-------------|-------:|------:|------------:|------------:|
| SD3         |  1,518 | 1,038 | 480 (31.6%) |      89,068 |
| InceptionV3 |    673 |   456 | 217 (32.2%) |      42,092 |
| Conformer   |    488 |   365 | 123 (25.2%) |      22,852 |

This change was authored with assistance from Codex.

Change-Id: I4de44b034aff33cbf2888801238cc48df5a9124d
Signed-off-by: Yufeng Shi <yufeng.shi@arm.com>
@YufengShi-dudu
YufengShi-dudu requested a review from zingo September 9, 2026 10:21
@YufengShi-dudu YufengShi-dudu added partner: arm For backend delegation, kernels, demo, etc. from the 3rd-party partner, Arm ciflow/trunk release notes: arm Changes to the ARM backend delegate module: arm Issues related to arm backend labels Sep 9, 2026
@pytorch-bot

pytorch-bot Bot commented Sep 9, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/22638

Note: Links to docs will display an error until the docs builds have been completed.

❌ You can merge normally! (1 Unrelated Failure), 1 Unclassified Failure

As of commit d0c222d with merge base 56a461f (image):

UNCLASSIFIED FAILURE - DrCI could not classify the following job because the workflow did not run on the merge base. The failure may be pre-existing on trunk or introduced by this PR:

FLAKY - The following job failed but was likely due to flakiness present on trunk:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 9, 2026
@YufengShi-dudu

Copy link
Copy Markdown
Collaborator Author

The test-arm-backend-no-driver failure exposed a memory leak issue. Will push a follow-up commit to resolve it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. module: arm Issues related to arm backend partner: arm For backend delegation, kernels, demo, etc. from the 3rd-party partner, Arm release notes: arm Changes to the ARM backend delegate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants