Repository: pytorch
Issue: NotImplementedError in torch.distributions
Labels: module: distributions,triaged

### 🐛 Describe the bug

Hi! I am trying to build a gaussian mixture model and call the cdf function.
But I found that function `cdf` does not exist in the class `Independent`, although it may be used elsewhere, such as class `MixtureSameFamily`.

You may be able to reproduce this error with the following code.

```python
import numpy as np

import torch
import torch.distributions as D

num_layers = 5
weights = torch.ones(num_layers)
means = torch.tensor(np.random.randn(num_layers, 2))
stdevs = torch.tensor(np.abs(np.random.randn(num_layers, 2)))

mix = D.Categorical(weights)
comp = D.Independent(D.Normal(means, stdevs), 1)
gmm = D.MixtureSameFamily(mix, comp)

x = torch.rand((5000, 2))
probs = gmm.cdf(x)

```

The output will be
```
Traceback (most recent call last):
  File "test_d.py", line 16, in <module>
    probs = gmm.cdf(x)
  File "/home/jkhu29/anaconda3/envs/cv_env/lib/python3.7/site-packages/torch/distributions/mixture_same_family.py", line 141, in cdf
    cdf_x = self.component_distribution.cdf(x)
  File "/home/jkhu29/anaconda3/envs/cv_env/lib/python3.7/site-packages/torch/distributions/distribution.py", line 172, in cdf
    raise NotImplementedError
NotImplementedError
```

I found that in the code of class `MixtureSameFamily`, the cdf method is implemented as
```python
def cdf(self, x):
    x = self._pad(x)
    cdf_x = self.component_distribution.cdf(x)
    mix_prob = self.mixture_distribution.probs
    return torch.sum(cdf_x * mix_prob, dim=-1)
```
When `self.component_distribution` is class `Independent`, the above problem will occur.

Thank you very much for any help!

cc @fritzo @neerajprad @alicanb @nikitaved @svenstaro @eklitzke @dreiss @huitseeker @jfsantos 


### Versions

```
Collecting environment information...
PyTorch version: 1.8.0+cu111
Is debug build: False
CUDA used to build PyTorch: 11.1
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: Could not collect
CMake version: version 3.21.20210715-g769c539
Libc version: glibc-2.17

Python version: 3.7.11 (default, Jul 27 2021, 14:32:16)  [GCC 7.5.0] (64-bit runtime)
Python platform: Linux-5.8.0-63-generic-x86_64-with-debian-bullseye-sid
Is CUDA available: True
CUDA runtime version: 11.2.67
GPU models and configuration: GPU 0: GeForce RTX 3060 Laptop GPU
Nvidia driver version: 460.27.04
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A

Versions of relevant libraries:
[pip3] flashtorch==0.1.3
[pip3] mypy-extensions==0.4.3
[pip3] numpy==1.21.4
[pip3] pytorch-ranger==0.1.1
[pip3] torch==1.8.0+cu111
[pip3] torch-optimizer==0.3.0
[pip3] torch-tb-profiler==0.3.1
[pip3] torchsummary==1.5.1
[pip3] torchvision==0.9.0+cu111
[conda] flashtorch                0.1.3                     <pip>
[conda] mypy-extensions           0.4.3                     <pip>
[conda] numpy                     1.21.4                    <pip>
[conda] pytorch-ranger            0.1.1                     <pip>
[conda] torch                     1.8.0+cu111               <pip>
[conda] torch-optimizer           0.3.0                     <pip>
[conda] torch-tb-profiler         0.3.1                     <pip>
[conda] torchsummary              1.5.1                     <pip>
[conda] torchvision               0.9.0+cu111               <pip>

```