prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Failing optim_wrapper due to missing Scaler argument
  When creating an optimizer and wrapping it via ``amp_handle.wrap_optimizer(optim)``, the handle [`calls the OptimWrapper`](https://github.com/NVIDIA/apex/blob/master/apex/amp/handle.py#L148), who wraps the optimizer and tries to instantiate a loss scaler per loss. 
  
  The `OptimWrapper` tries to [instantiate the loss-scaler without an argument](https://github.com/NVIDIA/apex/blob/master/apex/amp/opt.py#L16), but the loss-scaler [needs an argument `loss_scale`](https://github.com/NVIDIA/apex/blob/master/apex/amp/scaler.py#L28), which causes the whole wrapping process to fail.
  
  </issue>
  <code>
  [start of apex/amp/opt.py]
  1 import contextlib
  2 import logging
  3 import warnings
  4 
  5 from .scaler import LossScaler, master_params
  6 
  7 import numpy as np
  8 
  9 class OptimWrapper(object):
  10     def __init__(self, optimizer, amp_handle, num_loss):
  11         self._optimizer = optimizer
  12         self._amp_handle = amp_handle
  13         self._num_loss = num_loss
  14         self._loss_idx = 0
  15         self._skip_next = [False] * num_loss
  16         self._loss_scaler = [LossScaler() for _ in range(num_loss)]
  17 
  18     @contextlib.contextmanager
  19     def scale_loss(self, loss):
  20         if not self._amp_handle.is_active():
  21             yield loss
  22             return
  23 
  24         # When there are multiple losses per-optimizer, we need
  25         # to save out current grad accumulation, since we won't be
  26         # able to unscale this particulare loss once the grads are
  27         # all mixed together.
  28         cached_grads = []
  29         if self._loss_idx > 0:
  30             for p in master_params(self._optimizer):
  31                 if p.grad is not None:
  32                     cached_grads.append(p.grad.data.detach().clone())
  33                 else:
  34                     cached_grads.append(None)
  35             self._optimizer.zero_grad()
  36 
  37         loss_scale = self._cur_loss_scaler().loss_scale()
  38         yield loss * loss_scale
  39 
  40         self._cur_loss_scaler().clear_overflow_state()
  41         self._cur_loss_scaler().unscale(
  42             master_params(self._optimizer),
  43             master_params(self._optimizer),
  44             loss_scale)
  45         self._skip_next[self._loss_idx] = self._cur_loss_scaler().update_scale()
  46         self._loss_idx += 1
  47 
  48         if len(cached_grads) > 0:
  49             for p, cached_grad in zip(master_params(self._optimizer),
  50                                       cached_grads):
  51                 if cached_grad is not None:
  52                     p.grad.data.add_(cached_grad)
  53             cached_grads = []
  54 
  55     def _cur_loss_scaler(self):
  56         assert 0 <= self._loss_idx < self._num_loss
  57         return self._loss_scaler[self._loss_idx]
  58 
  59     def step(self, closure=None):
  60         if not self._amp_handle.is_active():
  61             return self._optimizer.step(closure=closure)
  62 
  63         self._loss_idx = 0
  64 
  65         for group in self._optimizer.param_groups:
  66             for p in group['params']:
  67                 self._amp_handle.remove_cache(p)
  68 
  69         if closure is not None:
  70             raise NotImplementedError(
  71                 'The `closure` argument is unsupported by the amp ' +
  72                 'optimizer wrapper.')
  73         if any(self._skip_next):
  74             logger = logging.getLogger('apex.amp')
  75             logger.info('Gradient overflow, skipping update')
  76             self._skip_next = [False] * self._num_loss
  77         else:
  78             return self._optimizer.step(closure=closure)
  79 
  80     # Forward any attribute lookups
  81     def __getattr__(self, attr):
  82         return getattr(self._optimizer, attr)
  83 
  84     # Forward all torch.optim.Optimizer methods
  85     def __getstate__(self):
  86         return self._optimizer.__getstate__()
  87 
  88     def __setstate__(self):
  89         return self._optimizer.__setstate__()
  90 
  91     def __repr__(self):
  92         return self._optimizer.__repr__()
  93 
  94     def state_dict(self):
  95         return self._optimizer.state_dict()
  96 
  97     def load_state_dict(self, state_dict):
  98         return self._optimizer.load_state_dict(state_dict)
  99 
  100     def zero_grad(self):
  101         return self._optimizer.zero_grad()
  102 
  103     def add_param_group(self, param_group):
  104         return self._optimizer.add_param_group(param_group)
  105
  [end of apex/amp/opt.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/apex/amp/opt.py b/apex/amp/opt.py
  --- a/apex/amp/opt.py
  +++ b/apex/amp/opt.py
  @@ -13,7 +13,7 @@
           self._num_loss = num_loss
           self._loss_idx = 0
           self._skip_next = [False] * num_loss
  -        self._loss_scaler = [LossScaler() for _ in range(num_loss)]
  +        self._loss_scaler = [LossScaler('dynamic') for _ in range(num_loss)]
   
       @contextlib.contextmanager
       def scale_loss(self, loss):
  
verification_info: {"golden_diff": "diff --git a/apex/amp/opt.py b/apex/amp/opt.py\n--- a/apex/amp/opt.py\n+++ b/apex/amp/opt.py\n@@ -13,7 +13,7 @@\n         self._num_loss = num_loss\n         self._loss_idx = 0\n         self._skip_next = [False] * num_loss\n-        self._loss_scaler = [LossScaler() for _ in range(num_loss)]\n+        self._loss_scaler = [LossScaler('dynamic') for _ in range(num_loss)]\n \n     @contextlib.contextmanager\n     def scale_loss(self, loss):\n", "issue": "Failing optim_wrapper due to missing Scaler argument\nWhen creating an optimizer and wrapping it via ``amp_handle.wrap_optimizer(optim)``, the handle [`calls the OptimWrapper`](https://github.com/NVIDIA/apex/blob/master/apex/amp/handle.py#L148), who wraps the optimizer and tries to instantiate a loss scaler per loss. \r\n\r\nThe `OptimWrapper` tries to [instantiate the loss-scaler without an argument](https://github.com/NVIDIA/apex/blob/master/apex/amp/opt.py#L16), but the loss-scaler [needs an argument `loss_scale`](https://github.com/NVIDIA/apex/blob/master/apex/amp/scaler.py#L28), which causes the whole wrapping process to fail.\n", "before_files": [{"content": "import contextlib\nimport logging\nimport warnings\n\nfrom .scaler import LossScaler, master_params\n\nimport numpy as np\n\nclass OptimWrapper(object):\n    def __init__(self, optimizer, amp_handle, num_loss):\n        self._optimizer = optimizer\n        self._amp_handle = amp_handle\n        self._num_loss = num_loss\n        self._loss_idx = 0\n        self._skip_next = [False] * num_loss\n        self._loss_scaler = [LossScaler() for _ in range(num_loss)]\n\n    @contextlib.contextmanager\n    def scale_loss(self, loss):\n        if not self._amp_handle.is_active():\n            yield loss\n            return\n\n        # When there are multiple losses per-optimizer, we need\n        # to save out current grad accumulation, since we won't be\n        # able to unscale this particulare loss once the grads are\n        # all mixed together.\n        cached_grads = []\n        if self._loss_idx > 0:\n            for p in master_params(self._optimizer):\n                if p.grad is not None:\n                    cached_grads.append(p.grad.data.detach().clone())\n                else:\n                    cached_grads.append(None)\n            self._optimizer.zero_grad()\n\n        loss_scale = self._cur_loss_scaler().loss_scale()\n        yield loss * loss_scale\n\n        self._cur_loss_scaler().clear_overflow_state()\n        self._cur_loss_scaler().unscale(\n            master_params(self._optimizer),\n            master_params(self._optimizer),\n            loss_scale)\n        self._skip_next[self._loss_idx] = self._cur_loss_scaler().update_scale()\n        self._loss_idx += 1\n\n        if len(cached_grads) > 0:\n            for p, cached_grad in zip(master_params(self._optimizer),\n                                      cached_grads):\n                if cached_grad is not None:\n                    p.grad.data.add_(cached_grad)\n            cached_grads = []\n\n    def _cur_loss_scaler(self):\n        assert 0 <= self._loss_idx < self._num_loss\n        return self._loss_scaler[self._loss_idx]\n\n    def step(self, closure=None):\n        if not self._amp_handle.is_active():\n            return self._optimizer.step(closure=closure)\n\n        self._loss_idx = 0\n\n        for group in self._optimizer.param_groups:\n            for p in group['params']:\n                self._amp_handle.remove_cache(p)\n\n        if closure is not None:\n            raise NotImplementedError(\n                'The `closure` argument is unsupported by the amp ' +\n                'optimizer wrapper.')\n        if any(self._skip_next):\n            logger = logging.getLogger('apex.amp')\n            logger.info('Gradient overflow, skipping update')\n            self._skip_next = [False] * self._num_loss\n        else:\n            return self._optimizer.step(closure=closure)\n\n    # Forward any attribute lookups\n    def __getattr__(self, attr):\n        return getattr(self._optimizer, attr)\n\n    # Forward all torch.optim.Optimizer methods\n    def __getstate__(self):\n        return self._optimizer.__getstate__()\n\n    def __setstate__(self):\n        return self._optimizer.__setstate__()\n\n    def __repr__(self):\n        return self._optimizer.__repr__()\n\n    def state_dict(self):\n        return self._optimizer.state_dict()\n\n    def load_state_dict(self, state_dict):\n        return self._optimizer.load_state_dict(state_dict)\n\n    def zero_grad(self):\n        return self._optimizer.zero_grad()\n\n    def add_param_group(self, param_group):\n        return self._optimizer.add_param_group(param_group)\n", "path": "apex/amp/opt.py"}]}