Sampling the Router: Langevin Posterior Routing for Multi-Task Mixture-of-Experts

Mixture-of-experts models split a network into many parallel sub-networks, the "experts", plus a small gating network, the "router", that picks a few experts for each input. When one such model learns many tasks at once, the router carries most of the burden of deciding which tasks share which experts. Current systems make that choice with a single, confident set of router weights. One option is a shared router, which lets tasks fight over the same experts. The other is a separate router per task, which isolates tasks but blocks useful sharing. We propose treating the router's weights as uncertain. We draw samples of them with stochastic gradient Langevin dynamics (SGLD), which is ordinary mini-batch gradient descent plus carefully sized Gaussian noise, so that the iterates wander over the Bayesian posterior instead of settling at one point. The experts themselves are still trained by plain gradient descent.

The main payoff is for data-poor tasks. Under SGLD, the injected noise stays the same size while each task's gradient signal grows with that task's data. A small task's routing therefore stays uncertain and keeps trying different experts, while a large task's routing settles down. This is the behaviour one would hand-design to protect low-resource tasks without cutting them off from shared experts. At test time, averaging predictions over several sampled routers should also give better-calibrated confidence. The parameters that need sampling are only the router and a small embedding per task, a tiny fraction of the model, so this avoids the cost of making the whole network Bayesian.

Core Claim

We claim that a single router shared across tasks and conditioned on a learned task embedding, with its parameters sampled by SGLD while the experts train by gradient descent, will do three things. It will match or beat per-task routers on multi-task accuracy, with the largest gains on low-resource tasks. It will use far fewer routing parameters as the number of tasks grows. It will be better calibrated than deterministic or variational routing.

What is new relative to prior work is the combination of three things: parameter-space posterior sampling, confined to the router, performed during joint multi-task training rather than after it. The evidence that this is the right place for uncertainty comes from two existing papers that seem to pull in opposite directions. Sparsely Activated Mixture-of-Experts are Robust Multi-Task Learners (MT-TaG) finds that a task-agnostic sparse mixture reintroduces interference between tasks. It fixes this with one deterministic gate per task over shared experts, which grows linearly in the number of tasks. Calibrated Knowledge Aggregation in Bayesian Mixture-of-Experts for Continual VQA finds that a "non-native" expert beats the task's own expert on nearly half of queries. That suggests hard task isolation wastes transferable knowledge.

Our reading is that neither a fixed shared route nor a fixed isolated route is right. The correct amount of sharing is uncertain, and the uncertainty differs by task. SGLD represents exactly this: the posterior spread of a task's routing shrinks roughly with that task's sample count, as it does for any Bayesian estimate.

Research Program

We treat the model as two parameter blocks. The first is the router block $\phi$: the gating weights plus one task embedding $e_k$ for each task $k$. The router sees a token's hidden state concatenated with $e_k$, so adding a task costs one embedding vector rather than a full gate. The second block, $\theta$, is everything else: the backbone and the experts.

At each step we draw a mini-batch of $n_k$ examples from each task $k$, whose full training set has $N_k$ examples. The experts take an ordinary optimizer step on $\theta$. The router takes an SGLD step, following the update in Bayesian Learning via Stochastic Gradient Langevin Dynamics but with each task's likelihood scaled up to its own dataset size:

$$\phi_{t+1} = \phi_t + \frac{\epsilon_t}{2}\Big[\nabla \log p(\phi_t) + \sum_k \frac{N_k}{n_k}\sum_{i \in B_k} \nabla \log p(y_i \mid x_i, \phi_t, \theta_t)\Big] + \eta_t, \qquad \eta_t \sim \mathcal{N}(0, \tau\,\epsilon_t I).$$

The symbols are as follows. $\epsilon_t$ is the router step size. $p(\phi)$ is a Gaussian prior on the router parameters. $B_k$ is task $k$'s mini-batch. $\tau$ is a posterior temperature, where $\tau=1$ gives the exact Bayesian posterior.

The per-task scaling by $N_k/n_k$ is what produces the protective effect described above. Gradient terms for an embedding like RTE's (about 2.5k examples) are small compared with those for MNLI's. The fixed-size noise therefore moves the small task's embedding and routing much more.

We keep a thinned set of $M$ router samples from the late part of training and use them in two ways. During training, the noise keeps small tasks exploring shared experts instead of committing early. At inference, we average the output distributions over the $M$ sampled routers, a form of Bayesian model averaging.

The main technical difficulty is that $\theta$ keeps moving, so the router's target posterior is not fixed. We handle this in two ways and compare them. The first is a joint regime in which samples are collected only after the expert learning rate has decayed. The second is a two-phase regime that freezes $\theta$ and then runs SGLD on $\phi$ alone, mirroring the frozen-expert design of Variational Routing: A Scalable Bayesian Framework for Calibrated Mixture-of-Experts Transformers.

The sampler's known weaknesses shape two further design choices. Stochastic gradient Markov chain Monte Carlo reports that SGLD is sensitive to step size. We therefore use a fixed small step size with thinning rather than annealing to zero. Annealing to zero would stall mixing, which is the known trade-off between mixing and accuracy. Sampling from Non-Log-Concave Distributions via Variance-Reduced Gradient Langevin Dynamics shows that guarantees for non-convex targets degrade badly as dimension grows. This is a direct argument for confining sampling to the router block of perhaps $10^5$ to $10^6$ parameters rather than the whole network.

Averaging over $M$ routers costs up to $M$ passes through each mixture layer. We measure this cost directly. We also test a cheaper variant that samples only the last few mixture layers.

We also build a diagnostic. For each pair of tasks, we measure how much their expert usage overlaps under the router posterior. We then test whether this overlap predicts the pairwise transfer gains observed when tasks are added or removed. This gives an interpretable account of which tasks actually share capacity.

Baselines

The naive reference points are the dense multi-task model (MT-Dense) and the task-agnostic sparse mixture (MT-Switch) from Sparsely Activated Mixture-of-Experts are Robust Multi-Task Learners. Each reports an 82.1 GLUE average there. We also include single-task models, which that paper reports at 70.7 accuracy on RTE.

The strongest existing multi-task competitor is MT-TaG, which gives each task its own deterministic gate over shared top-1 experts. It reports an 82.5 GLUE average and 81.1 RTE accuracy. It is strongest here because it attacks exactly our target, routing interference between tasks, and it does so without any sampling machinery. We reimplement it on our backbone, expert count and data mixture. We confirm that our reimplementation lands near the reported numbers before comparing anything.

The strongest Bayesian-routing competitor is a variational router in the style of VMoER. It learns a Gaussian over expert logits, in both mean-field and full-covariance forms. That paper reports Granite-MoE expected calibration error falling from 0.252 to 0.015 on its multiple-choice QA suite, at 1.07% extra computation. We apply it to the same task-conditioned shared router, so the only difference from our method is how the posterior is approximated: variational versus Langevin.

A third competitor is an ensemble of $M$ routers trained by ordinary gradient descent from different random seeds on shared, frozen experts. It matches our inference cost exactly.

Every method gets the same data mixture, the same number of training steps and the same hyperparameter search budget in trials. The budget covers step size and temperature for us, and the corresponding knobs for the other methods.

Three ablations isolate our key ingredient. The first runs the identical router schedule with the noise removed, which isolates Langevin exploration. The second trains with SGLD but tests with the mean router only, which separates the training-time effect from averaging. The third drops the per-task $N_k$ scaling in favour of uniform scaling, which tests the claimed mechanism for protecting small tasks.

We count the proposal as beating MT-TaG only if three conditions hold. The GLUE average must be at least equal to MT-TaG's. RTE and the other small tasks must improve by more than seed-to-seed variation. Routing parameters must be strictly fewer on 16-task GLUE++. We count it as beating the variational router if calibration error is lower at matched accuracy.

Why not just…?

Why not just use per-task gates (MT-TaG)? They already work: the reported 81.1 on RTE against 70.7 for a single-task model is a large gain. But they fix each task's route deterministically, and the gate count grows with the number of tasks. The continual-VQA finding that non-native experts win on about half of queries suggests fixed isolation leaves transfer unused, but that finding comes from sequential learning rather than joint training, so it is suggestive rather than decisive here. Our GLUE and GLUE++ comparison settles the question. If MT-TaG matches us on small tasks and calibration, the only remaining argument for our method is parameter count, and we would say so.

Why not just use a variational Gaussian router? It is cheap and strongly calibrating in its own setting. It is a genuine threat. Our specific bet is that routing posteriors in the multi-task setting have several distinct modes, meaning different expert sets that serve a task comparably well, and that a single Gaussian over logits cannot represent this. We test the bet directly by measuring agreement of expert assignments across posterior samples from each method. If SGLD samples do not visit distinct assignments more often than the variational router does, and calibration is equal, the variational method is simply the better choice.

Why not just ensemble a few independently trained routers? For a small router block this is cheap and naturally visits multiple modes, so it may match our averaging gains. Ensembling gives no training-time exploration for small tasks and needs $M$ separate runs, whereas one Langevin chain produces all $M$ samples. The ensemble baseline, together with the ablation that trains with SGLD but tests with the mean router, separates these two effects. If the ensemble matches us on every metric, the contribution shrinks to the training-time effect alone.

Why not just add noise to gate logits or activations (as in S2MoE)? S2MoE: Robust Sparse Mixture of Experts via Stochastic Learning injects Gaussian noise into token representations before routing and adds a contrastive loss, reporting 28% lower inference cost in single-task language modeling. Noise in activations regularizes, but its size is tuned by hand and does not depend on how much data a task has. The ablation that removes the per-task scaling approximates this kind of data-blind noise. Running S2MoE-style noise as a further baseline tells us whether task-dependent posterior width is what matters.

Proposed Experiments

The primary testbed is GLUE, following GLUE: A Multi-Task Benchmark and Analysis Platform for Natural Language Understanding. We report per-task scores and the average, with particular attention to RTE, CoLA and MRPC, and use at least five seeds. We add the 16-task GLUE++ mixture to measure how routing parameters and accuracy scale with the number of tasks.

We replicate MT-TaG's robustness test, training on GLUE with and without SST-2, a task unrelated to the small ones. That paper reports small-task performance changing by −0.47 points for MT-Dense and +0.97 for MT-TaG. We ask whether posterior routing gives similar or better protection without task-isolated gates.

For calibration we report expected calibration error on each GLUE validation set. No reported GLUE calibration result was found on Lacuna, so all methods are measured fresh under the same protocol. For out-of-distribution detection we train on GLUE and score SciTail and IMDB inputs, which appear in the MT-TaG evaluation, using predictive entropy and AUROC. No reported result was found on Lacuna for out-of-distribution AUROC on this pairing either.

Beyond accuracy and calibration, we report mixture-layer compute as a function of $M$, and the cross-task routing-overlap diagnostic correlated against measured pairwise transfer. We also report the representation-collapse measure from On the Representation Collapse of Sparse Mixture of Experts, the effective dimension of token representations entering the router. Its purpose is to check whether router noise by itself reduces collapse compared with the hypersphere-normalized router (X-MoE) proposed there.

Two decisive checks determine whether the idea holds. First, the no-noise ablation must lose clearly to full SGLD on small tasks while roughly tying on large ones. If it does not, the task-scaled exploration mechanism is not doing what we claim. Second, SGLD must beat both the variational router and the equal-cost router ensemble on calibration at matched accuracy. If it does not, Langevin sampling adds cost without benefit, and the honest conclusion is that a task-conditioned shared router trained deterministically is the useful part.