Repository navigation
[dynamic shapes] Don't truncate float expressions in guarding_hint_or_throw - #202324
laithsakka wants to merge 5 commits into
Conversation
PR Status: Approved 🚀Please fix all CI failures and trigger merge by commenting "@pytorchbot merge". ✅ AUTOMATED REVIEW - OUTDATED (earlier commit) - Ready for human review:
Findings (4): Reviewed commit: 🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/202324
Note: Links to docs will display an error until the docs builds have been completed. ❗ 1 Active SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below: ✅ No FailuresAs of commit 71c947a with merge base 0a133b7 ( 🟡 GREEN LIGHT - PR was reverted - re-landing requires human review:
Green Light will not review this PR again, on this or any later commit; re-landing it needs a human approval. This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
waiting for CI |
left comment its wrong issue
aorenste
left a comment
There was a problem hiding this comment.
(Reviewed by me, assisted by AI)
Merging is self-service: comment @pytorchbot merge and the bot lands it once required checks pass. Merging your Change | Bot commands
…_throw Fixes #201817 ShapeEnv.evaluate_expr on a float-valued expression without an explicit hint returned the value truncated to int and installed an unsound guard, e.g. for FloatTrueDiv(1.0, sqrt(ToFloat(s0))) with s0=64 it returned 0 and guarded Eq(..., 0), which fails on the very inputs it was created from. Since #177570, compute_concrete_val uses guarding_hint_or_throw, which goes through _maybe_realize_expr and does int(expr), truncating sympy.Float. _guarding_hint_or_throw_base now returns a Python float for sympy.Float. _maybe_realize_expr (shared with the int-only optimization_hint paths) is unchanged. Typing: - Add overloads to the module-level guarding_hint_or_throw so SymBool/bool -> bool, SymInt/int -> int, SymNode -> int | bool | float. - ShapeEnv and Inductor SizeVarAllocator guarding_hint_or_throw / guarding_hints_or_throw now return int | float (| bool for ShapeEnv). - Int-only Inductor call sites (expand's mark_reuse size products and the CUTLASS EVT size_hint_fn callback) convert explicitly with int(). Test: python test/test_dynamic_shapes.py -k test_evaluate_expr_float_without_hint ghstack-source-id: b6bcdc8 Pull-Request: #202324
…_throw Fixes #201817 ShapeEnv.evaluate_expr on a float-valued expression without an explicit hint returned the value truncated to int and installed an unsound guard, e.g. for FloatTrueDiv(1.0, sqrt(ToFloat(s0))) with s0=64 it returned 0 and guarded Eq(..., 0), which fails on the very inputs it was created from. Since #177570, compute_concrete_val uses guarding_hint_or_throw, which goes through _maybe_realize_expr and does int(expr), truncating sympy.Float. _guarding_hint_or_throw_base now returns a Python float for sympy.Float. _maybe_realize_expr (shared with the int-only optimization_hint paths) is unchanged. Typing: - Add overloads to the module-level guarding_hint_or_throw so SymBool/bool -> bool, SymInt/int -> int, SymNode -> int | bool | float. - ShapeEnv and Inductor SizeVarAllocator guarding_hint_or_throw / guarding_hints_or_throw now return int | float (| bool for ShapeEnv). - Int-only Inductor call sites (expand's mark_reuse size products and the CUTLASS EVT size_hint_fn callback) convert explicitly with int(). Test: python test/test_dynamic_shapes.py -k test_evaluate_expr_float_without_hint ghstack-source-id: f5cf443 Pull-Request: #202324
There was a problem hiding this comment.
Automated review of 0b558b8: nothing blocking; ready for human review.
The PR makes _guarding_hint_or_throw_base return a Python float for sympy.Float results, so ShapeEnv.evaluate_expr no longer truncates float expressions to int and installs a wrong guard. It also adds SymFloat/float support to guarding_hint_or_throw. Recommendation: Approve. Both earlier blocking findings are resolved and only non-blocking points remain.
⚪ 4 non-blocking findings
Non-blocking: infinite results are still truncated, even though the new docstring says "Float expressions return a Python float (never truncated to int)". The checks at :157 and :181 only catch sympy.Float. A float expression that evaluates to infinity becomes sympy.oo, which is not a Float. This happens with ToFloat(int_oo) or when FloatTrueDiv.eval overflows. _maybe_realize_expr then returns the int sys.maxsize, so compute_concrete_val can still install Eq(expr, 9223372036854775807), the same kind of unsound guard this PR fixes. NaN returns None and raises RuntimeError("unexpected None!"). This predates the PR and is rare. Either map oo/-oo/nan to float('inf')/float('-inf')/float('nan') next to the Float check, or narrow the docstring. (The reviewer couldn't run sympy to confirm the Float(inf) oo step.)
Non-blocking: stale docstrings and comments still say "integer". The Returns: sections at _size_hinting.py:131-132 and torch/_inductor/sizevars.py:1133-1134 still say "The concrete integer value of the expression", which contradicts the summary lines this PR updated just above them. The comment at symbolic_shapes.py:8833-8836 in compute_concrete_val says guarding_hint_or_throw returns bool/int, but this PR exists so that call site gets floats. The module docstring at _size_hinting.py:4-5 ("concrete integer hints") is also stale.
pytorch/torch/_inductor/lowering.py
Line 1518 in 0b558b8
Non-blocking, carried over: the int() casts on SizeVarAllocator.guarding_hint_or_throw results are applied unevenly. The PR adds them in expand (lowering.py:1501-1503, :1518) and at cutlass/gemm_template.py:1663. They are missing from the identical mark_reuse(guarding_hint_or_throw(...) // old_size_product) pattern in repeat (lowering.py:1584-1593) and from unfold (:2818-2820). There is no runtime effect, since Inductor sizes are integers. Either apply the casts consistently or narrow once inside SizeVarAllocator.
pytorch/test/test_dynamic_shapes.py
Line 655 in 0b558b8
Non-blocking, carried over: in test_guarding_hint_or_throw_float, the hint=None case tests the same thing as hint=0.125. With hint=None, SymNode.__init__ computes the hint eagerly (compute_hint), so _hint is already 0.125. Both cases return early at symbolic_shapes.py:159-160, and neither reaches the a.shape_env.guarding_hint_or_throw(a.expr) / a._hint = hint branch at :163-165. Building the node with hint=_NO_HINT would cover that branch. Also, assertEqual goes through RelaxedNumberPair, which ignores int/float type differences. Adding assertIsInstance(..., float) would lock in the documented "returns a Python float" behaviour for whole-number values like 8.0.
An earlier comment near this line has replies: #202324 (comment)
This review is AI-generated and advisory. Each new automated review replaces the previous one. Report a bad review
Withdrawn: the automated review of 0b558b8 found nothing blocking.
…_throw Fixes #201817 ShapeEnv.evaluate_expr on a float-valued expression without an explicit hint returned the value truncated to int and installed an unsound guard, e.g. for FloatTrueDiv(1.0, sqrt(ToFloat(s0))) with s0=64 it returned 0 and guarded Eq(..., 0), which fails on the very inputs it was created from. Since #177570, compute_concrete_val uses guarding_hint_or_throw, which goes through _maybe_realize_expr and does int(expr), truncating sympy.Float. _guarding_hint_or_throw_base now returns a Python float for sympy.Float. _maybe_realize_expr (shared with the int-only optimization_hint paths) is unchanged. Typing: - Add overloads to the module-level guarding_hint_or_throw so SymBool/bool -> bool, SymInt/int -> int, SymNode -> int | bool | float. - ShapeEnv and Inductor SizeVarAllocator guarding_hint_or_throw / guarding_hints_or_throw now return int | float (| bool for ShapeEnv). - Int-only Inductor call sites (expand's mark_reuse size products and the CUTLASS EVT size_hint_fn callback) convert explicitly with int(). Test: python test/test_dynamic_shapes.py -k test_evaluate_expr_float_without_hint ghstack-source-id: f1f992a Pull-Request: #202324
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 |
|
@pytorchbot merge |
|
The merge job was canceled or timed out. This most often happen if two merge requests were issued for the same PR, or if merge job was waiting for more than 6 hours for tests to finish. In later case, please do not hesitate to reissue the merge command |
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 |
Merge failedReason: Command Details for Dev Infra teamRaised by workflow job |
…_throw Fixes #201817 ShapeEnv.evaluate_expr on a float-valued expression without an explicit hint returned the value truncated to int and installed an unsound guard, e.g. for FloatTrueDiv(1.0, sqrt(ToFloat(s0))) with s0=64 it returned 0 and guarded Eq(..., 0), which fails on the very inputs it was created from. Since #177570, compute_concrete_val uses guarding_hint_or_throw, which goes through _maybe_realize_expr and does int(expr), truncating sympy.Float. _guarding_hint_or_throw_base now returns a Python float for sympy.Float. _maybe_realize_expr (shared with the int-only optimization_hint paths) is unchanged. Typing: - Add overloads to the module-level guarding_hint_or_throw so SymBool/bool -> bool, SymInt/int -> int, SymNode -> int | bool | float. - ShapeEnv and Inductor SizeVarAllocator guarding_hint_or_throw / guarding_hints_or_throw now return int | float (| bool for ShapeEnv). - Int-only Inductor call sites (expand's mark_reuse size products and the CUTLASS EVT size_hint_fn callback) convert explicitly with int(). Test: python test/test_dynamic_shapes.py -k test_evaluate_expr_float_without_hint ghstack-source-id: 16a2d62 Pull-Request: #202324
|
rebased |
|
@pytorchbot merge |
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 |
|
@claude anyreason this hasnt landed yet? |
|
Claude encountered an error after 13s —— View job I'll analyze this and get back to you. |
Stack from ghstack (oldest at bottom):
Fixes #201817
ShapeEnv.evaluate_expr on a float-valued expression without an explicit
hint returned the value truncated to int and installed an unsound guard,
e.g. for FloatTrueDiv(1.0, sqrt(ToFloat(s0))) with s0=64 it returned 0 and
guarded Eq(..., 0), which fails on the very inputs it was created from.
Since #177570, compute_concrete_val uses guarding_hint_or_throw, which goes
through _maybe_realize_expr and does int(expr), truncating sympy.Float.
_guarding_hint_or_throw_base now returns a Python float for sympy.Float.
_maybe_realize_expr (shared with the int-only optimization_hint paths) is
unchanged.
cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo