Skip to content
Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ changes that do not affect the user.
- Refactored internal verifications in the autojac engine so that they do not run at runtime
anymore. This should minimally improve the performance and reduce the memory usage of `backward`
and `mtl_backward`.
- Improved the implementation of `ConFIG` to be simpler and safer when normalizing vectors. It
should slightly improve the performance of `ConFIG` and minimally affect its behavior.

### Fixed

Expand Down
7 changes: 2 additions & 5 deletions src/torchjd/aggregation/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,9 @@ def forward(self, matrix: Tensor) -> Tensor:
units = torch.nan_to_num((matrix / (matrix.norm(dim=1)).unsqueeze(1)), 0.0)
best_direction = torch.linalg.pinv(units) @ weights

if best_direction.norm() == 0:
unit_target_vector = torch.zeros_like(best_direction)
else:
unit_target_vector = best_direction / best_direction.norm()
unit_target_vector = torch.nn.functional.normalize(best_direction, dim=0)

length = torch.sum(torch.stack([torch.dot(grad, unit_target_vector) for grad in matrix]))
length = torch.sum(matrix @ unit_target_vector)

return length * unit_target_vector

Expand Down