Skip to content

Commit 0b8f18c

Browse files
authored
Merge branch 'main' into use-docker
2 parents 2e811c7 + 25b44f0 commit 0b8f18c

4 files changed

Lines changed: 10 additions & 56 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ changelog does not include internal changes that do not affect the user.
88

99
## [Unreleased]
1010

11+
## [0.12.0] - 2026-05-28
12+
1113
### Added
1214

1315
- Added a new `torchjd.scalarization` package providing the abstract `Scalarizer` base class and

README.md

Lines changed: 6 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
[![Static Badge](https://img.shields.io/badge/%F0%9F%92%AC_ChatBot-chat.torchjd.org-blue?logo=%F0%9F%92%AC)](https://chat.torchjd.org)
1111
[![Tests](https://github.com/SimplexLab/TorchJD/actions/workflows/checks.yml/badge.svg)](https://github.com/SimplexLab/TorchJD/actions/workflows/checks.yml)
1212
[![codecov](https://codecov.io/gh/SimplexLab/TorchJD/graph/badge.svg?token=8AUCZE76QH)](https://codecov.io/gh/SimplexLab/TorchJD)
13-
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/SimplexLab/TorchJD/main.svg)](https://results.pre-commit.ci/latest/github/SimplexLab/TorchJD/main)
1413
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/torchjd)](https://pypi.org/project/torchjd/)
1514
[![Static Badge](https://img.shields.io/badge/PyTorch-%3E%3D2.3-blue?logo=pytorch&logoColor=white)](https://pytorch.org/)
1615
[![Static Badge](https://img.shields.io/badge/Discord%20-%20community%20-%20%235865F2?logo=discord&logoColor=%23FFFFFF&label=Discord)](https://discord.gg/76KkRnb3nk)
@@ -215,58 +214,7 @@ losses with Jacobian descent using [UPGrad](https://torchjd.org/stable/docs/aggr
215214
```
216215

217216
You can even go one step further by considering the multiple tasks and each element of the batch
218-
independently. We call that Instance-Wise Multitask Learning (IWMTL).
219-
220-
```python
221-
import torch
222-
from torch.nn import Linear, MSELoss, ReLU, Sequential
223-
from torch.optim import SGD
224-
225-
from torchjd.aggregation import Flattening, UPGradWeighting
226-
from torchjd.autogram import Engine
227-
228-
shared_module = Sequential(Linear(10, 5), ReLU(), Linear(5, 3), ReLU())
229-
task1_module = Linear(3, 1)
230-
task2_module = Linear(3, 1)
231-
params = [
232-
*shared_module.parameters(),
233-
*task1_module.parameters(),
234-
*task2_module.parameters(),
235-
]
236-
237-
optimizer = SGD(params, lr=0.1)
238-
mse = MSELoss(reduction="none")
239-
weighting = Flattening(UPGradWeighting())
240-
engine = Engine(shared_module, batch_dim=0)
241-
242-
inputs = torch.randn(8, 16, 10) # 8 batches of 16 random input vectors of length 10
243-
task1_targets = torch.randn(8, 16) # 8 batches of 16 targets for the first task
244-
task2_targets = torch.randn(8, 16) # 8 batches of 16 targets for the second task
245-
246-
for input, target1, target2 in zip(inputs, task1_targets, task2_targets):
247-
features = shared_module(input) # shape: [16, 3]
248-
out1 = task1_module(features).squeeze(1) # shape: [16]
249-
out2 = task2_module(features).squeeze(1) # shape: [16]
250-
251-
# Compute the matrix of losses: one loss per element of the batch and per task
252-
losses = torch.stack([mse(out1, target1), mse(out2, target2)], dim=1) # shape: [16, 2]
253-
254-
# Compute the gramian (inner products between pairs of gradients of the losses)
255-
gramian = engine.compute_gramian(losses) # shape: [16, 2, 2, 16]
256-
257-
# Obtain the weights that lead to no conflict between reweighted gradients
258-
weights = weighting(gramian) # shape: [16, 2]
259-
260-
# Do the standard backward pass, but weighted using the obtained weights
261-
losses.backward(weights)
262-
optimizer.step()
263-
optimizer.zero_grad()
264-
```
265-
266-
> [!NOTE]
267-
> Here, because the losses are a matrix instead of a simple vector, we compute a *generalized
268-
> Gramian* and we extract weights from it using a
269-
> [GeneralizedWeighting](https://torchjd.org/stable/docs/aggregation/#torchjd.aggregation.GeneralizedWeighting).
217+
independently (Instance-Wise Multitask Learning). See [this example](https://torchjd.org/stable/examples/iwmtl/) for more details.
270218

271219
More usage examples can be found [here](https://torchjd.org/stable/examples/).
272220

@@ -283,6 +231,7 @@ TorchJD provides many existing aggregators from the literature, listed in the fo
283231
| [Constant](https://torchjd.org/stable/docs/aggregation/constant#torchjd.aggregation.Constant) | [ConstantWeighting](https://torchjd.org/stable/docs/aggregation/constant#torchjd.aggregation.ConstantWeighting) | - |
284232
| - | [CRMOGMWeighting](https://torchjd.org/stable/docs/aggregation/cr_mogm/#torchjd.aggregation.CRMOGMWeighting) | [On the Convergence of Stochastic Multi-Objective Gradient Manipulation and Beyond](https://proceedings.neurips.cc/paper_files/paper/2022/file/f91bd64a3620aad8e70a27ad9cb3ca57-Paper-Conference.pdf) |
285233
| [DualProj](https://torchjd.org/stable/docs/aggregation/dualproj#torchjd.aggregation.DualProj) | [DualProjWeighting](https://torchjd.org/stable/docs/aggregation/dualproj#torchjd.aggregation.DualProjWeighting) | [Gradient Episodic Memory for Continual Learning](https://arxiv.org/pdf/1706.08840) |
234+
| [FairGrad](https://torchjd.org/stable/docs/aggregation/fairgrad#torchjd.aggregation.FairGrad) | [FairGradWeighting](https://torchjd.org/stable/docs/aggregation/fairgrad#torchjd.aggregation.FairGradWeighting) | [Fair Resource Allocation in Multi-Task Learning](https://arxiv.org/pdf/2402.15638) |
286235
| [GradDrop](https://torchjd.org/stable/docs/aggregation/graddrop#torchjd.aggregation.GradDrop) | - | [Just Pick a Sign: Optimizing Deep Multitask Models with Gradient Sign Dropout](https://arxiv.org/pdf/2010.06808) |
287236
| [GradVac](https://torchjd.org/stable/docs/aggregation/gradvac#torchjd.aggregation.GradVac) | [GradVacWeighting](https://torchjd.org/stable/docs/aggregation/gradvac#torchjd.aggregation.GradVacWeighting) | [Gradient Vaccine: Investigating and Improving Multi-task Optimization in Massively Multilingual Models](https://arxiv.org/pdf/2010.05874) |
288237
| [IMTLG](https://torchjd.org/stable/docs/aggregation/imtl_g#torchjd.aggregation.IMTLG) | [IMTLGWeighting](https://torchjd.org/stable/docs/aggregation/imtl_g#torchjd.aggregation.IMTLGWeighting) | [Towards Impartial Multi-task Learning](https://discovery.ucl.ac.uk/id/eprint/10120667/) |
@@ -307,6 +256,10 @@ include clear instructions on how to migrate.
307256
## Contribution
308257
Please read the [Contribution page](CONTRIBUTING.md).
309258

259+
Thanks to our amazing contributors for making this project possible:
260+
261+
<a href="https://github.com/SimplexLab/TorchJD/graphs/contributors"><img src="https://stg.contrib.rocks/image?repo=SimplexLab/TorchJD&max=240&columns=18" /></a>
262+
310263
## Citation
311264
If you use TorchJD for your research, please cite:
312265
```

docs/source/examples/index.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ This section contains some usage examples for TorchJD.
2020
dedicated backpropagation function :doc:`mtl_backward <../docs/autojac/mtl_backward>`.
2121
- :doc:`Instance-Wise Multi-Task Learning (IWMTL) <iwmtl>` shows how to combine multi-task learning
2222
with instance-wise risk minimization: one loss per task and per element of the batch, using the
23-
:doc:`autogram.Engine <../docs/autogram/engine>` and a :doc:`GeneralizedWeighting
24-
<../docs/aggregation/index>`.
23+
:doc:`autogram.Engine <../docs/autogram/engine>`.
2524
- :doc:`Recurrent Neural Network (RNN) <rnn>` shows how to apply Jacobian descent to RNN training,
2625
with one loss per output sequence element.
2726
- :doc:`Monitoring Aggregations <monitoring>` shows how to monitor the aggregation performed by the

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "torchjd"
7-
version = "0.11.0"
7+
version = "0.12.0"
88
description = "Library for Jacobian Descent with PyTorch."
99
readme = "README.md"
1010
authors = [

0 commit comments

Comments
 (0)