Commit 04a1910
Fix LFM2 MoE routing to match the HF reference (sigmoid gating) (ml-explore#1354)
Lfm2Moe is a sigmoid-gated MoE (DeepSeek-V3 style): the router scores are
sigmoid(gate(x)); expert_bias is an aux-loss-free load-balancing bias used only
to select the top-k experts; the combination weights are gathered from the
unbiased sigmoid scores and then scaled by routed_scaling_factor.
The current implementation used softmax, folded expert_bias into the weights, and
omitted routed_scaling_factor, so MLX routing diverges from the HF Transformers
reference (and llama.cpp). This aligns it with the reference; routed_scaling_factor
is added to ModelArgs and defaults to 1.0.
Co-authored-by: Yi Zhong <207368749+vincentzed@users.noreply.github.com>1 parent 8239c72 commit 04a1910
1 file changed
Lines changed: 15 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
| |||
196 | 197 | | |
197 | 198 | | |
198 | 199 | | |
| 200 | + | |
199 | 201 | | |
200 | 202 | | |
201 | 203 | | |
| |||
206 | 208 | | |
207 | 209 | | |
208 | 210 | | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
214 | 216 | | |
215 | 217 | | |
216 | | - | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
217 | 223 | | |
218 | | - | |
| 224 | + | |
219 | 225 | | |
220 | | - | |
| 226 | + | |
| 227 | + | |
221 | 228 | | |
222 | 229 | | |
223 | 230 | | |
| |||
0 commit comments