Summary:
_split_iteration_ranges in torch/_inductor/codegen/simd.py ended with a bare assert all(... == 1 for s in remaining) that fired whenever a node's iteration lengths were consumed cleanly but left a non-unit extent in the kernel's tiling groups. This happens when a pointwise epilogue whose iteration domain is a strict sub-multiple of a template's tiling is considered for fusion, e.g. fusing a [s, N] epilogue into a [K*s, N] matmul template tile. The three divisibility exits earlier in the same function already raise CantSplit, and both callers that drive epilogue fusion (SIMDKernel.is_compatible and Scheduler.speedup_by_fusion) wrap the split in try/except CantSplit specifically to skip range-incompatible fusions and fall back to unfused codegen. Because the final invariant raised AssertionError instead of CantSplit, it escaped those handlers and hard-failed the entire AOTInductor compile with InductorError: AssertionError: failed to set ranges ....
This PR converts the final invariant to raise CantSplit(remaining, lengths), matching the exception contract of the rest of the function so the existing safety nets catch it. The success path is byte-for-byte unchanged (identical trigger condition), so models that compile today are unaffected; models that previously crashed now lower with the incompatible epilogue left unfused (a separate kernel) instead of aborting the compile.
Test Plan:
Unit test (new regression):
buck2 test //caffe2/test/inductor:loop_ordering -- -r TestSplitIterationRanges
Result: Pass 7, Fail 0. testrun: https://www.internalfb.com/intern/testinfra/testrun/1688850234333388
The new case test_leftover_extent_raises_cant_split constructs groups=[2, 2], lengths=[[2], []]: every size divides cleanly as it is consumed (so no add_range divisibility exit trips), but group 1 is left with extent 2, producing remaining=[1, 2]. It asserts this raises CantSplit rather than AssertionError, exercising exactly the changed line.
Differential Revision: D108339950
Pull Request resolved: #187209
Approved by: https://github.com/ColinPeppler
SOCIAL SHARE CARD GENERATOR