Skip to content

Fix to_edge_transform_and_lower to respect preserve_ops without parti…#17493

Merged
psiddh merged 1 commit intomainfrom
preserve_ops_fix
Feb 18, 2026
Merged

Fix to_edge_transform_and_lower to respect preserve_ops without parti…#17493
psiddh merged 1 commit intomainfrom
preserve_ops_fix

Conversation

@psiddh
Copy link
Contributor

@psiddh psiddh commented Feb 17, 2026

…tioner

Summary:
to_edge_transform_and_lower silently ignores EdgeCompileConfig.preserve_ops when no partitioner is provided — ops like aten.linear.default get decomposed to addmm despite being listed in preserve_ops. This is inconsistent with to_edge, which correctly pops preserved ops from the decomposition table. The fix adds 3 lines to _gen_edge_manager_for_partitioners to pop config.preserve_ops from the table in the no-partitioner path, matching the existing to_edge behavior. When preserve_ops is empty (the default for all existing callers), the behavior is unchanged.

Test:
python3 -m unittest exir.program.test.test_program.TestProgramManagers.test_to_edge_transform_and_lower_with_preserve_ops_no_partitioner -v

Copilot AI review requested due to automatic review settings February 17, 2026 18:00
@psiddh psiddh requested a review from larryliu0820 as a code owner February 17, 2026 18:00
@pytorch-bot
Copy link

pytorch-bot bot commented Feb 17, 2026

🔗 Helpful Links

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

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

❌ 1 New Failure, 1 Unrelated Failure

As of commit eebc204 with merge base a24d3e7 (image):

NEW FAILURE - The following job has failed:

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 Feb 17, 2026
@github-actions
Copy link

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes to_edge_transform_and_lower so it respects EdgeCompileConfig.preserve_ops even when no partitioner is provided, aligning behavior with to_edge and preventing unintended decompositions (e.g., aten.linear.defaultaddmm).

Changes:

  • Update _gen_edge_manager_for_partitioners to remove config.preserve_ops entries from the default decomposition table in the no-partitioner path.
  • Add a regression test ensuring preserve_ops prevents decomposition in to_edge_transform_and_lower without a partitioner.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
exir/program/_program.py Pops config.preserve_ops from the decomposition table when partitioners_for_program is empty, preventing unwanted decompositions.
exir/program/test/test_program.py Adds a unit test covering preserve_ops behavior in to_edge_transform_and_lower with no partitioner.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 910 to 916
def count_nodes(graph_module, target):
count = 0
for node in graph_module.graph.nodes:
if node.op == "call_function" and node.target == target:
count += 1
return count

Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

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

This test duplicates a count_nodes helper that already exists in _test_to_edge_with_preserved_ops above. Consider extracting count_nodes into a shared helper (e.g., a private method on the test class) to avoid repeating the same graph-walk logic across tests.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

@psiddh psiddh Feb 17, 2026

Choose a reason for hiding this comment

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

Good suggestion! Will do this in follow up PR..

…tioner

Summary:
to_edge_transform_and_lower silently ignores EdgeCompileConfig.preserve_ops when no partitioner is provided — ops like aten.linear.default get decomposed to addmm despite being listed in preserve_ops. This is inconsistent with to_edge, which correctly pops preserved ops from the decomposition table. The fix adds 3 lines to _gen_edge_manager_for_partitioners to pop config.preserve_ops from the table in the no-partitioner path, matching the existing to_edge behavior. When preserve_ops is empty (the default for all existing callers), the behavior is unchanged.

Test:
python3 -m unittest exir.program.test.test_program.TestProgramManagers.test_to_edge_transform_and_lower_with_preserve_ops_no_partitioner -v
Copilot AI review requested due to automatic review settings February 17, 2026 18:25
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@psiddh
Copy link
Contributor Author

psiddh commented Feb 18, 2026

cc @rascani @AdrianLundell
This was the reason why aten.linear.default was decomposing to addmm. I will update the PR : #17075 accordingly removing the addmm impl from it (and extra pass that was added as result)

@psiddh psiddh merged commit 0358a46 into main Feb 18, 2026
201 of 203 checks passed
@psiddh psiddh deleted the preserve_ops_fix branch February 18, 2026 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments