Repository: pytorch
Issue: torch.unique acting up for a binary tensor
Labels: triaged,module: numpy,module: boolean tensor,module: correctness (silent),module: sorting and selection

## 🐛 Bug

weird and unexpected behavior for `torch.unique` on boolean arrays.

## To Reproduce

Steps to reproduce the behavior:

1. Download the `masks.pth` file here https://drive.google.com/file/d/1gF0HlLuvwrX665JoEX2z8dIAu9SupkQZ/view?usp=sharing
2. Run the following

```python
import torch
import numpy as np

t = torch.load("masks.pth")
print(torch.unique(t, return_counts=True))
print(torch.unique(~t, return_counts=True))
print(torch.unique(~(~t), return_counts=True))
print(torch.unique(torch.logical_not(t), return_counts=True))
print(torch.unique(t.type(torch.uint8), return_counts=True))
print(torch.unique(t.float(), return_counts=True))
print(np.unique(t.numpy(), return_counts=True))
```

The output is
```
(tensor([False,  True]), tensor([5425223,       0]))
(tensor([True, True]), tensor([5425223, 5425223]))
(tensor([False,  True]), tensor([5425223,       0]))
(tensor([True, True]), tensor([5425223, 5425223]))
(tensor([  0, 255], dtype=torch.uint8), tensor([5425223,   27577]))
(tensor([  0., 255.]), tensor([5425223,   27577]))
(array([False,  True]), array([5425223,   27577]))
```

## Expected behavior

I expect the first three lines to be
```
(tensor([False,  True]), tensor([5425223,       27577]))
(tensor([True, False]), tensor([5425223, 27577]))
(tensor([False,  True]), tensor([5425223,       27577]))
```

## Environment
```
PyTorch version: 1.9.0+cu102
Is debug build: False
CUDA used to build PyTorch: 10.2
ROCM used to build PyTorch: N/A

OS: Ubuntu 18.04.5 LTS (x86_64)
GCC version: (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
Clang version: Could not collect
CMake version: Could not collect
Libc version: glibc-2.10

Python version: 3.7.10 (default, Feb 26 2021, 18:47:35)  [GCC 7.3.0] (64-bit runtime)
Python platform: Linux-5.10.16.3-microsoft-standard-WSL2-x86_64-with-debian-buster-sid
Is CUDA available: False
CUDA runtime version: No CUDA
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
HIP runtime version: N/A
MIOpen runtime version: N/A

Versions of relevant libraries:
[pip3] mypy-extensions==0.4.3
[pip3] numpy==1.20.3
[pip3] torch==1.9.0
[pip3] torch-tb-profiler==0.2.1
[pip3] torchvision==0.10.0
[conda] blas                      1.0                         mkl  
[conda] cpuonly                   1.0                           0    pytorch
[conda] cudatoolkit               10.2.89              hfd86e86_1  
[conda] ffmpeg                    4.3                  hf484d3e_0    pytorch
[conda] mkl                       2021.3.0           h06a4308_520  
[conda] mkl-service               2.4.0            py37h7f8727e_0  
[conda] mkl_fft                   1.3.0            py37h42c9631_2  
[conda] mkl_random                1.2.2            py37h51133e4_0  
[conda] mypy_extensions           0.4.3                    py37_0  
[conda] numpy                     1.17.4                   pypi_0    pypi
[conda] numpy-base                1.20.3           py37h74d4b33_0  
[conda] torch                     1.7.0                    pypi_0    pypi
[conda] torch-tb-profiler         0.2.1                    pypi_0    pypi
[conda] torchvision               0.10.0                   pypi_0    pypi
```



cc @ezyang @gchanan @zou3519 @bdhirsh @jbschlosser @anjali411 @mruberry @rgommers @heitorschueroff