[inductor][cutlass] SiLU activation fusion via EVT + XPU GEMM template improvements#186198
Draft
xuhancn wants to merge 2 commits into
Draft
[inductor][cutlass] SiLU activation fusion via EVT + XPU GEMM template improvements#186198xuhancn wants to merge 2 commits into
xuhancn wants to merge 2 commits into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/186198
Note: Links to docs will display an error until the docs builds have been completed. ❌ 1 New Failure, 26 Pending, 2 Unrelated Failures, 7 Unclassified FailuresAs of commit bdd6e0c with merge base cc46af7 ( NEW FAILURE - The following job has failed:
UNCLASSIFIED FAILURES - DrCI could not classify the following jobs because the workflow did not run on the merge base. The failures may be pre-existing on trunk or introduced by this PR:
FLAKY - The following job failed but was likely due to flakiness present on trunk:
BROKEN TRUNK - The following job failed but was present on the merge base:👉 Rebase onto the `viable/strict` branch to avoid these failures
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
98a3351 to
daad671
Compare
daad671 to
bdd6e0c
Compare
…e fusion Add two missing EVT ops needed by decomposed SiLU (x / (1 + exp(-x))): - neg(x): Emits (0.0 - x) since CUTLASS PythonASTFrontend lacks visit_UnaryOp - constant(value, dtype): Returns str(float(value)) for CUTLASS literal parsing Without these ops, any epilogue containing neg or constant raises NotImplementedError, preventing SiLU (and sigmoid) from being fused into CUTLASS GEMM epilogues. Tests: - test_py_codegen_neg_constant: validates neg + constant + exp composition - test_py_codegen_sigmoid_decomposed: validates full sigmoid decomposition 1/(1+exp(-x)) Co-authored-by: Copilot <[email protected]>
…e improvements
Add post-codegen activation fusion framework (_fuse_activations) that
pattern-matches decomposed activations in generated EVT Python code and
folds them back into native CUTLASS functor calls. This approach is
simpler and more extensible than per-op reconstitution.
SiLU support:
- _match_silu: matches x/(1+exp(0.0-x)) pattern in AST
- _ActivationPattern('silu', '0.0 -', _match_silu) entry
- silu() and erf() ops added to CutlassEVTOpsMixIn
- Dead-code elimination removes unused decomposition temporaries
XPU GEMM template improvements:
- _device_cutlass_config: device-specific config lookup (xpu/cuda)
- _sort_ops: XPU tile scoring heuristic (penalize tile_M > problem M)
- Kernel naming uniquification: KERNEL_NAME placeholder in struct names
to avoid symbol collisions across compiled .so files
- _stride_compatible: support different-length strides for view/reshape
Tests:
- test_py_codegen_silu_fused: validates SiLU is folded to silu() call
- test_evt_silu_fusion: end-to-end silu(mm) epilogue fusion
- test_evt_llama_mlp_pattern: silu([email protected]) * ([email protected]) pattern
- test_evt_aux_load_mul: GEMM * external buffer via AuxLoad
Co-authored-by: Copilot <[email protected]>
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.
Summary
Add SiLU activation fusion into CUTLASS GEMM epilogues via a post-codegen AST rewriting framework (
_fuse_activations), plus XPU-specific GEMM template improvements.Depends on: #186197 (neg/constant EVT ops)
Related: #185824 (same
_fuse_activationsdesign for gelu; compatible — will merge cleanly)Changes
Activation Fusion Framework (
python_evt.py)Post-codegen AST rewriter that pattern-matches decomposed activations in generated EVT Python code and folds them back into native CUTLASS functor calls:
_match_silu: Matchesx / (1 + exp(0.0 - x))with commutativity-aware addition matchingsilu()op: New operation inCutlassEVTOpsMixInmapping to native CUTLASS SiLU functorerf()op: New operation for future gelu supportXPU GEMM Template (
gemm_template.py)_device_cutlass_config: Device-specific config lookup (readsconfig.xpuorconfig.cudabased on target)_sort_ops(): XPU-specific tile scoring heuristic — penalizes tiles where tile_M > problem M (wasting computation), prefers larger tiles (better data reuse)KERNEL_NAMEplaceholder to CUTLASS struct names to prevent SYCL kernel class name collisions when multiple .so files define same-named GEMM structs with different epilogues_stride_compatible: Support different-length strides for view/reshape compatibilityMotivation
Inductor decomposes
silu(x)intox / (1 + exp(-x)), producing 5+ primitive ops. While each primitive op (neg, constant, exp, add, truediv) is now supported in EVT (via #186197), the decomposed form generates unnecessary compute nodes. The_fuse_activationsrewriter folds these back intosilu(x), which maps directly to CUTLASS's native SiLU functor — reducing epilogue complexity and enabling better hardware utilization.The XPU tile scoring heuristic addresses a performance issue where alphabetical sort selects tiles with tile_M >> problem_M, wasting ~50% of compute on padding.
Design Compatibility with #185824
This PR implements the same
_fuse_activationsdesign as #185824 (which adds gelu support). When #185824 lands:_fuse_activationsfunction: merge keeps theirs (superset with gelu)constant(): identical implementation (str(float(value)))erf(): identicalneg(),silu(),_match_silu, silu_ActivationPatternTesting
test_py_codegen_silu_fused: Validates decomposed SiLU is folded tosilu()calltest_py_codegen_sigmoid_decomposed: Validates sigmoid is NOT incorrectly foldedtest_evt_silu_fusion: End-to-endsilu(mm)epilogue fusiontest_evt_llama_mlp_pattern: End-to-endsilu([email protected]) * ([email protected])patterntest_evt_aux_load_mul: End-to-end GEMM * external buffer via AuxLoadcc @eellison @etaf