Commit 8654241
committed
Update MoE and qMoE spec (#25619)
### Weight Shape Update
Make sure the shape reflects actual memory layout. The weight is stored
in column major.
### Add support for SwiGLU activation attributes
Add spec for the new activation type SwiGLU (Swish-Gated Linear Unit) by
introducing a few new attributes. For reference, see the [Triton kernel
implementation](https://github.com/triton-lang/triton/blob/main/python/triton_kernels/triton_kernels/swiglu.py).
#### New Attributes for SwiGLU
* **`swiglu_fusion`**:
* `0`: Not fused — two separate GEMMs (FC1 and FC3).
* `1`: Fused GEMMs using **interleaved** format (g and l are interleaved
per row).
* `2`: Fused GEMMs using **non-interleaved** (concatenated) format.
* **`swiglu_limit`**: Clamp threshold applied to `g` and `l`.
* **`activation_alpha`**: Scalar multiplier applied to `g` before
sigmoid.
* **`activation_beta`**: Added to `l` before the final output
computation.
---
### SwiGLU Activation Function
The SwiGLU function is defined as:
```
g = xW + b
l = xV + c
G = min(g, limit)
L = max(min(l, limit), -limit)
swiglu = G * sigmoid(alpha * G) * (L + beta)
```
* `x`: Input
* `W`, `V`: Weight matrices
* `b`, `c`: Bias vectors
* `alpha`, `beta`, `limit`: Float constants
---
### Fusion Behavior
* When `swiglu_fusion = 0`:
* Two GEMMs are computed independently.
* FC1 → computes `g`, FC3 → computes `l`.
* When `swiglu_fusion = 1`:
* `g` and `l` are computed in a **single fused GEMM** (FC1).
* Output is **interleaved** per row as: `gate, linear, gate, linear,
...`.
* When `swiglu_fusion = 2`:
* `g` and `l` are computed in a single GEMM (FC1).
* Output is **concatenated** per row: `[g | l]`.
### Implement swiglu_limit for CUDA
Update CUDA kernel to use default swiglu limit.
Update test_moe_cuda.py to have same logic in reference implementation.
### Remaining Works
The main purpose of this PR is to update spec instead of implementing
them.
Note that MoE/qMoE ops and tests still use hard-coded parameters and
will be changed later to read from those attributes.
Column-wise symmetric quantization is used for qMoE. We will add more
quantization details when we add support of block-wise quantization
soon.1 parent d83904b commit 8654241
File tree
14 files changed
+337
-488
lines changed- docs
- onnxruntime
- contrib_ops
- cpu
- moe
- quantization
- cuda
- collective
- moe
- ft_moe
- quantization
- core
- graph/contrib_ops
- util
- test
- contrib_ops
- python/transformers
14 files changed
+337
-488
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3079 | 3079 | | |
3080 | 3080 | | |
3081 | 3081 | | |
| 3082 | + | |
| 3083 | + | |
| 3084 | + | |
| 3085 | + | |
| 3086 | + | |
| 3087 | + | |
| 3088 | + | |
| 3089 | + | |
| 3090 | + | |
| 3091 | + | |
| 3092 | + | |
3082 | 3093 | | |
3083 | 3094 | | |
3084 | 3095 | | |
| |||
3088 | 3099 | | |
3089 | 3100 | | |
3090 | 3101 | | |
| 3102 | + | |
| 3103 | + | |
| 3104 | + | |
| 3105 | + | |
3091 | 3106 | | |
3092 | 3107 | | |
3093 | 3108 | | |
3094 | 3109 | | |
3095 | 3110 | | |
3096 | 3111 | | |
| 3112 | + | |
| 3113 | + | |
| 3114 | + | |
| 3115 | + | |
3097 | 3116 | | |
3098 | 3117 | | |
3099 | 3118 | | |
| |||
3106 | 3125 | | |
3107 | 3126 | | |
3108 | 3127 | | |
3109 | | - | |
| 3128 | + | |
3110 | 3129 | | |
3111 | 3130 | | |
3112 | 3131 | | |
3113 | | - | |
| 3132 | + | |
3114 | 3133 | | |
3115 | 3134 | | |
3116 | 3135 | | |
3117 | | - | |
| 3136 | + | |
3118 | 3137 | | |
3119 | 3138 | | |
3120 | 3139 | | |
| |||
4522 | 4541 | | |
4523 | 4542 | | |
4524 | 4543 | | |
| 4544 | + | |
| 4545 | + | |
| 4546 | + | |
| 4547 | + | |
4525 | 4548 | | |
4526 | 4549 | | |
4527 | 4550 | | |
| |||
4530 | 4553 | | |
4531 | 4554 | | |
4532 | 4555 | | |
| 4556 | + | |
| 4557 | + | |
| 4558 | + | |
| 4559 | + | |
4533 | 4560 | | |
4534 | 4561 | | |
4535 | 4562 | | |
| |||
4542 | 4569 | | |
4543 | 4570 | | |
4544 | 4571 | | |
4545 | | - | |
| 4572 | + | |
4546 | 4573 | | |
4547 | 4574 | | |
4548 | 4575 | | |
4549 | 4576 | | |
4550 | 4577 | | |
4551 | | - | |
| 4578 | + | |
4552 | 4579 | | |
4553 | 4580 | | |
4554 | 4581 | | |
4555 | 4582 | | |
4556 | 4583 | | |
4557 | | - | |
| 4584 | + | |
4558 | 4585 | | |
4559 | 4586 | | |
4560 | 4587 | | |
| |||
4575 | 4602 | | |
4576 | 4603 | | |
4577 | 4604 | | |
4578 | | - | |
4579 | | - | |
| 4605 | + | |
| 4606 | + | |
4580 | 4607 | | |
4581 | 4608 | | |
4582 | 4609 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | 14 | | |
27 | 15 | | |
28 | 16 | | |
| |||
31 | 19 | | |
32 | 20 | | |
33 | 21 | | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | 22 | | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | 23 | | |
212 | 24 | | |
213 | 25 | | |
| |||
0 commit comments