Skip to content

[dynamo] Add min/max bounds support to mark_unbacked#176313

Closed
laithsakka wants to merge 8 commits intogh/laithsakka/414/basefrom
gh/laithsakka/414/head
Closed

[dynamo] Add min/max bounds support to mark_unbacked#176313
laithsakka wants to merge 8 commits intogh/laithsakka/414/basefrom
gh/laithsakka/414/head

Conversation

@laithsakka
Copy link
Contributor

@laithsakka laithsakka commented Mar 3, 2026

Stack from ghstack (oldest at bottom):

Adds min and max parameters to mark_unbacked() to allow specifying
value range constraints for unbacked dimensions.

When an unbacked symbol is created with min/max bounds, torch._check()
calls are emitted to establish the constraints (e.g., torch._check(u0 >= 1)).

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

Summary:
Adds min and max parameters to mark_unbacked() to allow specifying
value range constraints for unbacked dimensions.

When an unbacked symbol is created with min/max bounds, torch._check()
calls are emitted to establish the constraints (e.g., torch._check(u0 >= 1)).
This allows the optimizer to reason about unbacked symbols the same way
it does for backed symbols, enabling constant folding and other
optimizations that require knowing value ranges.

Test Plan:
Added test_mark_unbacked_min_max_bounds in test_dynamic_shapes.py.

[ghstack-poisoned]
@pytorch-bot
Copy link

pytorch-bot bot commented Mar 3, 2026

🔗 Helpful Links

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

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 2e74e51 with merge base 07efc60 (image):

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.

laithsakka added a commit that referenced this pull request Mar 3, 2026
Summary:
Adds min and max parameters to mark_unbacked() to allow specifying
value range constraints for unbacked dimensions.

When an unbacked symbol is created with min/max bounds, torch._check()
calls are emitted to establish the constraints (e.g., torch._check(u0 >= 1)).
This allows the optimizer to reason about unbacked symbols the same way
it does for backed symbols, enabling constant folding and other
optimizations that require knowing value ranges.

Test Plan:
Added test_mark_unbacked_min_max_bounds in test_dynamic_shapes.py.

ghstack-source-id: 5f2f610
Pull Request resolved: #176313
Summary:
Adds min and max parameters to mark_unbacked() to allow specifying
value range constraints for unbacked dimensions.

When an unbacked symbol is created with min/max bounds, torch._check()
calls are emitted to establish the constraints (e.g., torch._check(u0 >= 1)).
This allows the optimizer to reason about unbacked symbols the same way
it does for backed symbols, enabling constant folding and other
optimizations that require knowing value ranges.

Test Plan:
Added test_mark_unbacked_min_max_bounds in test_dynamic_shapes.py.

[ghstack-poisoned]
Summary:
Adds min and max parameters to mark_unbacked() to allow specifying
value range constraints for unbacked dimensions.

When an unbacked symbol is created with min/max bounds, torch._check()
calls are emitted to establish the constraints (e.g., torch._check(u0 >= 1)).
This allows the optimizer to reason about unbacked symbols the same way
it does for backed symbols, enabling constant folding and other
optimizations that require knowing value ranges.

Test Plan:
Added test_mark_unbacked_min_max_bounds in test_dynamic_shapes.py.

[ghstack-poisoned]
laithsakka added a commit that referenced this pull request Mar 3, 2026
Summary:
Adds min and max parameters to mark_unbacked() to allow specifying
value range constraints for unbacked dimensions.

When an unbacked symbol is created with min/max bounds, torch._check()
calls are emitted to establish the constraints (e.g., torch._check(u0 >= 1)).
This allows the optimizer to reason about unbacked symbols the same way
it does for backed symbols, enabling constant folding and other
optimizations that require knowing value ranges.

Test Plan:
Added test_mark_unbacked_min_max_bounds in test_dynamic_shapes.py.

ghstack-source-id: 5f2f610
Pull Request resolved: #176313
Summary:
Adds min and max parameters to mark_unbacked() to allow specifying
value range constraints for unbacked dimensions.

When an unbacked symbol is created with min/max bounds, torch._check()
calls are emitted to establish the constraints (e.g., torch._check(u0 >= 1)).
This allows the optimizer to reason about unbacked symbols the same way
it does for backed symbols, enabling constant folding and other
optimizations that require knowing value ranges.

Test Plan:
Added test_mark_unbacked_min_max_bounds in test_dynamic_shapes.py.

[ghstack-poisoned]
Summary:
Adds min and max parameters to mark_unbacked() to allow specifying
value range constraints for unbacked dimensions.

When an unbacked symbol is created with min/max bounds, torch._check()
calls are emitted to establish the constraints (e.g., torch._check(u0 >= 1)).
This allows the optimizer to reason about unbacked symbols the same way
it does for backed symbols, enabling constant folding and other
optimizations that require knowing value ranges.

Test Plan:
Added test_mark_unbacked_min_max_bounds in test_dynamic_shapes.py.

[ghstack-poisoned]
laithsakka added a commit that referenced this pull request Mar 3, 2026
Summary:
Adds min and max parameters to mark_unbacked() to allow specifying
value range constraints for unbacked dimensions.

When an unbacked symbol is created with min/max bounds, torch._check()
calls are emitted to establish the constraints (e.g., torch._check(u0 >= 1)).
This allows the optimizer to reason about unbacked symbols the same way
it does for backed symbols, enabling constant folding and other
optimizations that require knowing value ranges.

Test Plan:
Added test_mark_unbacked_min_max_bounds in test_dynamic_shapes.py.

ghstack-source-id: 0fbc823
Pull Request resolved: #176313
@laithsakka laithsakka marked this pull request as draft March 3, 2026 19:28
Adds min and max parameters to mark_unbacked() to allow specifying
value range constraints for unbacked dimensions.

When an unbacked symbol is created with min/max bounds, torch._check()
calls are emitted to establish the constraints (e.g., torch._check(u0 >= 1)).


[ghstack-poisoned]
laithsakka added a commit that referenced this pull request Mar 3, 2026
Summary:
Adds min and max parameters to mark_unbacked() to allow specifying
value range constraints for unbacked dimensions.

When an unbacked symbol is created with min/max bounds, torch._check()
calls are emitted to establish the constraints (e.g., torch._check(u0 >= 1)).
This allows the optimizer to reason about unbacked symbols the same way
it does for backed symbols, enabling constant folding and other
optimizations that require knowing value ranges.

Test Plan:
Added test_mark_unbacked_min_max_bounds in test_dynamic_shapes.py.

ghstack-source-id: e057ce9
Pull Request resolved: #176313
Adds min and max parameters to mark_unbacked() to allow specifying
value range constraints for unbacked dimensions.

When an unbacked symbol is created with min/max bounds, torch._check()
calls are emitted to establish the constraints (e.g., torch._check(u0 >= 1)).


[ghstack-poisoned]
laithsakka added a commit that referenced this pull request Mar 4, 2026
Summary:
Adds min and max parameters to mark_unbacked() to allow specifying
value range constraints for unbacked dimensions.

When an unbacked symbol is created with min/max bounds, torch._check()
calls are emitted to establish the constraints (e.g., torch._check(u0 >= 1)).
This allows the optimizer to reason about unbacked symbols the same way
it does for backed symbols, enabling constant folding and other
optimizations that require knowing value ranges.

Test Plan:
Added test_mark_unbacked_min_max_bounds in test_dynamic_shapes.py.

ghstack-source-id: 97416af
Pull Request resolved: #176313
@laithsakka laithsakka marked this pull request as ready for review March 4, 2026 04:27
guard.user_stack,
)

# TODO we dont have guards on _dynamo_unbacked_indices like those of _dynamo_dynamic_indices this seems wrong!!
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we still need this todo now that we have guards? Or is this particularly saying these guards differ from dynamic_indices so need to change in the future?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeh we need those i am doing it in the PR on top of this basically
what this comment say

if we do mark_unbacked(x, [0,1]) then mark_unbacked(x, [0,1,2]), we do not recompile since we do not add any guards on _dynamo_unbacked_indices value.

Adds min and max parameters to mark_unbacked() to allow specifying
value range constraints for unbacked dimensions.

When an unbacked symbol is created with min/max bounds, torch._check()
calls are emitted to establish the constraints (e.g., torch._check(u0 >= 1)).


[ghstack-poisoned]
laithsakka added a commit that referenced this pull request Mar 4, 2026
Summary:
Adds min and max parameters to mark_unbacked() to allow specifying
value range constraints for unbacked dimensions.

When an unbacked symbol is created with min/max bounds, torch._check()
calls are emitted to establish the constraints (e.g., torch._check(u0 >= 1)).
This allows the optimizer to reason about unbacked symbols the same way
it does for backed symbols, enabling constant folding and other
optimizations that require knowing value ranges.

Test Plan:
Added test_mark_unbacked_min_max_bounds in test_dynamic_shapes.py.

ghstack-source-id: 9eb449b
Pull Request resolved: #176313
Copy link
Contributor

@Lucaskabela Lucaskabela left a comment

Choose a reason for hiding this comment

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

Thanks for the change - this looks good to me

@laithsakka
Copy link
Contributor Author

@pytorchbot merge

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Mar 9, 2026
@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

meta-codesync bot pushed a commit to pytorch/benchmark that referenced this pull request Mar 11, 2026
Summary:
Adds min and max parameters to mark_unbacked() to allow specifying
value range constraints for unbacked dimensions.

When an unbacked symbol is created with min/max bounds, torch._check()
calls are emitted to establish the constraints (e.g., torch._check(u0 >= 1)).

X-link: pytorch/pytorch#176313
Approved by: https://github.com/Lucaskabela, https://github.com/mlazos
ghstack dependencies: #175946, #175956

Reviewed By: huydhn

Differential Revision: D95914182

fbshipit-source-id: 0acdb0d80e3c4710a57deb70ebfbefe32af86f93
sandy-gags pushed a commit to sandy-gags/pytorch that referenced this pull request Mar 12, 2026
Summary:
Adds min and max parameters to mark_unbacked() to allow specifying
value range constraints for unbacked dimensions.

When an unbacked symbol is created with min/max bounds, torch._check()
calls are emitted to establish the constraints (e.g., torch._check(u0 >= 1)).
This allows the optimizer to reason about unbacked symbols the same way
it does for backed symbols, enabling constant folding and other
optimizations that require knowing value ranges.

Test Plan:
Added test_mark_unbacked_min_max_bounds in test_dynamic_shapes.py.

ghstack-source-id: 2304ec2
Pull Request resolved: pytorch/pytorch#176313
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.

4 participants