Skip to content

[Fix][DLight] Fall back when matmul epilogues cannot be inlined - #20957

Open
wawahejun wants to merge 1 commit into
apache:mainfrom
wawahejun:fix/20884-dlight-conditional-epilogue
Open

wawahejun wants to merge 1 commit into
apache:mainfrom
wawahejun:fix/20884-dlight-conditional-epilogue

Conversation

@wawahejun

Copy link
Copy Markdown

DLight's matmul rule can abort default CUDA compilation when a consumer block contains a conditional statement. In #20884, a valid FP32 matmul followed by a conditional epilogue raises a ScheduleError during compute_inline, preventing subsequent schedule rules from handling the function.

This change makes consumer-chain inlining report failure when a required inline operation is rejected or consumers remain unfused. Both Matmul and MetalMatmul discard the partially transformed schedule and return None, allowing subsequent rules to schedule the original function.

Regression tests cover redundant conditionals, conditionals with different branch results, preservation of the original function after a rejected schedule, and end-to-end CUDA execution through the default Relax compilation pipeline.

Fixes #20884.

Validation

Tested on an NVIDIA H200 with CUDA 12.2 and NVCC:

  • tests/python/s_tir/dlight/test_gpu_matmul_conditional.py: 4 passed. Both scheduling regression cases fail at the reported compute_inline call on the baseline before the fix. The CUDA execution cases check three inputs each against NumPy using exact comparisons.
  • Existing test_gpu_matmul.py, test_gpu_matmul_tensorize.py, and test_gpu_fallback.py: 16 passed, 1 failed.
  • The issue reproducer, adapted to the current APIs, compiles through the default pipeline without applying StmtSimplify first and passes exact NumPy comparisons for all three inputs.
  • Repository pre-commit checks using .pre-commit-config.yaml on both changed files: passed. Hooks with no matching files were skipped. git diff --check also passed.

The existing failure is test_gpu_fallback.py::test_fallback_reduction: this build does not recognize Target("apple/m1-gpu"), so the test fails during target creation. The unchanged baseline sources reproduce the same failure.

DLight's matmul rule can abort default CUDA compilation when a consumer
block contains a conditional statement. Consumer-chain inlining assumes
that all remaining consumers can be fused, preventing later schedule
rules from handling otherwise valid functions.

Report unsuccessful consumer-chain inlining and have both Matmul and
MetalMatmul discard the partially transformed schedule and return None.
Subsequent rules can then schedule the original function.

Add regression tests for redundant and nontrivial conditional epilogues,
preservation of the original function after a rejected schedule, and
CUDA execution through the default Relax compilation pipeline.

Validate on H200 with CUDA 12.2 and NVCC: all four new regression tests
and 16 existing tests pass. The issue reproducer, adapted to the current
APIs, passes exact NumPy comparisons without StmtSimplify. Ruff checks
pass. One existing fallback test fails because the apple/m1-gpu target
is unregistered; the same failure occurs on the unchanged base revision.

Fixes apache#20884

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] [DLight][CUDA] Matmul scheduling fails when inlining a conditional epilogue

1 participant