Variational Routing: A Scalable Bayesian Framework for Calibrated Mixture-of-Experts Transformers
Organizations: Department of Computing, Imperial College London.
Abstract
Foundation models are increasingly being deployed in contexts where understanding the uncertainty of their outputs is critical to ensuring responsible deployment. While Bayesian methods offer a principled approach to uncertainty quantification, their computational overhead renders their use impractical for training or inference at foundation model scale. State-of-the-art models achieve parameter counts in the trillions through carefully engineered sparsity including Mixture-of-Experts (MoE) layers. In this work, we demonstrate calibrated uncertainty at scale by introducing Variational Mixture-of-Experts Routing (VMoER), a structured Bayesian approach for modelling uncertainty in MoE layers. VMoER confines Bayesian inference to the expert-selection stage which is typically done by a deterministic routing network. We instantiate VMoER using two inference strategies: amortised variational inference over routing logits and inferring a temperature parameter for stochastic expert selection. Across fine-tuning tested foundation models, VMoER improves routing stability under noise by 38%, reduces calibration error by 94%, and increases out-of-distribution AUROC by 12%, while incurring less than 1% additional FLOPs. These results suggest VMoER offers a scalable path toward robust and uncertainty-aware foundation models.
Figures & tables
| Granite-MoE | Qwen-MoE | DeepSeek-MoE | |||||||||||
| Method | Type | ACC | NLL | ECE | MCE | ACC | NLL | ECE | MCE | ACC | NLL | ECE | MCE |
| MAP | Det. | 0.746 | 1.38 | 0.252 | 0.472 | 0.804 | 1.37 | 0.127 | 0.273 | 0.802 | 1.120 | 0.168 | 0.321 |
| Temp-Scale | Heur. | 0.716 | 0.773 | 0.107 | 0.201 | 0.817 | 1.12 | 0.102 | 0.224 | 0.808 | 0.870 | 0.146 | 0.402 |
| MCDropout | Wei. | 0.734 | 0.650 | 0.037 | 0.298 | 0.798 | 0.982 | 0.064 | 0.152 | 0.794 | 0.729 | 0.103 | 0.302 |
| SWAG | Wei. | 0.736 | 0.652 | 0.041 | 0.290 | 0.782 | 0.912 | 0.098 | 0.146 | 0.786 | 0.665 | 0.140 | 0.288 |
| VGLR-MF | Log. | 0.742 | 0.654 | 0.026 | 0.293 | 0.796 | 0.724 | 0.028 | 0.124 | 0.788 | 0.476 | 0.067 | 0.174 |
| Near-Domain | Far-Domain | |||||
| Method | Signal | ARC-E | ARC-C | Med | Law | Avg |
| MAP | Gate-Ent | 0.612 | 0.633 | 0.679 | 0.683 | 0.652 |
| MCDR | Gate-Ent | 0.612 | 0.632 | 0.684 | 0.691 | 0.655 |
| MC-Logit-Var | 0.610 | 0.677 | 0.786 | 0.793 | 0.717 | |
| VGLR-FC | Gate-Ent | 0.615 | 0.652 | 0.692 | 0.677 | 0.659 |
| Inf-Logit-Var | 0.609 | 0.709 | 0.844 | 0.834 | 0.749 | |
| Noise ( ) | MAP | MCDR | VGLR-FC | VTSR |
|---|---|---|---|---|
| 0.001 | 0.938 | 0.944 | 0.956 | 0.948 |
| 0.002 | 0.924 | 0.932 | 0.946 | 0.936 |
| 0.005 | 0.614 | 0.662 | 0.672 | 0.668 |
| 0.010 | 0.532 | 0.582 | 0.612 | 0.614 |
| Activation Memory | Computational Cost (FLOPs) | |||||
| Method | Complexity | Params | Add. % | Complexity | GFLOPs | Add. % |
| Weight-Space Baselines (MCDR[parallelised], SWAGR) | ||||||
| All | 20.9M | 2.61% | 0.0208 | 2.32% | ||
| VMoER (Ours) | ||||||
| VGLR-MF | 6.2M | 0.78% | 0.0069 | 0.77% | ||
| VGLR-FC | 9.2M | 1.15% | 0.0096 | 1.07% | ||
Appendix figures & tables11 assets
Supplementary material from the paper’s appendix.
Appendix
| Specification | Granite-MoE | Qwen1.5-MoE | DeepSeek-MoE |
|---|---|---|---|
| HuggingFace ID | granite-3.1-3b-a800m | Qwen1.5-MoE-A2.7B | deepseek-moe-16b |
| Total Parameters | 3.3B | 14.3B | 16.4B |
| Active Params | 800M | 2.7B | 2.8B |
| MoE Layers | 32 | 24 | 27 |
| Hidden Dimension | 1,536 | 2,048 | 2,048 |
| Routed Experts ( ) | 40 | 60 | 64 |
| Dataset | Domain | Role 1: ID Calibration | Role 2: OoD Detection |
|---|---|---|---|
| (Train / Val / Test) | (Shift Type) | ||
| OBQA | Commonsense Science | 5000 / 50 / 500 | ID Source (Training) |
| ARC-C | Primary Science (Hard) | 2000 / 50 / 500 | Near-OoD (OoD-S) |
| ARC-E | Primary Science (Easy) | – Not Used – | Near-OoD (OoD-S) |
| SciQ | Broad STEM | 5000 / 50 / 500 | – Not Used – |
| MedMCQA | Professional Medicine | 5000 / 50 / 500 | Far-OoD (OoD-L) |
| Granite-MoE | Qwen-MoE | DeepSeek-MoE | |||||||||||
| Method | ACC | NLL | ECE | MCE | ACC | NLL | ECE | MCE | ACC | NLL | ECE | MCE | |
| Dataset: ARC-Challenge (Reasoning) | |||||||||||||
| Base | MAP | 0.882 | 0.923 | 0.201 | 0.428 | 0.758 | 1.852 | 0.252 | 0.624 | 0.580 | 1.462 | 0.237 | 0.826 |
| Temp-Scale | 0.824 (.004) | 0.208 (.006) | 0.038 (.007) | 0.284 (.003) | 0.762 (.003) | 1.422 (.001) | 0.102 (.001) | 0.304 (.005) | 0.592 (.003) | 1.242 (.008) | 0.188 (.006) | 0.646 (.003) | |
| Weight | MCDR | 0.880 (.003) | 0.146 (.006) | 0.028 (.003) | 0.228 (.007) | 0.732 (.003) | 1.134 (.001) | 0.198 (.011) | 0.446 (.011) | 0.564 (.005) | 1.084 (.009) | 0.192 (.023) | 0.848 (.003) |
| SWAG | 0.872 (.003) | 0.138 (.006) | 0.030 (.007) | 0.266 (.002) | 0.746 (.002) | 1.122 (.006) | 0.202 (.010) | 0.387 (.002) | 0.568 (.002) | 1.183 (.001) | 0.198 (.004) | 0.842 (.009) | |
| Near-Domain Shift | Far-Domain Shift | Average | ||||||||||
| OBQA ARC-E | OBQA ARC-C | OBQA MedMCQA | OBQA MMLU-Law | Overall | ||||||||
| Model | Method | Signal | AUROC | AUPRC | AUROC | AUPRC | AUROC | AUPRC | AUROC | AUPRC | AUROC | AUPRC |
| Granite | MAP | Gate-Ent | 0.612 | 0.596 | 0.633 | 0.626 | 0.679 | 0.645 | 0.683 | 0.686 | 0.652 | 0.638 |
| MCDR | Gate-Ent | 0.612 | 0.599 | 0.632 | 0.610 | 0.684 | 0.651 | 0.691 | 0.672 | 0.655 | 0.633 | |
| MC-Logit-Var | 0.610 | 0.583 | 0.677 | 0.623 | 0.786 | 0.723 | 0.793 | 0.765 | 0.717 | 0.674 | ||
| VGLR-MF | Gate-Ent | 0.622 | 0.603 | 0.642 | 0.622 | 0.682 | 0.637 | 0.673 | 0.664 | 0.655 | 0.632 | |
| Granite | DeepSeek | QWen | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Noise ( ) | MAP | MCDR | VGLR-FC | VTSR | MAP | MCDR | VGLR-FC | VTSR | MAP | MCDR | VGLR-FC | VTSR |
| 0.001 | 0.946 | 0.954 | 0.970 | 0.962 | 0.956 | 0.958 | 0.948 | 0.954 | 0.938 | 0.944 | 0.956 | 0.948 |
| 0.002 | 0.922 | 0.932 | 0.940 | 0.934 | 0.918 | 0.944 | 0.940 | 0.922 | 0.924 | 0.932 | 0.946 | 0.936 |
| 0.005 | 0.650 | 0.822 | 0.886 | 0.840 | 0.712 | 0.732 | 0.758 | 0.746 | 0.614 | 0.662 | 0.672 | 0.668 |
| 0.010 | 0.422 | 0.654 | 0.702 | 0.692 | 0.624 | 0.684 | 0.718 | 0.702 | 0.532 | 0.582 | 0.612 | 0.614 |