SIGN IN SIGN UP

Fix SymBool equality handling in symbolic shapes (#186461)

I reviewed the implementation and confirm that the following AI-assisted summary accurately describes the change:

> SymBool equality can produce a SymPy relation whose operands are themselves boolean relations, such as `Eq(Eq(u0, 1), Eq(u1, 1))`. Boolean-expression canonicalization and `try_solve` assumed relational operands were arithmetic expressions and subtracted them, causing `expect_true` to raise `TypeError`.
>
> This change canonicalizes non-arithmetic relationals structurally while orienting `Gt`/`Ge` as `Lt`/`Le`, preserving the canonical form required by `ShapeEnv.get_implications`. It also makes `try_solve` conservatively give up when either operand is non-arithmetic. The overlapping boolean `ValueRanges.eq` fix has independently landed in #191886 and is not duplicated here.
>
> The regression test checks the exact deferred runtime assertion and implication set, including idempotence and the absence of `Gt`/`Ge` relations.
>
> Fixes #124110
> Generated by my agent
>
> Test Plan:
>
> ```
> python test/test_dynamic_shapes.py TestPySymInt.test_unbacked_symbool_eq_expect_true TestPySymInt.test_expect_true_with_s0 TestPySymInt.test_expect_true_prefer_later
> python test/test_sympy_utils.py TestSympySolve.test_give_up TestValueRanges.test_eq_ne_bool_ranges
> lintrunner -a
> ```

Pull Request resolved: https://github.com/pytorch/pytorch/pull/186461
Approved by: https://github.com/Skylion007, https://github.com/mlazos
J
Jason Ansel committed
b7930e431f5b3a5d138bf9209b5c6decff9e7050
Parent: a2ed3ae
Committed by PyTorch MergeBot <pytorchmergebot@users.noreply.github.com> on 8/24/2026, 2:06:33 AM