Repository: pytorch
Issue: Gamma distribution returns some wrong extreme values 
Labels: module: numerical-stability,module: distributions,module: cuda,triaged

### 🐛 Describe the bug

Rarely (and maybe only with this parameters) and only on GPU, the gamma distribution returns ~2.225e-305 with an abnormal probability (it should sample it with a frequency of like 1e-30 not 1e-8).
Probably to be linked to: 
double | 64 bits | -1.7E+308 to +1.7E+308

Maybe this is caused by the cuda version installed being different to the one used to build torch.

```
import torch

assert torch.cuda.is_available()
torch.set_default_tensor_type("torch.cuda.DoubleTensor")

distrib = torch.distributions.Gamma(torch.tensor(0.05), torch.tensor(1 / 1000))
batch_size = 10000000
for _ in range(100):
    samples = distrib.sample((batch_size,))
    assert torch.all(samples > 1e-200), f"min {torch.min(samples)}"

```

### Versions

Collecting environment information...
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 20.04.3 LTS (x86_64)
GCC version: (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
Clang version: 10.0.0-4ubuntu1 
CMake version: version 3.16.3
Libc version: glibc-2.31

Python version: 3.9.5 (default, Jun  4 2021, 12:28:51)  [GCC 7.5.0] (64-bit runtime)
Python platform: Linux-5.11.0-46-generic-x86_64-with-glibc2.31
Is CUDA available: True
CUDA runtime version: 10.1.243
GPU models and configuration: GPU 0: GeForce GTX 1070
Nvidia driver version: 460.91.03
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A

Versions of relevant libraries:
[pip3] mypy-extensions==0.4.3
[pip3] numpy==1.21.0
[pip3] torch==1.9.0
[pip3] torchviz==0.0.2
[conda] mypy-extensions           0.4.3                    pypi_0    pypi
[conda] numpy                     1.21.0                   pypi_0    pypi
[conda] torch                     1.9.0                    pypi_0    pypi
[conda] torchviz                  0.0.2                    pypi_0    pypi


Also happening with the following VM:
 
### Versions
Collecting environment information...
PyTorch version: 1.10.0+cu102
Is debug build: False
CUDA used to build PyTorch: 10.2
ROCM used to build PyTorch: N/A

OS: Debian GNU/Linux 10 (buster) (x86_64)
GCC version: (Debian 8.3.0-6) 8.3.0
Clang version: Could not collect
CMake version: version 3.13.4
Libc version: glibc-2.10

Python version: 3.7.12 | packaged by conda-forge | (default, Oct 26 2021, 06:08:53)  [GCC 9.4.0] (64-bit runtime)
Python platform: Linux-4.19.0-18-cloud-amd64-x86_64-with-debian-10.11
Is CUDA available: True
CUDA runtime version: 11.4.152
GPU models and configuration: 
GPU 0: Tesla V100-SXM2-16GB
GPU 1: Tesla V100-SXM2-16GB
GPU 2: Tesla V100-SXM2-16GB
GPU 3: Tesla V100-SXM2-16GB

Nvidia driver version: 470.82.01
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A

Versions of relevant libraries:
[pip3] mypy-extensions==0.4.3
[pip3] numpy==1.21.0
[pip3] torch==1.10.0
[pip3] torchaudio==0.10.0
[pip3] torchvision==0.11.1+cu111
[pip3] torchviz==0.0.2
[conda] blas                      2.112                       mkl    conda-forge
[conda] blas-devel                3.9.0            12_linux64_mkl    conda-forge
[conda] cudatoolkit               11.1.1               h6406543_9    conda-forge
[conda] dlenv-pytorch-1-10-gpu    1.0.20211104     py37h0ee201a_0    file:///tmp/conda-pkgs
[conda] ffmpeg                    4.3                  hf484d3e_0    pytorch
[conda] libblas                   3.9.0            12_linux64_mkl    conda-forge
[conda] libcblas                  3.9.0            12_linux64_mkl    conda-forge
[conda] liblapack                 3.9.0            12_linux64_mkl    conda-forge
[conda] liblapacke                3.9.0            12_linux64_mkl    conda-forge
[conda] mkl                       2021.4.0           h8d4b97c_729    conda-forge
[conda] mkl-devel                 2021.4.0           ha770c72_730    conda-forge
[conda] mkl-include               2021.4.0           h8d4b97c_729    conda-forge
[conda] mypy_extensions           0.4.3            py37h89c1867_4    conda-forge
[conda] numpy                     1.21.0                   pypi_0    pypi
[conda] pytorch-mutex             1.0                        cuda    pytorch
[conda] torch                     1.10.0                   pypi_0    pypi
[conda] torchaudio                0.10.0                   pypi_0    pypi
[conda] torchvision               0.11.1+cu111             pypi_0    pypi
[conda] torchviz                  0.0.2                    pypi_0    pypi


cc @fritzo @neerajprad @alicanb @nikitaved @ngimel