Skip to content

Commit ba197a9

Browse files
committed
Add MatrixWeighting and GramianWeighting
1 parent 630ffb9 commit ba197a9

15 files changed

Lines changed: 57 additions & 38 deletions

‎src/torchjd/aggregation/_aligned_mtl.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
from ._aggregator_bases import GramianWeightedAggregator
1313
from ._mean import MeanWeighting
1414
from ._utils.pref_vector import pref_vector_to_str_suffix, pref_vector_to_weighting
15-
from ._weighting_bases import Weighting
15+
from ._weighting_bases import GramianWeighting
1616

1717
SUPPORTED_SCALE_MODE: TypeAlias = Literal["min", "median", "rmse"]
1818

1919

20-
class AlignedMTLWeighting(Weighting[PSDMatrix]):
20+
class AlignedMTLWeighting(GramianWeighting):
2121
r"""
2222
:class:`~torchjd.aggregation._weighting_bases.Weighting` giving the weights of
2323
:class:`~torchjd.aggregation.AlignedMTL`.

‎src/torchjd/aggregation/_cagrad.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from torchjd._linalg import PSDMatrix
44

55
from ._utils.check_dependencies import check_dependencies_are_installed
6-
from ._weighting_bases import Weighting
6+
from ._weighting_bases import GramianWeighting
77

88
check_dependencies_are_installed(["cvxpy", "clarabel"])
99

@@ -18,7 +18,7 @@
1818
from ._utils.non_differentiable import raise_non_differentiable_error
1919

2020

21-
class CAGradWeighting(Weighting[PSDMatrix]):
21+
class CAGradWeighting(GramianWeighting):
2222
"""
2323
:class:`~torchjd.aggregation._weighting_bases.Weighting` giving the weights of
2424
:class:`~torchjd.aggregation.CAGrad`.

‎src/torchjd/aggregation/_constant.py‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
from torch import Tensor
22

3-
from torchjd._linalg import Matrix
4-
53
from ._aggregator_bases import WeightedAggregator
64
from ._utils.str import vector_to_str
7-
from ._weighting_bases import Weighting
5+
from ._weighting_bases import MatrixWeighting
86

97

10-
class ConstantWeighting(Weighting[Matrix]):
8+
class ConstantWeighting(MatrixWeighting):
119
"""
1210
:class:`~torchjd.aggregation._weighting_bases.Weighting` that returns constant, pre-determined
1311
weights.

‎src/torchjd/aggregation/_dualproj.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
from ._utils.dual_cone import SUPPORTED_SOLVER, project_weights
88
from ._utils.non_differentiable import raise_non_differentiable_error
99
from ._utils.pref_vector import pref_vector_to_str_suffix, pref_vector_to_weighting
10-
from ._weighting_bases import Weighting
10+
from ._weighting_bases import GramianWeighting
1111

1212

13-
class DualProjWeighting(Weighting[PSDMatrix]):
13+
class DualProjWeighting(GramianWeighting):
1414
r"""
1515
:class:`~torchjd.aggregation._weighting_bases.Weighting` giving the weights of
1616
:class:`~torchjd.aggregation.DualProj`.

‎src/torchjd/aggregation/_gradvac.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010

1111
from ._aggregator_bases import GramianWeightedAggregator
1212
from ._utils.non_differentiable import raise_non_differentiable_error
13-
from ._weighting_bases import Weighting
13+
from ._weighting_bases import GramianWeighting
1414

1515

16-
class GradVacWeighting(Weighting[PSDMatrix], Stateful):
16+
class GradVacWeighting(GramianWeighting, Stateful):
1717
r"""
1818
:class:`~torchjd.aggregation._mixins.Stateful`
1919
:class:`~torchjd.aggregation._weighting_bases.Weighting` giving the weights of

‎src/torchjd/aggregation/_imtl_g.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
from ._aggregator_bases import GramianWeightedAggregator
77
from ._utils.non_differentiable import raise_non_differentiable_error
8-
from ._weighting_bases import Weighting
8+
from ._weighting_bases import GramianWeighting
99

1010

11-
class IMTLGWeighting(Weighting[PSDMatrix]):
11+
class IMTLGWeighting(GramianWeighting):
1212
"""
1313
:class:`~torchjd.aggregation._weighting_bases.Weighting` giving the weights of
1414
:class:`~torchjd.aggregation.IMTLG`.

‎src/torchjd/aggregation/_krum.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
from torchjd._linalg import PSDMatrix
66

77
from ._aggregator_bases import GramianWeightedAggregator
8-
from ._weighting_bases import Weighting
8+
from ._weighting_bases import GramianWeighting
99

1010

11-
class KrumWeighting(Weighting[PSDMatrix]):
11+
class KrumWeighting(GramianWeighting):
1212
"""
1313
:class:`~torchjd.aggregation._weighting_bases.Weighting` giving the weights of
1414
:class:`~torchjd.aggregation.Krum`.

‎src/torchjd/aggregation/_mean.py‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import torch
22
from torch import Tensor
33

4-
from torchjd._linalg import Matrix
5-
64
from ._aggregator_bases import WeightedAggregator
7-
from ._weighting_bases import Weighting
5+
from ._weighting_bases import MatrixWeighting
86

97

10-
class MeanWeighting(Weighting[Matrix]):
8+
class MeanWeighting(MatrixWeighting):
119
r"""
1210
:class:`~torchjd.aggregation._weighting_bases.Weighting` that gives the weights
1311
:math:`\begin{bmatrix} \frac{1}{m} & \dots & \frac{1}{m} \end{bmatrix}^T \in

‎src/torchjd/aggregation/_mgda.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
from torchjd._linalg import PSDMatrix
55

66
from ._aggregator_bases import GramianWeightedAggregator
7-
from ._weighting_bases import Weighting
7+
from ._weighting_bases import GramianWeighting
88

99

10-
class MGDAWeighting(Weighting[PSDMatrix]):
10+
class MGDAWeighting(GramianWeighting):
1111
r"""
1212
:class:`~torchjd.aggregation._weighting_bases.Weighting` giving the weights of
1313
:class:`~torchjd.aggregation.MGDA`.

‎src/torchjd/aggregation/_nash_mtl.py‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
# Partly adapted from https://github.com/AvivNavon/nash-mtl — MIT License, Copyright (c) 2022 Aviv Navon.
22
# See NOTICES for the full license text.
33

4-
from torchjd._linalg import Matrix
54
from torchjd.aggregation._mixins import Stateful
65

76
from ._utils.check_dependencies import check_dependencies_are_installed
8-
from ._weighting_bases import Weighting
7+
from ._weighting_bases import MatrixWeighting
98

109
check_dependencies_are_installed(["cvxpy", "ecos"])
1110

@@ -21,7 +20,7 @@
2120
from ._utils.non_differentiable import raise_non_differentiable_error
2221

2322

24-
class _NashMTLWeighting(Weighting[Matrix], Stateful):
23+
class _NashMTLWeighting(MatrixWeighting, Stateful):
2524
"""
2625
:class:`~torchjd.aggregation._mixins.Stateful` :class:`~torchjd.aggregation.Weighting` that
2726
extracts weights using the step decision of Algorithm 1 of `Multi-Task Learning as a Bargaining

0 commit comments

Comments
 (0)