Trainable MoE in CUDA
ML JOURNEY / FULL WALKTHROUGH

Trainable MoE in CUDA

Build CUDA kernels for a complete sparse mixture-of-experts forward, backward, and training loop.

7 parts52 individual lessons4.3 estimated hours260 XP available
Trainable MoE in CUDA project artwork
0%0 of 52 complete
Start walkthrough
No compressed chapters.

Every source step is its own lesson with intuition, concepts, correctly rendered MathJax mathematics, implementation, tests, mistakes, and a checkpoint.

01
PART 1

CUDA Building Blocks

Implement the core CUDA primitives used everywhere in the layer: matmul variants, bias add and reduction, elementwise ops, activations, and row-wise softmax with their backward passes.

0/13
001define cuda building blocks+5 XP002derive cuda building blocks+5 XP003prepare cuda building blocks+5 XP004implement cuda building blocks+5 XP005connect cuda building blocks+5 XP006validate cuda building blocks+5 XP007debug cuda building blocks+5 XP008optimize cuda building blocks+5 XP009benchmark cuda building blocks+5 XP010integrate cuda building blocks+5 XP011define cuda building blocks+5 XP012derive cuda building blocks+5 XP013prepare cuda building blocks+5 XP
04
PART 4

Token Dispatch and Combine

Implement the sparse plumbing of MoE: counting tokens per expert, computing slot offsets, gathering tokens into per-expert buffers, scattering gradients back, and combining expert outputs weighted by gate values (with backward).

0/8
021define token dispatch and combine+5 XP022derive token dispatch and combine+5 XP023prepare token dispatch and combine+5 XP024implement token dispatch and combine+5 XP025connect token dispatch and combine+5 XP026validate token dispatch and combine+5 XP027debug token dispatch and combine+5 XP028optimize token dispatch and combine+5 XP
05
PART 5

Expert MLP Forward and Backward

Implement the two-layer expert MLP that runs on each expert's slice of tokens, including up/down projections, biases, activation, and the full set of backward kernels for inputs, weights, and biases.

0/12
029define expert mlp forward and backward+5 XP030derive expert mlp forward and backward+5 XP031prepare expert mlp forward and backward+5 XP032implement expert mlp forward and backward+5 XP033connect expert mlp forward and backward+5 XP034validate expert mlp forward and backward+5 XP035debug expert mlp forward and backward+5 XP036optimize expert mlp forward and backward+5 XP037benchmark expert mlp forward and backward+5 XP038integrate expert mlp forward and backward+5 XP039define expert mlp forward and backward+5 XP040derive expert mlp forward and backward+5 XP
07
PART 7

Loss, Optimizer, and Training Loop

Add the task loss (MSE), gradient-zeroing and SGD update kernels, and host-side orchestration for the full forward pass, backward pass, single training step, and overall training loop.

0/8
045define loss optimizer and training loop+5 XP046derive loss optimizer and training loop+5 XP047prepare loss optimizer and training loop+5 XP048implement loss optimizer and training loop+5 XP049connect loss optimizer and training loop+5 XP050validate loss optimizer and training loop+5 XP051debug loss optimizer and training loop+5 XP052optimize loss optimizer and training loop+5 XP