Skip to content

Commit 7832c32

Browse files
authored
Merge branch 'main' into add-tagger-to-ci
2 parents 7bf4a86 + 73c1965 commit 7832c32

142 files changed

Lines changed: 4710 additions & 1086 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/build-deploy-docs.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ on:
66
tags:
77
- 'v[0-9]*.[0-9]*.[0-9]*'
88

9+
env:
10+
UV_NO_SYNC: 1
11+
PYTHON_VERSION: '3.14'
12+
913
jobs:
1014
build-deploy-doc:
1115
name: Build & deploy doc
@@ -20,10 +24,10 @@ jobs:
2024
- name: Set up uv
2125
uses: astral-sh/setup-uv@v5
2226
with:
23-
python-version: '3.13'
27+
python-version: ${{ env.PYTHON_VERSION }}
2428

2529
- name: Install dependencies (default with full options & doc)
26-
run: uv pip install '.[full]' --group doc
30+
run: uv pip install --python-version=${{ env.PYTHON_VERSION }} -e '.[full]' --group doc
2731

2832
- name: Determine deployment folder
2933
id: deploy_folder

.github/workflows/release.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ on:
44
release:
55
types: [published]
66

7+
env:
8+
PYTHON_VERSION: 3.14
9+
710
jobs:
811
pypi-publish:
912
name: Publish to PyPI
@@ -19,7 +22,7 @@ jobs:
1922
- name: Set up uv
2023
uses: astral-sh/setup-uv@v5
2124
with:
22-
python-version: '3.13'
25+
python-version: ${{ env.PYTHON_VERSION }}
2326

2427
- name: Build
2528
run: uv build

.github/workflows/tests.yml

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,18 @@ on:
66
schedule:
77
- cron: '41 16 * * *' # Every day at 16:41 UTC (to avoid high load at exact hour values).
88

9+
env:
10+
UV_NO_SYNC: 1
11+
PYTHON_VERSION: 3.14
12+
913
jobs:
1014
tests-full-install:
1115
name: Run tests with full install
1216
runs-on: ${{ matrix.os }}
1317
strategy:
1418
fail-fast: false # Ensure matrix jobs keep running even if one fails
1519
matrix:
16-
python-version: ['3.10', '3.11', '3.12', '3.13']
20+
python-version: ['3.10', '3.11', '3.12', '3.13', '3.14']
1721
os: [ubuntu-latest, macOS-latest, windows-latest]
1822

1923
steps:
@@ -23,9 +27,9 @@ jobs:
2327
with:
2428
python-version: ${{ matrix.python-version }}
2529
- name: Install default (with full options) and test dependencies
26-
run: uv pip install '.[full]' --group test
30+
run: uv pip install --python-version=${{ matrix.python-version }} -e '.[full]' --group test
2731
- name: Run unit and doc tests with coverage report
28-
run: uv run pytest tests/unit tests/doc --cov=src --cov-report=xml
32+
run: uv run pytest -W error tests/unit tests/doc --cov=src --cov-report=xml
2933
- name: Upload results to Codecov
3034
uses: codecov/codecov-action@v4
3135
with:
@@ -39,12 +43,12 @@ jobs:
3943
- name: Set up uv
4044
uses: astral-sh/setup-uv@v5
4145
with:
42-
python-version: '3.13'
46+
python-version: ${{ env.PYTHON_VERSION }}
4347
- name: Install default (without any option) and test dependencies
44-
run: uv pip install . --group test
48+
run: uv pip install --python-version=${{ env.PYTHON_VERSION }} -e . --group test
4549
- name: Run unit and doc tests with coverage report
4650
run: |
47-
uv run pytest tests/unit tests/doc \
51+
uv run pytest -W error tests/unit tests/doc \
4852
--ignore tests/unit/aggregation/test_cagrad.py \
4953
--ignore tests/unit/aggregation/test_nash_mtl.py \
5054
--ignore tests/doc/test_aggregation.py \
@@ -64,10 +68,10 @@ jobs:
6468
- name: Set up uv
6569
uses: astral-sh/setup-uv@v5
6670
with:
67-
python-version: '3.13'
71+
python-version: ${{ env.PYTHON_VERSION }}
6872

6973
- name: Install dependencies (default with full options & doc)
70-
run: uv pip install '.[full]' --group doc
74+
run: uv pip install --python-version=${{ env.PYTHON_VERSION }} -e '.[full]' --group doc
7175

7276
- name: Build Documentation
7377
working-directory: docs
@@ -83,10 +87,10 @@ jobs:
8387
- name: Set up uv
8488
uses: astral-sh/setup-uv@v5
8589
with:
86-
python-version: '3.13'
90+
python-version: ${{ env.PYTHON_VERSION }}
8791

8892
- name: Install dependencies (default with full options & check)
89-
run: uv pip install '.[full]' --group check
93+
run: uv pip install --python-version=${{ env.PYTHON_VERSION }} -e '.[full]' --group check
9094

9195
- name: Run mypy
9296
run: uv run mypy src/torchjd

.pre-commit-config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v5.0.0
3+
rev: v6.0.0
44
hooks:
55
- id: trailing-whitespace # Trim trailing whitespace at the end of lines.
66
- id: end-of-file-fixer # Make sure files end in a newline and only a newline.
@@ -19,7 +19,7 @@ repos:
1919
]
2020

2121
- repo: https://github.com/pycqa/isort
22-
rev: 6.0.1
22+
rev: 6.1.0
2323
hooks:
2424
- id: isort # Sort imports.
2525
args: [
@@ -31,8 +31,8 @@ repos:
3131
--ensure-newline-before-comments,
3232
]
3333

34-
- repo: https://github.com/psf/black
35-
rev: 25.1.0
34+
- repo: https://github.com/psf/black-pre-commit-mirror
35+
rev: 25.9.0
3636
hooks:
3737
- id: black # Format code.
3838
args: [--line-length=100]

CHANGELOG.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,43 @@ changes that do not affect the user.
88

99
## [Unreleased]
1010

11+
### Added
12+
13+
- Added the `autogram` package, with the `autogram.Engine`. This is an implementation of Algorithm 3
14+
from [Jacobian Descent for Multi-Objective Optimization](https://arxiv.org/pdf/2406.16232),
15+
optimized for batched computations, as in IWRM. Generalized Gramians can also be obtained by using
16+
the autogram engine on a tensor of losses of arbitrary shape.
17+
- For all `Aggregator`s based on the weighting of the Gramian of the Jacobian, made their
18+
`Weighting` class public. It can be used directly on a Gramian (computed via the
19+
`autogram.Engine`) to extract some weights. The list of new public classes is:
20+
- `Weighting` (abstract base class)
21+
- `UPGradWeighting`
22+
- `AlignedMTLWeighting`
23+
- `CAGradWeighting`
24+
- `ConstantWeighting`
25+
- `DualProjWeighting`
26+
- `IMTLGWeighting`
27+
- `KrumWeighting`
28+
- `MeanWeighting`
29+
- `MGDAWeighting`
30+
- `PCGradWeighting`
31+
- `RandomWeighting`
32+
- `SumWeighting`
33+
- Added `GeneralizedWeighting` (base class) and `Flattening` (implementation) to extract tensors of
34+
weights from generalized Gramians.
35+
- Added usage example for IWRM with autogram.
36+
- Added usage example for IWRM with partial autogram.
37+
- Added usage example for IWMTL with autogram.
38+
- Added Python 3.14 classifier in pyproject.toml (we now also run tests on Python 3.14 in the CI).
39+
40+
### Changed
41+
42+
- Removed an unnecessary internal reshape when computing Jacobians. This should have no effect but a
43+
slight performance improvement in `autojac`.
44+
- Revamped documentation.
45+
- Made `backward` and `mtl_backward` importable from `torchjd.autojac` (like it was prior to 0.7.0).
46+
- Deprecated importing `backward` and `mtl_backward` from `torchjd` directly.
47+
1148
## [0.7.0] - 2025-06-04
1249

1350
### Changed

CONTRIBUTING.md

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,35 @@ mandatory, we only provide installation steps with this tool. You can install it
1212
1) Pre-requisites: Use `uv` to install a Python version compatible with TorchJD and to pin it to the
1313
`torchjd` folder. From the root of the `torchjd` repo, run:
1414
```bash
15-
uv python install 3.13.3
16-
uv python pin 3.13.3
15+
uv python install 3.14.0
16+
uv python pin 3.14.0
1717
```
1818

1919
2) Create a virtual environment and install the project in it. From the root of `torchjd`, run:
2020
```bash
2121
uv venv
22-
CC=gcc uv pip install -e '.[full]' --group check --group doc --group test --group plot
22+
CC=gcc uv pip install --python-version=3.14 -e '.[full]' --group check --group doc --group test --group plot
23+
```
24+
If you want to install PyTorch with a different CUDA version (this could be required depending on
25+
your GPU), you'll need to specify and extra index. For instance, for CUDA 12.6, run:
26+
```bash
27+
uv venv
28+
CC=gcc uv pip install --python-version=3.14 -e '.[full]' --group check --group doc --group test --group plot --index-strategy unsafe-best-match --extra-index-url https://download.pytorch.org/whl/cu126
29+
```
30+
31+
We also advise using `UV_NO_SYNC=1` to prevent `uv` from syncing all the time. This is because by
32+
default, it tries to resolve libraries compatible with the whole range of Python versions
33+
supported by TorchJD, but in reality, we just need an installation compatible with the currently
34+
used Python version. That's also why we specify `--python-version=3.14` when running
35+
`uv pip install`. To follow that recommendation, add the following line to your `.bashrc`:
36+
```bash
37+
export UV_NO_SYNC=1
38+
```
39+
and start a new terminal. The alternative is to use the `--no-sync` flag whenever you run a pip
40+
command that would normally sync (like `uv run`).
41+
42+
3) Install pre-commit:
43+
```bash
2344
uv run pre-commit install
2445
```
2546

@@ -37,12 +58,30 @@ mandatory, we only provide installation steps with this tool. You can install it
3758
> created by `uv`, using `source .venv/bin/activate` from the root of `torchjd`. This will, however,
3859
> only work in the current terminal until it is closed.
3960
61+
62+
## Clean reinstallation
63+
64+
If you want to update all dependencies or just reinstall from scratch, run the following command
65+
from the root of `torchjd`:
66+
```bash
67+
rm -rf .venv
68+
rm uv.lock
69+
uv venv
70+
CC=gcc uv pip install --python-version=3.14 -e '.[full]' --group check --group doc --group test --group plot
71+
uv run pre-commit install
72+
```
73+
4074
## Running tests
41-
- To verify that your installation was successful, and that all unit tests pass, run:
75+
- To verify that your installation was successful, and that unit tests pass, run:
4276
```bash
4377
uv run pytest tests/unit
4478
```
4579

80+
- To also run the unit tests that are marked as slow, add the `--runslow` flag:
81+
```bash
82+
uv run pytest tests/unit --runslow
83+
```
84+
4685
- If you have access to a cuda-enabled GPU, you should also check that the unit tests pass on it:
4786
```bash
4887
CUBLAS_WORKSPACE_CONFIG=:4096:8 PYTEST_TORCH_DEVICE=cuda:0 uv run pytest tests/unit
@@ -100,29 +139,31 @@ We ask contributors to implement the unit tests necessary to check the correctne
100139
implementations. Besides, whenever usage examples are provided, we require the example's code to be
101140
tested in `tests/doc`. We require a very high code coverage for newly introduced sources (~95-100%).
102141
To ensure that the tensors generated during the tests are on the right device, you have to use the
103-
partial functions defined in `tests/unit/_utils.py` to instantiate tensors. For instance, instead of
142+
partial functions defined in `tests/utils/tensors.py` to instantiate tensors. For instance, instead
143+
of
104144
```python
105145
import torch
106146
a = torch.ones(3, 4)
107147
```
108148
use
109149
```python
110-
from unit._utils import ones_
150+
from utils.tensors import ones_
111151
a = ones_(3, 4)
112152
```
113153
114-
This will automatically call `torch.ones` with `device=unit.conftest.DEVICE`.
115-
If the function you need does not exist yet as a partial function in `_utils.py`, add it.
154+
This will automatically call `torch.ones` with `device=DEVICE`.
155+
If the function you need does not exist yet as a partial function in `tensors.py`, add it.
116156
Lastly, when you create a model or a random generator, you have to move them manually to the right
117-
device (the `DEVICE` defined in `unit.conftest`):
157+
device (the `DEVICE` defined in `device.py`).
118158
```python
119159
import torch
120160
from torch.nn import Linear
121-
from unit.conftest import DEVICE
161+
from device import DEVICE
122162
123163
model = Linear(3, 4).to(device=DEVICE)
124164
rng = torch.Generator(device=DEVICE)
125165
```
166+
You may also use a `ModuleFactory` to make the modules on `DEVICE` automatically.
126167
127168
### Coding
128169
@@ -149,6 +190,11 @@ implementation of a mathematical aggregator.
149190
> Before working on the implementation of a new aggregator, please contact us via an issue or a
150191
> discussion: in many cases, we have already thought about it, or even started an implementation.
151192
193+
## Deprecation
194+
195+
To deprecate some public functionality, make it raise a `DeprecationWarning`. A test should also be
196+
added in `tests/units/test_deprecations.py`, ensuring that this warning is issued.
197+
152198
## Release
153199
154200
*This section is addressed to maintainers.*

LICENSE

Lines changed: 0 additions & 21 deletions
This file was deleted.

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
[![Tests](https://github.com/TorchJD/torchjd/actions/workflows/tests.yml/badge.svg)](https://github.com/TorchJD/torchjd/actions/workflows/tests.yml)
55
[![codecov](https://codecov.io/gh/TorchJD/torchjd/graph/badge.svg?token=8AUCZE76QH)](https://codecov.io/gh/TorchJD/torchjd)
66
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/TorchJD/torchjd/main.svg)](https://results.pre-commit.ci/latest/github/TorchJD/torchjd/main)
7-
[![PyPI - Downloads](https://img.shields.io/pypi/dm/torchjd)](https://pypistats.org/packages/torchjd)
87
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/torchjd)](https://pypi.org/project/torchjd/)
98
[![Static Badge](https://img.shields.io/badge/Discord%20-%20community%20-%20%235865F2?logo=discord&logoColor=%23FFFFFF&label=Discord)](https://discord.gg/76KkRnb3nk)
109

docs/source/docs/aggregation/aligned_mtl.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,8 @@ Aligned-MTL
77
:members:
88
:undoc-members:
99
:exclude-members: forward
10+
11+
.. autoclass:: torchjd.aggregation.AlignedMTLWeighting
12+
:members:
13+
:undoc-members:
14+
:exclude-members: forward

docs/source/docs/aggregation/bases.rst

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)