KEMBAR78
Delay mul/pow expansion for `_SympyT` to enable more folding by StrongerXi · Pull Request #138235 · pytorch/pytorch · GitHub
Skip to content

Conversation

@StrongerXi
Copy link
Contributor

@StrongerXi StrongerXi commented Oct 17, 2024

Instead of calling safe_expand right after symbolic expression construction, we invoke it in ShapeEnv.simplify. This enables more simplification with product form, e.g.,

(a + b)^2 / (a + b) --> (a + b)

which won't happen if we expand eagerly during product construction:

(a^2 + 2ab + b^2) / (a + b) --> no change

Fixes #136044.

cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @chenyang78 @kadeng @chauhang @amjames @rec

@pytorch-bot
Copy link

pytorch-bot bot commented Oct 17, 2024

🔗 Helpful Links

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

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

❌ 5 New Failures, 2 Unrelated Failures

As of commit ca264be with merge base f3c3f3a (image):

NEW FAILURES - The following jobs have failed:

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

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

@pytorch-bot pytorch-bot bot added ciflow/inductor release notes: fx release notes category labels Oct 17, 2024
@StrongerXi StrongerXi force-pushed the ryanguo99/enhance-modulo-folding branch from 58b8608 to edf9cb9 Compare October 17, 2024 21:19
@StrongerXi
Copy link
Contributor Author

StrongerXi commented Oct 17, 2024

add_loop_eager_dynamic, compile_time_instruction_count, 5563298740, 0.025
add_loop_inductor, compile_time_instruction_count, 24064639114, 0.015
add_loop_inductor_dynamic_gpu, compile_time_instruction_count, 40992578178, 0.025
add_loop_inductor_dynamic_gpu, compile_time_instruction_count, 38593682350, 0.025
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change turned out to be a flake, I'll revert.

@StrongerXi StrongerXi force-pushed the ryanguo99/enhance-modulo-folding branch from edf9cb9 to bd1f72e Compare October 18, 2024 16:48
Instead of calling `safe_expand` right after symbolic expression
construction, we invoke it in `ShapeEnv.simplify`. This enables more
simplification with product form, e.g.,
```
(a + b)^2 / (a + b) --> (a + b)
```
which won't happen if we expand eagerly during product construction:
```
(a^2 + 2ab + b^2) / (a + b) --> no change
```

Fixes #136044.
@StrongerXi StrongerXi force-pushed the ryanguo99/enhance-modulo-folding branch from bd1f72e to ca264be Compare October 18, 2024 16:49
@StrongerXi StrongerXi changed the title [EXPERIMENT][DO NOT LAND] Delay mul/pow expansion for _SympyT Delay mul/pow expansion for _SympyT to enable more folding Oct 18, 2024
@StrongerXi StrongerXi requested a review from ezyang October 18, 2024 16:50
Copy link
Contributor

@ezyang ezyang left a comment

Choose a reason for hiding this comment

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

Wow! Passing all tests. You probably should also import to fbcode and see what happens there.

@facebook-github-bot
Copy link
Contributor

@StrongerXi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@StrongerXi
Copy link
Contributor Author

Wow! Passing all tests. You probably should also import to fbcode and see what happens there.

Internals all passed. The red ones are OSS flaky tests from main. Merging

@StrongerXi
Copy link
Contributor Author

@pytorchbot merge

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Oct 21, 2024
@pytorchmergebot
Copy link
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
Collaborator

Merge failed

Reason: 1 jobs have failed, first few of them are: linux-binary-manywheel / manywheel-py3_9-cuda12_1-build / build

Details for Dev Infra team Raised by workflow job

@StrongerXi
Copy link
Contributor Author

@pytorchbot merge -f "unrelated failure"

@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

@ezyang
Copy link
Contributor

ezyang commented Oct 22, 2024

This improves compile time on detectron2_fcos_r_50_fpn inference compilation:

image

Nice work!

@github-actions github-actions bot deleted the ryanguo99/enhance-modulo-folding branch November 22, 2024 02:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/inductor ciflow/trunk Trigger trunk jobs on your pull request Merged module: dynamo release notes: fx release notes category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot solve divisibility test on non-trivial expression

4 participants