SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2001.06782 · NeurIPS · 2020

Gradient Surgery for Multi-Task Learning

U Berkeley, Tianhe Yu, Saurabh Kumar, Abhishek Gupta, Sergey Levine, Karol Hausman, Chelsea Finn, Robotics At Google

arXiv · PDF · Open in the Atlas

Code that ran

7 of 10 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (5 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 6 have no contract verdict; 1 failure of our instrument; 3 no recorded run), measured 2026-11-21; repository links from the Papers with Code archive attributed under CC BY-SA, no affiliation; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2001.06782.json · badge: /api/ran/2001.06782.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
cranial-xix/famo community
Papers with Code archive
2 ran · 0 no recorded run
avivnavon/nash-mtl community
Papers with Code archive
2 ran · 0 no recorded run
grtzsohalf/SpeechNet-codebase community
Papers with Code archive
1 ran · 0 no recorded run
WeiChengTseng/Pytorch-PCGrad community
Papers with Code archive
1 ran · 0 no recorded run
OrthoDex/PCGrad-PyTorch community
Papers with Code archive
1 ran · 0 no recorded run
tianheyu927/PCGrad marked official in Papers with Code
Papers with Code archive
0 ran · 1 no recorded run
wgchang/PCGrad-pytorch-example community
Papers with Code archive
0 ran · 1 no recorded run
rangwani-harsh/PC_Grad_Pytorch community
Papers with Code archive
0 ran · 1 no recorded run
FunctionStatusWhere it lives
PCGrad Ran
ran on a synthesized input · constructed an object; no result was computed
grtzsohalf/SpeechNet-codebase/src/pcgrad.py
code served (permissive licence) · get_code("16a092a4692eb73d")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned an instance of its own class, PCGrad: the run constructed the object and did not call it, so no result was computed. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

torch.manual_seed(0)

# Create a minimal optimizer that satisfies the interface expected by PCGrad
class MinimalOptimizer:
    def __init__(self, params):
        self.param_groups = [{'params': list(params)}]
        self.lr_scheduler = None
    
    def zero_grad(self, set_to_none=True):
        for group in self.param_groups:
            for p in group['params']:
                if set_to_none:
                    p.grad = None
                else:
                    if p.grad is not None:
                        p.grad.zero_()
    
    def post_step(self, step, set_to_none=True):
        pass
    
    def step(self):
        pass
    
    def create_msg(self):
        return "optimizer"
    
    def get_opt_state_dict(self):
        return {}
    
    def load_opt_state_dict(self, state_dict):
        pass
    
    def get_param_groups(self):
        return self.param_groups

# Create a small neural network model
class TinyModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear1 = nn.Linear(4, 3)
        self.linear2 = nn.Linear(3, 2)
    
    def forward(self, x):
        x = torch.relu(self.linear1(x))
        x = self.linear2(x)
        return x

# Instantiate model and optimizer
model = TinyModel()
optimizer = MinimalOptimizer(model.parameters())

# Create sample data and objectives
x = torch.randn(2, 4)
y_task1 = torch.randn(2, 2)
y_task2 = torch.randn(2, 2)

# Define loss functions for two tasks
loss_fn = nn.MSELoss()

def objective1():
    pred = model(x)
    return loss_fn(pred, y_task1)

def objective2():
    pred = model(x)
    return loss_fn(pred, y_task2)

objectives = [objective1, objective2]

# Construct ARGS
ARGS = {
    'optimizer': optimizer
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type PCGrad — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a PCGrad output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
PCGrad Ran
ran on a synthesized input · constructed an object; no result was computed
WeiChengTseng/Pytorch-PCGrad/pcgrad.py
code served (permissive licence) · get_code("5e1ac35b4889d3d9")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned an instance of its own class, PCGrad: the run constructed the object and did not call it, so no result was computed. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn
import torch.optim as optim

torch.manual_seed(0)

# Create a simple neural network model
class SimpleModel(nn.Module):
    def __init__(self):
        super(SimpleModel, self).__init__()
        self.linear1 = nn.Linear(4, 3)
        self.linear2 = nn.Linear(3, 2)
    
    def forward(self, x):
        x = torch.relu(self.linear1(x))
        x = self.linear2(x)
        return x

# Instantiate the model
model = SimpleModel()

# Create an optimizer
optimizer = optim.SGD(model.parameters(), lr=0.01)

# Create dummy objectives (loss tensors)
# We need at least 2 objectives for pc_backward to work meaningfully
dummy_input = torch.randn(2, 4)
output = model(dummy_input)
objective1 = output.sum()
objective2 = output.mean()

objectives = [objective1, objective2]

ARGS = {
    'optimizer': optimizer,
    'reduction': 'mean'
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type PCGrad — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a PCGrad output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
PCGrad Ran
ran on a synthesized input
cranial-xix/famo/methods/weight_methods.py
code served (permissive licence) · get_code("31aa3418224baf69")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) and returned tuple, ndim 1, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

# Create a simple multi-task setup
n_tasks = 3
device = torch.device('cpu')

# Create shared parameters (e.g., from a shared encoder)
shared_layer = nn.Linear(4, 6)
shared_parameters = list(shared_layer.parameters())

# Create task-specific parameters (e.g., from task-specific heads)
task_heads = nn.ModuleList([nn.Linear(6, 2) for _ in range(n_tasks)])
task_specific_parameters = list(task_heads.parameters())

# Create some dummy losses for each task
losses = torch.tensor([0.5, 0.8, 0.3], requires_grad=True)

# For PCGrad, we need actual computational graph losses
# So let's create a proper forward pass
batch_size = 2
input_dim = 4
x = torch.randn(batch_size, input_dim)

# Forward pass through shared layer
shared_output = shared_layer(x)

# Forward pass through task-specific heads and compute losses
task_losses = []
for i in range(n_tasks):
    task_output = task_heads[i](shared_output)
    target = torch.randn(batch_size, 2)
    loss = torch.nn.functional.mse_loss(task_output, target)
    task_losses.append(loss)

losses_tensor = torch.stack(task_losses)

INIT_ARGS = {
    'n_tasks': n_tasks,
    'device': device,
    'reduction': 'sum'
}

ARGS = {
    'losses': losses_tensor,
    'parameters': shared_parameters,
    'shared_parameters': shared_parameters,
    'task_specific_parameters': task_specific_parameters
}

METHOD = 'backward'
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple, ndim 1, dtype family float — a tuple output has no array shape of its own; none is stated
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
PCGrad Ran
ran on a synthesized input · constructed an object; no result was computed
avivnavon/nash-mtl/methods/weight_methods.py
pointer only (licence: NONE) · get_code("c34a09ae701d0f40")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, avivnavon/nash-mtl when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

WeightMethod Ran
ran on a synthesized input · constructed an object; no result was computed
cranial-xix/famo/methods/weight_methods.py
code served (permissive licence) · get_code("654cdad96608431e")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned an instance of its own class, WeightMethod: the run constructed the object and did not call it, so no result was computed. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

torch.manual_seed(0)

# Create a concrete implementation of WeightMethod for testing
class ConcreteWeightMethod(nn.Module):
    def __init__(self, n_tasks: int, device: torch.device, max_norm=1.0):
        super().__init__()
        self.n_tasks = n_tasks
        self.device = device
        self.max_norm = max_norm

    def get_weighted_loss(self, losses, shared_parameters=None, task_specific_parameters=None, last_shared_parameters=None, representation=None, **kwargs):
        # Simple weighted loss computation
        weighted_loss = losses.mean()
        return weighted_loss, {"info": "loss computed"}

    def backward(self, losses, shared_parameters=None, task_specific_parameters=None, last_shared_parameters=None, representation=None, **kwargs):
        loss, extra_outputs = self.get_weighted_loss(
            losses=losses,
            shared_parameters=shared_parameters,
            task_specific_parameters=task_specific_parameters,
            last_shared_parameters=last_shared_parameters,
            representation=representation,
            **kwargs
        )
        if self.max_norm > 0 and shared_parameters is not None:
            torch.nn.utils.clip_grad_norm_(shared_parameters, self.max_norm)
        loss.backward()
        return (loss, extra_outputs)

# Set up arguments for WeightMethod
device = torch.device('cpu')
n_tasks = 3

# Create tensors for losses
losses = torch.tensor([0.5, 0.3, 0.2], dtype=torch.float32, requires_grad=True)

# Create shared parameters as a list of Parameters
shared_params = [
    nn.Parameter(torch.randn(4, 3, requires_grad=True)),
    nn.Parameter(torch.randn(3, 2, requires_grad=True))
]

# Create task-specific parameters
task_specific_params = [
    nn.Parameter(torch.randn(2, 4, requires_grad=True))
]

# Create last shared parameters
last_shared_params = [
    nn.Parameter(torch.randn(4, 4, requires_grad=True))
]

# Create representation tensor
representation = torch.randn(2, 4, dtype=torch.float32, requires_grad=True)

ARGS = {
    "n_tasks": n_tasks,
    "device": device,
    "max_norm": 1.0,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type WeightMethod — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a WeightMethod output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
WeightMethod Ran
ran on a synthesized input · constructed an object; no result was computed
avivnavon/nash-mtl/methods/weight_methods.py
pointer only (licence: NONE) · get_code("9b136fce78a21563")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, avivnavon/nash-mtl when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

pc_grad_update Ran
ran; our contract draft was wrong, not the code
OrthoDex/PCGrad-PyTorch/pcgrad.py
code served (permissive licence) · get_code("4cf729e96cf2c9fe")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1) and returned generator. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import numpy as np

torch.manual_seed(0)
np.random.seed(0)

# Create a list of gradient tensors for multiple tasks
# Each task has gradients for multiple parameters
# Task 1: 3 parameter gradients with shapes (4,), (3,), (2,)
task1_grads = [
    torch.randn(4),
    torch.randn(3),
    torch.randn(2)
]

# Task 2: 3 parameter gradients with same shapes
task2_grads = [
    torch.randn(4),
    torch.randn(3),
    torch.randn(2)
]

# Task 3: 3 parameter gradients with same shapes
task3_grads = [
    torch.randn(4),
    torch.randn(3),
    torch.randn(2)
]

gradient_list = [task1_grads, task2_grads, task3_grads]

ARGS = {
    "gradient_list": gradient_list
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type generator — a generator output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a generator output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
PCGrad Not yet run
unverified (harvested, no recorded run)
tianheyu927/PCGrad/PCGrad_tf.py
code served (permissive licence) · get_code("a64df2e1bec39655")
How it ran

no invocation recorded.

PCGrad_backward Not yet run
unverified (harvested, no recorded run)
wgchang/PCGrad-pytorch-example/pcgrad-example.py
pointer only (licence: NONE) · get_code("0b13eb7dd654266c")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, wgchang/PCGrad-pytorch-example when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. No invocation recorded.

PCGrad_loss Not yet run
unverified (harvested, no recorded run)
rangwani-harsh/PC_Grad_Pytorch/pc_grad_pytorch.py
pointer only (licence: NONE) · get_code("3e75577924697c22")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, rangwani-harsh/PC_Grad_Pytorch when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. No invocation recorded.

Also present in other papers' code

Of 10 samples lifted from this paper's linked repositories, 10 carry a function identity and 0 do not. Of the 10 distinct functions with an identity, 2 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 2 later) and 8 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

FunctionAlso present inEarliest-datedOthers named
WeightMethod
brick of this paper's assembly: helper
3 other papers
3 later · 3 only as an assembly brick
2202.01017 (2022-02)
Multi-Task Learning as a Bargaining Game
2507.07883 (2025-07)
SAMO: A Lightweight Sharpness-Aware Approach for Multi-Task Optimization with Joint Global-Local Perturbation
2608.11749 (2026-08)
MOON: Multi-Objective OrthoNormalized Updates for Multitask Learning
WeightMethod 2 other papers
2 later · 1 only as an assembly brick
2202.01017 (2022-02)
Multi-Task Learning as a Bargaining Game
2301.13501 (2023-01)
Auxiliary Learning as an Asymmetric Bargaining Game

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-21.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

While deep learning and deep reinforcement learning (RL) systems have demonstrated impressive results in domains such as image classification, game playing, and robotic control, data efficiency remains a major challenge. Multi-task learning has emerged as a promising approach for sharing structure across multiple tasks to enable more efficient learning. However, the multi-task setting presents a number of optimization challenges, making it difficult to realize large efficiency gains compared to learning tasks independently. The reasons why multi-task learning is so challenging compared to single-task learning are not fully understood. In this work, we identify a set of three conditions of the multi-task optimization landscape that cause detrimental gradient interference, and develop a simple yet general approach for avoiding such interference between task gradients. We propose a form of gradient surgery that projects a task's gradient onto the normal plane of the gradient of any other task that has a conflicting gradient. On a series of challenging multi-task supervised and multi-task RL problems, this approach leads to substantial gains in efficiency and performance. Further, it is model-agnostic and can be combined with previously-proposed multi-task architectures for enhanced performance.

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2001.06782")
get_code_for_paper("2001.06782")
have("2001.06782")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2001.06782.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2001.06782.svg)](https://syntology.ai/paper/2001.06782)

Connect an agent — have() is free.