From db0f91d74489847b228bd8cdd74fe617817ddb0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Val=C3=A9rian=20Rey?= Date: Sun, 27 Apr 2025 19:11:04 +0200 Subject: [PATCH 1/7] Update documentation about how to install optional dependencies --- README.md | 2 ++ docs/source/installation.md | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/README.md b/README.md index 047b7071..b2775201 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,8 @@ TorchJD can be installed directly with pip: pip install torchjd ``` +Some aggregators may have additional dependencies. Please refer to the +[installation documentation](https://torchjd.org/stable/installation) for them. ## Usage The main way to use TorchJD is to replace the usual call to `loss.backward()` by a call to diff --git a/docs/source/installation.md b/docs/source/installation.md index 843c31a2..0adcc4ec 100644 --- a/docs/source/installation.md +++ b/docs/source/installation.md @@ -6,3 +6,17 @@ ``` Note that `torchjd` requires python 3.10, 3.11, 3.12 or 3.13 and `torch>=2.0`. + +Some aggregators (CAGrad and Nash-MTL) have additional dependencies that are not included by default +when installing `torchjd`. To install them, you can use: +``` +pip install torchjd[cagrad] +``` +``` +pip install torchjd[nash_mtl] +``` + +To install `torchjd` with all of its optional dependencies, you can also use: +``` +pip install torchjd[all] +``` From a968bdd345df70c7cbabc60e73216745525ea827 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Val=C3=A9rian=20Rey?= Date: Sun, 27 Apr 2025 19:11:30 +0200 Subject: [PATCH 2/7] Make cvxpy and ecos optional --- pyproject.toml | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 01e68561..66cc4736 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,8 +17,6 @@ dependencies = [ "quadprog>=0.1.9, != 0.1.10", # Doesn't work before 0.1.9, 0.1.10 is yanked "numpy>=1.21.0", # Does not work before 1.21 "qpsolvers>=1.0.1", # Does not work before 1.0.1 - "cvxpy>=1.3.0", # No Clarabel solver before 1.3.0 - "ecos>=2.0.14", # Does not work before 2.0.14 ] classifiers = [ "Development Status :: 4 - Beta", @@ -67,3 +65,16 @@ plot = [ "dash>=2.16.0", # Recent version to avoid problems, could be relaxed "kaleido==0.2.1", # Only works with locked version ] + +[project.optional-dependencies] +nash_mtl = [ + "cvxpy>=1.3.0", # Could be relaxed + "ecos>=2.0.14", # Does not work before 2.0.14 +] +cagrad = [ + "cvxpy>=1.3.0", # No Clarabel solver before 1.3.0 +] +all = [ + "cvxpy>=1.3.0", # No Clarabel solver before 1.3.0 + "ecos>=2.0.14", # Does not work before 2.0.14 +] From b7ebc2a2472e02a6c21a412ff02484ed66426afb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Val=C3=A9rian=20Rey?= Date: Sun, 27 Apr 2025 19:19:28 +0200 Subject: [PATCH 3/7] Add changelog entry --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c130fb2..70840bd8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,13 @@ changes that do not affect the user. ## [Unreleased] +### Changed + +- **BREAKING**: Changed the dependencies of `CAGrad` and `NashMTL` to be optional when installing + TorchJD. Users of these aggregators will have to use `pip install torchjd[cagrad]`, `pip install + torchjd[nash_mtl]` or `pip install torchjd[all]` to install TorchJD alongside those dependencies. + This should make TorchJD more lightweight. + ## [0.6.0] - 2025-04-19 ### Added From 5b4ef6b8c0c54cbb68a13b801c1e0aa823fa6400 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Val=C3=A9rian=20Rey?= Date: Sun, 27 Apr 2025 19:30:54 +0200 Subject: [PATCH 4/7] Rename all to full --- CHANGELOG.md | 2 +- docs/source/installation.md | 2 +- pyproject.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 70840bd8..86493027 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ changes that do not affect the user. - **BREAKING**: Changed the dependencies of `CAGrad` and `NashMTL` to be optional when installing TorchJD. Users of these aggregators will have to use `pip install torchjd[cagrad]`, `pip install - torchjd[nash_mtl]` or `pip install torchjd[all]` to install TorchJD alongside those dependencies. + torchjd[nash_mtl]` or `pip install torchjd[full]` to install TorchJD alongside those dependencies. This should make TorchJD more lightweight. ## [0.6.0] - 2025-04-19 diff --git a/docs/source/installation.md b/docs/source/installation.md index 0adcc4ec..eb1307f8 100644 --- a/docs/source/installation.md +++ b/docs/source/installation.md @@ -18,5 +18,5 @@ pip install torchjd[nash_mtl] To install `torchjd` with all of its optional dependencies, you can also use: ``` -pip install torchjd[all] +pip install torchjd[full] ``` diff --git a/pyproject.toml b/pyproject.toml index 66cc4736..8ab9d8a2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -74,7 +74,7 @@ nash_mtl = [ cagrad = [ "cvxpy>=1.3.0", # No Clarabel solver before 1.3.0 ] -all = [ +full = [ "cvxpy>=1.3.0", # No Clarabel solver before 1.3.0 "ecos>=2.0.14", # Does not work before 2.0.14 ] From 094d6b976252e2dc1693b3370e86dfdcb3b54127 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Val=C3=A9rian=20Rey?= Date: Sun, 27 Apr 2025 19:34:23 +0200 Subject: [PATCH 5/7] Change test CI to install optional dependencies --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c5614a47..0adc6979 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -22,7 +22,7 @@ jobs: with: python-version: ${{ matrix.python-version }} - name: Install default and test dependencies - run: pdm install --group test --frozen-lockfile + run: pdm install --group full --group test --frozen-lockfile - name: Run unit and doc tests with coverage report run: pdm run pytest tests/unit tests/doc --cov=src --cov-report=xml - name: Upload results to Codecov From f5b2cde81e55062f0a4c40425c71313819844b41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Val=C3=A9rian=20Rey?= Date: Sun, 27 Apr 2025 19:42:33 +0200 Subject: [PATCH 6/7] Add notes about installing optional dependencies in cagrad and nashmtl --- src/torchjd/aggregation/cagrad.py | 4 ++++ src/torchjd/aggregation/nash_mtl.py | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/torchjd/aggregation/cagrad.py b/src/torchjd/aggregation/cagrad.py index 93075fc0..2fdf670d 100644 --- a/src/torchjd/aggregation/cagrad.py +++ b/src/torchjd/aggregation/cagrad.py @@ -29,6 +29,10 @@ class CAGrad(_WeightedAggregator): >>> >>> A(J) tensor([0.1835, 1.2041, 1.2041]) + + .. note:: + The aggregator has dependencies that are not included by default when installing `torchjd`. + To install them, use `pip install torchjd[cagrad]`. """ def __init__(self, c: float, norm_eps: float = 0.0001): diff --git a/src/torchjd/aggregation/nash_mtl.py b/src/torchjd/aggregation/nash_mtl.py index c9681fbb..0258afd5 100644 --- a/src/torchjd/aggregation/nash_mtl.py +++ b/src/torchjd/aggregation/nash_mtl.py @@ -60,6 +60,10 @@ class NashMTL(_WeightedAggregator): >>> A(J) tensor([0.0542, 0.7061, 0.7061]) + .. note:: + The aggregator has dependencies that are not included by default when installing `torchjd`. + To install them, use `pip install torchjd[nash_mtl]`. + .. warning:: This implementation was adapted from the `official implementation `_, which has some flaws. Use with caution. From 2c9940949aff7dcc05f042df40319028b95ba519 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Val=C3=A9rian=20Rey?= Date: Mon, 28 Apr 2025 11:15:34 +0200 Subject: [PATCH 7/7] Fix docstring formatting --- src/torchjd/aggregation/cagrad.py | 4 ++-- src/torchjd/aggregation/nash_mtl.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/torchjd/aggregation/cagrad.py b/src/torchjd/aggregation/cagrad.py index 2fdf670d..e1d4e117 100644 --- a/src/torchjd/aggregation/cagrad.py +++ b/src/torchjd/aggregation/cagrad.py @@ -31,8 +31,8 @@ class CAGrad(_WeightedAggregator): tensor([0.1835, 1.2041, 1.2041]) .. note:: - The aggregator has dependencies that are not included by default when installing `torchjd`. - To install them, use `pip install torchjd[cagrad]`. + This aggregator has dependencies that are not included by default when installing + ``torchjd``. To install them, use ``pip install torchjd[cagrad]``. """ def __init__(self, c: float, norm_eps: float = 0.0001): diff --git a/src/torchjd/aggregation/nash_mtl.py b/src/torchjd/aggregation/nash_mtl.py index 0258afd5..a314630b 100644 --- a/src/torchjd/aggregation/nash_mtl.py +++ b/src/torchjd/aggregation/nash_mtl.py @@ -61,15 +61,15 @@ class NashMTL(_WeightedAggregator): tensor([0.0542, 0.7061, 0.7061]) .. note:: - The aggregator has dependencies that are not included by default when installing `torchjd`. - To install them, use `pip install torchjd[nash_mtl]`. + This aggregator has dependencies that are not included by default when installing + ``torchjd``. To install them, use ``pip install torchjd[nash_mtl]``. .. warning:: This implementation was adapted from the `official implementation `_, which has some flaws. Use with caution. .. warning:: - The aggregator is stateful. Its output will thus depend not only on the input matrix, but + This aggregator is stateful. Its output will thus depend not only on the input matrix, but also on its state. It thus depends on previously seen matrices. It should be reset between experiments. """