Skip to content

Revert "[fx] Move the rest of torch.fx.Node to C++ (#170946)"#177047

Closed
wdvr wants to merge 1 commit intopytorch:mainfrom
wdvr:revert-170946
Closed

Revert "[fx] Move the rest of torch.fx.Node to C++ (#170946)"#177047
wdvr wants to merge 1 commit intopytorch:mainfrom
wdvr:revert-170946

Conversation

@wdvr
Copy link
Contributor

@wdvr wdvr commented Mar 10, 2026

Summary

Reverts #170946

This reverts commit fa27d4f.

The two stacked PRs (#170962 and #170973) have already been reverted on main:

The only merge conflict was in torch/fx/node.py due to a type annotation modernization PR (#176308, Optional[X]X | None). The conflict was resolved by keeping the modern annotation style while restoring the original Python implementation.

Test plan

CI

cc @albanD @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo

@pytorch-bot
Copy link

pytorch-bot bot commented Mar 10, 2026

🔗 Helpful Links

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

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

❌ 1 New Failure, 1 Unrelated Failure

As of commit 7dc74f6 with merge base 52dd8fe (image):

NEW FAILURE - The following job has failed:

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.

@pytorch-bot pytorch-bot bot added ci-no-td Do not run TD on this PR ciflow/inductor ciflow/torchtitan Run TorchTitan integration tests module: inductor release notes: fx release notes category labels Mar 10, 2026
@wdvr wdvr marked this pull request as ready for review March 10, 2026 18:09
@huydhn huydhn added suppress-bc-linter Suppresses the failures of API backward-compatibility linter (Lint/bc_linter) skip-pr-sanity-checks labels Mar 11, 2026
@huydhn
Copy link
Contributor

huydhn commented Mar 11, 2026

@pytorchbot merge -f 'This is a revert'

@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes). Please use -f as last resort and instead consider -i/--ignore-current to continue the merge ignoring current failures. This will allow currently pending tests to finish and report signal before the merge.

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@pytorch-auto-revert
Copy link

@pytorchbot revert -m "Reverted automatically by pytorch's autorevert, to avoid this behaviour add the tag autorevert: disable" -c autorevert

This PR is attributed to have caused regression in:

Please investigate and fix the issues.
@claude Can you please read this revert comment, follow the links and read the errors, to then give a brief diagnostics on the cause of the error? If you judge the error to be legitimate reason for a revert, please provide brief guidance on how the author could fix it.

@claude
Copy link

claude bot commented Mar 11, 2026

Claude finished @pytorch-auto-revert[bot]'s task in 1m 24s —— View job


Diagnosis of Revert Cause

  • Read the revert trigger and identify the failing job
  • Investigate the lint failure
  • Analyze root cause and provide guidance

Root Cause

The revert was caused by RUFF UP045 lint violations in torch/fx/node.py. The linter requires the modern X | None annotation style instead of Optional[X].

When this revert PR (#177047) restored the original Python implementation of torch.fx.Node, it reintroduced several Optional[...] type annotations that had been removed when the code was moved to C++. Meanwhile, PR #176308 had landed on main to modernize annotations (Optional[X]X | None) across the codebase, and the RUFF UP045 rule now enforces this.

The PR description noted the merge conflict was resolved keeping the modern style, but a few Optional[...] annotations were missed in the restored code. Specifically, the violations are at these locations in torch/fx/node.py:

Line(s) Function Issue
597-598 format_node Optional[list[str]] params
601 format_node Optional[str] return type
695 replace_all_uses_with Optional[Callable[["Node"], bool]] param
789-790 normalized_arguments Optional[tuple[Any]], Optional[dict[str, Any]] params
792 normalized_arguments Optional[ArgsKwargsPair] return type

Is this a legitimate revert?

Yes, the revert is legitimate. Lint failures on trunk block the CI pipeline for all contributors. The fix is trivial, but since this was already merged, a revert is the standard procedure.

How to fix

The fix is straightforward — replace the remaining Optional[X] annotations with X | None in torch/fx/node.py. The linter output even provides the exact diff. The changes needed:

# Line 597-598: format_node params
-        placeholder_names: Optional[list[str]] = None,
-        maybe_return_typename: Optional[list[str]] = None,
+        placeholder_names: list[str] | None = None,
+        maybe_return_typename: list[str] | None = None,

# Line 601: format_node return type
-    ) -> Optional[str]:
+    ) -> str | None:

# Line 695: replace_all_uses_with param
-        delete_user_cb: Optional[Callable[["Node"], bool]] = None,
+        delete_user_cb: Callable[["Node"], bool] | None = None,

# Line 789-790: normalized_arguments params
-        arg_types: Optional[tuple[Any]] = None,
-        kwarg_types: Optional[dict[str, Any]] = None,
+        arg_types: tuple[Any] | None = None,
+        kwarg_types: dict[str, Any] | None = None,

# Line 792: normalized_arguments return type
-    ) -> Optional[ArgsKwargsPair]:
+    ) -> ArgsKwargsPair | None:

The author should apply these annotation fixes and re-land the revert. Running lintrunner -a would auto-fix these.


@pytorchmergebot
Copy link
Collaborator

@pytorchbot successfully started a revert job. Check the current status here.
Questions? Feedback? Please reach out to the PyTorch DevX Team

pytorchmergebot added a commit that referenced this pull request Mar 11, 2026
This reverts commit 68bcdcb.

Reverted #177047 on behalf of https://github.com/pytorch-auto-revert due to Reverted automatically by pytorch's autorevert, to avoid this behaviour add the tag autorevert: disable ([comment](#177047 (comment)))
@pytorchmergebot
Copy link
Collaborator

@wdvr your PR has been successfully reverted.

@wdvr
Copy link
Contributor Author

wdvr commented Mar 11, 2026

@pytorchmergebot rebase -b main

@pytorchmergebot
Copy link
Collaborator

@pytorchbot started a rebase job onto refs/remotes/origin/main. Check the current status here

@pytorchmergebot
Copy link
Collaborator

Rebase failed due to

Aborting rebase because rebasing the branch resulted in the same sha as the target branch.
This usually happens because the PR has already been merged.  Please rebase locally and push.

Raised by https://github.com/pytorch/pytorch/actions/runs/22968090201

@wdvr wdvr closed this Mar 12, 2026
pytorchmergebot pushed a commit that referenced this pull request Mar 12, 2026
Reland of #177047 which was auto-reverted due to lint failures.

This reverts commit 4bc9d7f ("Reapply "[fx] Move the rest of torch.fx.Node to C++ (#170946)" (#177047)").

Authored with Claude.
Pull Request resolved: #177183
Approved by: https://github.com/huydhn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-no-td Do not run TD on this PR ciflow/inductor ciflow/torchtitan Run TorchTitan integration tests Merged module: inductor release notes: fx release notes category Reverted skip-pr-sanity-checks suppress-bc-linter Suppresses the failures of API backward-compatibility linter (Lint/bc_linter)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants