Skip to content

torch.equal yields False if tensor contains NaN values. #137337

@randolf-scholz

Description

@randolf-scholz

🐛 Describe the bug

According to the documentation

True if two tensors have the same size and elements, False otherwise.

From this description, it would be expected that torch.equal(x, x) always returns True, however:

import torch
x = torch.tensor([float("nan")])
assert torch.equal(x, x)  # ❌ fails

Versions

Details

Collecting environment information...
PyTorch version: 2.4.1+cu121
Is debug build: <function debug at 0x758250499800>
CUDA used to build PyTorch: 12.1
ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.5 LTS (x86_64)
GCC version: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Clang version: 14.0.0-1ubuntu1.1
CMake version: version 3.30.4
Libc version: glibc-2.35

Python version: 3.12.4 (main, Jun 17 2024, 10:48:36) [GCC 11.4.0] (64-bit runtime)
Python platform: Linux-6.8.0-45-generic-x86_64-with-glibc2.35
Is CUDA available: True
CUDA runtime version: 12.6.77
GPU models and configuration: GPU 0: NVIDIA GeForce RTX 3090
Nvidia driver version: 560.35.03
cuDNN version: Probably one of the following:
/usr/lib/x86_64-linux-gnu/libcudnn.so.8.9.7
/usr/lib/x86_64-linux-gnu/libcudnn_adv_infer.so.8.9.7
/usr/lib/x86_64-linux-gnu/libcudnn_adv_train.so.8.9.7
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_infer.so.8.9.7
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_train.so.8.9.7
/usr/lib/x86_64-linux-gnu/libcudnn_ops_infer.so.8.9.7
/usr/lib/x86_64-linux-gnu/libcudnn_ops_train.so.8.9.7
HIP runtime version: N/A
MIOpen runtime version: N/A

Versions of relevant libraries:
[pip3] mypy==1.11.2
[pip3] mypy-extensions==1.0.0
[pip3] numpy==2.1.1
[pip3] torch==2.4.1
[pip3] torchinfo==1.8.0
[conda] Could not collect

cc @svekars @brycebortree @sekyondaMeta

Metadata

Metadata

Assignees

Labels

actionablemodule: docsRelated to our documentation, both in docs/ and docblockstriagedThis 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