Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output shape of torch.linalg.norm diverges from numpy equivalent in edge case. #59198

Closed
pmeier opened this issue May 31, 2021 · 1 comment
Closed
Assignees
Labels
high priority module: linear algebra Issues related to specialized linear algebra operations in PyTorch; includes matrix multiply matmul module: norms and normalization triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Comments

@pmeier
Copy link
Collaborator

pmeier commented May 31, 2021

馃悰 Bug

Output shape of torch.linalg.norm diverges from numpy equivalent in edge case.

To Reproduce

import torch
import numpy as np

t = torch.rand((1, 1, 0))
a = t.numpy()

t_norm = torch.linalg.norm(t, ord=2, dim=(0, 1), keepdim=False)
a_norm = np.linalg.norm(a, ord=2, axis=(0, 1), keepdims=False)

assert t_norm.shape == a_norm.shape
  • This also fails for ord=-2 but works for all other orders
  • This works fine for keepdim=True
  • This also works fine for other degenerate input shapes

Environment

PyTorch version: 1.9.0a0+gitc9de3e3
Is debug build: True
CUDA used to build PyTorch: Could not collect
ROCM used to build PyTorch: N/A

OS: Arch Linux (x86_64)
GCC version: (crosstool-NG 1.24.0.133_b0863d8_dirty) 9.3.0
Clang version: Could not collect
CMake version: version 3.20.2
Libc version: glibc-2.9

Python version: 3.6 (64-bit runtime)
Python platform: Linux-5.12.5-arch1-1-x86_64-with-arch
Is CUDA available: False
CUDA runtime version: 11.1.105
GPU models and configuration: GPU 0: NVIDIA GeForce GTX 1080
Nvidia driver version: 465.31
cuDNN version: Probably one of the following:
/usr/local/cudnn-8.1.1-cuda-11/lib64/libcudnn.so.8.1.1
/usr/local/cudnn-8.1.1-cuda-11/lib64/libcudnn_adv_infer.so.8.1.1
/usr/local/cudnn-8.1.1-cuda-11/lib64/libcudnn_adv_train.so.8.1.1
/usr/local/cudnn-8.1.1-cuda-11/lib64/libcudnn_cnn_infer.so.8.1.1
/usr/local/cudnn-8.1.1-cuda-11/lib64/libcudnn_cnn_train.so.8.1.1
/usr/local/cudnn-8.1.1-cuda-11/lib64/libcudnn_ops_infer.so.8.1.1
/usr/local/cudnn-8.1.1-cuda-11/lib64/libcudnn_ops_train.so.8.1.1
HIP runtime version: N/A
MIOpen runtime version: N/A

Versions of relevant libraries:
[pip3] numpy==1.19.5
[pip3] pytest-pytorch==0.0.0
[pip3] torch==1.9.0a0+gitc9de3e3
[conda] magma-cuda111             2.5.2                         1    pytorch
[conda] mkl                       2021.2.0           h726a3e6_389    conda-forge
[conda] mkl-include               2021.2.0           h726a3e6_389    conda-forge
[conda] numpy                     1.19.5           py36h2aa4a07_1    conda-forge
[conda] pytest-pytorch            0.2.0              pyh44b312d_0    conda-forge
[conda] torch                     1.9.0a0+gitc9de3e3           dev_0    <develop>

Additional context

This is tested in

def test_norm_matrix_degenerate_shapes(self, device, dtype):

but the test never failed due to a bug in the underlying comparison mechanism. #59067 will disable the failing test case, but it should be reinstated as soon as this issue is fixed.

cc @ezyang @gchanan @zou3519 @bdhirsh @jbschlosser @anjali411 @jianyuh @nikitaved @pearu @mruberry @heitorschueroff @walterddr @IvanYashchuk @xwang233 @lezcano @VitalyFedyunin

@pmeier pmeier added module: linear algebra Issues related to specialized linear algebra operations in PyTorch; includes matrix multiply matmul module: tests Issues related to tests (not the torch.testing module) labels May 31, 2021
@mruberry mruberry added high priority module: norms and normalization and removed module: tests Issues related to tests (not the torch.testing module) labels May 31, 2021
@mruberry
Copy link
Collaborator

Thank you for identifying this issue, @pmeier. We would definitely accept a fix for this!

@mruberry mruberry added triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module and removed triage review labels May 31, 2021
@kurtamohler kurtamohler self-assigned this Jun 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
high priority module: linear algebra Issues related to specialized linear algebra operations in PyTorch; includes matrix multiply matmul module: norms and normalization triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants