|
1 | 1 | r""" |
2 | 2 | When doing Jacobian descent, the Jacobian matrix has to be aggregated into a vector to store in the |
3 | 3 | ``.grad`` fields of the model parameters. The |
4 | | -:class:`~torchjd.aggregation._aggregator_bases.Aggregator` is responsible for these aggregations. |
| 4 | +:class:`~torchjd.aggregation.Aggregator` is responsible for these aggregations. |
5 | 5 |
|
6 | 6 | When using the :doc:`autogram <../autogram/index>` engine, we rather need to extract a vector |
7 | 7 | of weights from the Gramian of the Jacobian. The |
8 | | -:class:`~torchjd.aggregation._weighting_bases.Weighting` is responsible for this. |
| 8 | +:class:`~torchjd.aggregation.Weighting` is responsible for this. |
9 | 9 |
|
10 | 10 | .. note:: |
11 | 11 | Most aggregators rely on computing the Gramian of the Jacobian, extracting a vector of weights |
12 | | - from this Gramian using a :class:`~torchjd.aggregation._weighting_bases.Weighting`, and then |
13 | | - combining the rows of the Jacobian using these weights. For all of them, we provide both the |
14 | | - :class:`~torchjd.aggregation._aggregator_bases.Aggregator` interface (to be used in autojac) and |
15 | | - the :class:`~torchjd.aggregation._weighting_bases.Weighting` interface (to be used in autogram). |
16 | | - For the rest, we only provide the :class:`~torchjd.aggregation._aggregator_bases.Aggregator` |
| 12 | + from this Gramian using a :class:`~torchjd.aggregation.GramianWeighting`, and then combining the |
| 13 | + rows of the Jacobian using these weights. For all of them, we provide both the |
| 14 | + :class:`~torchjd.aggregation.Aggregator` interface (to be used in autojac) and the |
| 15 | + :class:`~torchjd.aggregation.Weighting` interface (to be used in autogram). |
| 16 | + For the rest, we only provide the :class:`~torchjd.aggregation.Aggregator` |
17 | 17 | interface -- they are not compatible with autogram. |
18 | 18 |
|
19 | | -:class:`Aggregators <torchjd.aggregation._aggregator_bases.Aggregator>` and :class:`Weightings |
20 | | -<torchjd.aggregation._weighting_bases.Weighting>` are callables that take a Jacobian matrix or a |
| 19 | +:class:`Aggregators <torchjd.aggregation.Aggregator>` and |
| 20 | +:class:`Weightings <torchjd.aggregation.Weighting>` are callables that take a Jacobian matrix or a |
21 | 21 | Gramian matrix as inputs, respectively. The following example shows how to use UPGrad to either |
22 | 22 | aggregate a Jacobian (of shape ``[m, n]``, where ``m`` is the number of objectives and ``n`` is the |
23 | 23 | number of parameters), or obtain the weights from the Gramian of the Jacobian (of shape ``[m, m]``). |
|
39 | 39 | When dealing with a more general tensor of objectives, of shape ``[m_1, ..., m_k]`` (i.e. not |
40 | 40 | necessarily a simple vector), the Jacobian will be of shape ``[m_1, ..., m_k, n]``, and its Gramian |
41 | 41 | will be called a `generalized Gramian`, of shape ``[m_1, ..., m_k, m_k, ..., m_1]``. One can use a |
42 | | -:class:`GeneralizedWeighting<torchjd.aggregation._weighting_bases.GeneralizedWeighting>` to extract |
| 42 | +:class:`GeneralizedWeighting<torchjd.aggregation.GeneralizedWeighting>` to extract |
43 | 43 | a tensor of weights (of shape ``[m_1, ..., m_k]``) from such a generalized Gramian. The simplest |
44 | | -:class:`GeneralizedWeighting<torchjd.aggregation._weighting_bases.GeneralizedWeighting>` is |
45 | | -:class:`Flattening<torchjd.aggregation._flattening.Flattening>`: it simply "flattens" the |
| 44 | +:class:`GeneralizedWeighting<torchjd.aggregation.GeneralizedWeighting>` is |
| 45 | +:class:`Flattening<torchjd.aggregation.Flattening>`: it simply "flattens" the |
46 | 46 | generalized Gramian into a square Gramian matrix (of shape ``[m_1 * ... * m_k, m_1 * ... * m_k]``), |
47 | 47 | applies a normal weighting to it to obtain a vector of weights, and returns the reshaped tensor of |
48 | 48 | weights. |
|
59 | 59 | [0.1667, 0.1667, 0.1667]]) |
60 | 60 | """ |
61 | 61 |
|
62 | | -from ._aggregator_bases import Aggregator |
| 62 | +from ._aggregator_bases import Aggregator, GramianWeightedAggregator, WeightedAggregator |
63 | 63 | from ._aligned_mtl import AlignedMTL, AlignedMTLWeighting |
64 | 64 | from ._config import ConFIG |
65 | 65 | from ._constant import Constant, ConstantWeighting |
|
80 | 80 | from ._utils.check_dependencies import ( |
81 | 81 | OptionalDepsNotInstalledError as _OptionalDepsNotInstalledError, |
82 | 82 | ) |
83 | | -from ._weighting_bases import GeneralizedWeighting, Weighting |
| 83 | +from ._weighting_bases import GeneralizedWeighting, GramianWeighting, MatrixWeighting, Weighting |
84 | 84 |
|
85 | 85 | __all__ = [ |
86 | 86 | "Aggregator", |
|
96 | 96 | "GradDrop", |
97 | 97 | "GradVac", |
98 | 98 | "GradVacWeighting", |
| 99 | + "GramianWeightedAggregator", |
| 100 | + "GramianWeighting", |
99 | 101 | "IMTLG", |
100 | 102 | "IMTLGWeighting", |
101 | 103 | "Krum", |
102 | 104 | "KrumWeighting", |
| 105 | + "MatrixWeighting", |
103 | 106 | "Mean", |
104 | 107 | "MeanWeighting", |
105 | 108 | "MGDA", |
|
114 | 117 | "TrimmedMean", |
115 | 118 | "UPGrad", |
116 | 119 | "UPGradWeighting", |
| 120 | + "WeightedAggregator", |
117 | 121 | "Weighting", |
118 | 122 | ] |
119 | 123 |
|
|
0 commit comments