Skip to content
Closed
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
10 changes: 5 additions & 5 deletions src/torchjd/autogram/_module_hook_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def __init__(
self.gramian_accumulator = gramian_accumulator
self.has_batch_dim = has_batch_dim

def __call__(self, module: nn.Module, args: PyTree, output: PyTree) -> PyTree:
def __call__(self, module: nn.Module, args: tuple[PyTree, ...], output: PyTree) -> PyTree:
if self.gramian_accumulation_phase:
return output

Expand Down Expand Up @@ -154,7 +154,7 @@ def forward(
gramian_accumulation_phase: BoolRef,
output_spec: TreeSpec,
vjp: VJP,
args: PyTree,
args: tuple[PyTree, ...],
gramian_accumulator: GramianAccumulator,
module: nn.Module,
*xs: Tensor,
Expand Down Expand Up @@ -199,7 +199,7 @@ class AccumulateJacobian(torch.autograd.Function):
def forward(
output_spec: TreeSpec,
vjp: VJP,
args: PyTree,
args: tuple[PyTree, ...],
gramian_accumulator: GramianAccumulator,
module: nn.Module,
*flat_grad_outputs: Tensor,
Expand All @@ -213,10 +213,10 @@ def forward(
@staticmethod
def vmap(
_,
in_dims: PyTree,
in_dims: tuple[PyTree, ...],
output_spec: TreeSpec,
vjp: VJP,
args: PyTree,
args: tuple[PyTree, ...],
gramian_accumulator: GramianAccumulator,
module: nn.Module,
*flat_jac_outputs: Tensor,
Expand Down
4 changes: 2 additions & 2 deletions src/torchjd/autogram/_vjp.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class VJP(ABC):
"""Represents an abstract VJP function."""

@abstractmethod
def __call__(self, grad_outputs: PyTree, args: PyTree) -> dict[str, Tensor]:
def __call__(self, grad_outputs: PyTree, args: tuple[PyTree, ...]) -> dict[str, Tensor]:
"""
Computes and returns the dictionary of parameter names to their gradients for the given
grad_outputs (cotangents) and at the given inputs.
Expand Down Expand Up @@ -56,7 +56,7 @@ def __init__(self, module: nn.Module):
super().__init__(module)
self.vmapped_vjp = torch.vmap(self._call_on_one_instance)

def __call__(self, grad_outputs: PyTree, args: PyTree) -> dict[str, Tensor]:
def __call__(self, grad_outputs: PyTree, args: tuple[PyTree, ...]) -> dict[str, Tensor]:
return self.vmapped_vjp(grad_outputs, args)

def _call_on_one_instance(self, grad_outputs_j: PyTree, args_j: PyTree) -> dict[str, Tensor]:
Expand Down
Loading