Skip to content

Add scale_mode options to AlignedMTL#526

Closed
rkhosrowshahi wants to merge 4 commits intoSimplexLab:mainfrom
rkhosrowshahi:aligned-mtl-scale-mode
Closed

Add scale_mode options to AlignedMTL#526
rkhosrowshahi wants to merge 4 commits intoSimplexLab:mainfrom
rkhosrowshahi:aligned-mtl-scale-mode

Conversation

@rkhosrowshahi
Copy link
Copy Markdown
Contributor

Summary

  • add scale_mode to AlignedMTL and weighting
  • support min, median, and rmse scaling to match original behavior

Test plan

  • pytest tests/unit/aggregation/test_aligned_mtl.py tests/unit/aggregation/test_values.py

Expose median and rmse scaling modes for the balance transformation to match
original behavior while keeping min as default.
@rkhosrowshahi
Copy link
Copy Markdown
Contributor Author

Local tests passed: . CI appears blocked pending workflow approval—please approve when convenient.

@rkhosrowshahi
Copy link
Copy Markdown
Contributor Author

All unit tests passed following CONTRIBUTING.md guidelines:

UV_NO_SYNC=1 uv run pytest tests/unit

Results: 2435 passed, 63 skipped, 33 xfailed

CI workflows are currently awaiting maintainer approval before they can run.

@codecov
Copy link
Copy Markdown

codecov bot commented Jan 23, 2026

Codecov Report

❌ Patch coverage is 70.58824% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/torchjd/aggregation/_aligned_mtl.py 70.58% 5 Missing ⚠️
Files with missing lines Coverage Δ
src/torchjd/aggregation/_aligned_mtl.py 89.58% <70.58%> (-10.42%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ValerianRey ValerianRey self-requested a review January 23, 2026 16:07
Copy link
Copy Markdown
Contributor

@ValerianRey ValerianRey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! This looks really nice, and I think it can be merged as long as a few things are fixed.

Where is the official implementation located? It seems that the link to it (https://github.com/SamsungLabs/MTL) is now broken. I'm not sure why I used min instead of the default. Maybe the original implementation has changed in the meantime?

Comment on lines +125 to +128
elif scale_mode == "median":
scale = torch.median(lambda_)
elif scale_mode == "rmse":
scale = lambda_.mean()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add code coverage for this? I think it should be enough to just parametrize test_expected_structure and test_permutation_invariant (from tests/unit/aggregation/test_aligned_mtl.py) with AlignedMTL(scale_mode="median") and AlignedMTL(scale_mode="rmse") (on top of the already existing AlignedMTL()).

Comment on lines +129 to +132
else:
raise ValueError(
f"Invalid scale_mode={scale_mode!r}. Expected 'min', 'median', or 'rmse'."
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also need coverage for this. A simple test should be enough:

from pytest import raises
from utils.tensors import ones_

def test_invalid_scale_mode():
    aggregator = AlignedMTL(scale_mode="test")
    matrix = ones_(3, 4)
    with raises(ValueError):
        aggregator(matrix)

def __init__(
self,
pref_vector: Tensor | None = None,
scale_mode: Literal["min", "median", "rmse"] = "min",
Copy link
Copy Markdown
Contributor

@ValerianRey ValerianRey Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a changelog entry (under "Unreleased") saying that it's now possible to provide a scale_mode parameter for AlignedMTL and AlignedMTLWeighting?

@rkhosrowshahi
Copy link
Copy Markdown
Contributor Author

Hi! This looks really nice, and I think it can be merged as long as a few things are fixed.

Where is the official implementation located? It seems that the link to it (https://github.com/SamsungLabs/MTL) is now broken. I'm not sure why I used min instead of the default. Maybe the original implementation has changed in the meantime?

Hi, the original repo is no longer accessible, but based on my memory, they have implemented three scale modes: min, median, and RMSE. I think they reported min, but min is significantly noisy in many-objective optimization. I found this repo still using the old implementation, which I use as reference:
https://github.com/Daisy-1227/SSCF/blob/49aec64a43b461a87fc3ad14ffe05947e5d5c331/src/utils/grad_utils.py
I will fix the merge issues.

rkhosrowshahi and others added 3 commits January 23, 2026 11:32
Add coverage for median/rmse modes and invalid scale_mode handling.
Document the new scale_mode parameter for AlignedMTL and AlignedMTLWeighting.
@rkhosrowshahi
Copy link
Copy Markdown
Contributor Author

Addressed review feedback:

  • added coverage for scale_mode='median' and 'rmse' in test_expected_structure / test_permutation_invariant
  • added a simple ValueError test for invalid scale_mode
  • added a [Unreleased] changelog entry for the new scale_mode parameter (AlignedMTL + AlignedMTLWeighting)

Unit tests: UV_NO_SYNC=1 uv run pytest tests/unit (2604 passed, 63 skipped, 33 xfailed).

@rkhosrowshahi rkhosrowshahi closed this by deleting the head repository Jan 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants