class_docstr: Helper class to simplify the handling of gradient buckets
class_docstr_tok: ["Helper","class","to","simplify","the","handling","of","gradient","buckets"]
docstr: Given the parameter gradients which have been registered previously, rebuild the whole bucket
docstr_tok: ["Given","the","parameter","gradients","which","have","been","registered","previously",",","rebuild","the","whole","bucket"]
code: def rebuild(self) -> None:
      """
      Given the parameter gradients which have been registered previously, rebuild the whole bucket
      """
      assert len(self._params) > 0
  
      if self._is_collapsed:
          self.buffer = torch.zeros(
              self._max_size,
              dtype=self._params[0].dtype,
              device=self._params[0].device,
          )
  
          for p in self._params:
              self._add_grad_as_view(p)
  
          self._is_collapsed = False
  
imports: from typing import Any, Callable, List, Optional, Union
  import torch
label_desc: Use image node_id 9 for calling the GradBucket obj's underlying member method code with example usage: obj.rebuild() without return types