wikillm

Paper · 2021-10-26 · cs.LG, cs.AI

Conflict-Averse Gradient Descent for Multi-task Learning

CAGrad merges the task gradients into one update. It starts from their average and picks the direction that most improves the worst task, staying within a radius c of the average. c=0 gives plain gradient descent. For c<1 it provably converges to a minimum of the average loss. Author-reported: best NYU-v2 and CityScapes Δm, best Meta-World MT10 and MT50 success without metadata.

Multi-task learningGradient conflict resolutionSemi-supervised learningoptimizationmulti-task-learninggradient-methodsreinforcement-learning

arXivPDFCodeMarkdown14 min read

AI-compiled by claude-haiku-5-5 on 2026-10-19, not yet reviewed by a human. Every claim cites its source; check it when a detail matters.

In plain words

Training one network on several goals at once is common: for example, label every pixel of a photo and also estimate how far each pixel is from the camera. The simplest approach averages the learning signals from all goals and takes one step. That step can help one goal while quietly hurting another, and the damage is often worst for the goal that is hardest to learn.

The method described here, CAGrad, keeps the average as its starting point but does not follow it blindly. It looks for a nearby step that makes the currently worst-off goal improve as much as possible, and it limits how far that step may stray from the average. A single knob sets that limit. At zero the method is plain averaging. Larger values let the step lean more toward protecting the weakest goal. The authors show that, with a suitable knob setting, the method still settles at a good point for the average goal.

The paper reports better results than several earlier ways of combining these signals, on supervised vision, robot-control and semi-supervised benchmarks. These are the authors' own numbers on their own setups.

TL;DR

  • Changes how the gradients of several losses are combined into one update. It is a drop-in replacement for averaging §3.1.
  • It is plain gradient descent when c = 0, and approximates the MGDA direction for large c §3.1.
  • For c < 1 the paper proves convergence to a stationary point of the average loss §3.2. The experiments do not use the theorem's plain step; see Pitfalls.
  • Costs one backward pass per task each step, plus a small solve over the task weights §3.3.
  • Official MIT-licensed code exists and implements the same rule in three variants cagrad.py.

Problem

With several losses L_1 ... L_K on shared parameters θ, the usual goal is the average loss L_0 = (1/K) Σ_i L_i §2.1 eq. 1. Following its gradient can still hurt individual tasks, because the task gradients may point in different directions or have very different sizes §1 §2.1. Earlier remedies either re-weight the losses by heuristics, which gives no convergence guarantee, or change the update direction, which may converge to any point on the Pareto set and so ignores L_0 §2.2. The paper wants a method that keeps the average loss as the target and still protects each task §1 §3.1.

Method

Setup. Let g_i = ∇L_i(θ) and g_0 = ∇L_0(θ) = (1/K) Σ_i g_i §2.1. For a step θ' = θ − α·d, the paper measures conflict with the worst local improvement across tasks, R(θ, d), which is approximately −min_i ⟨g_i, d⟩ for small α §3.1 eq. 2. A direction d that keeps every task decreasing has R < 0 §3.1.

CAGrad direction. CAGrad chooses d to maximise the worst per-task decrease, subject to staying within a ball of radius c‖g_0‖ around g_0 §3.1 eq. 3:

\max_{d}\; \min_{i \in [K]} \langle g_i, d \rangle \quad \text{s.t.} \quad \lVert d - g_0 \rVert \le c\,\lVert g_0 \rVert eq. 3

Here c ∈ [0, 1) is a fixed hyperparameter that controls the convergence rate §3.1. The paper states that the ball is centred on the average gradient because the average loss is the chosen main objective §3.1.

Dual form used in practice. The primal in eq. 3 has one variable per parameter, which is too large for a network. Let φ = c²‖g_0‖² and let g_w = Σ_i w_i g_i, where w lies on the probability simplex W. The paper derives a problem in the K weights only §3.1:

w^* = \arg\min_{w \in \mathcal{W}} \; g_w^\top g_0 + \sqrt{\phi}\,\lVert g_w \rVert

The optimal direction is then d* = g_0 + (√φ / ‖g_{w*}‖) · g_{w*}, equivalent to d* = g_0 + g_{w*}/λ* with λ* = ‖g_{w*}‖ / √φ §3.1. The derivation is in Lagrangian form and uses strong duality §3.1 app. A.3. Because √φ = c‖g_0‖, the update adds a term of length c‖g_0‖ pointing along the normalised blended gradient.

Algorithm. The paper's CAGrad loop is shown in alg. 1. The pseudocode below is a restatement of it, with the citations kept.

Pseudocode
# One CAGrad update for K task losses  [alg. 1]
# Input:  parameters theta, K task losses, c in [0, 1), step size alpha
# Output: updated parameters

def cagrad_step(theta, task_losses, c, alpha):
    # Gradient of each task loss at theta  [alg. 1]
    grads = [gradient(loss, theta) for loss in task_losses]
    # Average gradient, the gradient of the main objective  [§2.1] [alg. 1]
    g0 = sum(grads) / len(grads)
    # Radius of the search ball, sqrt(phi) = c * ||g0||  [§3.1] [alg. 1]
    radius = c * norm(g0)
    # Task weights on the simplex minimising g_w.g0 + radius*||g_w||  [§3.1]
    w = solve_simplex_problem(grads, g0, radius)
    # Blended gradient g_w = sum_i w_i * g_i  [§3.1] [alg. 1]
    g_w = sum(w_i * g_i for w_i, g_i in zip(w, grads))
    # Update direction d = g0 + radius * g_w / ||g_w||  [§3.1] [alg. 1]
    d = g0 + radius * g_w / norm(g_w)
    # Plain step with size alpha, as written in the algorithm  [alg. 1]
    return theta - alpha * d

Special cases. With c = 0 the radius is zero and the rule reduces to d = g_0, plain gradient descent on L_0 §3.1 alg. 1. As c grows without bound, minimising the blended-gradient norm becomes the MGDA rule, which the paper calls its generalisation of MGDA. It notes that MGDA can settle at any Pareto point, whereas CAGrad aims at the average loss §3.1 app. A.1.

Practical speedup for many tasks. Each step needs one backward pass per task. The paper therefore proposes sampling a subset S of tasks, computing their gradients and the average g_0, and solving the same problem with the unsampled part replaced by its average §3.3 eq. 4:

\max_{d} \; \min \Big( \Big\langle \frac{K g_0 - \sum_{i \in S} g_i}{K - |S|},\, d \Big\rangle,\; \min_{i \in S} \langle g_i, d \rangle \Big) \quad \text{s.t.} \quad \lVert d - g_0 \rVert \le c\,\lVert g_0 \rVert eq. 4

The constraint is unchanged, so the convergence statement still applies according to the paper §3.3 app. A.3. The stated cost is O((|S|N + T)), where N is one backpropagation pass and T the optimisation time. The paper says T is much smaller than N when K < 10 §3.3.

Convergence (theory). Assume each L_i is differentiable with H-Lipschitz gradient and that L_0 is bounded below §3.2. With a fixed step α ≤ 1/H and 0 ≤ c < 1, the paper's Theorem 1 bounds the accumulated squared gradient norm of L_0 over T steps by 2(L_0(θ_0) − L_0*) / (α(1 − c²)) §3.2. This means the iterates approach a stationary point of L_0 §3.2. For c ≥ 1 the theorem only states that fixed points are Pareto-stationary §3.2. The proof is in app. A.3.

Hyperparameters

NameValueWhereNotes
convergence control c[0, 1) for the guarantee§3.1 §3.2c = 0 gives GD; large c approaches MGDA §3.1
step size α (theorem)0 < α ≤ 1/H§3.2H is not estimated in the paper
step size α (experiments)not stated in the paper as a value for the CAGrad step§5.2 §5.3 §5.4experiments pass the CAGrad direction to Adam or SAC optimisers; see Pitfalls
c, toy examplesweep {0, 0.2, 0.5, 0.8, 10}§5.1 fig. 3the paper names these values in the figure caption
c, Multi-Fashion+MNIST"best" is 0.2; search grid not stated§5.1 fig. 4result only in a figure, no table
c, NYU-v20.4§5.2 tab. 1 app. B.2 run.shselected by average training loss app. B.2
c, CityScapes0.4 in table and appendix; 0.2 in text§5.2 tab. 2 app. B.2 run.shconflicting, see Paper vs code
c, semi-supervised0.1, fixed in all runsapp. B.4not tuned
c, Meta-World MT100.9app. B.3 run.shsearched over {0.1, 0.5, 0.9} app. B.3
c, Meta-World MT500.5app. B.3 run.shsearched over {0.1, 0.5, 0.9} app. B.3
sampled tasksSfor CAGrad-Fast, MT104
sampled tasksSfor CAGrad-Fast, MT508
task-weight solver, RL20 gradient steps, lr 25 (MT10) or 50 (MT50), momentum 0.5app. B.3 cagrad.pythe paper says "approximately solve"; code uses softmax weights
task-weight solver, supervisednot stated in the paper; "standard optimisation libraries" §3.1utils.pycode uses bounded SLSQP via scipy
toy optimisernot stated in the papertoy.pycode uses Adam, lr 0.001
toy iterationsnot stated in the papertoy.pycode uses 100,000 steps
toy start points(-8.5, 7.5), (-8.5, 5), (0, 0), (9, 9), (10, -8)§5.1 fig. 3the code uses three different starts; see Paper vs code
supervised optimiserAdam, lr 1e-4, halved at epoch 100app. B.2 model_segnet_mt.py model_segnet_mt.pysame schedule for all methods
supervised epochs200app. B.2 model_segnet_mt.py
supervised batch size2 (NYU-v2), 8 (CityScapes)app. B.2 model_segnet_mt.py model_segnet_mt.py
supervised reportingmean of last 10 epochs, 3 seedsapp. B.2
supervised loss weightsequal weighting§5.2the paper compares under equal weighting
MNIST-pair optimiserAdam, lr 0.001, weight decay 0.01app. B.1main text gives lr and epochs only §5.1
MNIST-pair training50 epochs, batch 256; 120,000 train and 20,000 test images, 36×36§5.1 app. B.1shrunk LeNet app. B.1
RL algorithmSAC; 2M steps; batch 1280; eval every 10k steps; 10 seedsapp. B.3 run.shreports best average test score over training app. B.3
SSL setupCIFAR-10, 50k train with 10% held out for validation; 500, 1000 or 2000 labels§5.4 app. B.4200 epochs §5.4
SSL model and optimiserWRN-28-2; Adam, batch 256; lr 0.005, then 0.001 after 160k iterationsapp. B.4moving-average feature model, factor 0.95 app. B.4
SSL auxiliary weightsw_1, w_2 "from ARML"§5.4values are not given in this paper

Results

Author-reported throughout. Setups differ between experiments, so the numbers do not compare across tables.

Multi-task supervised learning, NYU-v2 (SegNet with MTAN attention, 3 tasks). Δm is the average per-task relative change from single-task training; lower is better. Values are means over 3 seeds tab. 1 §5.2.

#PMethodSeg mIoU ↑Seg PixAcc ↑Depth Abs ↓Depth Rel ↓Normal Mean ↓Normal Median ↓≤11.25 ↑≤22.5 ↑≤30 ↑Δm % ↓
3Independent38.3063.760.67540.278025.0119.2130.1457.2069.15–
≈3Cross-Stitch37.4263.510.54870.218828.8524.5222.7546.5859.566.96
1.77MTAN39.2965.330.54930.226328.1523.9622.0947.5061.085.59
1.77MGDA30.4759.900.60700.255524.8819.4529.1856.8869.361.38
1.77PCGrad38.0664.640.55500.232527.4122.8023.8649.8363.143.97
1.77GradDrop39.3965.120.54550.227927.4822.9623.3849.4462.873.58
1.77CAGrad (c = 0.4)39.7965.490.54860.225026.3121.5825.6152.3665.580.20

The caption marks baseline entries that differ significantly from CAGrad at p = 0.1, using asterisks in the table tab. 1. Under the paper's text, CAGrad matches the other methods on segmentation and depth, and is better on surface normals, which the other methods leave behind §5.2.

Multi-task supervised learning, CityScapes (2 tasks). Values are means over 3 seeds tab. 2.

#PMethodSeg mIoU ↑Seg PixAcc ↑Depth Abs ↓Depth Rel ↓Δm % ↓
2Independent74.0193.160.012527.77–
≈3Cross-Stitch73.0892.790.0165118.590.02
1.77MTAN75.1893.490.015546.7722.60
1.77MGDA68.8491.540.030933.5044.14
1.77PCGrad75.1393.480.015442.0718.29
1.77GradDrop75.2793.530.015747.5423.73
1.77CAGrad (c = 0.4)75.1693.480.014137.6011.64

Appendix sweep over c on the same setup tab. 5 tab. 6 (Δm %):

Settingc = 0.2c = 0.4c = 0.6c = 0.8
NYU-v2, equal weights tab. 51.550.20-1.36-2.29
CityScapes, equal weights tab. 613.6911.6411.4610.74

Multi-task reinforcement learning, Meta-World (SAC; success rate; mean ± standard error over 10 runs) tab. 3 §5.3.

MethodMT10 successMT50 success
Multi-task SAC0.49 ±0.0730.36 ±0.013
Multi-task SAC + task encoder0.54 ±0.0470.40 ±0.024
Multi-headed SAC0.61 ±0.0360.45 ±0.064
PCGrad0.72 ±0.0220.50 ±0.017
Soft Modularization0.73 ±0.0430.50 ±0.035
CAGrad0.83 ±0.0450.52 ±0.023
CAGrad-Fast0.82 ±0.0390.50 ±0.016
CARE (uses task language metadata)0.84 ±0.0510.54 ±0.031
One SAC agent per task (upper bound)0.90 ±0.0320.74 ±0.041

Per-step training time on the same benchmarks, in seconds, as reported tab. 7 app. B.3: PCGrad 9.7 (MT10) and 59.8 (MT50); CAGrad 10.3 and 27.8; CAGrad-Fast 4.8 and 11.4. The paper states the CAGrad-Fast speedups as about 2× (MT10) and 5× (MT50) over PCGrad §5.3.

Semi-supervised learning on CIFAR-10 (ARML auxiliary tasks; average test accuracy over 3 runs) tab. 4 §5.4.

Method500 labels1000 labels2000 labels
ARML67.05 ±0.1673.22 ±0.2681.35 ±0.36
ARML + PCGrad67.49 ±0.6473.23 ±0.6281.91 ±0.19
ARML + MGDA49.27 ±0.6860.11 ±2.3560.78 ±0.17
ARML + CAGrad68.25 ±0.3774.37 ±0.4282.81 ±0.48
GradNorm67.35 ±0.1573.53 ±0.2381.03 ±0.71
GradNorm + PCGrad67.83 ±0.1973.91 ±0.0982.72 ±0.19
GradNorm + MGDA36.99 ±2.1157.94 ±0.9259.12 ±0.63
GradNorm + CAGrad67.53 ±0.2674.72 ±0.1983.15 ±0.56

Toy and MNIST-pair experiments §5.1. On a two-dimensional toy problem, the paper shows that plain GD gets stuck in 2 of 5 starting points, and that CAGrad with c = 0 recovers GD while c = 10 approximates MGDA §5.1 fig. 3. On Multi-Fashion+MNIST, the paper reports final training losses over three runs only in a figure, with CAGrad at c = 0.2 lowest in average loss §5.1 fig. 4. No numbers are given in text or table.

Paper vs code

Official code: https://github.com/Cranial-XIX/CAGrad at commit dc3d48152b6196945cfd56144879b9d42353b095, MIT licence (Copyright Bo Liu, 2022) LICENSE. The code repository covers the toy example, supervised NYU-v2 and CityScapes, and the Meta-World RL agent. It contains no code for the MNIST-pair or semi-supervised experiments, which the paper says use other codebases app. B.1 app. B.4.

  1. Normalisation of the update. The paper's update has no extra scale alg. 1. Every code path divides the update by a constant:
    • supervised, both datasets: 1 + c² utils.py utils.py utils.py;
    • Meta-World agent: 1 + c² in the default path [code: mtrl/mtrl_files/cagrad.py#L254-L256]; 1 + c in the fast path cagrad.py; 1 + λ in the exact path cagrad.py;
    • toy example: 1 + c toy.py. The code's scaling is not described in the paper. At c = 0.4 the 1 + c² divisor shrinks the step by about 14%.
  2. Optimiser. The paper's algorithm is a plain step θ − αd alg. 1. The code writes the CAGrad direction into the gradients, then calls an Adam optimiser in the supervised trainer utils.py model_segnet_mt.py, and the toy example uses Adam toy.py. The Meta-World agent writes the vector into .grad and leaves stepping to the configured SAC optimisers cagrad.py.
  3. Sampled average for CAGrad-Fast. Eq. 4 averages the unsampled tasks over K − |S| tasks §3.3. The code sums the K − n tasks after the first n − 1 sampled ones and divides by K − n + 1. The sampled task at position n − 1 is therefore dropped, and the average is scaled [code: mtrl/mtrl_files/cagrad.py#L173-L180]. This is a deviation from the paper's formula.
  4. Task-weight solver. The paper leaves the solver open §3.1. The Meta-World default uses softmax-parameterised weights, 20 SGD steps, and keeps the best iterate cagrad.py. The exact variant uses SLSQP cagrad.py. The supervised trainer uses bounded SLSQP utils.py. The CityScapes trainer uses a one-dimensional bounded search, because it has two tasks utils.py.
  5. Toy example formula. The paper's f_2 contains −tanh(−θ_2) §5.1. The code adds the term: +torch.tanh(-x2) toy.py. The paper's figures may come from either version; the card cannot say which.
  6. Toy starting points. The paper uses five starts §5.1 fig. 3. The code runs three: (-8.5, 7.5), (-8.5, -5), (9, 9) toy.py. The Figure 1 caption says three runs fig. 1. The starts differ from the paper's list in the second and third positions.
  7. CityScapes c. The text says c = 0.2 §5.2. The appendix says c = 0.4 app. B.2, and so does the reported table row tab. 2 tab. 6. The code runs c = 0.4 and c = 0.6 run.sh. Nothing in the repository shows c = 0.2 for CityScapes.
  8. Degenerate weight norm. The update divides by ‖g_w‖, which the paper does not address §3.1. The code adds small constants: 1e-8 in the supervised trainer utils.py, 1e-4 in the Meta-World agent cagrad.py, and 1e-4 in the toy example toy.py.
  9. Default config. The Meta-World YAML sets cagrad_method: "exact" cagrad_state_sac.yaml. The agent's assertion accepts only cagrad, cagrad_exact and cagrad_fast<k> cagrad.py, so the default fails unless overridden. The run script overrides it run.sh.

Pitfalls

  • The theorem does not cover the experiments. Theorem 1 is for the plain step θ − αd with α ≤ 1/H §3.2 alg. 1. The supervised, toy and RL runs feed the direction into Adam or SAC optimisers. The step-size condition and the convergence bound therefore do not carry over automatically.
  • Two statements of the theorem disagree. The main text says fixed points are Pareto-stationary for c ≥ 1 §3.2. The appendix says any c ≥ 0 app. A.3. Use the appendix version only with its proof in hand.
  • c is picked on training loss, but the appendix sweep favours other values. The supervised text selects c by average training performance app. B.2. In the appendix sweep for CityScapes, c = 0.8 gives a lower Δm than the c = 0.4 row reported in the main table tab. 6.
  • Significance is weak. The test uses p = 0.1 and three seeds tab. 1 tab. 2. Several baseline differences are marked, but the margins in segmentation are small: CAGrad 75.16 against MTAN 75.18 mIoU on CityScapes tab. 2.
  • Best-epoch reporting in RL. The RL setup reports the highest average test performance seen during training app. B.3. That is an optimistic estimate, and the paper does not report a held-out selection.
  • Per-step cost. Each step needs K backward passes §3.3 [code: mtrl/mtrl_files/cagrad.py#L194-L205]. The task-weight solve adds up to 20 inner steps in the RL setup app. B.3. Timings in tab. 7 are per update step and the hardware is not stated in the table.
  • Degenerate directions. If g_w = 0 the update is undefined. The paper says nothing about this case; the code adds small constants instead.
  • Ambiguous c for CityScapes. Three sources give 0.2, 0.4, or both. Use 0.4 only with the table and code, and say so in any reproduction.
  • Small, unseen components. The MNIST-pair setup and the semi-supervised setup have no code in this repository. Reproducing them relies on the appendix descriptions and on other codebases app. B.1 app. B.4.
  • Unstated weights. The semi-supervised auxiliary weights w_1 and w_2 are "the same as ARML", and their values are not given in this paper §5.4.
  • Toy optimiser and length. The paper does not state the toy optimiser or number of steps. Figure 1 says GD and the other methods run with Adam fig. 1; the code uses 100,000 Adam steps toy.py.
  • Compute scaling. The paper says T ≪ N usually holds for K < 10 §3.3, which is the regime of its supervised experiments. The 10- and 50-task RL speedups rest on the timing table alone tab. 7, and the paper gives no scaling analysis beyond the O((|S|N + T)) expression §3.3.

Lineage

  • Builds on: gradient descent, which it recovers at c = 0 §3.1; multiple gradient descent (MGDA), which it approximates as c grows §3.1 app. A.1.
  • Compared against: MGDA, PCGrad, GradDrop, Cross-Stitch, MTAN, GradNorm, Soft Modularization, CARE, and multi-task SAC variants, as listed in tab. 1–tab. 4.
  • Superseded by: not known from wiki content.

Source and license

Adapted from “Conflict-Averse Gradient Descent for Multi-task Learning” by Bo Liu, Xingchao Liu, Xiaojie Jin, Peter Stone, Qiang Liu (arXiv:2110.14048), used under CC BY 4.0. Changes: condensed and restructured for implementation, with tables, equations and algorithms taken from the paper and its code, each cited to its source. Not affiliated with or endorsed by the authors. Code citations refer to https://github.com/Cranial-XIX/CAGrad at commit dc3d48152b61 (MIT). Any quoted code is shown under that license.