[Fix][S-TIR][DLight] Fall back from non-affine reduction write-back - #20057
Open
Junius-Wynn wants to merge 1 commit into
Open
[Fix][S-TIR][DLight] Fall back from non-affine reduction write-back#20057Junius-Wynn wants to merge 1 commit into
Junius-Wynn wants to merge 1 commit into
Conversation
Contributor
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
Issue apache#20048 reports that relax.build can abort with ScheduleError while compiling a valid CUDA conv2d. The GPU Reduction rule fuses all spatial loops, but its inner-spatial schedule derives the thread extent from the original innermost spatial extent. For some output shapes, rfactor and reverse_compute_at then produce non-quasi-affine write-back bindings, and bind aborts the default schedule chain. Guard the known unsafe write-back geometry and let GeneralReduction or Fallback handle those blocks, while preserving the dedicated Reduction schedule for affine cases. Also let default rule selection continue after ScheduleError so an applicability mistake in one rule does not become a hard compilation failure. Add regression coverage for the reported convolution-like access, a plain sum without mixed spatial/reduction indices, affine write-back shapes, and transform-level fallback. The tests directly verify that Reduction declines unsafe shapes and document the remaining dominant-read spatial-ordering edge case with a strict xfail. Fixes apache#20048
Junius-Wynn
force-pushed
the
fix/issue-20048-dlight-reduction
branch
from
July 27, 2026 16:19
3369c9d to
688c22e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #20048.
Motivation
A valid Relax
conv2dcan fail duringrelax.build(..., target="cuda")when the DLight GPU Reduction rule selects its inner-spatial schedule. Instead of falling through to another schedule rule, the pass raisesScheduleErrorfrombindand aborts compilation.The Reduction rule first fuses all spatial loops. However,
_sch_inner_spatialchooses itsthreadIdx.xextent using only the original innermost spatial extent. For the reported output shape, the non-unit spatial extents are(2, 2, 20)and the selected thread extent is 10. Afterrfactorandreverse_compute_at, the write-back block must recover the original axes from the remaining fused loop. This produces bindings that are not recognized as quasi-affine, sobindrejects the block's compact dataflow.Changes
This PR adds an applicability guard for the known non-affine write-back geometry. Unsupported inner-spatial reductions now return
None, allowingGeneralReductionorFallbackto produce a legal schedule. Affine cases continue to use the dedicated Reduction schedule.The thread-extent selection is moved into a shared helper so that the guard and the scheduling path use the same value. Symbolic spatial extents are handled conservatively.
The default rule-selection loop now catches
ScheduleErrorfrom an individual rule and continues to the next rule. This prevents an applicability mistake in one schedule rule from becoming a hard compilation failure.The regression tests cover the reported convolution-like access, a plain reduction without mixed spatial/reduction indices, an affine write-back shape, and transform-level fallback after
ScheduleError. They also directly verify that Reduction declines known unsafe shapes instead of relying on the transform-level exception handler.A strict
xfailrecords a dominant-read spatial-ordering edge case where the shape guard still uses the original block-iterator order. The rule-selection fallback prevents this case from aborting the default schedule chain, while the strict marker ensures that a future guard refinement cannot pass unnoticed.Testing
The changes were tested in a Python 3.12.13 environment with CUDA 13.0 .
Result:
24 passed, 1 xfailed.The Relax reproduction from #20048 now builds and runs on CUDA. Its result was compared against a NumPy convolution reference:
The previously uncovered
relax.op.sumcase with input shape(2, 2, 3, 20)and reduction axis 2 also builds successfully through the fallback schedule.