move subgraph_has_impure_ops from node.is_impure into const_fold to unblock production#167443
Closed
jazlyn5 wants to merge 1 commit intopytorch:mainfrom
Closed
move subgraph_has_impure_ops from node.is_impure into const_fold to unblock production#167443jazlyn5 wants to merge 1 commit intopytorch:mainfrom
node.is_impure into const_fold to unblock production#167443jazlyn5 wants to merge 1 commit intopytorch:mainfrom
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/167443
Note: Links to docs will display an error until the docs builds have been completed. ✅ You can merge normally! (1 Unrelated Failure)As of commit 46aee4d with merge base 3cfbf98 ( UNSTABLE - The following job is marked as unstable, possibly due to flakiness on trunk:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
b3ea4b1 to
a361d90
Compare
jazlyn5
added a commit
to jazlyn5/pytorch
that referenced
this pull request
Nov 10, 2025
…nblock production (pytorch#167443) Summary: pytorch#166609 updates `node.is_impure` to consider a submodule as impure if submodule contains impure node. Prior to pytorch#166609, we always consider a submodule as pure, regardless of what ops contained inside. pytorch#166609 fixed that impurity gap, and in turn changed `graph.eliminate_dead_code()` function behavior, which does not eliminate nodes with side effects, see [pytorch documentation](https://docs.pytorch.org/docs/stable/fx.html#torch.fx.Graph.eliminate_dead_code) > Remove all dead code from the graph, based on each node’s number of users, and whether the nodes have any side effects. As a result, dead code elimination may no longer remove *some* unused submodules if they have impure ops. While this is logically correct, some customers rely on the dead code elimination to eliminate impure submodules. Due to such production environment constraints, we have to revert pytorch#166609 and move the side-effectful submodule check logic to `const_fold.py`, which will correctly **not** const-fold a submodule that contains impure ops. NOTE other call sites that use `node.is_impure()` to make decisions are still incorrectly eliminating impure submodules, but we can't safely change that today. ## This pr - move `_subgraph_has_impure_op` into `fx/experimental/const_fold.py`, check and prevent const-folding an impure submodule - added a note in `node.is_impure` to highlight the incorrect behavior and context in case people go looking in the future. Test Plan: run test_fx_const_fold and all tests pass Differential Revision: D86641994
68d60b3 to
6918379
Compare
…nblock production (pytorch#167443) Summary: pytorch#166609 updates `node.is_impure` to consider a submodule as impure if submodule contains impure node. Prior to pytorch#166609, we mostly always consider a GraphModule submodule as pure, regardless of if it has impure ops. pytorch#166609 fixed that impurity gap, and in turn changed `graph.eliminate_dead_code()` function behavior, which does not eliminate nodes with side effects, see [pytorch documentation](https://docs.pytorch.org/docs/stable/fx.html#torch.fx.Graph.eliminate_dead_code) > Remove all dead code from the graph, based on each node’s number of users, and whether the nodes have any side effects. As a result, dead code elimination may no longer remove *some* unused submodules if they have impure ops. While this is logically correct, some customers rely on the dead code elimination to eliminate impure submodules. Due to such production environment constraints, we have to revert pytorch#166609 and move the side-effectful submodule check logic to `const_fold.py`, which will correctly **not** const-fold a submodule that contains impure ops. NOTE other call sites that use `node.is_impure()` to make decisions are still incorrectly eliminating impure submodules, but we can't safely change that today. ## This pr - move `_subgraph_has_impure_op` into `fx/experimental/const_fold.py`, check and prevent const-folding an impure submodule - added a note in `node.is_impure` to highlight the incorrect behavior and context in case people go looking in the future. Test Plan: run test_fx_const_fold and all tests pass Differential Revision: D86641994
6918379 to
46aee4d
Compare
jfix71
approved these changes
Nov 10, 2025
Contributor
Author
|
@pytorchbot merge |
Collaborator
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Silv3S
pushed a commit
to Silv3S/pytorch
that referenced
this pull request
Nov 18, 2025
… unblock production (pytorch#167443) Summary: pytorch#166609 updates `node.is_impure` to consider a submodule as impure if submodule contains impure node. This in turn changes `graph.eliminate_dead_code()` function behavior, which does not eliminate nodes with side effects, see [pytorch documentation](https://docs.pytorch.org/docs/stable/fx.html#torch.fx.Graph.eliminate_dead_code) > Remove all dead code from the graph, based on each node’s number of users, and whether the nodes have any side effects. While this is correct that a submodule containing side-effectful ops is side-effectful and should not be dead code eliminated, some customers rely on the dead code elimination to eliminate submodules that contain impure ops which is the behavior before pytorch#166609 fix. Due to production environment constraints, we have to revert pytorch#166609 and move the side-effectful submodule check logic to `const_fold.py`, which will correctly **not** const-fold a submodule that contains impure ops. NOTE other call sites that use `node.is_impure()` to make decisions are still incorrectly eliminating side-effectful submodules, but we can't safely change that today. ## This pr - move `_subgraph_has_impure_op` into `fx/experimental/const_fold.py`, check and prevent const-folding an impure submodule - added a note in `node.is_impure` to highlight the incorrect behavior and context in case people go looking in the future. Test Plan: run test_fx_const_fold and all tests pass Differential Revision: D86641994 Pull Request resolved: pytorch#167443 Approved by: https://github.com/jfix71
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.
Summary:
#166609 updates
node.is_impureto consider a submodule as impure if submodule contains impure node. This in turn changesgraph.eliminate_dead_code()function behavior, which does not eliminate nodes with side effects, see pytorch documentationWhile this is correct that a submodule containing side-effectful ops is side-effectful and should not be dead code eliminated, some customers rely on the dead code elimination to eliminate submodules that contain impure ops which is the behavior before #166609 fix.
Due to production environment constraints, we have to revert #166609 and move the side-effectful submodule check logic to
const_fold.py, which will correctly not const-fold a submodule that contains impure ops.NOTE other call sites that use
node.is_impure()to make decisions are still incorrectly eliminating side-effectful submodules, but we can't safely change that today.This pr
_subgraph_has_impure_opintofx/experimental/const_fold.py, check and prevent const-folding an impure submodulenode.is_impureto highlight the incorrect behavior and context in case people go looking in the future.Test Plan: run test_fx_const_fold and all tests pass
Differential Revision: D86641994
cc @ezyang @EikanWang @jgong5 @wenzhe-nrv