We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[bug] pyro.distributions.InverseGamma.sample does not work on GPU
### Issue Description
`pyro.distributions.InverseGamma.sample` fails with the following error when its arguments are on the GPU:
```
RuntimeError: iter.device(arg).is_cuda() INTERNAL ASSERT FAILED at /pytorch/aten/src/ATen/native/cuda/Loops.cuh:197, please report a bug to PyTorch.
```

I think the problem is in `__init__`:
```python
    def __init__(self, concentration, rate, validate_args=None):
        base_dist = Gamma(concentration, rate)
        super().__init__(base_dist, PowerTransform(-1.0), validate_args=validate_args)
```
The argument to `PowerTransform` should probably be something like `-torch.ones_like(rate)`.

### Environment
Ubuntu 16.04, Python 3.7, PyTorch 1.4.0, Pyro 1.3.0

### Code Snippet
```python
>>> import torch
>>> from pyro.distributions import Gamma, InverseGamma, TransformedDistribution
>>> from pyro.distributions.transforms import PowerTransform
>>>
>>> concentration = torch.tensor(1.0).to("cuda")
>>> rate = torch.tensor(1.0).to("cuda")
>>> 
>>> # InverseGamma.sample fails with an error
>>> InverseGamma(concentration, rate).sample()
RuntimeError: iter.device(arg).is_cuda() INTERNAL ASSERT FAILED at /pytorch/aten/src/ATen/native/cuda/Loops.cuh:197, please report a bug to PyTorch.
>>> 
>>> # The equivalent TransformedDistribution is fine
>>> TransformedDistribution(
...     Gamma(concentration, rate),
...     PowerTransform(torch.tensor(-1.0).to("cuda")),
... ).sample()
tensor(0.5707, device='cuda:0')
```

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `pyro/distributions/inverse_gamma.py`
Content:
```
1 # Copyright (c) 2017-2019 Uber Technologies, Inc.
2 # SPDX-License-Identifier: Apache-2.0
3 
4 from torch.distributions import constraints
5 from torch.distributions.transforms import PowerTransform
6 from pyro.distributions.torch import Gamma, TransformedDistribution
7 
8 
9 class InverseGamma(TransformedDistribution):
10     r"""
11     Creates an inverse-gamma distribution parameterized by
12     `concentration` and `rate`.
13 
14         X ~ Gamma(concentration, rate)
15         Y = 1/X ~ InverseGamma(concentration, rate)
16 
17     :param torch.Tensor concentration: the concentration parameter (i.e. alpha).
18     :param torch.Tensor rate: the rate parameter (i.e. beta).
19     """
20     arg_constraints = {'concentration': constraints.positive, 'rate': constraints.positive}
21     support = constraints.positive
22     has_rsample = True
23 
24     def __init__(self, concentration, rate, validate_args=None):
25         base_dist = Gamma(concentration, rate)
26         super().__init__(base_dist, PowerTransform(-1.0), validate_args=validate_args)
27 
28     def expand(self, batch_shape, _instance=None):
29         new = self._get_checked_instance(InverseGamma, _instance)
30         return super().expand(batch_shape, _instance=new)
31 
32     @property
33     def concentration(self):
34         return self.base_dist.concentration
35 
36     @property
37     def rate(self):
38         return self.base_dist.rate
39
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/pyro/distributions/inverse_gamma.py b/pyro/distributions/inverse_gamma.py
--- a/pyro/distributions/inverse_gamma.py
+++ b/pyro/distributions/inverse_gamma.py
@@ -23,7 +23,8 @@
 
     def __init__(self, concentration, rate, validate_args=None):
         base_dist = Gamma(concentration, rate)
-        super().__init__(base_dist, PowerTransform(-1.0), validate_args=validate_args)
+        super().__init__(base_dist, PowerTransform(-base_dist.rate.new_ones(())),
+                         validate_args=validate_args)
 
     def expand(self, batch_shape, _instance=None):
         new = self._get_checked_instance(InverseGamma, _instance)

{"golden_diff": "diff --git a/pyro/distributions/inverse_gamma.py b/pyro/distributions/inverse_gamma.py\n--- a/pyro/distributions/inverse_gamma.py\n+++ b/pyro/distributions/inverse_gamma.py\n@@ -23,7 +23,8 @@\n \n     def __init__(self, concentration, rate, validate_args=None):\n         base_dist = Gamma(concentration, rate)\n-        super().__init__(base_dist, PowerTransform(-1.0), validate_args=validate_args)\n+        super().__init__(base_dist, PowerTransform(-base_dist.rate.new_ones(())),\n+                         validate_args=validate_args)\n \n     def expand(self, batch_shape, _instance=None):\n         new = self._get_checked_instance(InverseGamma, _instance)\n", "issue": "[bug] pyro.distributions.InverseGamma.sample does not work on GPU\n### Issue Description\r\n`pyro.distributions.InverseGamma.sample` fails with the following error when its arguments are on the GPU:\r\n```\r\nRuntimeError: iter.device(arg).is_cuda() INTERNAL ASSERT FAILED at /pytorch/aten/src/ATen/native/cuda/Loops.cuh:197, please report a bug to PyTorch.\r\n```\r\n\r\nI think the problem is in `__init__`:\r\n```python\r\n    def __init__(self, concentration, rate, validate_args=None):\r\n        base_dist = Gamma(concentration, rate)\r\n        super().__init__(base_dist, PowerTransform(-1.0), validate_args=validate_args)\r\n```\r\nThe argument to `PowerTransform` should probably be something like `-torch.ones_like(rate)`.\r\n\r\n### Environment\r\nUbuntu 16.04, Python 3.7, PyTorch 1.4.0, Pyro 1.3.0\r\n\r\n### Code Snippet\r\n```python\r\n>>> import torch\r\n>>> from pyro.distributions import Gamma, InverseGamma, TransformedDistribution\r\n>>> from pyro.distributions.transforms import PowerTransform\r\n>>>\r\n>>> concentration = torch.tensor(1.0).to(\"cuda\")\r\n>>> rate = torch.tensor(1.0).to(\"cuda\")\r\n>>> \r\n>>> # InverseGamma.sample fails with an error\r\n>>> InverseGamma(concentration, rate).sample()\r\nRuntimeError: iter.device(arg).is_cuda() INTERNAL ASSERT FAILED at /pytorch/aten/src/ATen/native/cuda/Loops.cuh:197, please report a bug to PyTorch.\r\n>>> \r\n>>> # The equivalent TransformedDistribution is fine\r\n>>> TransformedDistribution(\r\n...     Gamma(concentration, rate),\r\n...     PowerTransform(torch.tensor(-1.0).to(\"cuda\")),\r\n... ).sample()\r\ntensor(0.5707, device='cuda:0')\r\n```\n", "before_files": [{"content": "# Copyright (c) 2017-2019 Uber Technologies, Inc.\n# SPDX-License-Identifier: Apache-2.0\n\nfrom torch.distributions import constraints\nfrom torch.distributions.transforms import PowerTransform\nfrom pyro.distributions.torch import Gamma, TransformedDistribution\n\n\nclass InverseGamma(TransformedDistribution):\n    r\"\"\"\n    Creates an inverse-gamma distribution parameterized by\n    `concentration` and `rate`.\n\n        X ~ Gamma(concentration, rate)\n        Y = 1/X ~ InverseGamma(concentration, rate)\n\n    :param torch.Tensor concentration: the concentration parameter (i.e. alpha).\n    :param torch.Tensor rate: the rate parameter (i.e. beta).\n    \"\"\"\n    arg_constraints = {'concentration': constraints.positive, 'rate': constraints.positive}\n    support = constraints.positive\n    has_rsample = True\n\n    def __init__(self, concentration, rate, validate_args=None):\n        base_dist = Gamma(concentration, rate)\n        super().__init__(base_dist, PowerTransform(-1.0), validate_args=validate_args)\n\n    def expand(self, batch_shape, _instance=None):\n        new = self._get_checked_instance(InverseGamma, _instance)\n        return super().expand(batch_shape, _instance=new)\n\n    @property\n    def concentration(self):\n        return self.base_dist.concentration\n\n    @property\n    def rate(self):\n        return self.base_dist.rate\n", "path": "pyro/distributions/inverse_gamma.py"}], "after_files": [{"content": "# Copyright (c) 2017-2019 Uber Technologies, Inc.\n# SPDX-License-Identifier: Apache-2.0\n\nfrom torch.distributions import constraints\nfrom torch.distributions.transforms import PowerTransform\nfrom pyro.distributions.torch import Gamma, TransformedDistribution\n\n\nclass InverseGamma(TransformedDistribution):\n    r\"\"\"\n    Creates an inverse-gamma distribution parameterized by\n    `concentration` and `rate`.\n\n        X ~ Gamma(concentration, rate)\n        Y = 1/X ~ InverseGamma(concentration, rate)\n\n    :param torch.Tensor concentration: the concentration parameter (i.e. alpha).\n    :param torch.Tensor rate: the rate parameter (i.e. beta).\n    \"\"\"\n    arg_constraints = {'concentration': constraints.positive, 'rate': constraints.positive}\n    support = constraints.positive\n    has_rsample = True\n\n    def __init__(self, concentration, rate, validate_args=None):\n        base_dist = Gamma(concentration, rate)\n        super().__init__(base_dist, PowerTransform(-base_dist.rate.new_ones(())),\n                         validate_args=validate_args)\n\n    def expand(self, batch_shape, _instance=None):\n        new = self._get_checked_instance(InverseGamma, _instance)\n        return super().expand(batch_shape, _instance=new)\n\n    @property\n    def concentration(self):\n        return self.base_dist.concentration\n\n    @property\n    def rate(self):\n        return self.base_dist.rate\n", "path": "pyro/distributions/inverse_gamma.py"}]}