Repository: pyro-ppl/pyro

Issue:
[bug] MCMC run throws exception when using num_chains>1 as of Pyro 1.2.0.
### Issue Description

MCMC run throws exception when using num_chains>1 as of Pyro 1.2.0.  When num_chains is set to 1 the below code will execute in both Pyro 1.1.0 and Pyro 1.2.0. When num_chains is set to >1 the below code will execute in Pyro 1.1.0, but raises an AttributeException as of Pyro 1.2.0. 

```
AttributeError                            Traceback (most recent call last)
<ipython-input-13-5a1da811afef> in <module>()
      8 mcmc = MCMC(nuts_kernel, num_samples=25, warmup_steps=100, num_chains=cpu_count)
      9 
---> 10 mcmc.run(y)

~/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/pyro/poutine/messenger.py in _context_wrap(context, fn, *args, **kwargs)
      9 def _context_wrap(context, fn, *args, **kwargs):
     10     with context:
---> 11         return fn(*args, **kwargs)
     12 
     13 

~/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/pyro/infer/mcmc/api.py in run(self, *args, **kwargs)
    397 
    398         # transform samples back to constrained space
--> 399         for name, transform in self.transforms.items():
    400             z_acc[name] = transform.inv(z_acc[name])
    401         self._samples = z_acc

AttributeError: 'NoneType' object has no attribute 'items'
```

### Environment
- OS X and Python 3.6 / rhel fedora and Python 3.6
- PyTorch 1.4.0
- Pyro version
    - Throws error on 1.2.0
    - Does not throw error on 1.1.0

### Code Snippet
```python
import numpy as np

import torch
print(torch.__version__)
assert torch.__version__.startswith('1.4.0')

import pyro
import pyro.distributions as dist
from pyro.infer import MCMC, NUTS
print(pyro.__version__)
assert pyro.__version__.startswith('1.2.0') or pyro.__version__.startswith('1.1.0')

# set 
seed = 2020
pyro.set_rng_seed(seed)

def nrv(n=1000, loc=5, scale=2, seed=2020):
    np.random.seed(2020)
    z = np.random.normal(loc, scale, size=n)
    y = torch.from_numpy(z).type(torch.float)
    return y

def model(y):
    scale_guess = torch.tensor(20, dtype=torch.float)
    scale_prior = pyro.sample('scale', dist.HalfNormal(scale_guess))
    mean_guess = torch.tensor(0, dtype=torch.float)
    mean_prior = pyro.sample('loc', dist.Normal(mean_guess, scale_prior), obs=y)

def main(num_chains):
    nuts_kernel = NUTS(model, adapt_step_size=True)
    mcmc = MCMC(nuts_kernel, num_samples=25, warmup_steps=100, num_chains=chains)
    mcmc.run(y)

if __name__ == '__main__':
    main(1)
    main(2)
```




Discussion:

Resolving patch:
diff --git a/pyro/infer/mcmc/api.py b/pyro/infer/mcmc/api.py
--- a/pyro/infer/mcmc/api.py
+++ b/pyro/infer/mcmc/api.py
@@ -385,13 +385,15 @@ def run(self, *args, **kwargs):
         # If transforms is not explicitly provided, infer automatically using
         # model args, kwargs.
         if self.transforms is None:
-            if hasattr(self.kernel, 'transforms'):
-                if self.kernel.transforms is not None:
-                    self.transforms = self.kernel.transforms
+            # Use `kernel.transforms` when available
+            if hasattr(self.kernel, 'transforms') and self.kernel.transforms is not None:
+                self.transforms = self.kernel.transforms
+            # Else, get transforms from model (e.g. in multiprocessing).
             elif self.kernel.model:
                 _, _, self.transforms, _ = initialize_model(self.kernel.model,
                                                             model_args=args,
                                                             model_kwargs=kwargs)
+            # Assign default value
             else:
                 self.transforms = {}
 


Test patch: