Skip to content

[inductor] Stop re-running DtypePropagationOpsHandler's meta programming on every construction - #192820

Closed
anijain2305 wants to merge 6 commits into
gh/anijain2305/1300/basefrom
gh/anijain2305/1300/head
Closed

anijain2305 wants to merge 6 commits into
gh/anijain2305/1300/basefrom
gh/anijain2305/1300/head

Conversation

@anijain2305

@anijain2305 anijain2305 commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

DtypePropagationOpsHandler is a singleton whose init meta programs a dtype
rule onto the instance for every op in three registries, then validates coverage
with OP_NAMES - OrderedSet(dir(self)). The singleton is implemented in new,
but Python calls init after new regardless, so all of that work reran on
every construction - 7343 times on a FairChem UMA compile, for a total of 0.79s.

Skip it when the registry it is built from is unchanged. The comment on the class
notes the rules are only defined after other inductor state has run, so this
can't be a plain do-once: key the skip on the contents of
op_dtype_propagation_rules, which is the only one of the three registries read
that grows over time (the other two are module level literals). A late
registration therefore still gets picked up on the next construction.

Measured on UMA: 7343 calls, 0.786s -> 0.067s. This is below the run to run
noise of an end to end compile, so it shows up as directly measured init
time rather than as a wall clock delta.

Test Plan:

python test/inductor/test_op_dtype_prop.py    # 624 tests, OK
python test/inductor/test_codegen_triton.py   # 23 tests, OK (skipped=2)

Also checked directly that the singleton still observes a rule registered after
the first construction.

This PR was authored with the assistance of an AI coding agent.

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

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Aug 10, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

✅ No Failures

As of commit 8f0cb0a with merge base c00fc93 (image):
💚 Looks good so far! There are no failures yet. 💚

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

[ghstack-poisoned]
[ghstack-poisoned]
@anijain2305
anijain2305 requested review from eellison and mlazos August 10, 2026 23:54
[ghstack-poisoned]
[ghstack-poisoned]
@anijain2305 anijain2305 added ciflow/trunk Trigger trunk jobs on your pull request topic: not user facing topic category labels Aug 11, 2026

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

Did not realize that even though it's a singleton... init gets re-run.

Failing jobs:
- linux-jammy-cuda13.0-py3.10-gcc11 / test (pr_time_benchmarks, 1, 1, mt-l-bx86iavx512-94-344-t4-8)
- linux-jammy-cuda13.2-py3.10-gcc11 / test (pr_time_benchmarks, 1, 1, mt-l-bx86iavx512-94-344-t4-8)

Failing target: benchmark ('add_loop_inductor', 'compile_time_instruction_count')
CI command: python benchmarks/dynamo/pr_time_benchmarks/check_results.py benchmarks/dynamo/pr_time_benchmarks/expected_results.csv /__w/pytorch/pytorch/test/test-reports/pr_time_benchmarks_results.csv /__w/pytorch/pytorch/test/test-reports/new_expected_results.csv

Error:
  WIN: benchmark ('add_loop_inductor', 'compile_time_instruction_count') failed,
  actual result 28861813332 is -12.09% lower than expected
  32830000000 +/-10.00%.

The approved change avoids rebuilding dtype propagation rules on every handler construction. The add_loop_inductor compile benchmark repeatedly constructs those handlers, so both CUDA configurations consistently report the same instruction-count improvement. Refresh its expected count to 28860000000 while retaining the existing 10% tolerance.

Lint: lintrunner -a (infrastructure failure downloading the Python toolchain); git diff --check passed. Tests were not run because CI instruction counts are the source of truth.

This fix was prepared with an AI assistant.

[ghstack-poisoned]
anijain2305 added a commit that referenced this pull request Aug 11, 2026
…ing on every construction

DtypePropagationOpsHandler is a singleton whose __init__ meta programs a dtype
rule onto the instance for every op in three registries, then validates coverage
with OP_NAMES - OrderedSet(dir(self)). The singleton is implemented in __new__,
but Python calls __init__ after __new__ regardless, so all of that work reran on
every construction - 7343 times on a FairChem UMA compile, for a total of 0.79s.

Skip it when the registry it is built from is unchanged. The comment on the class
notes the rules are only defined after other inductor state has run, so this
can't be a plain do-once: key the skip on the contents of
op_dtype_propagation_rules, which is the only one of the three registries read
that grows over time (the other two are module level literals). A late
registration therefore still gets picked up on the next construction.

Measured on UMA: 7343 calls, 0.786s -> 0.067s. This is below the run to run
noise of an end to end compile, so it shows up as directly measured __init__
time rather than as a wall clock delta.

Test Plan:

```
python test/inductor/test_op_dtype_prop.py    # 624 tests, OK
python test/inductor/test_codegen_triton.py   # 23 tests, OK (skipped=2)
```

Also checked directly that the singleton still observes a rule registered after
the first construction.

This PR was authored with the assistance of an AI coding agent.

ghstack-source-id: 283c947
Pull-Request: #192820


add_loop_inductor,compile_time_instruction_count,32830000000,0.1
add_loop_inductor,compile_time_instruction_count,28860000000,0.1

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 hunk was LLM-generated by mergedog in commit d6fc676e50c8. Review that commit for context and justification.

Note

This PR is being shepherded by mergedog, an automation tool run by a maintainer. It watches CI and may push fixes; the PR author does not need to act unless a maintainer asks.

@anijain2305

Copy link
Copy Markdown
Contributor Author

@pytorchbot 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: trunk / linux-jammy-rocm-py3.10-mi350 / test (default, 2, 8, linux.rocm.gpu.gfx950.1)

Details for Dev Infra team Raised by workflow job

@anijain2305

Copy link
Copy Markdown
Contributor Author

@pytorchbot 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

ankitbhrdwj pushed a commit to ankitbhrdwj/pytorch that referenced this pull request Aug 12, 2026
…ing on every construction (pytorch#192820)

DtypePropagationOpsHandler is a singleton whose __init__ meta programs a dtype
rule onto the instance for every op in three registries, then validates coverage
with OP_NAMES - OrderedSet(dir(self)). The singleton is implemented in __new__,
but Python calls __init__ after __new__ regardless, so all of that work reran on
every construction - 7343 times on a FairChem UMA compile, for a total of 0.79s.

Skip it when the registry it is built from is unchanged. The comment on the class
notes the rules are only defined after other inductor state has run, so this
can't be a plain do-once: key the skip on the contents of
op_dtype_propagation_rules, which is the only one of the three registries read
that grows over time (the other two are module level literals). A late
registration therefore still gets picked up on the next construction.

Measured on UMA: 7343 calls, 0.786s -> 0.067s. This is below the run to run
noise of an end to end compile, so it shows up as directly measured __init__
time rather than as a wall clock delta.

Test Plan:

```
python test/inductor/test_op_dtype_prop.py    # 624 tests, OK
python test/inductor/test_codegen_triton.py   # 23 tests, OK (skipped=2)
```

Also checked directly that the singleton still observes a rule registered after
the first construction.

This PR was authored with the assistance of an AI coding agent.

Pull Request resolved: pytorch#192820
Approved by: https://github.com/eellison
gavinwang269 pushed a commit to gavinwang269/pytorch that referenced this pull request Aug 13, 2026
…ing on every construction (pytorch#192820)

DtypePropagationOpsHandler is a singleton whose __init__ meta programs a dtype
rule onto the instance for every op in three registries, then validates coverage
with OP_NAMES - OrderedSet(dir(self)). The singleton is implemented in __new__,
but Python calls __init__ after __new__ regardless, so all of that work reran on
every construction - 7343 times on a FairChem UMA compile, for a total of 0.79s.

Skip it when the registry it is built from is unchanged. The comment on the class
notes the rules are only defined after other inductor state has run, so this
can't be a plain do-once: key the skip on the contents of
op_dtype_propagation_rules, which is the only one of the three registries read
that grows over time (the other two are module level literals). A late
registration therefore still gets picked up on the next construction.

Measured on UMA: 7343 calls, 0.786s -> 0.067s. This is below the run to run
noise of an end to end compile, so it shows up as directly measured __init__
time rather than as a wall clock delta.

Test Plan:

```
python test/inductor/test_op_dtype_prop.py    # 624 tests, OK
python test/inductor/test_codegen_triton.py   # 23 tests, OK (skipped=2)
```

Also checked directly that the singleton still observes a rule registered after
the first construction.

This PR was authored with the assistance of an AI coding agent.

Pull Request resolved: pytorch#192820
Approved by: https://github.com/eellison
@github-actions
github-actions Bot deleted the gh/anijain2305/1300/head branch November 3, 2026 01:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/inductor ciflow/torchtitan Run TorchTitan integration tests ciflow/trunk Trigger trunk jobs on your pull request Merged module: dynamo module: inductor topic: not user facing topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants