Expert-threshold routing keeps expert loads near even like expert choice, but stays causal: each expert has a score cutoff learned from earlier batches, and a token goes to every expert whose cutoff its score beats. Tokens therefore get a variable number of experts. Implement the cutoff, the routing and the streaming loop.
et_cutoffs(scores, k)
scores: (T, N). With target (assume ), return the (N,) array whose entry is the -th largest score in column : the cutoff that exactly of this batch's tokens beat for that expert (the cutoff expert choice would have used on this batch).et_route(scores, thresholds)
(T, N) mask with True where (strictly). It must depend on each token's own scores and the given thresholds only.et_stream(calib, batches, k, ema)
et_cutoffs(calib, k) from a calibration batch.et_cutoffs(batch, k)."maxvio" ( of the per-expert counts; assume every batch routes at least one token), "mean_experts" (mean number of experts per token), "zero_share" (share of tokens with no expert), plus "thresholds" (the final as a list rounded to 4).