Skip to content

Commit bbe4957

Browse files
committed
add readme
1 parent 1aed3c3 commit bbe4957

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Scalarization
2+
3+
A `Scalarizer` reduces a tensor of values (typically a vector of per-task or per-instance losses)
4+
into a single scalar that can be optimized with a standard `loss.backward()`. Scalarizers are the
5+
simple baseline against which the Jacobian-descent [aggregators](../aggregation) are compared:
6+
instead of combining the per-loss gradients, a scalarizer combines the losses directly.
7+
8+
Full documentation for every scalarizer is at
9+
[torchjd.org](https://torchjd.org/latest/docs/scalarization/).
10+
11+
## Usage
12+
13+
```python
14+
import torch
15+
from torch.nn import Linear
16+
from torchjd.scalarization import Mean
17+
18+
model = Linear(3, 2)
19+
scalarizer = Mean()
20+
21+
features = torch.randn(8, 3)
22+
losses = model(features).pow(2).mean(dim=0) # one loss per output dimension
23+
loss = scalarizer(losses)
24+
loss.backward() # gradients flow to the model parameters
25+
```
26+
27+
## Available scalarizers
28+
29+
- **Constant**: combines the values with constant, pre-determined weights.
30+
- **COSMOS**: linear scalarization minus a cosine-similarity penalty toward a preference direction.
31+
- **DWA**: weights each value by the relative rate at which its loss decreased over the two previous
32+
epochs.
33+
- **FAMO**: decreases all task losses at an approximately equal rate, learning the task weights
34+
internally.
35+
- **GeometricMean**: geometric mean of the values (also known as GLS).
36+
- **IMTLL**: learns a per-task scale and combines the values as the sum of `exp(s_i) * L_i - s_i`.
37+
- **Mean**: mean of the values.
38+
- **PBI**: decomposes the values along a preference direction and penalizes the perpendicular
39+
distance.
40+
- **Random**: combines the values with positive random weights summing to one.
41+
- **STCH**: smooth approximation of the weighted, shifted maximum of the values.
42+
- **Sum**: sum of the values.
43+
- **UW**: weights the values using learned per-task uncertainties.
44+
45+
`UW`, `IMTLL`, and `FAMO` are trainable, and `DWA` and `FAMO` carry state between calls, so they
46+
need a little more than a single call (an optimizer, a per-epoch `step()`, or an `update()`). See
47+
the documentation for the exact usage.

0 commit comments

Comments
 (0)