Commit afcb5ff
committed
Overlap moe comms with collective matmul
Implements Overlapped All-Gather and GMM Computation (Collective Matmul) for Ring of Experts (RoE) in MoE layers to hide communication overhead and token sorting latency. The changes include:
- Chunks input activations along the contracting embedding dimension (embed_dim // num_moe_emb_chunks). While chunk i computes GMM up-projections, chunk i+1 concurrently executes Ring of Experts All-Gather and routing across expert parallel shards.
- Update kernel to use in-place Partial Sum Accumulation to avoid unnecessary copies using input_output_aliases.
Testing
- Layer Tests (tests/unit/moe_test.py): Verified chunked GMM v2 routing, partial sum accumulation, and MLP bias addition (test_moe_emb_chunking_gmm_v2 with mlp_bias=True).
- AOT Compilation Tests (tests/unit/train_compile_test.py): Verified ahead-of-time HLO compilation and sharding on multi-slice topologies for chunked MoE (test_moe_emb_chunking and test_moe_emb_chunking_with_mlp_bias).
- Low-Level Pallas Kernel Tests (tests/unit/pallas_mosaic_tpu_v2_kernel_test.py): Verified numerical correctness and in-place buffer aliasing for partial sum accumulation across GMM (test_gmm_partial_sum0/1) and TGMM with zero-initialized empty expert groups (test_tgmm_empty_group_with_partial_sum0-3).
- End-to-End Execution & Profiling: Verified E2E training execution on v6e-8 TPU VM (deepseek3-tiny with num_moe_emb_chunks=4) and generated XPlane / XProf traces confirming communication-compute overlap.1 parent 2ee9fe1 commit afcb5ff
9 files changed
Lines changed: 493 additions & 136 deletions
File tree
- src/maxtext
- configs
- kernels/megablox
- layers
- tests/unit
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
220 | 220 | | |
221 | 221 | | |
222 | 222 | | |
| 223 | + | |
223 | 224 | | |
224 | 225 | | |
225 | 226 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
623 | 623 | | |
624 | 624 | | |
625 | 625 | | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
626 | 629 | | |
627 | 630 | | |
628 | 631 | | |
| |||
2591 | 2594 | | |
2592 | 2595 | | |
2593 | 2596 | | |
| 2597 | + | |
| 2598 | + | |
| 2599 | + | |
| 2600 | + | |
| 2601 | + | |
| 2602 | + | |
| 2603 | + | |
| 2604 | + | |
| 2605 | + | |
| 2606 | + | |
| 2607 | + | |
2594 | 2608 | | |
2595 | 2609 | | |
2596 | 2610 | | |
| |||
3200 | 3214 | | |
3201 | 3215 | | |
3202 | 3216 | | |
| 3217 | + | |
3203 | 3218 | | |
3204 | 3219 | | |
3205 | 3220 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
| 77 | + | |
77 | 78 | | |
78 | 79 | | |
79 | 80 | | |
| |||
112 | 113 | | |
113 | 114 | | |
114 | 115 | | |
| 116 | + | |
115 | 117 | | |
116 | 118 | | |
117 | 119 | | |
| |||
142 | 144 | | |
143 | 145 | | |
144 | 146 | | |
| 147 | + | |
145 | 148 | | |
146 | 149 | | |
147 | 150 | | |
| |||
200 | 203 | | |
201 | 204 | | |
202 | 205 | | |
| 206 | + | |
203 | 207 | | |
204 | 208 | | |
205 | 209 | | |
| |||
234 | 238 | | |
235 | 239 | | |
236 | 240 | | |
237 | | - | |
| 241 | + | |
238 | 242 | | |
239 | 243 | | |
240 | 244 | | |
| |||
256 | 260 | | |
257 | 261 | | |
258 | 262 | | |
| 263 | + | |
259 | 264 | | |
260 | 265 | | |
261 | | - | |
| 266 | + | |
262 | 267 | | |
263 | 268 | | |
264 | | - | |
| 269 | + | |
265 | 270 | | |
266 | 271 | | |
267 | 272 | | |
| |||
406 | 411 | | |
407 | 412 | | |
408 | 413 | | |
409 | | - | |
| 414 | + | |
| 415 | + | |
Lines changed: 14 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
909 | 909 | | |
910 | 910 | | |
911 | 911 | | |
912 | | - | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
913 | 915 | | |
914 | 916 | | |
915 | 917 | | |
| |||
999 | 1001 | | |
1000 | 1002 | | |
1001 | 1003 | | |
1002 | | - | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
1003 | 1007 | | |
1004 | 1008 | | |
1005 | 1009 | | |
| |||
1341 | 1345 | | |
1342 | 1346 | | |
1343 | 1347 | | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
| 1354 | + | |
1344 | 1355 | | |
1345 | 1356 | | |
1346 | 1357 | | |
| |||
1357 | 1368 | | |
1358 | 1369 | | |
1359 | 1370 | | |
| 1371 | + | |
1360 | 1372 | | |
Lines changed: 8 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
763 | 763 | | |
764 | 764 | | |
765 | 765 | | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
766 | 773 | | |
767 | 774 | | |
768 | 775 | | |
| |||
781 | 788 | | |
782 | 789 | | |
783 | 790 | | |
| 791 | + | |
784 | 792 | | |
785 | 793 | | |
786 | 794 | | |
| |||
0 commit comments