Skip to content

Commit 8b7c012

Browse files
committed
Change Grad to return zero tensors instead of nan tensors when applied to an empty list of outputs
1 parent 5706a93 commit 8b7c012

File tree

1 file changed

+1
-6
lines changed
  • src/torchjd/autojac/_transform

1 file changed

+1
-6
lines changed

src/torchjd/autojac/_transform/grad.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,7 @@ def _differentiate(self, grad_outputs: Sequence[Tensor]) -> tuple[Tensor, ...]:
3737
return tuple()
3838

3939
if len(outputs) == 0:
40-
return tuple(
41-
[
42-
torch.empty(input.shape, device=input.device, dtype=input.dtype)
43-
for input in inputs
44-
]
45-
)
40+
return tuple([torch.zeros_like(input) for input in inputs])
4641

4742
optional_grads = torch.autograd.grad(
4843
outputs,

0 commit comments

Comments
 (0)