simplify max(1,x) to x when x known >=1#157189
Closed
laithsakka wants to merge 4 commits intogh/laithsakka/233/basefrom
Closed
simplify max(1,x) to x when x known >=1#157189laithsakka wants to merge 4 commits intogh/laithsakka/233/basefrom
laithsakka wants to merge 4 commits intogh/laithsakka/233/basefrom
Conversation
[ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/157189
Note: Links to docs will display an error until the docs builds have been completed. ✅ You can merge normally! (1 Unrelated Failure)As of commit 8b30dd2 with merge base feea575 ( 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. |
Creating contiguous strides creates an expression max(1, x). Often we know that x >= 1, in which case we should simplify max(1, x) to x. This appeared in two situations: 1) An internal user complained about statically_known_true(x == max(1, x)) failing (internal link: https://fb.workplace.com/groups/1028545332188949/permalink/1232958568414290). This #155938 won't be needed with this. 3) Not simplifying the above could result in wrong ConstraintViolationErrors. Because we assume non-trival single arg guards shall evaporate see the logic at this line with this change we longer throw ConstraintViolationErrors with the program bellow this is blocking landing this [PR](#155590) from landing internally. Due to internal export tests throwing ConstraintViolationErrors. ``` x = torch.rand(10) torch._dynamo.mark_dynamic(x, 0, max=20, min=5) torch.compile(fullgraph=True, dynamic=True) def func(x): if max(1, (-1 + x.size()[0]//2)) == (-1+x.size()[0]//2): return x*400 else: return (x*10)*100 func(x) ``` [ghstack-poisoned]
pianpwk
reviewed
Jun 28, 2025
pianpwk
approved these changes
Jun 28, 2025
Contributor
pianpwk
left a comment
There was a problem hiding this comment.
change makes sense, approving to avoid revert. let's generalize this better later?
Contributor
Author
|
@pytorchbot merge |
Collaborator
Merge startedYour 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stack from ghstack (oldest at bottom):
Creating contiguous strides creates an expression max(1, x). Often we know that x >= 1, in
which case we should simplify max(1, x) to x.
This appeared in two situations:
An internal user complained about statically_known_true(x == max(1, x)) failing (internal link: https://fb.workplace.com/groups/1028545332188949/permalink/1232958568414290).
This Fix stride comparison max(512 - s, 1) vs. (512 - s) #155938 won't be needed with this.
Not simplifying the above could result in wrong ConstraintViolationErrors.
Because we assume non-trival single arg guards shall evaporate see the logic in the function
issue_guard in symbolic_shapes.py
with this change we longer throw ConstraintViolationErrors with the program bellow
this is blocking landing this PR from landing
internally. Due to internal export tests throwing ConstraintViolationErrors.
like
cc @ezyang @SherlockNoMad @EikanWang @jgong5 @wenzhe-nrv