class_docstr: Helper class to simplify the handling of gradient buckets
class_docstr_tok: ["Helper","class","to","simplify","the","handling","of","gradient","buckets"]
docstr: Shrink the buffer to the size of the parameter gradients currently checked in, release the extra memory
docstr_tok: ["Shrink","the","buffer","to","the","size","of","the","parameter","gradients","currently","checked","in",",","release","the","extra","memory"]
code: def shrink(self) -> None:
      """
      Shrink the buffer to the size of the parameter gradients currently checked in, release the extra memory
      """
      assert (
          self.buffer.numel() > 0
      ), "Cannot shrink a collapsed bucket, please rebuild"
  
      self.buffer = self.buffer.resize_(self._fill).clone()
      self._fill = 0
      for p in self._params:
          self._add_grad_as_view(p)
  
      self._max_size = self._fill
  
imports: from typing import Any, Callable, List, Optional, Union
  import torch
label_desc: Use image node_id 10 for calling the GradBucket obj's underlying member method code with example usage: obj.shrink() without return types