parameters: (self, set_to_zero=True)
docstring: Clear the gradients of all optimized parameters for model.
  
          If not, new gradient will accumulat on previous gradient.
  
          There are two method to clear grad: set_to_zero or delete grad.
          
          Args:
              set_to_zero (bool, optional): If set grads to zero or not, default is True.
          
          Returns:
              None
          
          Examples:
              .. code-block:: python
  
                  import numpy as np
                  import paddle
  
                  value = np.arange(26).reshape(2, 13).astype("float32")
                  a = paddle.to_tensor(value)
                  linear = paddle.nn.Linear(13, 5)
                  # This can be any optimizer supported by dygraph.
                  adam = paddle.optimizer.Adam(learning_rate = 0.01, 
                                              parameters = linear.parameters())
                  out = linear(a)
                  out.backward()
                  adam.step()
                  adam.clear_grad()
docstring_summary: Clear the gradients of all optimized parameters for model.
docstring_tokens: Clear the gradients of all optimized parameters for model .
function: def clear_grad(self, set_to_zero=True):
          """
          Clear the gradients of all optimized parameters for model.
  
          If not, new gradient will accumulat on previous gradient.
  
          There are two method to clear grad: set_to_zero or delete grad.
          
          Args:
              set_to_zero (bool, optional): If set grads to zero or not, default is True.
          
          Returns:
              None
          
          Examples:
              .. code-block:: python
  
                  import numpy as np
                  import paddle
  
                  value = np.arange(26).reshape(2, 13).astype("float32")
                  a = paddle.to_tensor(value)
                  linear = paddle.nn.Linear(13, 5)
                  # This can be any optimizer supported by dygraph.
                  adam = paddle.optimizer.Adam(learning_rate = 0.01, 
                                              parameters = linear.parameters())
                  out = linear(a)
                  out.backward()
                  adam.step()
                  adam.clear_grad()
  
          """
          param_list = []
          if self._parameter_list is None or not isinstance(
                  self._parameter_list[0], dict):
              for p in self._parameter_list:
                  if not p.stop_gradient:
                      param_list.append(p)
          else:
              for param_group in self._param_groups:
                  for p in param_group['params']:
                      if not p.stop_gradient:
                          param_list.append(p)
          core.clear_gradients(param_list, set_to_zero)
function_tokens: def clear_grad ( self , set_to_zero = True ) : param_list = [ ] if self . _parameter_list is None or not isinstance ( self . _parameter_list [ 0 ] , dict ) : for p in self . _parameter_list : if not p . stop_gradient : param_list . append ( p ) else : for param_group in self . _param_groups : for p in param_group [ 'params' ] : if not p . stop_gradient : param_list . append ( p ) core . clear_gradients ( param_list , set_to_zero )