Repository: pytorch
Issue: `torch.distributions.Pareto.sample` sometimes gives `inf`
Labels: module: distributions,triaged,module: NaNs and Infs

### 🐛 Describe the bug

On my local checkout of PyTorch, the following script fails when it reaches `seed=6`:

```python
import torch

param = { 
    'scale': torch.tensor([
        [1.7549, 1.1252, 1.1057, 1.2407, 0.8933],
        [0.7661, 0.9723, 0.2869, 1.1382, 0.1948],
        [0.3116, 0.5687, 0.0172, 0.2296, 0.1637],
        [0.6526, 0.8761, 0.0142, 2.0804, 1.3138],
        [0.8522, 2.6757, 0.9873, 0.6828, 1.1830]],
        dtype=torch.double, requires_grad=True),
    'alpha': torch.tensor([
        [0.3219, 2.0156, 0.5705, 1.0555, 0.0485],
        [0.1138, 0.1064, 0.4582, 0.3166, 0.0073],
        [0.3978, 0.3402, 0.4575, 2.7605, 0.3148],
        [0.0442, 1.2770, 1.3061, 1.4474, 0.6836],
        [0.1606, 1.1500, 0.2150, 0.2591, 0.1284]],
        dtype=torch.double, requires_grad=True)
}

dist = torch.distributions.Pareto(**param)

for seed in range(100_000):
    torch.manual_seed(seed)
    print(seed)
    samples = dist.sample(sample_shape=(20,))

    assert not samples.isinf().any()
```

The reason I found this is that in my PR #107246, I modified the tests in `test/distributions/test_distributions.py` such that the `Pareto` distribution here gets regenerated for each of the unit tests, instead of just being generated once for all the tests:
https://github.com/pytorch/pytorch/blob/36399d067a56d9875fd9c2bf61434126398ffb87/test/distributions/test_distributions.py#L380-L383

This caused the [`test_cdf_icdf_inverse`](https://github.com/pytorch/pytorch/blob/36399d067a56d9875fd9c2bf61434126398ffb87/test/distributions/test_distributions.py#L2985) test to fail on just one CI job because an unlucky seed produced the `scale` and `alpha` values from the code snippet above and `Pareto.sample()` gave an output with infinities. Then when the infinities went through `dist.cdf` and `dist.icdf`, they turned into `nan`'s, causing comparisons to fail. So up to now, that test has not failed from this issue, just due to lucky seeds being used.

In my PR, I think have a workaround where I've added `0.1` to `scale` and `alpha` to try to get the test to pass, because values further from 0 are evidently less likely to produce infinities. So if that passes, this issue is not blocking my PR

### Versions

```
Collecting environment information...
PyTorch version: 2.1.0a0+git51d0d12
Is debug build: False
CUDA used to build PyTorch: 12.1
ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.2 LTS (x86_64)
GCC version: (conda-forge gcc 9.5.0-19) 9.5.0
Clang version: Could not collect
CMake version: version 3.21.3
Libc version: glibc-2.35

Python version: 3.9.7 | packaged by conda-forge | (default, Sep 29 2021, 19:23:11)  [GCC 9.4.0] (64-bit runtime)
Python platform: Linux-5.15.0-76-generic-x86_64-with-glibc2.35
Is CUDA available: True
CUDA runtime version: 12.1.66
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: 
GPU 0: NVIDIA GeForce RTX 2060
GPU 1: NVIDIA GeForce RTX 2060

Nvidia driver version: 530.30.02
cuDNN version: Probably one of the following:
/usr/local/cuda-11.7.1/targets/x86_64-linux/lib/libcudnn.so.8
/usr/local/cuda-11.7.1/targets/x86_64-linux/lib/libcudnn_adv_infer.so.8
/usr/local/cuda-11.7.1/targets/x86_64-linux/lib/libcudnn_adv_train.so.8
/usr/local/cuda-11.7.1/targets/x86_64-linux/lib/libcudnn_cnn_infer.so.8
/usr/local/cuda-11.7.1/targets/x86_64-linux/lib/libcudnn_cnn_train.so.8
/usr/local/cuda-11.7.1/targets/x86_64-linux/lib/libcudnn_ops_infer.so.8
/usr/local/cuda-11.7.1/targets/x86_64-linux/lib/libcudnn_ops_train.so.8
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture:                    x86_64
CPU op-mode(s):                  32-bit, 64-bit
Address sizes:                   43 bits physical, 48 bits virtual
Byte Order:                      Little Endian
CPU(s):                          64
On-line CPU(s) list:             0-63
Vendor ID:                       AuthenticAMD
Model name:                      AMD Ryzen Threadripper 3970X 32-Core Processor
CPU family:                      23
Model:                           49
Thread(s) per core:              2
Core(s) per socket:              32
Socket(s):                       1
Stepping:                        0
Frequency boost:                 enabled
CPU max MHz:                     3700.0000
CPU min MHz:                     2200.0000
BogoMIPS:                        7400.28
Flags:                           fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good nopl nonstop_tsc cpuid extd_apicid aperfmperf rapl pni pclmulqdq monitor ssse3 fma cx16 sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs skinit wdt tce topoext perfctr_core perfctr_nb bpext perfctr_llc mwaitx cpb cat_l3 cdp_l3 hw_pstate ssbd mba ibpb stibp vmmcall fsgsbase bmi1 avx2 smep bmi2 cqm rdt_a rdseed adx smap clflushopt clwb sha_ni xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local clzero irperf xsaveerptr rdpru wbnoinvd amd_ppin arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif v_spec_ctrl umip rdpid overflow_recov succor smca sme sev sev_es
Virtualization:                  AMD-V
L1d cache:                       1 MiB (32 instances)
L1i cache:                       1 MiB (32 instances)
L2 cache:                        16 MiB (32 instances)
L3 cache:                        128 MiB (8 instances)
NUMA node(s):                    1
NUMA node0 CPU(s):               0-63
Vulnerability Itlb multihit:     Not affected
Vulnerability L1tf:              Not affected
Vulnerability Mds:               Not affected
Vulnerability Meltdown:          Not affected
Vulnerability Mmio stale data:   Not affected
Vulnerability Retbleed:          Mitigation; untrained return thunk; SMT enabled with STIBP protection
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl and seccomp
Vulnerability Spectre v1:        Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:        Mitigation; Retpolines, IBPB conditional, STIBP always-on, RSB filling, PBRSB-eIBRS Not affected
Vulnerability Srbds:             Not affected
Vulnerability Tsx async abort:   Not affected

Versions of relevant libraries:
[pip3] flake8==6.0.0
[pip3] flake8-bugbear==23.3.23
[pip3] flake8-comprehensions==3.12.0
[pip3] flake8-executable==2.1.3
[pip3] flake8-logging-format==0.9.0
[pip3] flake8-pyi==23.3.1
[pip3] flake8-simplify==0.19.3
[pip3] mypy==1.4.1
[pip3] mypy-extensions==1.0.0
[pip3] numpy==1.24.3
[pip3] torch==2.1.0a0+gitb0bc323
[conda] magma-cuda117             2.6.1                         1    pytorch
[conda] mkl                       2023.2.0         h84fe81f_49572    conda-forge
[conda] mkl-include               2023.2.0         h84fe81f_49572    conda-forge
[conda] numpy                     1.24.3                   pypi_0    pypi
[conda] torch                     2.1.0a0+gitb0bc323           dev_0    <develop>
```

cc @fritzo @neerajprad @alicanb @nikitaved