Repository navigation
Commit af9e1d1
authored
[rocm-libraries] ROCm/rocm-libraries#9396 (commit e1aa8ce)
feat(ck): Added Gelu with Tanh approx to XDL 2-stage MoE epilogue
## Motivation
Enable the tanh-approximation GELU activation `(gelu_tanh, 0.5 * x * (1
+ tanh(sqrt(2/pi) * (x + 0.044715 * x^3))))` in the Composable Kernel
XDL 2-stage MoE path. The MoE gridwise kernel epilogue currently
supports only `silu/gelu/swiglustep/swiglu_oai`; this adds
`gelu_tanh_and_mul` so models whose MoE experts use the GELU tanh
approximation (e.g. [Gemma-family
MoE](https://huggingface.co/google/gemma-4-26B-A4B/blob/main/config.json))
can use this path.
JIRA ID : ROCM-27619
## Technical Details
- `gridwise_gemm_xdl_cshuffle_common.hpp`: add
`Activation::gelu_tanh_and_mul = 4` to the activation enum.
- `gridwise_moe_gemm.hpp`, `gridwise_moe_gemm_blockscale.hpp`,
`gridwise_moe_mx_gemm_<>.hpp`: wire `gelu_tanh_and_mul` into epilogue
paths, delegating to the existing
`ck::tensor_operation::element_wise::FastGelu` helper (the single source
of truth for the tanh-GELU math, `FastGelu(gate) * up`). Also added
`static_assert` for validation of supported activations
- The activation is applied in fp32 in the epilogue and is orthogonal to
the GEMM compute (MFMA/tile/pipeline untouched) and to quantization
(existing per-token dequant reused). Only the non-blockscale gridwise
kernel is changed.
- Then I plan to port these changes to AITER after
ROCm/aiter#3886 to avoid merge conflicts
## Test Plan
Use `ActOP = 4` in the example `moe_gemm1_xdl_fp8`, rebuild example and
launch ctest
## Test Result
```
ctest -R "^example_moe_gemm1_xdl_fp8$" -V'
Constructing a list of tests
Done constructing a list of tests
Updating test list for fixtures
Added 0 tests to meet fixture requirements
Checking test dependency graph...
Checking test dependency graph end
test 257
Start 257: example_moe_gemm1_xdl_fp8
257: Test command: example_moe_gemm1_xdl_fp8
257: Working Directory: example/65_gemm_multiply_multiply
257: Test timeout computed to be: 1500
257: a0_t_k: dim 2, lengths {16384, 6144}, strides {6144, 1}
257: b0_e_n_k: dim 3, lengths {8, 6144, 8192}, strides {50331648, 1, 6144}
257: d1_e_n: dim 2, lengths {8, 8192}, strides {8192, 1}
257: d2_e_n: dim 2, lengths {32768, 4096}, strides {1, 0}
257: d0_t_n: dim 2, lengths {16384, 4096}, strides {1, 16384}
257: d2_e_n: dim 2, lengths {32768, 4096}, strides {1, 0}
257: e_t_n: dim 3, lengths {16384, 2, 4096}, strides {8192, 4096, 1}
1/1 Test #257: example_moe_gemm1_xdl_fp8 ........ Passed 83.51 sec
The following tests passed:
example_moe_gemm1_xdl_fp8
100% tests passed, 0 tests failed out of 1
Label Time Summary:
SMOKE_TEST = 83.51 sec*proc (1 test)
Total Test time (real) = 83.59 sec
```
## Submission Checklist
- [ ] Look over the contributing guidelines at
https://github.com/ROCm/ROCm/blob/develop/CONTRIBUTING.md#pull-requests.1 parent b974e7e commit af9e1d1
16 files changed
Lines changed: 310 additions & 30 deletions
File tree
- example
- 65_gemm_multiply_multiply
- 67_gemm_microscaling
- include/ck/tensor_operation/gpu/grid
- library/include/ck/library/reference_tensor_operation/cpu
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
23 | 28 | | |
24 | 29 | | |
25 | 30 | | |
| |||
69 | 74 | | |
70 | 75 | | |
71 | 76 | | |
| 77 | + | |
72 | 78 | | |
73 | 79 | | |
74 | 80 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
176 | 176 | | |
177 | 177 | | |
178 | 178 | | |
179 | | - | |
180 | | - | |
181 | | - | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
182 | 189 | | |
183 | 190 | | |
184 | 191 | | |
| |||
Lines changed: 3 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
133 | | - | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
134 | 136 | | |
135 | 137 | | |
136 | 138 | | |
| |||
Lines changed: 6 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
120 | 122 | | |
121 | 123 | | |
122 | 124 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
84 | 85 | | |
85 | 86 | | |
86 | 87 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
84 | 85 | | |
85 | 86 | | |
86 | 87 | | |
| |||
Lines changed: 5 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
86 | 87 | | |
87 | 88 | | |
88 | 89 | | |
| |||
Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
| 34 | + | |
| 35 | + | |
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
| |||
Lines changed: 78 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1156 | 1156 | | |
1157 | 1157 | | |
1158 | 1158 | | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
1159 | 1166 | | |
1160 | 1167 | | |
1161 | 1168 | | |
| |||
1505 | 1512 | | |
1506 | 1513 | | |
1507 | 1514 | | |
| 1515 | + | |
| 1516 | + | |
| 1517 | + | |
| 1518 | + | |
| 1519 | + | |
| 1520 | + | |
| 1521 | + | |
| 1522 | + | |
| 1523 | + | |
| 1524 | + | |
| 1525 | + | |
| 1526 | + | |
| 1527 | + | |
| 1528 | + | |
| 1529 | + | |
| 1530 | + | |
| 1531 | + | |
| 1532 | + | |
| 1533 | + | |
| 1534 | + | |
1508 | 1535 | | |
1509 | 1536 | | |
1510 | 1537 | | |
| |||
1606 | 1633 | | |
1607 | 1634 | | |
1608 | 1635 | | |
| 1636 | + | |
| 1637 | + | |
| 1638 | + | |
| 1639 | + | |
| 1640 | + | |
| 1641 | + | |
| 1642 | + | |
| 1643 | + | |
| 1644 | + | |
| 1645 | + | |
| 1646 | + | |
| 1647 | + | |
1609 | 1648 | | |
1610 | 1649 | | |
1611 | 1650 | | |
| |||
1686 | 1725 | | |
1687 | 1726 | | |
1688 | 1727 | | |
| 1728 | + | |
| 1729 | + | |
| 1730 | + | |
| 1731 | + | |
| 1732 | + | |
| 1733 | + | |
| 1734 | + | |
1689 | 1735 | | |
1690 | 1736 | | |
1691 | 1737 | | |
| |||
2042 | 2088 | | |
2043 | 2089 | | |
2044 | 2090 | | |
| 2091 | + | |
| 2092 | + | |
| 2093 | + | |
| 2094 | + | |
| 2095 | + | |
| 2096 | + | |
| 2097 | + | |
| 2098 | + | |
| 2099 | + | |
| 2100 | + | |
| 2101 | + | |
| 2102 | + | |
| 2103 | + | |
| 2104 | + | |
| 2105 | + | |
| 2106 | + | |
| 2107 | + | |
| 2108 | + | |
| 2109 | + | |
| 2110 | + | |
2045 | 2111 | | |
2046 | 2112 | | |
2047 | 2113 | | |
| |||
2143 | 2209 | | |
2144 | 2210 | | |
2145 | 2211 | | |
| 2212 | + | |
| 2213 | + | |
| 2214 | + | |
| 2215 | + | |
| 2216 | + | |
| 2217 | + | |
| 2218 | + | |
| 2219 | + | |
| 2220 | + | |
| 2221 | + | |
| 2222 | + | |
| 2223 | + | |
2146 | 2224 | | |
2147 | 2225 | | |
2148 | 2226 | | |
| |||
Lines changed: 46 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1140 | 1140 | | |
1141 | 1141 | | |
1142 | 1142 | | |
1143 | | - | |
1144 | | - | |
1145 | | - | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
1146 | 1149 | | |
1147 | 1150 | | |
1148 | 1151 | | |
| |||
1642 | 1645 | | |
1643 | 1646 | | |
1644 | 1647 | | |
| 1648 | + | |
| 1649 | + | |
| 1650 | + | |
| 1651 | + | |
| 1652 | + | |
| 1653 | + | |
| 1654 | + | |
| 1655 | + | |
| 1656 | + | |
| 1657 | + | |
| 1658 | + | |
| 1659 | + | |
| 1660 | + | |
| 1661 | + | |
| 1662 | + | |
| 1663 | + | |
| 1664 | + | |
1645 | 1665 | | |
1646 | 1666 | | |
1647 | 1667 | | |
| |||
1697 | 1717 | | |
1698 | 1718 | | |
1699 | 1719 | | |
1700 | | - | |
1701 | | - | |
1702 | | - | |
| 1720 | + | |
| 1721 | + | |
| 1722 | + | |
| 1723 | + | |
| 1724 | + | |
| 1725 | + | |
1703 | 1726 | | |
1704 | 1727 | | |
1705 | 1728 | | |
| |||
2190 | 2213 | | |
2191 | 2214 | | |
2192 | 2215 | | |
| 2216 | + | |
| 2217 | + | |
| 2218 | + | |
| 2219 | + | |
| 2220 | + | |
| 2221 | + | |
| 2222 | + | |
| 2223 | + | |
| 2224 | + | |
| 2225 | + | |
| 2226 | + | |
| 2227 | + | |
| 2228 | + | |
| 2229 | + | |
| 2230 | + | |
| 2231 | + | |
| 2232 | + | |
2193 | 2233 | | |
2194 | 2234 | | |
2195 | 2235 | | |
| |||


0 commit comments