code: def zero_optim_grads(optim, set_to_none=True):
      """Sets the gradient of all optimized tensors to None.
  
      This is an optimization alternative to calling `optimizer.zero_grad()`
  
      Args:
          optim (torch.nn.Optimizer): The optimizer instance
              to zero parameter gradients.
          set_to_none (bool): Set gradients to None
              instead of calling `zero_grad()`which
              sets to 0.
      """
      if not set_to_none:
          optim.zero_grad()
          return
  
      for group in optim.param_groups:
          for param in group["params"]:
              param.grad = None
  
imports: import copy
  import math
  import warnings
  import torch
  from torch import nn
  import torch.nn.functional
label_desc: Use image node_id 1 for calling a global function with example usage: zero_optim_grads(optim, set_to_none) without return types