The loss-free balancer adds a per-expert bias to the router scores, used only to choose the top- experts, and nudges it after every batch: down for overloaded experts, up for underloaded ones. No gradient is involved. Implement biased routing and three update rules, and run them over a stream of batches.
biased_topk(scores, bias, k)
scores: (T, N) positive gate scores (e.g. sigmoid outputs); bias: (N,).scores + bias, in descending order of that sum (ties: lower expert index first).(idx, w), both (T, k).run_bias(batches, k, rate, rule)
batches: a list of (T, N) score arrays (all with the same ); the bias starts at zero."sign": (an expert exactly at the target gets 0; compare with in integers);"centered": the sign step minus its mean over experts, ;"linear": ."maxvio" (list, one per batch, rounded to 4 decimals), "bias" (the final bias as a list rounded to 4 decimals) and "bias_mean" (its mean, rounded to 4).