Skip to content

Pass a tensor of -inf to nn.Softmax and return a tensor of nan #25110

@zhangguanheng66

Description

@zhangguanheng66

Issue description

Just to check. When passing a tensor of -inf to nn.Softmax, it returns a tensor of nan. I know it's a very rare case but do we expect this result? Should we add a warning there?
Relevant issue #24816

Code example

Please try to provide a minimal example to repro the bug.

import torch
x = torch.Tensor([[[float("-inf"), float("-inf"), float("-inf")]]])
softmax = torch.nn.Softmax(dim=-1)
softmax(x)
>>> tensor([[[ nan, nan, nan]]])

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions