Skip to content

Add partitioner pre-decomposition transform hook - #22141

Merged
YufengShi-dudu merged 2 commits into
pytorch:mainfrom
YufengShi-dudu:add-partitioner-pre-decomposition-hook
Aug 27, 2026
Merged

Add partitioner pre-decomposition transform hook#22141
YufengShi-dudu merged 2 commits into
pytorch:mainfrom
YufengShi-dudu:add-partitioner-pre-decomposition-hook

Conversation

@YufengShi-dudu

@YufengShi-dudu YufengShi-dudu commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator

Some backend-specific transformations must run before EXIR's initial run_decompositions({}) call because decomposition can remove the ATen patterns they need to inspect or rewrite. Previously, backends needed frontend wrappers or call-site-specific pass scheduling, exposing lowering order details outside the backend.

This PR adds a partitioner hook for this preprocessing. The relevant lowering order becomes:

to_edge_transform_and_lower()
  -> partitioner.transform_for_pre_decomposition()
  -> program.run_decompositions({})
  -> Edge transformation and partitioning

Pre-decomposition transforms from multiple partitioners run in the supplied order. The default implementation is a no-op, so existing partitioners and call sites remain unchanged.

Assisted by Codex.

Change-Id: I9e67b896c22fd2043c3b4f5439016016acc05362

cc @JacobSzwejbka @angelayi

Invoke partitioner-provided transforms before EXIR's initial
run_decompositions({}) call in to_edge_transform_and_lower(). This
avoids backend-specific frontend wrappers for required transformations.

The lowering order becomes:

  to_edge_transform_and_lower()
    -> partitioner.transform_for_pre_decomposition()
    -> program.run_decompositions({})
    -> Edge transformation and partitioning

Run multiple partitioner transforms in the supplied order and retain a
no-op default for backward compatibility.

Assisted by Codex.

Change-Id: I9e67b896c22fd2043c3b4f5439016016acc05362
Signed-off-by: Yufeng Shi <yufeng.shi@arm.com>
@YufengShi-dudu YufengShi-dudu added the module: exir Issues related to Export IR and the code under exir/ label Aug 25, 2026
@YufengShi-dudu YufengShi-dudu added ciflow/trunk release notes: exir Changes to any dialects and passes on these dialects, such as memory planning labels Aug 25, 2026
@pytorch-bot

pytorch-bot Bot commented Aug 25, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ 1 New Failure

As of commit 1110df8 with merge base 88a5f60 (image):

NEW FAILURE - The following job has failed:

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 Aug 25, 2026
Comment thread exir/program/_program.py
program: ExportedProgram, partitioners: List[Partitioner]
) -> ExportedProgram:
for partitioner in partitioners:
program = partitioner.transform_for_pre_decomposition(program)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC do_not_decomp will complain if a partitioner asked for something to be not decomposed and then it didn't partition, is this true for this as well? I can imagine that as a good thing if we are planning to do some transforms here in this pass.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your comment. No, we don't record the same info to check whether the generated ops remain undelegated after the following decomposition and partitioning. Tracking them may require a new metedata field.
transform_for_annotation_pipeline() also applies transforms without tracking generated nodes. Do you think we should introduce such tracking for this hook?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah quantizer being backend specific yet no direct enforcement for its actions is something I am not very happy about.

The reason I am a bit nervous this is, now we are modifying the graph in the paritioner and without any consequences if this hook misbehaves.

That said, with your hook, since its a pass, writing a '_sanity_check_graph_for_non_decomp_ops` like fn can get tricky if multiple passes or even multiple partitioners have worked on the graph.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok let's hope this doesn't get out of control, I will stamp this as is.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you, we need to be more cautious when adding new passes to this hook.

@digantdesai digantdesai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Also please list your motivation for this hook in the PR summary before merging.

@YufengShi-dudu
YufengShi-dudu merged commit 35adf60 into pytorch:main Aug 27, 2026
505 of 506 checks passed
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: exir Issues related to Export IR and the code under exir/ release notes: exir Changes to any dialects and passes on these dialects, such as memory planning

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants