prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <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')
  ```
  
  </issue>
  <code>
  [start of pyro/distributions/inverse_gamma.py]
  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 of pyro/distributions/inverse_gamma.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: 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)
  
verification_info: {"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"}]}