
Mixture-of-experts top-k routing with auxiliary load-balance loss
Source:R/moetop_native.R
Moetop.RdRouter and combination per Lepikhin et al. (2021) GShard, ICLR 2021, arXiv:2006.16668, Section 2.1/Algorithm 1: G(x) = softmax(W_g x), each token dispatched to its top-k experts, output the renormalised gate-weighted sum. Auxiliary loss per Fedus, Zoph and Shazeer (2022), Switch Transformers, JMLR 23(120), arXiv:2101.03961, Eqs 4-6: aux = alpha N sum_i f_i P_i; uniform routing gives exactly alpha (the anchor).
Value
List with output, gates, topk_indices
(1-based), topk_gates, aux_loss, f, P,
n_experts, k, estimate, n,
method.