# Router ekspertów i równoważenie obciążenia

EN: **Expert routing and load balancing in MoE** · id `moerouting` · aliases: expert routing, top-k routing, MoE routing, routing ekspertów

Path: [AI Atlas](https://aiatlasgraph.com/llms.txt) › [Sieci i modele generatywne](https://aiatlasgraph.com/t/neural.md) › [Architektury efektywne](https://aiatlasgraph.com/t/efficientarch.md) › [Mixture of Experts (MoE) — mieszanka ekspertów](https://aiatlasgraph.com/t/moe.md) › Router ekspertów i równoważenie obciążenia

## Description

- PL: Bramka (router) w warstwach MoE wybierająca top-k ekspertów na token oraz techniki wyrównywania obciążenia: pojemność ekspertów, strata pomocnicza i korekty biasu routera.
- EN: The gate (router) in MoE layers choosing top-k experts per token, plus load-balancing techniques: expert capacity, auxiliary loss and router-bias corrections.

## In one sentence

- PL: Sposób, w jaki model z wieloma podsieciami-ekspertami decyduje, który z nich zajmie się danym kawałkiem tekstu.
- EN: How a model with many expert subnetworks decides which of them handles each piece of text.

## Problem it solves

- PL: Gdy prawie wszystko trafia do kilku ulubionych ekspertów, reszta się nie uczy, a sprzęt z nimi stoi bezczynnie.
- EN: When nearly everything goes to a few favourite experts, the rest never learn and their hardware sits idle.

## What it does

- PL: Jak dyspozytor taksówek: kieruje kursy do najlepiej pasujących kierowców, ale pilnuje, żeby jedni nie mieli kolejki, a inni nie stali.
- EN: Like a taxi dispatcher: sends rides to the best-matching drivers while making sure no one has a queue and no one sits idle.

## Everyday example

- PL: Pytanie o przepis kulinarny trafia do innych części modelu niż pytanie o kod, a obciążenie serwerów pozostaje wyrównane.
- EN: A recipe question goes to different parts of the model than a coding question, while server load stays even.

## This concerns you if you…

- PL: trenujesz lub dostrajasz model z ekspertami
- PL: zastanawiasz się, czemu modele z ekspertami trudno uruchomić
- EN: train or fine-tune a model with experts
- EN: wonder why expert models are hard to deploy

## Keywords

top-k gating · Switch Transformer · capacity factor · auxiliary load balancing loss · router z-loss · auxiliary-loss-free balancing · expert parallelism · token dropping · expert choice routing

## How it works

- PL: Router liczy softmax z iloczynu stanu tokenu i macierzy routera, wybiera k ekspertów i sumuje ich wyjścia ważone prawdopodobieństwami. Każdy ekspert ma pojemność (capacity factor); nadmiarowe tokeny przechodzą tylko połączeniem resztkowym. Strata pomocnicza karze nierówny rozkład, a nowsze metody korygują bias routera bez dodatkowej straty.
- EN: The router takes a softmax of the token state times a router matrix, picks k experts and sums their outputs weighted by probabilities. Each expert has a capacity (capacity factor); overflow tokens pass only through the residual connection. An auxiliary loss penalises uneven distribution, and newer methods adjust router bias without an extra loss.

## Limits

- PL: Za mała pojemność gubi tokeny, za duża marnuje obliczenia i pamięć. Zbyt silna strata pomocnicza pogarsza jakość. Routing bywa niestabilny w niskiej precyzji i wymaga komunikacji między urządzeniami przy zrównoleglaniu ekspertów.
- EN: Too little capacity drops tokens, too much wastes compute and memory. An overly strong auxiliary loss hurts quality. Routing can be unstable in low precision and needs cross-device communication under expert parallelism.

## Key terms

- PL: **top-k**: Wybór k ekspertów z najwyższą oceną routera dla tokenu.
- PL: **capacity factor**: Zapas miejsc u eksperta ponad równy podział tokenów.
- PL: **strata pomocnicza**: Dodatkowy składnik straty zachęcający do równego rozkładu tokenów.
- EN: **top-k**: Choosing the k experts with the highest router score for a token.
- EN: **capacity factor**: Spare expert slots beyond an even split of tokens.
- EN: **auxiliary loss**: An extra loss term encouraging even token distribution.

## Know first

- [Funkcje straty (entropia krzyżowa, MSE) (Loss functions (cross-entropy, MSE))](https://aiatlasgraph.com/t/lossfunctions.md)

## Related topics

Untyped, symmetric "see also" links.

- [Strategie zrównoleglania treningu (Training parallelism strategies)](https://aiatlasgraph.com/t/parallelism.md)

## Sources

- [Switch Transformers: Scaling to Trillion Parameter Models with Simple and Efficient Sparsity](<https://arxiv.org/abs/2101.03961>) `switch-transformer-2021` · by William Fedus, Barret Zoph, Noam Shazeer

---

AI Atlas revision 129 (2026-11-05) · HTML: https://aiatlasgraph.com/t/moerouting · index: https://aiatlasgraph.com/llms.txt · everything: https://aiatlasgraph.com/llms-full.txt · updated 2026-11-05
