Left alone, a learned router tends to send most tokens to a few favourite experts, leaving the rest unused. Switch Transformers add an auxiliary loss that penalizes uneven routing, so that the experts share the work.
Implement load_balancing_loss(expert_index, probs, n_experts), returning E * sum_i f_i P_i.
f_i counts the tokens assigned to expert i divided by T.Use np.bincount for the token fractions, take the mean of probs over tokens, then combine.
No results yet
Run your code to check it against the examples, or submit to run every test.