Skip to content
Merged
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
7 changes: 3 additions & 4 deletions src/torchjd/autogram/_module_hook_manager.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import weakref
from typing import Any, cast
from typing import Any

import torch
from torch import Tensor, nn
Expand Down Expand Up @@ -129,9 +129,8 @@ def __call__(
# We only care about running the AutogramNode, so we need one of its child
# edges (the edges of the original outputs of the model) as target. For memory
# efficiency, we select the smallest one (that requires grad).
preference = torch.tensor([t.numel() for t in rg_outputs])
index = cast(int, preference.argmin().item())
self.target_edges.register(get_gradient_edge(rg_outputs[index]))
smallest_rg_output = min(rg_outputs, key=lambda t: t.numel())
self.target_edges.register(get_gradient_edge(smallest_rg_output))

autograd_fn_rg_outputs = AutogramNode.apply(
self.gramian_accumulation_phase,
Expand Down
Loading