prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Using print_nan_grads in the Trainer results in an error
  **Describe the bug**
  When using 
  ```
  print_nan_grads=True
  ```
  in the Trainer, I am getting the error below.
  
  trainer.fit(lstm_model)
    File "/Users/anaconda3/envs/snorkel/lib/python3.6/site-packages/pytorch_lightning/trainer/trainer.py", line 364, in fit
      self.run_pretrain_routine(model)
    File "/Users/anaconda3/envs/snorkel/lib/python3.6/site-packages/pytorch_lightning/trainer/trainer.py", line 471, in run_pretrain_routine
      self.train()
    File "/Users/anaconda3/envs/snorkel/lib/python3.6/site-packages/pytorch_lightning/trainer/train_loop_mixin.py", line 60, in train
      self.run_training_epoch()
    File "/Users/anaconda3/envs/snorkel/lib/python3.6/site-packages/pytorch_lightning/trainer/train_loop_mixin.py", line 99, in run_training_epoch
      output = self.run_training_batch(batch, batch_nb)
    File "/Users/anaconda3/envs/snorkel/lib/python3.6/site-packages/pytorch_lightning/trainer/train_loop_mixin.py", line 219, in run_training_batch
      self.print_nan_gradients()
    File "/Users/anaconda3/envs/snorkel/lib/python3.6/site-packages/pytorch_lightning/trainer/training_tricks_mixin.py", line 16, in print_nan_gradients
      if torch.isnan(param.grad.float()).any():
  AttributeError: 'NoneType' object has no attribute 'float'
  
  **To Reproduce**
  Steps to reproduce the behavior:
  If some param object, does not have **.grad**, then that object should not be checked for nans
  
  
  </issue>
  <code>
  [start of pytorch_lightning/trainer/training_tricks_mixin.py]
  1 import torch
  2 import logging
  3 from pytorch_lightning.callbacks import GradientAccumulationScheduler
  4 
  5 
  6 class TrainerTrainingTricksMixin(object):
  7 
  8     def clip_gradients(self):
  9         if self.gradient_clip_val > 0:
  10             model = self.get_model()
  11             torch.nn.utils.clip_grad_norm_(model.parameters(), self.gradient_clip_val)
  12 
  13     def print_nan_gradients(self):
  14         model = self.get_model()
  15         for param in model.parameters():
  16             if torch.isnan(param.grad.float()).any():
  17                 logging.info(param, param.grad)
  18 
  19     def configure_accumulated_gradients(self, accumulate_grad_batches):
  20         self.accumulate_grad_batches = None
  21 
  22         if isinstance(accumulate_grad_batches, dict):
  23             self.accumulation_scheduler = GradientAccumulationScheduler(accumulate_grad_batches)
  24         elif isinstance(accumulate_grad_batches, int):
  25             schedule = {1: accumulate_grad_batches}
  26             self.accumulation_scheduler = GradientAccumulationScheduler(schedule)
  27         else:
  28             raise TypeError("Gradient accumulation supports only int and dict types")
  29
  [end of pytorch_lightning/trainer/training_tricks_mixin.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/pytorch_lightning/trainer/training_tricks_mixin.py b/pytorch_lightning/trainer/training_tricks_mixin.py
  --- a/pytorch_lightning/trainer/training_tricks_mixin.py
  +++ b/pytorch_lightning/trainer/training_tricks_mixin.py
  @@ -13,7 +13,7 @@
       def print_nan_gradients(self):
           model = self.get_model()
           for param in model.parameters():
  -            if torch.isnan(param.grad.float()).any():
  +            if (param.grad is not None) and torch.isnan(param.grad.float()).any():
                   logging.info(param, param.grad)
   
       def configure_accumulated_gradients(self, accumulate_grad_batches):
  
verification_info: {"golden_diff": "diff --git a/pytorch_lightning/trainer/training_tricks_mixin.py b/pytorch_lightning/trainer/training_tricks_mixin.py\n--- a/pytorch_lightning/trainer/training_tricks_mixin.py\n+++ b/pytorch_lightning/trainer/training_tricks_mixin.py\n@@ -13,7 +13,7 @@\n     def print_nan_gradients(self):\n         model = self.get_model()\n         for param in model.parameters():\n-            if torch.isnan(param.grad.float()).any():\n+            if (param.grad is not None) and torch.isnan(param.grad.float()).any():\n                 logging.info(param, param.grad)\n \n     def configure_accumulated_gradients(self, accumulate_grad_batches):\n", "issue": "Using print_nan_grads in the Trainer results in an error\n**Describe the bug**\r\nWhen using \r\n```\r\nprint_nan_grads=True\r\n```\r\nin the Trainer, I am getting the error below.\r\n\r\ntrainer.fit(lstm_model)\r\n  File \"/Users/anaconda3/envs/snorkel/lib/python3.6/site-packages/pytorch_lightning/trainer/trainer.py\", line 364, in fit\r\n    self.run_pretrain_routine(model)\r\n  File \"/Users/anaconda3/envs/snorkel/lib/python3.6/site-packages/pytorch_lightning/trainer/trainer.py\", line 471, in run_pretrain_routine\r\n    self.train()\r\n  File \"/Users/anaconda3/envs/snorkel/lib/python3.6/site-packages/pytorch_lightning/trainer/train_loop_mixin.py\", line 60, in train\r\n    self.run_training_epoch()\r\n  File \"/Users/anaconda3/envs/snorkel/lib/python3.6/site-packages/pytorch_lightning/trainer/train_loop_mixin.py\", line 99, in run_training_epoch\r\n    output = self.run_training_batch(batch, batch_nb)\r\n  File \"/Users/anaconda3/envs/snorkel/lib/python3.6/site-packages/pytorch_lightning/trainer/train_loop_mixin.py\", line 219, in run_training_batch\r\n    self.print_nan_gradients()\r\n  File \"/Users/anaconda3/envs/snorkel/lib/python3.6/site-packages/pytorch_lightning/trainer/training_tricks_mixin.py\", line 16, in print_nan_gradients\r\n    if torch.isnan(param.grad.float()).any():\r\nAttributeError: 'NoneType' object has no attribute 'float'\r\n\r\n**To Reproduce**\r\nSteps to reproduce the behavior:\r\nIf some param object, does not have **.grad**, then that object should not be checked for nans\r\n\n", "before_files": [{"content": "import torch\nimport logging\nfrom pytorch_lightning.callbacks import GradientAccumulationScheduler\n\n\nclass TrainerTrainingTricksMixin(object):\n\n    def clip_gradients(self):\n        if self.gradient_clip_val > 0:\n            model = self.get_model()\n            torch.nn.utils.clip_grad_norm_(model.parameters(), self.gradient_clip_val)\n\n    def print_nan_gradients(self):\n        model = self.get_model()\n        for param in model.parameters():\n            if torch.isnan(param.grad.float()).any():\n                logging.info(param, param.grad)\n\n    def configure_accumulated_gradients(self, accumulate_grad_batches):\n        self.accumulate_grad_batches = None\n\n        if isinstance(accumulate_grad_batches, dict):\n            self.accumulation_scheduler = GradientAccumulationScheduler(accumulate_grad_batches)\n        elif isinstance(accumulate_grad_batches, int):\n            schedule = {1: accumulate_grad_batches}\n            self.accumulation_scheduler = GradientAccumulationScheduler(schedule)\n        else:\n            raise TypeError(\"Gradient accumulation supports only int and dict types\")\n", "path": "pytorch_lightning/trainer/training_tricks_mixin.py"}]}