6.1.6 · HinglishScaling & Efficient Architectures

Load balancing in MoE

3,240 words15 min readRead in English

6.1.6 · AI-ML › Scaling & Efficient Architectures

MoE Mein Load Balancing Kya Hai?

Iski zaroorat kyun hai?

  • Balancing ke bina: Gating network (router) ek degenerate solution par converge kar sakta hai jahan wo zyaadatar tokens ek chote subset of experts ko bhejta hai. Baaki experts ko almost koi gradient signal nahi milta aur wo seekh nahi paate.
  • Balancing ke saath: Saare experts diverse data par train hote hain, specialized skills develop karte hain, aur model apna poora parameter budget efficiently use karta hai.

Load Balancing Problem: First Principles Se

Step 1: Routing Kaise Kaam Karta Hai

MoE gating function yaad karo. Token ke liye, hum experts ke liye gating scores compute karte hain:

jahan expert ko route karne ki probability hai. Top-K routing mein (typically ), hum experts choose karte hain jinki sabse zyaada ho aur normalize karte hain:

Output yeh hai:

Step 2: Collapse Kyun Hota Hai

Gating network ko main task loss par gradient descent se seekha jaata hai. Training ke shuruaat mein, random initialization ki wajah se expert 1 kisi common pattern mein thoda behtar ho sakta hai. Router zyaada tokens expert 1 ko bhejta hai, usse zyaada gradient milta hai, wo aur tezi se improve hota hai, aur aur bhi tokens attract karta hai — ek feedback loop. Experts 2-8 bhookhe reh jaate hain.

Step 3: Load Imbalance Measure Karna

tokens ke ek batch mein expert ko route hone wale tokens ka fraction define karo:

Perfectly balanced: sabhi ke liye (agar 8 experts mein se Top-2 hai, toh har expert ko average par tokens milne chahiye).

Collapsed: , , .

Load Balancing Loss: Scratch Se Derivation

Standard approach Switch Transformer (aur related GShard) paper se aata hai. Key insight: hum ek saath do cheezein balanced chahte hain, aur hume ek aisa term chahiye jo (a) uniform distribution par minimize ho aur (b) router weights ke through differentiable ho.

Wo Do Quantities Jo Hum Track Karte Hain

tokens aur experts ke ek batch par define karo:

  • : expert ko actually dispatch hone wale tokens ka fraction (yeh ek hard count hai, non-differentiable):
  • : router dwara expert ko assign ki gayi average routing probability (yeh ke through differentiable hai):

Switch Transformer Auxiliary Loss

jahan ek hyperparameter hai (typically ).

Key takeaways (corrected mental model):

  • Loss magically par minimal nahi hota jaise ek unconstrained dot product mein. Iski purpose dynamically achieve hoti hai: gradients load ke saath scale karte hain aur busy experts ke liye niche push karte hain.
  • Training ke fixed point par, agar router probabilities equalize kare () aur dispatch equalize ho (), toh loss par settle hota hai, ek chota constant. Imbalance ise isse upar uthata hai.

Total Training Loss

Router ab ek trade-off optimize karta hai: tokens ko task ke liye best expert tak route karo ( minimize karo) jabki load balanced rakho ( minimize karo by already-busy experts par probability over-concentrate na karo).

Alternative: Capacity Factor aur Token Dropping

Kuch MoE implementations (jaise Switch Transformer) ek capacity factor bhi use karte hain:

Yeh kaise kaam karta hai:

  • Agar hai, toh har expert exactly tokens handle kar sakta hai (perfect balance).
  • Agar expert ki assignments capacity se zyaada ho jaayein, toh excess tokens drop ho jaate hain (unki representation residual ke roop mein pass hoti hai, expert ko bypass karke).
  • Dropping back-pressure create karta hai: agar expert 1 overloaded hai, toh tokens drop hote hain, model un tokens par worse perform karta hai, aur gradients expert 1 ko over-routing discourage karte hain.

Yeh kyun help karta hai:

  • Hard constraint: physically ek expert ko saare tokens lene se rokta hai.
  • Router ko under-utilized experts explore karne ke liye encourage karta hai.
  • Trade-off: tokens drop karna performance hurt kar sakta hai agar bahut low ho. Typical values: .

Common Hyperparameters

Hyperparameter Typical Value Purpose
(aux loss weight) 0.01 Task loss aur balance ke beech trade-off
Capacity factor 1.0 - 1.5 Load variation ke liye buffer
Top-K 1 ya 2 Har token ke liye experts ki sankhya

kyun? Empirically tuned. Bahut zyaada: router probabilities ko flat kar deta hai balance satisfy karne ke liye aur ignore karta hai ki kaunsa expert best hai (accuracy hurt hoti hai). Bahut kam: load collapse wapas aata hai. ek robust sweet spot hai.

Jab Load Balancing Kaafi Nahi Hota

  1. Bahut chote batch sizes: aur experts (Top-2) ke saath, stochastic imbalance unavoidable hai. Solution: micro-batches par stats accumulate karo, ya badhao.
  2. Highly skewed data: Agar 90% English hai aur 10% code, toh ek early-specialized expert dominate kar sakta hai. Solution: data-aware balancing ya mild imbalance accept karo agar task performance improve hoti hai.
  3. Sparse expert gradients: Kam tokens se feed hone wale experts ko noisy updates milte hain. Solution: capacity factor badhao ya gradient accumulation use karo.
Recall Ek 12-Saal Ke Bacche Ko Explain Karo

Ek group project imagine karo jisme 8 dost hain aur ek team leader (router) hai jo tasks baanta hai. Agar akela chhod do, toh leader SAARI drawing Alex ko de sakta hai kyunki Alex ne achha start kiya. Alex overloaded ho jaata hai aur baaki 7 kabhi drawing seekh hi nahi paate.

Load balancing aisa hai jaise teacher ek tally sheet dekh raha ho ki kisne kitne tasks liye. Agar Alex ka tally bahut bada hai, toh teacher leader ko ek nudge deta hai Alex ke tally ke proportional: "Alex ko itna prefer karna band karo." Nudge us insaan ke liye bada hota hai jo sabse zyaada overloaded hai. Kyunki leader ki preferences 100% mein add honi chahiye, Alex se preference kheenchne par quiet dosto ko automatically zyaada milta hai — toh unhe finally tasks milte hain aur wo seekhte hain.

Clever baat yeh hai: tally khud (kisne kitne tasks liye) sirf ek number hai jo teacher padhta hai — teacher sirf leader ki preferences badalta hai, aur unhe sabse busy insaan ke liye zyaada strongly badalta hai. Yahi exactly MoE auxiliary loss kaam karta hai.

Connections

  • Mixture of Experts (MoE) Architecture: Base architecture; load balancing MoE ke liye scale par essential hai.
  • Top-K Routing in MoE: Routing mechanism jo load imbalance problem create karta hai.
  • Switch Transformer: auxiliary loss aur capacity factor ka source.
  • GShard: Large sharded MoE ke liye related importance/load auxiliary losses.
  • Expert Capacity and Token Dropping: Soft auxiliary loss ka hard-constraint alternative.
  • MoE Training Dynamics: MoE models kaise converge karte hain, balancing effects including.
  • Gradient Routing in MoE: Gradients router ke through kaise flow karte hain (sirf ke via).

#flashcards/ai-ml

MoE mein load balancing kaunsi core problem solve karta hai?
Load balancing ke bina, kuch experts ko zyaadatar tokens milte hain aur wo training dominate karte hain, jabki dusre experts useless mein collapse ho jaate hain, parameters aur compute waste karte hain. Load balancing ensure karta hai ki saare experts ko roughly equal training signal mile aur wo diverse skills develop karen.
Switch Transformer auxiliary load-balancing loss state karo.
, jahan expert ko dispatch hone wale tokens ka fraction hai (non-differentiable count), expert ke liye average router softmax probability hai (differentiable), experts ki sankhya hai, aur . Note karo ki pehle se andar hai, toh total loss hai (na ki ).
Auxiliary loss mein kaun sa term gradients carry karta hai, aur wo gradient kya hai?
Sirf gradients carry karta hai (softmax differentiable hai). ek hard dispatch count hai aur ise constant maana jaata hai. Gradient hai , yaani expert ke measured load ke proportional.
Yeh kehna kyun galat hai ki uniform point par minimize hota hai?
True constraints aur ke under, dot product ek corner par minimize hota hai — sabse chote- expert par saara -mass concentrate karke — uniformity par nahi. Loss is baat se kaam nahi karta ki uniform par minimal ho, balki ek feedback controller ki tarah: uska gradient probability ko overloaded experts se door push karta hai, aur softmax redistribute karta hai.
Cross term akele ya ki jagah kyun use karte hain?
Akela non-differentiable hai (hard count se koi gradient nahi). Akela sirf router confidence regularize karta hai aur actual dispatched load jo real compute imbalance cause karta hai use ignore karta hai. Cross term measured hard load (ek constant scaling ke roop mein) ko differentiable se couple karta hai, toh har par corrective gradient observed overload ke saath directly scale karta hai.
Top-K routing mein "perfectly balanced" ka kya matlab hai?
Har expert ko average par tokens milte hain. 8 experts mein se Top-2 ke liye, har expert ko milna chahiye.
Capacity factor kya hai aur yeh balance kaise enforce karta hai?
Expert capacity . Capacity se zyaada assign hone wale tokens drop ho jaate hain (residual ke roop mein pass hote hain). Overloaded experts tokens drop karte hain, performance hurt hoti hai, toh gradients over-routing discourage karte hain. Typical .
Kya hota hai agar bahut zyaada set kar dein (e.g., 1.0)?
Auxiliary gradient bahut bada ho jaata hai, router probabilities ko uniform ki taraf flatten kar deta hai chahe har token ke liye kaunsa expert actually best ho. Experts mediocre generalists ban jaate hain aur performance ek dense base se bhi niche aa sakti hai.

Concept Map

computes softmax scores

early bias

leads to

causes

adds

encourages

prevents

target f_i equals K over N

measures imbalance

applied to

achieves

Gating network router

Top-K routing

Feedback loop

Expert collapse

Wasted parameters and compute

Load balancing

Auxiliary loss

Uniform token distribution

Fraction f_i per expert

Full expert utilization