Skip to content

[BE][inductor] Apply PEP 604 type annotations (part 3/3)#175677

Closed
Lucaskabela wants to merge 3 commits intomainfrom
pep604-inductor-part3
Closed

[BE][inductor] Apply PEP 604 type annotations (part 3/3)#175677
Lucaskabela wants to merge 3 commits intomainfrom
pep604-inductor-part3

Conversation

@Lucaskabela
Copy link
Copy Markdown
Contributor

@Lucaskabela Lucaskabela commented Feb 24, 2026

Convert Union[X, Y] to X | Y and Optional[X] to X | None using ruff rules UP007 and UP045 in torch/_inductor. This covers files from fx_passes/misc_patterns through wrapper_benchmark.

Split with Claude.

See also #175675 and #175676

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

@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented Feb 24, 2026

🔗 Helpful Links

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

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

❌ 1 Cancelled Job, 4 Unrelated Failures

As of commit d924e21 with merge base 4416f11 (image):

CANCELLED JOB - The following job was cancelled. Please retry:

FLAKY - The following jobs failed but were likely due to flakiness present on trunk:

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

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

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
Copy link
Copy Markdown

pytorch-bot Bot commented Feb 24, 2026

This PR needs a release notes: label

If your changes are user facing and intended to be a part of release notes, please use a label starting with release notes:.

If not, please add the topic: not user facing label.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "topic: not user facing"

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

@Lucaskabela
Copy link
Copy Markdown
Contributor Author

Quick note for reviewers:

  1. Usages of "Optional" and "Union" may still exist in some files after this change - we need to import future annotaiton to remove those. That will be handled in a later PR as this PR is already quite large

  2. We used ruff for this PR - claude was used to split a branch with all inductor changes into these 3 PRs which are more manageable

@Lucaskabela
Copy link
Copy Markdown
Contributor Author

@pytorchbot label "topic: not user facing"

@pytorch-bot pytorch-bot Bot added the topic: not user facing topic category label Feb 24, 2026
@Lucaskabela Lucaskabela force-pushed the pep604-inductor-part3 branch 2 times, most recently from a0f7fec to c4cfd5b Compare February 25, 2026 21:02
@Lucaskabela
Copy link
Copy Markdown
Contributor Author

@pytorchbot merge -i

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Feb 26, 2026
@pytorchmergebot
Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged while ignoring the following 2 checks: Limited CI on H100 / linux-jammy-cuda12_8-py3_10-gcc11-sm90-FA3-ABI-stable-test / test, rocm-mi300 / linux-noble-rocm-py3.12-mi300 / test (default, 2, 6, linux.rocm.gpu.gfx942.1)

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
Copy Markdown

@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
Copy Markdown

claude Bot commented Feb 26, 2026

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


Revert Analysis

  • Fetch and analyze the lintrunner-pyrefly-all error from the CI link
  • Diagnose the root cause
  • Provide guidance on how to fix the issue

Root Cause

The pyrefly linter found an unresolved Optional reference at torch/_inductor/output_code.py:473:

_original_gm: Optional[torch.fx.GraphModule] = None

The issue is that the PR converted most Optional[X]X | None annotations but missed this one instance. The file imports from __future__ import annotations (line 23) but does not import Optional from typing (line 29 only imports Any, TYPE_CHECKING, TypeAlias).

Since the file already uses from __future__ import annotations, string annotations are deferred and not evaluated at runtime, but the pyrefly static type checker still requires all names used in type annotations to be defined in the module scope.

Verdict

This is a legitimate reason for revert. The PR introduced a bug where Optional is used but not imported.

Fix

The author should change line 473 from:

_original_gm: Optional[torch.fx.GraphModule] = None

to:

_original_gm: torch.fx.GraphModule | None = None

This follows the PEP 604 style that the rest of the file (and the rest of the PR) uses, and removes the need for the Optional import entirely.


@pytorchmergebot
Copy link
Copy Markdown
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 Feb 26, 2026
…5677)"

This reverts commit dbf26c1.

Reverted #175677 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](#175677 (comment)))
@Lucaskabela
Copy link
Copy Markdown
Contributor Author

@pytorchmergebot merge -i

@Lucaskabela
Copy link
Copy Markdown
Contributor Author

Failures are 32bit indexing, unrelated to this PR

@pytorchmergebot
Copy link
Copy Markdown
Collaborator

Merge failed

Reason: 1 jobs have failed, first few of them are: trunk / linux-jammy-cuda13.0-py3.10-gcc11 / test (distributed, 2, 3, lf.linux.g4dn.12xlarge.nvidia.gpu)

Details for Dev Infra team Raised by workflow job

@Lucaskabela
Copy link
Copy Markdown
Contributor Author

@pytorchmergebot merge

@Lucaskabela
Copy link
Copy Markdown
Contributor Author

This test also fails on #175676

@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

@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 jobs have failed, first few of them are: Limited CI on H100 / linux-jammy-cuda12_8-py3_10-gcc11-sm90-FA3-ABI-stable-test / test

Details for Dev Infra team Raised by workflow job

@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 3 checks: Limited CI on H100 / linux-jammy-cuda12_8-py3_10-gcc11-sm90-FA3-ABI-stable-test / test, inductor / inductor-cpu-test / test (cpu_inductor_torchbench, 1, 2, linux.2xlarge.amx, unstable), inductor / inductor-test / test (inductor_torchbench, 1, 2, linux.g5.4xlarge.nvidia.gpu)

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

postmath pushed a commit to postmath/pytorch that referenced this pull request Mar 3, 2026
)

Convert Union[X, Y] to X | Y and Optional[X] to X | None using ruff rules UP007 and UP045 in torch/_inductor. This covers files from fx_passes/misc_patterns through wrapper_benchmark.

Split with Claude.

See also pytorch#175675 and pytorch#175676

Pull Request resolved: pytorch#175677
Approved by: https://github.com/v0i0
EmanueleCoradin pushed a commit to EmanueleCoradin/pytorch that referenced this pull request Mar 30, 2026
)

Convert Union[X, Y] to X | Y and Optional[X] to X | None using ruff rules UP007 and UP045 in torch/_inductor. This covers files from fx_passes/misc_patterns through wrapper_benchmark.

Split with Claude.

See also pytorch#175675 and pytorch#175676

Pull Request resolved: pytorch#175677
Approved by: https://github.com/v0i0
EmanueleCoradin pushed a commit to EmanueleCoradin/pytorch that referenced this pull request Mar 30, 2026
…orch#175677)"

This reverts commit dbf26c1.

Reverted pytorch#175677 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](pytorch#175677 (comment)))
EmanueleCoradin pushed a commit to EmanueleCoradin/pytorch that referenced this pull request Mar 30, 2026
)

Convert Union[X, Y] to X | Y and Optional[X] to X | None using ruff rules UP007 and UP045 in torch/_inductor. This covers files from fx_passes/misc_patterns through wrapper_benchmark.

Split with Claude.

See also pytorch#175675 and pytorch#175676

Pull Request resolved: pytorch#175677
Approved by: https://github.com/v0i0
@github-actions github-actions Bot deleted the pep604-inductor-part3 branch April 2, 2026 02:24
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/b200 ciflow/h100 ciflow/inductor ciflow/rocm-mi300 Trigger "default" config CI on ROCm MI300 ciflow/trunk Trigger trunk jobs on your pull request Merged module: inductor Reverted topic: not user facing topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants