Skip to content

Commit 6d1b76f

Browse files
michael-digginpytorchmergebot
authored andcommitted
use union for py 3.9 compatibilty
1 parent 04d779a commit 6d1b76f

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

torch/nn/functional.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3230,7 +3230,7 @@ def poisson_nll_loss(
32303230
def gaussian_nll_loss(
32313231
input: Tensor,
32323232
target: Tensor,
3233-
var: Tensor | float,
3233+
var: Union[Tensor, float],
32343234
full: bool = False,
32353235
eps: float = 1e-6,
32363236
reduction: str = "mean",

torch/nn/modules/loss.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# mypy: allow-untyped-defs
2-
from typing import Callable, Optional
2+
from typing import Callable, Optional, Union
33
from typing_extensions import deprecated
44

55
from torch import Tensor
@@ -438,7 +438,9 @@ def __init__(
438438
self.full = full
439439
self.eps = eps
440440

441-
def forward(self, input: Tensor, target: Tensor, var: Tensor | float) -> Tensor:
441+
def forward(
442+
self, input: Tensor, target: Tensor, var: Union[Tensor, float]
443+
) -> Tensor:
442444
return F.gaussian_nll_loss(
443445
input, target, var, full=self.full, eps=self.eps, reduction=self.reduction
444446
)

0 commit comments

Comments
 (0)