8000 torch.norm is numerically unstable at zero for multidim reductions · Issue #37323 · pytorch/pytorch · GitHub
[go: up one dir, main page]

Skip to content

torch.norm is numerically unstable at zero for multidim reductions #37323

@vadimkantorov

Description

@vadimkantorov

Note the inconsistent gradient computation:

import torch
a = torch.zeros(3, 3, 3, requires_grad = True)
print(torch.autograd.grad(a.norm(dim = 1).sum(), (a,))[0])
print(torch.autograd.grad(a.norm(dim = (1, 2)).sum(), (a,))[0])
print(torch.__version__)
tensor([[[0., 0., 0.],
         [0., 0., 0.],
         [0., 0., 0.]],

        [[0., 0., 0.],
         [0., 0., 0.],
         [0., 0., 0.]],

        [[0., 0., 0.],
         [0., 0., 0.],
         [0., 0., 0.]]])
tensor([[[nan, nan, nan],
         [nan, nan, nan],
         [nan, nan, nan]],

        [[nan, nan, nan],
         [nan, nan, nan],
         [nan, nan, nan]],

        [[nan, nan, nan],
         [nan, nan, nan],
         [nan, nan, nan]]])
1.6.0.dev20200417

Relevant code: https://github.com/pytorch/pytorch/blob/master/aten/src/ATen/native/LinearAlgebra.cpp#L558

Relevant discussion: #37272 (comment)

cc @ezyang @ssnl @albanD @zou3519 @gqchen @ngimel

Metadata

Metadata

Assignees

Labels

module: autogradRelated to torch.autograd, and the autograd engine in generalmodule: numerical-stabilityProblems related to numerical stability of operationstriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0