Practical overview
When it fits
Use it when a PyTorch multi-task training loop already produces separate task losses and you want to apply PCGrad gradient modification before optimizer updates.
Who it is for
- Developers implementing multi-task learning experiments in PyTorch.
- Researchers who want to incorporate PCGrad gradient surgery into an optimizer-based training loop.
Documented uses
- Wrap an existing optimizer so updates use PCGrad-modified gradients.
- Pass losses for multiple tasks through the PCGrad backward method before an optimization step.
- Consult or run the included Multi-MNIST training example.
Requirements & limits
- The repository identifies PyTorch 1.6.0 as the implementation target.
- The documented integration wraps an optimizer and calls pc_backward with a loss list before step.
- The repository is licensed under BSD-3-Clause.
- Cifar100-MTL is listed as “coming soon” in the README.
Check current requirements in the official documentation. Source-based guidance does not mean OpenViST has run or independently tested this project.
Add PCGrad to a PyTorch training loop
Use PCGrad to modify gradients computed from per-task losses before an optimizer update.
Before you start
- A PyTorch training loop with a model and optimizer.
- Project dependencies installed with pip install -r requirements.txt.
- A list of per-task losses, with one loss for each task.
Steps
Install the required packages from requirements.txt.
Import PCGrad and wrap the chosen optimizer, for example by wrapping an Adam optimizer.
Pass the per-task loss list to optimizer.pc_backward(losses).
Apply the update with optimizer.step().
Expected outcome
The optimizer update uses gradients processed by PCGrad.
Guide limitations
- The README identifies PyTorch 1.6.0 for the reimplementation.
- The guide documents the optimizer integration pattern, not results for a particular model or task.
Run the included Multi-MNIST training script
Use the repository’s documented command for its Multi-MNIST training example.
Before you start
- The repository and its required packages installed.
Steps
Install the required packages with pip install -r requirements.txt.
Run python main_multi_mnist.py.
Expected outcome
The repository’s Multi-MNIST training script is started.
Guide limitations
- The README provides no comparable run command for Cifar100-MTL, which it labels “coming soon.”
Sources & review
Source record details
- Source availability
- Active
- Sources checked
- 17 October 2026
- Original website title
- WeiChengTseng/Pytorch-PCGrad · Official homepage title · retained in its source language

