← All questions
LLM FoundationsMedium· MoE· Architecture· Inference

Walk me through the forward pass of a MoE layer.

The forward pass begins with affinity scoring to determine which experts are most suitable for a given token. Next, a top-K selection mechanism identifies the K most relevant experts. Each selected expert then performs its forward pass on the token. Finally, the outputs are aggregated using weighted summation, typically combined with a residual connection. The routing cost is generally negligible compared to the FFN compute, and top-K selection is essential to preserve the FLOP budget of a dense model while expanding the parameter count.

Code playground (Python)