Fix symbolic stride-order sorting without explicit ShapeEnv (#185871)
Inductor stride-order computation was only symbolic-aware when callers explicitly passed a ShapeEnv into get_stride_order/get_fill_order. Some lowering paths call get_stride_order with symbolic strides while an Inductor graph is active but without passing shape_env. That made get_fill_order fall back to the generic argsort helper, and Python sorting then tried to truth-test SymPy relationals such as 1 < s53. Recover a ShapeEnv from SymInt stride values or from the active V.graph before sorting symbolic strides, so the existing argsort_sym path handles these comparisons with ShapeEnv guards/hints. This keeps the fast plain argsort path for fully static stride lists, and uses the already-established symbolic comparator instead of introducing a separate stride-specific ordering rule. The alternative was to thread shape_env through every current and future get_stride_order caller. That would be more invasive and would still leave this helper fragile for missed call sites, so the fix centralizes the fallback at the symbolic sort boundary. Benchmark Results: A focused timeit benchmark for the four-stride helper showed static old behavior median 759.17 ns/call and static new behavior median 1235.47 ns/call. For symbolic [s, 1, s, s], explicit shape_env median was 90308.02 ns/call and the new implicit V.graph fallback median was 92420.08 ns/call. Before this fix, the implicit symbolic path crashed with TypeError: cannot determine truth value of Relational: 1 < s53, so no runtime was available for that failing case. Test Plan: - python test/inductor/test_inductor_utils.py -k symbolic_stride_order - Issue repro from #185510 before fix: reproduced InductorError wrapping TypeError: cannot determine truth value of Relational: 1 < s53 - Same issue repro after fix: eager ok, compiled forward ok, compiled backward ok - lintrunner -a - git diff --check -- torch/_inductor/ir.py test/inductor/test_inductor_utils.py Fixes #185510 Generated by my agent Pull Request resolved: https://github.com/pytorch/pytorch/pull/185871 Approved by: https://github.com/nandesuka
J
Jason Ansel committed
31f0501595dd38556b9d06d66e8a8413d43bdd95
Parent: f91e138
Committed by PyTorch MergeBot <pytorchmergebot@users.noreply.github.com>
on 9/30/2026, 10:28:48 PM