Skip to content
AI.info

Advanced techniques

Multi-Task Learning and Mixture-of-Experts

Learn how shared representations, task-specific heads, sparse routing, and expert load balancing support related tasks at scale.

By the end you can

Shared learning is valuable only when the tasks share something worth learning

Multi-task learning trains several objectives together. Related tasks can then share representations, examples, or regularization, and a low-data task may benefit from features learned on a high-volume relative. Auxiliary tasks can force the encoder to preserve information that improves generalization on the primary task.

The same sharing can cause negative transfer. Gradients from one task may move shared parameters in a direction that harms another. Differences in label noise, scale, sampling frequency, or loss magnitude let one task dominate. A task that is semantically related but measured poorly can be worse than an unrelated clean one.

Mixture-of-experts introduces conditional computation. A router selects a subset of expert subnetworks for each input or token, so parameter capacity grows without activating every expert every time. It does not remove multi-task tradeoffs. It moves some of them into routing, specialization, communication, and capacity allocation.

The claim is old, and it was measured. Multitask learning “improves generalization by using the domain information contained in the training signals of related tasks as an inductive bias”, Rich Caruana wrote in 1997. On the simulated 1D-ALVINN steering task his shared nets beat single-task nets: “on the important steering task, MTL outperforms STL 15–30%”. Both were trained on “exactly the same training patterns”. Only the extra output signals differed.

What that argument does not supply is a way to know in advance which tasks will do this for each other. The paper that asked the question asked it plainly: “Unfortunately, this often leads to inferior overall performance as task objectives can compete, which consequently poses the question: which tasks should and should not be learned together in one network when employing multi-task learning?” Standley and colleagues then answered it the expensive way. In 2020 they trained every one of the 31 subsets of a five-task set on the Taskonomy dataset — about 4 million examples from 3D scans of about 600 buildings, with no building overlap between train and test. Some groupings paid. Semantic segmentation trained alongside depth came out 4.17% better than trained alone, on a half-size network. Some pairs hurt both tasks. And their measured pairwise affinities did not track Taskonomy's own transfer affinities: Pearson's r = −0.14. A published taxonomy of task relatedness did not predict which tasks belonged in one network. Relatedness is a property of your setup. It is measured there or not at all.

Sharing helps when tasks reinforce reusable structure — and a published taxonomy of relatedness predicted these groupings at r = −0.14.

Visual

Inside a sparse expert layer

A router converts each input representation into expert assignments and weights. Mixtral 8x7B makes the arity concrete. Each layer is composed of 8 feedforward blocks, and a router network selects two of them for each token, at every layer. Mistral's own paper states the consequence: “As a result, each token has access to 47B parameters, but only uses 13B active parameters during inference.”

Those are two numbers, and they are not interchangeable. 47B is what has to be resident. 13B is what does the work per token. Hugging Face's write-up of the same model pins both halves down from outside the lab that built it. The arithmetic the name suggests is wrong — “The total number of parameters is not 56B, but about 45B.” — and it is the active count, not the total, that sets the speed. Selecting two experts for each timestep “allows the model to decode at the speed of a 12B parameter-dense model, despite containing 4x the number of effective parameters”.

Note also that the two organisations do not agree on the total: 47B against about 45B. That is exactly the kind of number to quote with its source rather than round into a headline. A serving plan that budgets memory from the compute figure, or latency from the memory figure, is planning for a model that does not exist.

FigureProcess · 5 steps
  1. 1

    Compute routing scores

    A gating network scores the available experts.

  2. 2

    Select top experts

    Only one or a few experts receive the input.

  3. 3

    Process in parallel

    Selected expert networks transform their assigned inputs.

  4. 4

    Combine expert outputs

    Weighted expert results return to the shared network.

  5. 5

    Balance and monitor

    Auxiliary objectives and capacity limits discourage routing collapse.

47B held against 13B used: sparse routing splits one parameter count into two, and a serving plan needs both.

Comparison

Ways to share—and ways to keep tasks apart

The architecture should reflect how much common structure the tasks truly have. Hard sharing bets that a single trunk can serve every objective. Soft sharing buys specialization with parameters and tuning. Sparse routing buys it with conditional computation: in Mixtral 8x7B, 8 feedforward blocks per layer, of which the router picks two per token. The capacity sits in memory whether or not a given token uses it.

None of the three escapes the others' failures. Standley and colleagues found task pairs that hurt both members, and routed models add the load-balancing machinery this lesson takes up under expert collapse.

FigureComparison · 3 columns

Hard parameter sharing

Use one shared trunk with separate task heads.

  • Efficient and strongly regularizing
  • Simple production footprint
  • Shared gradients can conflict
  • Common in related prediction tasks

Soft parameter sharing

Give tasks separate parameters with penalties or learned connections between them.

  • Allows more task specialization
  • Higher memory and tuning cost
  • Can encode task relationships explicitly
  • Useful when relatedness is partial

Sparse mixture-of-experts

Route each input to a small subset of experts.

  • Large parameter capacity at limited active compute
  • Experts can specialize conditionally
  • Needs routing and load balancing
  • Communication cost can dominate at scale

Key idea

More experts do not guarantee more expertise

A router may send most inputs to a few experts while others receive too little data to learn. Capacity limits can then drop or reroute tokens, creating training instability. Experts can also become redundant, specializing by superficial frequency or hardware placement rather than useful semantics.

This failure has a name in the literature, and its standard cure has a measured price. A 2024 paper on load balancing opens with both halves of the bind: “For Mixture-of-Experts (MoE) models, an unbalanced expert load will lead to routing collapse or increased computational overhead. Existing methods commonly employ an auxiliary loss to encourage load balance, but a large auxiliary loss will introduce non-negligible interference gradients into training and thus impair the model performance.” The balancing objective is not a free repair. It pushes shared parameters in a direction the task loss did not ask for. Wang and Dai's alternative adds an expert-wise bias before the top-K routing decision, and no auxiliary loss at all, validated on MoE models up to 3B parameters trained on up to 200B tokens.

That idea left the paper. The DeepSeek-V3 technical report — 671B total parameters, 37B activated for each token, 14.8 trillion pre-training tokens — states that the model “pioneers an auxiliary-loss-free strategy for load balancing”. NVIDIA's Megatron Core developer guide lists it beside the older options it supports: aux_loss, seq_aux_loss, global_aux_loss, sinkhorn, none, and “aux loss free — Dynamic bias-based load balancing strategy without auxiliary loss”, behind --moe-router-enable-expert-bias with --moe-router-bias-update-rate 1e-3, alongside --moe-expert-capacity-factor and --moe-token-drop-policy for overflow. Those flags are also a list of what to instrument: expert utilization, routing entropy, overflow, per-expert quality, and performance by task or domain.

Expert count is potential capacity; useful specialization must be measured, and the loss that enforces balance is itself a cost.

Case

A thousandfold of capacity, and the core-years that came with it

The sparsely-gated mixture-of-experts layer arrived in 2017. Applied convolutionally between stacked LSTM layers, it reached “up to 137 billion parameters”. Shazeer and colleagues reported “greater than 1000x improvements in model capacity with only minor losses in computational efficiency”. Capacity was the part that scaled cheaply.

Three years later the same idea arrived with its bill attached. GShard scaled a Sparsely-Gated Mixture-of-Experts translation Transformer beyond 600 billion parameters and trained it on 2048 TPU v3 accelerators in 4 days, translating 100 languages into English. The caption to the paper's first figure carries the price: “The 600B parameters model that achieved the best translation quality was trained with 2048 TPU v3 cores for 4 days, a total cost of 22 TPU v3 core-years.”

The number that makes this a case rather than a boast is the one beside it. The best dense Transformer in the same paper, at 2.3B parameters, cost 235.5 TPU v3 core-years — an order of magnitude more than the sparse model's 22. It gained 6.1 average ΔBLEU, where the 600B MoE gained 13.5. The table carries the rows: MoE(2048E, 36L) at BLEU 44.3, ΔBLEU 13.5, 600B weights, against T(96L) at 36.9, 6.1, 2.3B. Far more parameters, far less compute, and better than twice the quality gain. Three quantities, moving in different directions, reported together. That is the shape an argument for sparse capacity has to take. A capacity multiplier on its own, with no core-years and no BLEU column beside it, is one third of this paragraph.

Example

Where task conflict comes from

Conflict is not a single phenomenon, so one weighting trick rarely solves every case. The first item on this list has a test rather than a description: “We define two gradients to be conflicting if they point away from one another, i.e., have a negative cosine similarity.” That is Yu and Finn, in the 2020 gradient-surgery paper. Its §2.2 is titled “The Tragic Triad: Conflicting Gradients, Dominating Gradients, High Curvature” — the first, second and last bullet below, under other names.

The cost of leaving the triad alone is measured. On the Meta-World benchmarks, projecting conflicting gradients (PCGrad) with SAC “successfully solves all of the 10 tasks in MT10 and about 70% of the 50 tasks in MT50”, while a single SAC policy and a multi-head policy are “unable to acquire half of the skills in both MT10 and MT50”.

  • Gradient direction: Two tasks request opposing updates to shared parameters — operationally, their gradients have a negative cosine similarity, a quantity you can log each step rather than infer afterwards from a disappointing result.
  • Loss scale: A numerically larger loss dominates even when it is not more important; this is the dominating-gradients corner of the tragic triad.
  • Data volume: A high-traffic task receives many more updates than a rare task, so a task can dominate through sampling alone without any single gradient being large.
  • Label quality: Noisy auxiliary supervision can corrupt the shared representation, and a related task measured badly can cost more than an unrelated task measured well.
  • Temporal mismatch: Tasks update on different schedules or react differently to drift, so a grouping that held at training time can come apart in production.
  • Capacity mismatch: A small shared trunk cannot represent every task, while a large one may permit harmful shortcuts; high curvature, the third corner of the triad, lives in those same shared parameters.

Analogy

A shared clinic with specialist referrals

Patients at a clinic all pass through the same general team, and only some are referred onward to specialists. Shared intake procedures save effort and expose common patterns. Specialists help when cases differ enough to need focused expertise. If referrals concentrate on one specialist or become random, the system loses the intended benefit.

In a clinic the specialists qualified before anyone was referred to them. Neural experts are trained by the routing decisions themselves. Early imbalance changes which expert becomes competent, and that feedback loop is what the routing design has to control.

The Switch Transformer rebuilt that machinery. It simplified “the MoE routing algorithm” and trained large sparse models “with lower precision (bfloat16) formats”. Models “based off T5-Base and T5-Large” obtained “up to 7x increases in pre-training speed with the same computational resources”. Fedus and Zoph published it in January 2021.

Multi-task systems need both a reason to share and a mechanism for fair, useful specialization.

Steps

An evaluation plan for shared and routed models

An aggregate gain can hide a task or an expert that regressed badly. The baselines at the top of this plan are not a formality, and there is a published result to prove it. In 2022 a separate group re-ran the specialised multi-task optimisers — PCGrad among them — against the plainest baseline available, simply summing the task losses. Kurin and Kumar report the outcome: “We show that unitary scalarization, coupled with standard regularization and stabilization techniques from single-task learning, matches or improves upon the performance of complex multi-task optimizers in popular supervised and reinforcement learning settings.” Much of the machinery's advantage, they argue, is regularisation in disguise. They close with a demand: “We believe our results call for a critical reevaluation of recent research in the area.”

That is the reason step 2 comes before step 5. If the summed-loss baseline is never tuned as carefully as the clever method, a gain credited to gradient surgery or to sparse routing may be a gain from regularisation that nobody tried on its own. It will be credited to the wrong component for as long as the comparison is missing.

FigureProcess · 6 steps
  1. 1. Train single-task baselines

    Measure each task without shared interference.

  2. 2. Normalize data and losses deliberately

    Control update frequency and numeric scale.

  3. 3. Add simple hard sharing

    Establish whether shared representations help at all.

  4. 4. Inspect task gradients and slices

    Find where sharing creates conflict or transfer.

  5. 5. Add routing only with evidence

    Compare dense shared capacity against sparse experts at matched active compute.

  6. 6. Monitor expert health

    Track utilization, overflow, specialization, latency, and communication.

Visual

Where shared capacity helps—and where it collides

A shared model should be evaluated as a network of task interactions rather than one aggregate score. Every layer of that audit has a measurable quantity attached to it, and this lesson has named one for each. Whether shared representations pay: 4.17% for semantic segmentation trained alongside depth, and pairs that hurt both tasks. Whether task gradients conflict: negative cosine similarity, logged per step. What routing costs on both axes: 22 TPU v3 core-years against 235.5, and 47B parameters resident against 13B active per token. And what the system does when a task label, an expert or a route is unavailable. A single headline score can be produced while every one of those is unmeasured.

FigureLayers · 5 layers
  1. 01

    Shared input and backbone

    Measures whether common representations improve data efficiency.

  2. 02

    Task-specific heads

    Separates output contracts, labels, and thresholds.

  3. 03

    Gradient interaction

    Reveals conflict, domination, and scale mismatch between tasks.

  4. 04

    Routing and experts

    Adds conditional capacity, load balance, and dispatch costs.

  5. 05

    Operational fallback

    Defines behavior when a task label, expert, or route is unavailable.

A shared architecture is successful only when each task improves or accepts a documented tradeoff.

Position

Capacity scaled a thousandfold; the quality numbers in this lesson did not

Capacity is the word in the headline, and quality is the word a reader hears. Shazeer and colleagues reported “greater than 1000x improvements in model capacity with only minor losses in computational efficiency on modern GPU clusters,” in a layer that reached up to 137 billion parameters. Every noun there is doing precise work. Capacity is how much a model can hold, not how well it answers. And the clause after the comma reports a loss in efficiency: minor, but a loss, not a saving.

The Switch Transformer figure behaves the same way. Simplified routing and bfloat16 training gave models based on T5-Base and T5-Large “up to 7x increases in pre-training speed with the same computational resources.” That is a statement about pre-training speed at a fixed compute budget, on two named model sizes, and “up to” marks it as the best case rather than the usual one. Neither figure is a claim about answer quality per unit of compute. That is the quantity a team choosing between a dense model and a routed one has to compare.

That quantity does get reported, and its grammar is visibly different. GLaM is a 1.2-trillion-parameter sparse model with 64 experts per MoE layer. Each token activates a 96.6B-parameter subnetwork — 8% of the 1.2T total. Its abstract says: “It consumes only 1/3 of the energy used to train GPT-3 and requires half of the computation flops for inference”, and reports that it still scores better across 29 NLP tasks. Count the parts that sentence needs. A named model on the other side of the comparison. A resource on each side, training energy and inference flops. And a quality result, over a stated number of tasks, that did not go down. A capacity multiplier has none of them. It is a numerator with no denominator and no quality column.

The quality claim inherited by this lesson has the opposite shape: small, old and specific. On the simulated 1D-ALVINN steering task, Caruana's shared nets beat single-task nets by 15–30%, with identical training patterns and only the extra output signals differing. One task, one simulated domain, 1997. That asymmetry belongs in the design review, because the two kinds of number do not convert into each other. This lesson's own routing failures are the reason. A router may send most inputs to a few experts while the others receive too little data to learn, and capacity that never becomes specialization is capacity paid for and left unused.

A thousandfold more capacity is a claim about what a model can hold, not about what it answers.

Figure

The three multipliers a sparse-expert argument leans on, drawn together so that what each one multiplies is visible beside how large it is.

Key takeaways