Repository: pytorch
Issue: [docker] test_corrcoef_cpu_complex64 fails on CPU build
Labels: module: tests,triaged

### 🐛 Describe the bug

I'm building pytorch from sources out of curiosity and I noticed that several tests fail consistently across different platforms I'm using.

## Dockerfile

```Dockerfile
FROM ubuntu:18.04
RUN apt-get update && apt-get install -y --no-install-recommends \
        build-essential \
        ca-certificates \
        cmake \
        curl \
        libjpeg-dev \
        libpng-dev && \
    rm -rf /var/lib/apt/lists/*
ENV PATH /opt/conda/bin:$PATH

ENV INSTALL_CHANNEL pytorch
ENV PYTHON_VERSION 3.9
ENV PYTORCH_VERSION v1.10.2

RUN curl -fsSL -o ~/miniconda.sh -O https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh  && \
    chmod +x ~/miniconda.sh && \
    ~/miniconda.sh -b -p /opt/conda && \
    rm ~/miniconda.sh && \
    /opt/conda/bin/conda install -y python=${PYTHON_VERSION} conda-build pyyaml numpy ipython requests typing_extensions && \
    /opt/conda/bin/conda clean -ya

WORKDIR /opt/pytorch
RUN curl -fsSL -o pytorch.tar.gz https://github.com/pytorch/pytorch/releases/download/${PYTORCH_VERSION}/pytorch-${PYTORCH_VERSION}.tar.gz && tar xzf pytorch.tar.gz && rm pytorch.tar.gz

RUN cd pytorch-${PYTORCH_VERSION} && \
    echo ${PYTORCH_VERSION} | tail -c +2 > version.txt && \
    CMAKE_PREFIX_PATH="$(dirname $(which conda))/../" \
    USE_ROCM=0 USE_CUDA=0 \
    python setup.py install

ENV PATH /opt/conda/bin:$PATH
```

## Failed tests

Test command (inside a docker container)
```
$ python /opt/pytorch/pytorch-v1.11.0/test/test_torch.py
```

Test output

```
======================================================================
FAIL: test_corrcoef_cpu_complex64 (__main__.TestTorchDeviceTypeCPU)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/opt/conda/lib/python3.9/site-packages/torch/testing/_internal/common_device_type.py", line 376, in instantiated_test
    result = test(self, **param_kwargs)
  File "/opt/conda/lib/python3.9/site-packages/torch/testing/_internal/common_device_type.py", line 951, in only_fn
    return fn(self, *args, **kwargs)
  File "/opt/pytorch/pytorch-v1.11.0/test/test_torch.py", line 1745, in test_corrcoef
    self.assertEqual(res, ref, exact_dtype=False)
  File "/opt/conda/lib/python3.9/site-packages/torch/testing/_internal/common_utils.py", line 2121, in assertEqual
    assert_equal(
  File "/opt/conda/lib/python3.9/site-packages/torch/testing/_comparison.py", line 1080, in assert_equal
    raise error_metas[0].to_error()
AssertionError: Tensor-likes are not close!

Mismatched elements: 4 / 4 (100.0%)
Greatest absolute difference: nan at index (0, 1) (up to 1e-05 allowed)
Greatest relative difference: nan at index (0, 1) (up to 1.3e-06 allowed)


======================================================================
FAIL: test_cov_cpu_complex64 (__main__.TestTorchDeviceTypeCPU)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/opt/conda/lib/python3.9/site-packages/torch/testing/_internal/common_device_type.py", line 376, in instantiated_test
    result = test(self, **param_kwargs)
  File "/opt/pytorch/pytorch-v1.11.0/test/test_torch.py", line 1758, in test_cov
    check(x)
  File "/opt/pytorch/pytorch-v1.11.0/test/test_torch.py", line 1755, in check
    self.assertEqual(res, ref, atol=1e-05, rtol=1e-05, exact_dtype=False)
  File "/opt/conda/lib/python3.9/site-packages/torch/testing/_internal/common_utils.py", line 2121, in assertEqual
    assert_equal(
  File "/opt/conda/lib/python3.9/site-packages/torch/testing/_comparison.py", line 1080, in assert_equal
    raise error_metas[0].to_error()
AssertionError: Tensor-likes are not close!

Mismatched elements: 4 / 4 (100.0%)
Greatest absolute difference: 83.38657060851698 at index (1, 1) (up to 1e-05 allowed)
Greatest relative difference: 1.6077072050069752 at index (0, 0) (up to 1e-05 allowed)

----------------------------------------------------------------------
Ran 599 tests in 14.380s

FAILED (failures=2, skipped=90)
```

I'm not sure if I'm testing pytorch correctly. Following [this guide](https://github.com/pytorch/pytorch/blob/b7307687e9cee6689c8ad513939ac406221efd9a/CONTRIBUTING.md#unit-testing), I'm getting another issue:

```
$ python /opt/pytorch/pytorch-v1.11.0/test/run_test.py

======================================================================
FAIL: test_join_kwargs (__main__.TestJoin)
Tests passing keyword arguments to the context manager.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/opt/conda/lib/python3.9/site-packages/torch/testing/_internal/common_distributed.py", line 484, in wrapper
    self._join_processes(fn)
  File "/opt/conda/lib/python3.9/site-packages/torch/testing/_internal/common_distributed.py", line 703, in _join_processes
    self._check_return_codes(elapsed_time)
  File "/opt/conda/lib/python3.9/site-packages/torch/testing/_internal/common_distributed.py", line 758, in _check_return_codes
    self.assertEqual(
  File "/opt/conda/lib/python3.9/site-packages/torch/testing/_internal/common_utils.py", line 2121, in assertEqual
    assert_equal(
  File "/opt/conda/lib/python3.9/site-packages/torch/testing/_comparison.py", line 1080, in assert_equal
    raise error_metas[0].to_error()
AssertionError: Expect process 1 exit code to match Process 0 exit code of -6, but got 0

----------------------------------------------------------------------
Ran 9 tests in 10.582s

FAILED (failures=1)
Traceback (most recent call last):
  File "/opt/pytorch/pytorch-v1.11.0/test/run_test.py", line 1114, in <module>
    main()
  File "/opt/pytorch/pytorch-v1.11.0/test/run_test.py", line 1092, in main
    raise RuntimeError(err_message)
RuntimeError: distributed/algorithms/test_join failed!
```

### Versions

Tested v1.10.2 and v1.11.0.

```
$ python collect_env.py 

Collecting environment information...
PyTorch version: 1.11.0
Is debug build: False
CUDA used to build PyTorch: 10.2
ROCM used to build PyTorch: N/A

OS: Ubuntu 18.04.6 LTS (x86_64)
GCC version: (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
Clang version: Could not collect
CMake version: version 3.10.2
Libc version: glibc-2.27

Python version: 3.9.7 (default, Sep 16 2021, 13:09:58)  [GCC 7.5.0] (64-bit runtime)
Python platform: Linux-4.15.0-161-generic-x86_64-with-glibc2.27
Is CUDA available: False
CUDA runtime version: 10.2.89
GPU models and configuration: Could not collect
Nvidia driver version: Could not collect
cuDNN version: /usr/lib/x86_64-linux-gnu/libcudnn.so.7.6.5
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

Versions of relevant libraries:
[pip3] numpy==1.21.2
[pip3] torch==1.11.0+gitunknown
[conda] blas                      1.0                         mkl  
[conda] mkl                       2021.4.0           h06a4308_640  
[conda] mkl-service               2.4.0            py39h7f8727e_0  
[conda] mkl_fft                   1.3.1            py39hd3c417c_0  
[conda] mkl_random                1.2.2            py39h51133e4_0  
[conda] numpy                     1.21.2           py39h20f2e39_0  
[conda] numpy-base                1.21.2           py39h79a1101_0  
[conda] torch                     1.11.0+gitunknown          pypi_0    pypi
```

cc @mruberry