Foundations to Frontier
Tests
E. Deep Learning › E19 Continual, Multi-Task and Transfer Learning

Multi-Task Learning: Hard and Soft Parameter Sharing

Multi-task learning trains one model on several tasks at once so that they can share what they learn. Hard parameter sharing uses one common body with a small head per task. Soft sharing gives each task its own network but pulls their weights together with a penalty. Sharing pools data and regularises, but tasks can also compete for capacity and send conflicting gradients (negative transfer). This page covers hard and soft sharing, loss weighting (including uncertainty weighting), gradient conflict and PCGrad, and when to share. In the exercises you count parameters, write the soft-sharing penalty and uncertainty weighting, then train six regression tasks with 40 labels each. On related tasks, hard sharing scored mean R² 0.72, soft sharing 0.61 and separate networks 0.55. On unrelated tasks, hard sharing collapsed to −0.35, while soft sharing (0.50) stayed close to separate networks (0.56). The same ordering held in all three seeds.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Learning several things at once

A drone’s camera network might need to detect obstacles, estimate depth and segment the runway. Instead of three separate networks, one network can share most of its layers and add a small output head for each job. If the jobs need similar features, each one effectively gets more training data. If they pull in different directions, they can hurt each other. The demo shows two task gradients: when they point in opposite directions, the tasks conflict.

Transfer and efficiency lab
Task gradients (green, red) have cosine -0.50. Summed update (grey) length 1.00; they conflict, so PCGrad projects each off the other (black), length 1.50.
Why engineers care

Autonomous vehicles and robots run many perception tasks on limited onboard compute. Shared multi-task networks save computation and often improve accuracy, provided the tasks are compatible.

📝 Quick check (Level 0)
0/3 answered
  1. 1. Hard parameter sharing uses…
  2. 2. Sharing helps most when tasks…
  3. 3. Opposite task gradients mean the tasks…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

By hand

  • Hard sharing: a shared body θ_s and task heads θ_t; loss Σ_t w_t L_t(θ_s, θ_t). Six tasks with a 30 → 6 body and 6 → 1 heads need 186 + 6·7 = 228 parameters, against 6·193 = 1158 for separate networks.
  • Soft sharing: each task has its own parameters, with a penalty λ Σ_t ‖W_t − W̄‖² (or cross-stitch and attention units that mix features between task networks).
  • Loss weighting:
    • fixed weights;
    • uncertainty weighting (Kendall et al.): Σ_t exp(−s_t) L_t + s_t, where s_t = log σ_t² is learned;
    • GradNorm, which balances gradient magnitudes.
  • Gradient conflict: if cos(g₁, g₂) < 0, a step for one task increases the other’s loss. PCGrad projects each gradient off the other when they conflict: g₁ − (g₁·g₂ / ‖g₂‖²) g₂.
📝 Quick check (Level 1)
0/3 answered
  1. 1. Parameters of six separate 30 → 6 → 1 networks:
  2. 2. Uncertainty weighting learns…
  3. 3. PCGrad acts when the gradient cosine is…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.

Multi-task learning in code

Exercise 1.

  • Count shared-body parameters.
  • Compute the soft-sharing penalty.
  • Compute the uncertainty-weighted loss.

Practice.

  • Build one backbone with a nn.ModuleDict of heads and sum the weighted losses.
  • Normalise losses that live on different scales: per-task standardisation or learned weights.
  • Monitor every task’s validation metric separately. A rising average can hide one task getting worse.
  • If a task suffers, try task-specific layers higher up, soft sharing, or gradient surgery (PCGrad, CAGrad).
class MTL(nn.Module):
    def __init__(self, tasks):
        super().__init__()
        self.body = nn.Sequential(nn.Linear(30, 64), nn.ReLU(), nn.Linear(64, 64), nn.ReLU())
        self.heads = nn.ModuleDict({t: nn.Linear(64, c) for t, c in tasks.items()})
        self.log_var = nn.Parameter(torch.zeros(len(tasks)))           # uncertainty weighting
    def forward(self, x): h = self.body(x); return {t: head(h) for t, head in self.heads.items()}
🐍 Exercise 1: sharing and weighting
Count hard-sharing parameters, compute the soft-sharing penalty and uncertainty weighting.
📝 Quick check (Level 2)
0/3 answered
  1. 1. Heads are commonly stored in…
  2. 2. Always monitor…
  3. 3. Gradient surgery methods include…

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

Why sharing helps. Baxter’s model of inductive bias learning shows that if T tasks share a representation, learning it from all tasks needs fewer examples per task. The representation’s complexity is amortised over T. Hard sharing also acts as a regulariser: the shared body must serve every task, so it cannot overfit one.

Why sharing hurts. A fixed shared bottleneck must represent every task’s features. If tasks need different features, it lacks the capacity, and their gradients conflict. Soft sharing relaxes the constraint, so with a small λ it degrades gracefully to independent training.

Choosing. Share more when tasks are related and data is scarce. Use soft sharing, task-specific upper layers or learned branching when relatedness is uncertain. Task-grouping methods measure inter-task affinity to decide which tasks to train together.

📝 Quick check (Level 3)
0/3 answered
  1. 1. Shared representations reduce…
  2. 2. Hard sharing fails when tasks need…
  3. 3. Soft sharing with small λ approaches…

Level 4: Expert

★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.

When does parameter sharing help, and when does it hurt?

History.

  • R. Caruana, “Multitask learning” (Machine Learning, 1997).
  • J. Baxter, “A model of inductive bias learning” (JAIR, 2000).
  • A. Kendall, Y. Gal and R. Cipolla, “Multi-task learning using uncertainty to weigh losses” (CVPR 2018).
  • T. Yu et al., “Gradient surgery for multi-task learning” (NeurIPS 2020).

Exercise 2.

  • Tasks: 6 regression tasks y_t = tanh(x A_t) w_t + noise, with x ∈ ℝ³⁰ and 3 latent directions.
    • Related family: all tasks share one A.
    • Unrelated family: each task has its own A_t.
  • Data: 40 training examples per task; tested on 2000 per task.
  • Model: a tanh body with 6 units and a linear head per task; weight decay 0.01; Adam for 500 steps.
    • separate networks;
    • hard sharing (one body);
    • soft sharing (separate bodies, λ = 0.05 towards their mean).
task family separate hard sharing soft sharing
related (mean R²) 0.549 0.718 0.609
unrelated (mean R²) 0.560 −0.351 0.503
  • Related tasks: sharing wins. Hard sharing pools 240 examples to learn the common projection: +0.17 R² over separate networks. Soft sharing gets part of the benefit.
  • Unrelated tasks: hard sharing collapses. Six tasks need 18 latent directions but the shared body has 6 units, so the tasks fight over capacity (R² below zero, worse than predicting the mean).
  • Soft sharing is the safe middle: close to separate networks when tasks are unrelated, better than them when tasks are related.
seed related: separate / hard / soft unrelated: separate / hard / soft
1 0.601 / 0.860 / 0.650 0.618 / 0.024 / 0.593
2 0.558 / 0.688 / 0.569 0.497 / −0.113 / 0.482
  • Settings were tuned: a wider body (16 units) or no weight decay let every model interpolate the 40 examples, and the ordering then varied with the seed. With 6 units and weight decay it was the same in all three seeds.
🐍 Exercise 2 (research): when does parameter sharing help, and when does it hurt?
Train six regression tasks with separate networks, hard sharing and soft sharing, for related and unrelated task families.

Multi-task learning in AI, robotics and aerospace

  • Autonomous driving: shared backbones for detection, segmentation, depth and lane estimation.
  • Spacecraft health monitoring: one model predicting several subsystem anomalies from shared telemetry.
  • Robotics: multi-task policies sharing perception across manipulation skills.
  • Design lesson: share when tasks are related; measure per-task effects and back off to soft or partial sharing when one task suffers.

References

  1. R. Caruana (1997). “Multitask learning.” Machine Learning 28.
  2. J. Baxter (2000). “A model of inductive bias learning.” JAIR 12.
  3. A. Kendall, Y. Gal and R. Cipolla (2018). “Multi-task learning using uncertainty to weigh losses for scene geometry and semantics.” Proc. CVPR.
  4. T. Yu et al. (2020). “Gradient surgery for multi-task learning.” NeurIPS.