Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ changelog does not include internal changes that do not affect the user.

## [Unreleased]

### Fixed

- Added a fallback for when the inner optimization of `NashMTL` fails (which can happen for example
on the matrix [[0., 0.], [0., 1.]]).

## [0.9.0] - 2026-02-24

### Added
Expand Down
5 changes: 3 additions & 2 deletions src/torchjd/aggregation/_nash_mtl.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,10 @@ def _solve_optimization(self, gtg: np.ndarray) -> np.ndarray:

try:
self.prob.solve(solver=cp.ECOS, warm_start=True, max_iters=100)
except SolverError:
# On macOS, this can happen with: Solver 'ECOS' failed.
except (SolverError, ValueError):
# On macOS, SolverError can happen with: Solver 'ECOS' failed.
# No idea why. The corresponding matrix is of shape [9, 11] with rank 5.
# ValueError happens with for example matrix [[0., 0.], [0., 1.]].
# Maybe other exceptions can happen in other cases.
self.alpha_param.value = self.prvs_alpha_param.value

Expand Down
10 changes: 8 additions & 2 deletions tests/unit/aggregation/test_nash_mtl.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pytest import mark
from torch import Tensor
from torch.testing import assert_close
from utils.tensors import ones_, randn_
from utils.tensors import ones_, randn_, tensor_

try:
from torchjd.aggregation import NashMTL
Expand All @@ -19,6 +19,10 @@ def _make_aggregator(matrix: Tensor) -> NashMTL:


standard_pairs = [(_make_aggregator(matrix), matrix) for matrix in nash_mtl_matrices]
edge_case_matrices = [
tensor_([[0.0, 0.0], [0.0, 1.0]]) # This leads to a (caught) ValueError in _solve_optimization.
]
edge_case_pairs = [(_make_aggregator(matrix), matrix) for matrix in edge_case_matrices]
requires_grad_pairs = [(NashMTL(n_tasks=3), ones_(3, 5, requires_grad=True))]


Expand All @@ -27,8 +31,10 @@ def _make_aggregator(matrix: Tensor) -> NashMTL:
@mark.filterwarnings(
"ignore:Solution may be inaccurate.",
"ignore:You are solving a parameterized problem that is not DPP.",
"ignore:divide by zero encountered in divide",
"ignore:invalid value encountered in matmul",
)
@mark.parametrize(["aggregator", "matrix"], standard_pairs)
@mark.parametrize(["aggregator", "matrix"], standard_pairs + edge_case_pairs)
def test_expected_structure(aggregator: NashMTL, matrix: Tensor) -> None:
assert_expected_structure(aggregator, matrix)

Expand Down
Loading