Canonicalize trunc of symbolic integer division by one#186194
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/186194
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit e2a7273 with merge base 16de8e3 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a
|
|
@claude review these changes |
|
Claude finished @jansel's task in 1m 32s —— View job Review of PR #186194: Canonicalize trunc of symbolic integer division by one
Overall: This looks good. The fix is well-scoped and placed at the right layer.
|
Stack from ghstack (oldest at bottom):
Issue #138926 reported a torch.cond metadata mismatch where one branch
returned a tensor sized with TruncToInt(IntTrueDiv(s, 1)) while the other
returned the same tensor sized with s. The branches were semantically
compatible, but the symbolic expressions were not canonicalized before the
metadata check.
The root cause is that math.trunc(SymInt / 1) lowered to TruncToInt over an
IntTrueDiv expression instead of simplifying back to the original symbolic
integer. Canonicalize integer-valued TruncToInt inputs and the IntTrueDiv by
+/-1 cases in the SymPy helper layer so all downstream users see the same
shape expression. This fixes the cond branch metadata check without adding a
cond-specific workaround.
Fixes #138926
Generated by my agent
Test Plan:
cc @jgong5 @mingfeima @XiaobingSuper @sanchitintel @ashokei @jingxu10 @aditew01