Skip to content

torch.norm does not work when p="nuc" #18275

@LeeJZh

Description

@LeeJZh

🐛 Bug

torch.norm does not work as expected when p="nuc" , x is a 4 dimensional tensor, dim=(2,3)

To Reproduce

Steps to reproduce the behavior:
`
import torch

w = torch.randn(2, 1024, 3, 3)

torch.norm(w, p="fro", dim=(2,3)) ## this works fine

torch.norm(w, p="nuc", dim=(2,3)) ## this produce an error message
`

RuntimeError Traceback (most recent call last)
in ()
----> 1 torch.norm(w, p="nuc", dim=(2,3))

~/anaconda3/lib/python3.6/site-packages/torch/functional.py in norm(input, p, dim, keepdim, out)
726 elif p == "nuc":
727 if out is None:
--> 728 torch._C._VariableFunctions.nuclear_norm(input, keepdim=keepdim)
729 return torch._C._VariableFunctions.nuclear_norm(input, keepdim=keepdim, out=out)
730 else:

RuntimeError: Expected a tensor with 2 dimensions, but got a 4 dimensions tensor instead.

Expected behavior

return the track norm.

Environment

Please copy and paste the output from our
environment collection script
(or fill out the checklist below manually).

You can get the script and run it with:

wget https://raw.githubusercontent.com/pytorch/pytorch/master/torch/utils/collect_env.py
# For security purposes, please check the contents of collect_env.py before running it.
python collect_env.py
  • PyTorch Version (e.g., 1.0): 1.0.0
  • OS (e.g., Linux): Ubuntu 18.04
  • How you installed PyTorch (conda, pip, source): conda
  • Build command you used (if compiling from source):
  • Python version: 3.6.8
  • CUDA/cuDNN version: 10.0
  • GPU models and configuration: Two Titan XP
  • Any other relevant information:

Additional context

I also run the above code with Pytorch 1.0.1.post2, the error is the same.

Metadata

Metadata

Assignees

Labels

high prioritymodule: error checkingBugs related to incorrect/lacking error checkingsmallWe think this is a small issue to fix. Consider knocking off high priority small issuestriagedThis 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