INTERNAL ASSERT FAILED for `S.unique().shape`

🐛 Bug

To Reproduce

The stacktrace is

  File "/home/ezheltonozhskii/dense_c3dpo/model.py", line 122, in get_optimal_view
    if S.unique().shape != S.shape: 
  File "/opt/conda/lib/python3.7/site-packages/torch/tensor.py", line 519, in unique
    return torch.unique(self, sorted=sorted, return_inverse=return_inverse, return_counts=return_counts, dim=dim)
  File "/opt/conda/lib/python3.7/site-packages/torch/_jit_internal.py", line 267, in fn
    return if_false(*args, **kwargs)
  File "/opt/conda/lib/python3.7/site-packages/torch/_jit_internal.py", line 267, in fn
    return if_false(*args, **kwargs)
  File "/opt/conda/lib/python3.7/site-packages/torch/functional.py", line 768, in _return_output
    output, _, _ = _unique_impl(input, sorted, return_inverse, return_counts, dim)
  File "/opt/conda/lib/python3.7/site-packages/torch/functional.py", line 683, in _unique_impl
    return_counts=return_counts,
RuntimeError: isDifferentiableType(variable.scalar_type()) INTERNAL ASSERT FAILED at "/pytorch/torch/csrc/autograd/functions/utils.h":64, please report a bug to PyTorch.

I can’t share exact code but I have different behaviour depending on whether all elements of tensor are unique in spirit of

if S.unique().shape != S.shape: 
  return x
return y

Expected behavior

The code works or raises exception.

Environment

You can get the script and run it with:

PyTorch version: 1.8.0.dev20201024+cu110
Is debug build: True
CUDA used to build PyTorch: 11.0
ROCM used to build PyTorch: N/A

OS: Debian GNU/Linux 9.13 (stretch) (x86_64)
GCC version: (Debian 6.3.0-18+deb9u1) 6.3.0 20170516
Clang version: Could not collect
CMake version: Could not collect

Python version: 3.7 (64-bit runtime)
Is CUDA available: True
CUDA runtime version: Could not collect
GPU models and configuration: GPU 0: A100-SXM4-40GB
Nvidia driver version: 450.51.06
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A

Versions of relevant libraries:
[pip3] efficientnet-pytorch==0.6.3
[pip3] numpy==1.18.5
[pip3] numpydoc==1.1.0
[pip3] pytorch3d==0.2.5
[pip3] segmentation-models-pytorch==0.1.2
[pip3] torch==1.8.0.dev20201024+cu110
[pip3] torchvision==0.8.0.dev20201024+cu110
[conda] efficientnet-pytorch      0.6.3                    pypi_0    pypi
[conda] mkl                       2019.5                      281    conda-forge
[conda] mkl-service               2.3.0            py37h516909a_0    conda-forge
[conda] mkl_fft                   1.1.0            py37hc1659b7_1    conda-forge
[conda] mkl_random                1.1.0            py37hb3f55d8_0    conda-forge
[conda] numpy                     1.16.5           py37h95a1406_0    conda-forge
[conda] numpy-base                1.18.5           py37h2f8d375_0  
[conda] numpydoc                  1.1.0              pyh9f0ad1d_0    conda-forge
[conda] pytorch3d                 0.2.5                    pypi_0    pypi
[conda] segmentation-models-pytorch 0.1.2                    pypi_0    pypi
[conda] torch                     1.8.0.dev20201024+cu110          pypi_0    pypi
[conda] torchvision               0.8.0.dev20201024+cu110          pypi_0    pypi

cc @ezyang @gchanan @zou3519 @bdhirsh @albanD @gqchen @pearu @nikitaved

Author: Fantashit

1 thought on “INTERNAL ASSERT FAILED for `S.unique().shape`

  1. I’m also facing this issue with PyTorch1.7. Simple code to reproduce the bug:

    x1 = torch.rand(10, 3, requires_grad=True)
    torch.unique(x1, dim=0)

    This raises the following error:

    RuntimeError: isDifferentiableType(variable.scalar_type()) INTERNAL ASSERT FAILED at "..\\torch/csrc/autograd/functions/utils.h":64, please report a bug to PyTorch.
    

Comments are closed.