class_docstr: Helper class to simplify the handling of gradient buckets
class_docstr_tok: ["Helper","class","to","simplify","the","handling","of","gradient","buckets"]
docstr: Add a new parameter gradient to the bucket. Param.grad becomes a view of this bucket buffer
docstr_tok: ["Add","a","new","parameter","gradient","to","the","bucket",".","Param.grad","becomes","a","view","of","this","bucket","buffer"]
code: def add_grad(self, param: torch.Tensor) -> None:
      """
      Add a new parameter gradient to the bucket. Param.grad becomes a view of this bucket buffer
      """
  
      assert (
          id(param) not in self._param_ids
      ), "The same gradients cannot be checked in twice"
  
      if param.grad is None:
          param.grad = torch.zeros_like(param)
  
      self._add_grad_as_view(param)
      self._params.append(param)
      self._param_ids.append(id(param))
  
imports: from typing import Any, Callable, List, Optional, Union
  import torch
label_desc: Use image node_id 7 for calling the GradBucket obj's underlying member method code with example usage: obj.add_grad(param) without return types