Skip to content

[pyrefly] Add type annotations to torch/fx/passes - #179731

Closed
Lucaskabela wants to merge 2 commits into
mainfrom
pyrefly/fx-passes
Closed

Lucaskabela wants to merge 2 commits into
mainfrom
pyrefly/fx-passes

Conversation

@Lucaskabela

Copy link
Copy Markdown
Contributor

Remove mypy suppressions. Add return type, parameter type, and generic type annotations. Backward-compatible APIs use pyrefly ignore comments.

Authored with Claude.

@pytorch-bot

pytorch-bot Bot commented Apr 8, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

✅ You can merge normally! (2 Unrelated Failures)

As of commit bfd4c4b with merge base c5acdfb (image):

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

BROKEN TRUNK - The following job failed but was present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

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

@pytorch-bot pytorch-bot Bot added the release notes: fx release notes category label Apr 8, 2026
@Lucaskabela Lucaskabela added the suppress-bc-linter Suppresses the failures of API backward-compatibility linter (Lint/bc_linter) label Apr 8, 2026
@Lucaskabela

Copy link
Copy Markdown
Contributor Author

BC suppression because Callable -> Callable[..., Any] is not a BC breaking change...

Comment thread torch/fx/passes/infra/pass_manager.py Resolved
Comment thread torch/fx/passes/fake_tensor_prop.py Resolved
Comment thread torch/fx/passes/pass_manager.py Resolved
Comment thread torch/fx/passes/regional_inductor.py Resolved
Comment thread torch/fx/passes/splitter_base.py Resolved
@Lucaskabela
Lucaskabela marked this pull request as ready for review April 8, 2026 22:34

@aorenste aorenste 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.

There are a few minor behavior changes mixed in (RuntimeError in split_utils.py, bool return in _needs_inductor_compile in regional_inductor.py). Should we split those into a separate PR for easier landing/tracking?

@aorenste aorenste 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.

There are a LOT of Anys here. Maybe do a pass with Claude to have it guess at some of those types?

Comment thread torch/fx/passes/pass_manager.py Resolved
Comment thread torch/fx/passes/backends/cudagraphs.py Resolved
Comment thread torch/fx/passes/backends/cudagraphs.py Resolved
Comment thread torch/fx/passes/backends/cudagraphs.py Resolved
@Lucaskabela

Copy link
Copy Markdown
Contributor Author

There are a LOT of Anys here. Maybe do a pass with Claude to have it guess at some of those types?

I had the same thought and already gave it a pass with claude - let me try again but with a bit more manual oversight

# If input is a get_attr node, copy it to current component's graph.
# Returns the get_attr node in current component's graph.
if x.op == "get_attr":
if not isinstance(x.target, str):

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

cc @aorenste this is not truly a change - this is to make pyrefly happy as opposed to asserts doing type narrowing.

This is the new preferred way to do this as Alban has landed a series of PRs enabling S101 (no asserts in code)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We can remove this and just throw a pyrefly suppression if you are concerned about the correctness here though

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 - I dislike S101 enforcement. Sometimes assertions are actually useful as a concept of something that disappears w/ optimization turned on.

This is a behavior change - but a reasonable change.

def _needs_inductor_compile(node: torch.fx.Node):
return (
def _needs_inductor_compile(node: torch.fx.Node) -> bool:
return bool(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is also a "make pyrefly happy" change - just explicitly narrowing and returning bool as opposed to implicit (no behavior change)

@aorenste aorenste Apr 10, 2026 •

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.

But it IS a behavior change - previously we sometimes returned None (which is "falsy" - but the type was a lie). But I'm okay with the change.

@Lucaskabela
Lucaskabela force-pushed the pyrefly/fx-passes branch 3 times, most recently from 173cb54 to fee6ec9 Compare April 9, 2026 17:42
const_mod_name, non_const_mod_name = "submod_0", "submod_1"
# Safely get submod_1 in case there are no non-const nodes
const_gm, non_const_gm = split.submod_0, getattr(split, non_const_mod_name, None)
const_gm = getattr(split, const_mod_name)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

These are purely to support pyrefly - I can remove these and just silent the error if we are concerned about correctness (cc @aorenste )

@Lucaskabela
Lucaskabela requested a review from aorenste April 9, 2026 17:46
@Lucaskabela

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Apr 13, 2026
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your 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

Advanced Debugging
Check the merge workflow status
here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: 1 mandatory check(s) failed. The first few are:

Dig deeper by viewing the failures on hud

Details for Dev Infra team Raised by workflow job

Failing merge rule: Core Maintainers

@Lucaskabela

Copy link
Copy Markdown
Contributor Author

@pytorchmergebot merge

@Lucaskabela

Copy link
Copy Markdown
Contributor Author

@pytorchmergebot merge

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your 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

Advanced Debugging
Check the merge workflow status
here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: 1 mandatory check(s) failed. The first few are:

Dig deeper by viewing the failures on hud

Details for Dev Infra team Raised by workflow job

Failing merge rule: Core Maintainers

BoyuanFeng pushed a commit that referenced this pull request Apr 15, 2026
This reverts commit 8c49f56.

Reverted #180251 on behalf of https://github.com/jeanschmidt due to sorry, need to revert in order to revert #179731, feel free to resolve conflicts and merge into main after that ([comment](#180251 (comment)))
BoyuanFeng pushed a commit that referenced this pull request Apr 15, 2026
@Lucaskabela

Copy link
Copy Markdown
Contributor Author

@pytorchmergebot merge -i

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged while ignoring the following 1 checks: pull / linux-jammy-py3.10-gcc11 / test (distributed, 3, 3, linux.2xlarge.amx)

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

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: 1 jobs have failed, first few of them are: trunk / linux-jammy-rocm-py3.10-mi355 / test (default, 3, 6, linux.rocm.gpu.gfx950.1)

Details for Dev Infra team Raised by workflow job

@Lucaskabela

Copy link
Copy Markdown
Contributor Author

@pytorchmergebot merge

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your 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

Advanced Debugging
Check the merge workflow status
here

@github-actions
github-actions Bot deleted the pyrefly/fx-passes branch May 16, 2026 02:26
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
Remove mypy suppressions. Add return type, parameter type, and generic type annotations. Backward-compatible APIs use pyrefly ignore comments.

Authored with Claude.
Pull Request resolved: pytorch#179731
Approved by: https://github.com/aorenste
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
)"

This reverts commit 8c49f56.

Reverted pytorch#180251 on behalf of https://github.com/jeanschmidt due to sorry, need to revert in order to revert pytorch#179731, feel free to resolve conflicts and merge into main after that ([comment](pytorch#180251 (comment)))
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
Remove mypy suppressions. Add return type, parameter type, and generic type annotations. Backward-compatible APIs use pyrefly ignore comments.

Authored with Claude.
Pull Request resolved: pytorch#179731
Approved by: https://github.com/aorenste
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
Remove mypy suppressions. Add return type, parameter type, and generic type annotations. Backward-compatible APIs use pyrefly ignore comments.

Authored with Claude.
Pull Request resolved: pytorch#179731
Approved by: https://github.com/aorenste
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
)"

This reverts commit 8c49f56.

Reverted pytorch#180251 on behalf of https://github.com/jeanschmidt due to sorry, need to revert in order to revert pytorch#179731, feel free to resolve conflicts and merge into main after that ([comment](pytorch#180251 (comment)))
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
Remove mypy suppressions. Add return type, parameter type, and generic type annotations. Backward-compatible APIs use pyrefly ignore comments.

Authored with Claude.
Pull Request resolved: pytorch#179731
Approved by: https://github.com/aorenste
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/trunk Trigger trunk jobs on your pull request Merged release notes: fx release notes category Reverted 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.

4 participants