Practice in Lab: Project conflicting task gradients without mutating their owners →
Project conflicting task gradients without mutating their owners
Multi-task objectives can produce gradients that oppose one another even when the shared model is differentiable. PCGrad edits a task gradient by removing conflicting components relative to original peer gradients. Projection order matters with three or more tasks, so order and randomness are part of the reproducibility contract. Returning separate rows preserves the distinction between surgery and the later task-weighting decision. This is a local vector algorithm; it does not claim a Pareto optimum or execute distributed reduction.
Prepare offline
Choose Download entire course or Download entire category first. After completion, code and checks run locally on CPU. The independent example needs no account, remote service or API key.
import torch
a = torch.tensor([1., -1.])
b = torch.tensor([0., 1.])
print(torch.dot(a, b))Review the evidence
Compare original and projected directions on several task geometries. Audit parameter alignment, missing gradients and aggregation weights before applying surgery to real shared and task-specific model parameters.
Your task
Return a detached [tasks, parameters] matrix of PCGrad gradients. For each task, visit the other ORIGINAL task gradients in a seed-local shuffled order. If the current projected gradient has a negative dot product with an original peer, remove that component. Skip zero-norm peers. Do not mutate the input or global RNG. The caller chooses how to combine the projected rows; this Lab does not assert that a mean improves every task.
The explanation opens here once every check passes.