Repository navigation
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/177214
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 822fddb with merge base a4de454 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a
|
21424be to
49ff39b
Compare
|
Resolved conflicts with main. |
| def _is_multiple_of(self, numerator: Expr, denominator: int) -> bool: | ||
| """ | ||
| Structural divisibility check: returns True only if numerator is | ||
| provably a multiple of denominator. Recurses over sympy expression | ||
| structure before falling back to statically_known_true. | ||
| """ | ||
| # Rule 1 — concrete value | ||
| if isinstance(numerator, (int, sympy.Integer)): | ||
| return int(numerator) % denominator == 0 | ||
|
|
||
| # Rule 2 — product: any factor divisible → product divisible | ||
| if isinstance(numerator, sympy.Mul): | ||
| for factor in numerator.args: | ||
| if self._is_multiple_of(factor, denominator): | ||
| return True | ||
| # Also check if combined constant factors are divisible | ||
| const = 1 | ||
| for factor in numerator.args: | ||
| if isinstance(factor, (int, sympy.Integer)): | ||
| const *= int(factor) | ||
| if const != 1 and const % denominator == 0: | ||
| return True | ||
|
|
||
| # Rule 3 — sum: all terms divisible → sum divisible | ||
| if isinstance(numerator, sympy.Add): | ||
| if all(self._is_multiple_of(term, denominator) for term in numerator.args): | ||
| return True | ||
|
|
||
| # Rule 4 — FloorDiv(a, b): if a is multiple of b*n | ||
| if isinstance(numerator, FloorDiv): | ||
| a, b = numerator.args | ||
| if isinstance(b, (int, sympy.Integer)): | ||
| if self._is_multiple_of(a, int(b) * denominator): | ||
| return True |
There was a problem hiding this comment.
Could you simplify to:
return sympy.gcd(numerator, denominator) == denominator
There was a problem hiding this comment.
Thanks for the suggestion. It doesn't work with a simple repalcement using sympy.gcd.
Why doesn't work:
The divisibility facts are stored as axioms in ShapeEnv, shape_env.axioms[Eq(Mod(s1, 16), 0)] = True.
This does not change s1's sympy representation, it is still a bare symbol.
So sympy.gcd(s1 * s2, 16) returns 1 instead of 16, even though s1 is axiomatically a multiple of 16.
To make it work: we need the following steps which seems non-trivial.
- Scan ShapeEnv axioms for all
Mod(symbol, k) == 0facts, - Substitute each such symbol with
k * fresh_symbol, - Call
sympy.gcdon the rewritten expression.
| """ | ||
| # Rule 1 — concrete value | ||
| if isinstance(numerator, (int, sympy.Integer)): | ||
| return int(numerator) % denominator == 0 |
There was a problem hiding this comment.
- do we want to use class Mod(sympy.Function).
is this not handled by statically_known_true trivially? or we are just trying to be faster.
There was a problem hiding this comment.
- No, it goes to
expr = sympy.Eq(Mod(numerator, denominator), 0)even bothnumeratoranddenominatorareint. - It is a performance optimization, but also required to terminate the recursion, e.g.,
(ks * 1024) % 16will iterate toks % 16and1024 % 16
| for factor in numerator.args: | ||
| if isinstance(factor, (int, sympy.Integer)): | ||
| const *= int(factor) | ||
| if const != 1 and const % denominator == 0: |
There was a problem hiding this comment.
It was initilized to 1, stays at 1 means no const factors.
Not absolutely required. Added to skip evaluating 1 % denominator.
| if len(free_symbols(numerator)) > 20: | ||
| return False | ||
|
|
||
| if isinstance(denominator, (int, sympy.Integer)): |
There was a problem hiding this comment.
mm which one shall go first this or self.statically_known_true(expr)...
the cheaper probably i cant tel which one is cheaper, but given that self.statically_known_true is not giving regressions shall we do it first?
There was a problem hiding this comment.
good point. I don't have data about the cost, but the following code comment seems to suggest thatstatically_known_true is not cheap.
# The reason we skip compute here is to avoid the cost of trying to eval this symbolically.
# see https://github.com/sympy/sympy/issues/28200
There was a problem hiding this comment.
right but _is_multiple_of calls it many times vs one time in the other branch
(each leaf in the recursion is return self.statically_known_true(expr))
| expr = left > right | ||
| return self.statically_known_true(expr) | ||
|
|
||
| def _is_multiple_of(self, numerator: Expr, denominator: int) -> bool: |
There was a problem hiding this comment.
FYI many of the ideas here work also if denominator is not int, consider generalizing but its fine as is we can do that incrementally as we need.
|
@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 |
Merge failedReason: 1 jobs have failed, first few of them are: trunk / linux-jammy-cuda13.0-py3.10-gcc11-no-ops / build Details for Dev Infra teamRaised by workflow job |
…ion and strict validation **Overview:** This PR refactors `statically_known_multiple_of` to resolve 42 test failures (including `vision_maskrcnn`) and aligns the implementation with the structural recursion logic introduced in pytorch#177214. **Key Improvements:** * **Integration with `_is_multiple_of`:** Leveraged the new structural recursion helper for integer denominators to ensure consistency with pytorch#177214 and avoid logic duplication. * **Strict Validation Fix:** Enforced `is_integer == True` post-algebraic cancellation. This specifically addresses the regressions in vision models where indeterminate symbolic states (`None`) were previously misidentified as multiples. * **GCD Fallback:** Retained a guarded `sympy.gcd` check to handle complex additive symbolic expressions (e.g., $2a + 2b$ being a multiple of $2$) that structural recursion might miss. * **Performance Guards:** Maintained a 15-symbol complexity cap and added exception handling to prevent backend hangs during complex graph compilations. **Validation:** Verified that strict validation prevents over-optimistic optimizations, ensuring all downstream model tests pass while maintaining robust symbolic propagation.
|
@claude please diagnose the CI failures |
|
Claude finished @jansel's task in 2m 27s —— View job CI Failure Diagnosis
SummaryAll CI failures are pre-existing trunk issues, unrelated to this PR. This PR only modifies Root CauseEvery failing job hits the same C++ compilation error in This was introduced by commit Affected Jobs
RecommendationRebasing onto |
|
@pytorchbot rebase |
|
@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here |
|
Successfully rebased |
6a7db52 to
822fddb
Compare
|
@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 |
… logic with pytorch#177214 This commit addresses critical CI failures caused by the accidental removal of core methods during a previous merge conflict resolution. Key changes include: - Restored `expect_true` and `statically_known_power_of_2` methods to `sizevars.py`, resolving widespread AttributeErrors across the inductor test suite. - Refactored `statically_known_multiple_of` to eliminate redundancy with pytorch#177214. - Removed expensive `sympy.gcd` and `sympy.cancel` fallbacks to prevent performance regressions, relying instead on the structural `_is_multiple_of` helper for efficiency. - Validated that the simplified logic maintains compliance with structural divisibility rules while reducing symbolic overhead.
…ultiple_of (pytorch#177214) Add `_is_multiple_of()` that recurses over sympy expression structure (Mul, Add, FloorDiv, Mod) to prove divisibility, before falling back to statically_known_true. This is a demand-driven variant of the modular arithmetic analysis used in Halide and TVM. Unlocks tt.divisibility hints for product expressions like `shape[0] * shape[1]` when `torch._check(shape[1] % 16 == 0)`. Fixes pytorch#177146 Pull Request resolved: pytorch#177214 Approved by: https://github.com/jansel, https://github.com/laithsakka
…ultiple_of (#177214) Add `_is_multiple_of()` that recurses over sympy expression structure (Mul, Add, FloorDiv, Mod) to prove divisibility, before falling back to statically_known_true. This is a demand-driven variant of the modular arithmetic analysis used in Halide and TVM. Unlocks tt.divisibility hints for product expressions like `shape[0] * shape[1]` when `torch._check(shape[1] % 16 == 0)`. Fixes #177146 Pull Request resolved: #177214 Approved by: https://github.com/jansel, https://github.com/laithsakka
…ultiple_of (pytorch#177214) Add `_is_multiple_of()` that recurses over sympy expression structure (Mul, Add, FloorDiv, Mod) to prove divisibility, before falling back to statically_known_true. This is a demand-driven variant of the modular arithmetic analysis used in Halide and TVM. Unlocks tt.divisibility hints for product expressions like `shape[0] * shape[1]` when `torch._check(shape[1] % 16 == 0)`. Fixes pytorch#177146 Pull Request resolved: pytorch#177214 Approved by: https://github.com/jansel, https://github.com/laithsakka
…bility registration This commit refactors `statically_known_multiple_of` in `torch/_inductor/sizevars.py` to align with the structural divisibility logic merged in pytorch#177214. Key changes: - Updated the performance guard to use the 20 free_symbols limit. - Delegated integer denominator checks directly to `_is_multiple_of` to leverage new structural recursion rules (Rules 1-6). - Removed redundant identical-expression and zero-check guards as they are now handled internally by the structural helper. - Fixed `test_symbolic_multiplication_divisibility_propagation` by properly registering divisibility constraints via `ShapeEnv.divisible`. - Cleaned up unused imports in `test/inductor/test_utils.py` to resolve linting failures. Fixes: pytorch#177146
…ultiple_of (pytorch#177214) Add `_is_multiple_of()` that recurses over sympy expression structure (Mul, Add, FloorDiv, Mod) to prove divisibility, before falling back to statically_known_true. This is a demand-driven variant of the modular arithmetic analysis used in Halide and TVM. Unlocks tt.divisibility hints for product expressions like `shape[0] * shape[1]` when `torch._check(shape[1] % 16 == 0)`. Fixes pytorch#177146 Pull Request resolved: pytorch#177214 Approved by: https://github.com/jansel, https://github.com/laithsakka
…ultiple_of (pytorch#177214) Add `_is_multiple_of()` that recurses over sympy expression structure (Mul, Add, FloorDiv, Mod) to prove divisibility, before falling back to statically_known_true. This is a demand-driven variant of the modular arithmetic analysis used in Halide and TVM. Unlocks tt.divisibility hints for product expressions like `shape[0] * shape[1]` when `torch._check(shape[1] % 16 == 0)`. Fixes pytorch#177146 Pull Request resolved: pytorch#177214 Approved by: https://github.com/jansel, https://github.com/laithsakka
…ultiple_of (pytorch#177214) Add `_is_multiple_of()` that recurses over sympy expression structure (Mul, Add, FloorDiv, Mod) to prove divisibility, before falling back to statically_known_true. This is a demand-driven variant of the modular arithmetic analysis used in Halide and TVM. Unlocks tt.divisibility hints for product expressions like `shape[0] * shape[1]` when `torch._check(shape[1] % 16 == 0)`. Fixes pytorch#177146 Pull Request resolved: pytorch#177214 Approved by: https://github.com/jansel, https://github.com/laithsakka
Add
_is_multiple_of()that recurses over sympy expression structure (Mul, Add, FloorDiv, Mod) to prove divisibility, before falling back to statically_known_true. This is a demand-driven variant of the modular arithmetic analysis used in Halide and TVM.Unlocks tt.divisibility hints for product expressions like
shape[0] * shape[1]whentorch._check(shape[1] % 16 == 0).Fixes #177146
cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo