docstr: Flush content of the bucket.
docstr_tok: ["Flush","content","of","the","bucket","."]
code: def flush(self) -> None:
      """Flush content of the bucket."""
      if self.offset == 0:
          assert len(self.callbacks) == 0
          return
      # reduce-scatter bucket
      if (
          hasattr(dist, "_reduce_scatter_base")
          and enable_nccl_base_collectives
      ):
          dist._reduce_scatter_base(
              self.output_shard[: self.offset],
              self.buffer[:, : self.offset].contiguous(),
              group=self.group,
          )
      else:
          dist.reduce_scatter(
              self.output_shard[: self.offset],
              list(self.buffer[:, : self.offset].unbind(0)),
              group=self.group,
          )
      # execute post-reduction callbacks
      for callback_fn in self.callbacks:
          callback_fn()
      # reuse input bucket but allocate a fresh output shard
      self.buffer[:, : self.offset].zero_()
      self.offset = 0
      self.callbacks.clear()
      self.output_shard = torch.zeros_like(self.buffer[0])
  
file_path: ColossalAI/colossalai/legacy/zero/sharded_model/reduce_scatter.py
imports: import functools
  import os
  from typing import Callable, Dict, List, Optional, Tuple
  import torch
  import torch.distributed
  from torch import Tensor
  from torch.distributed import ProcessGroup
label_desc: Use image node_id 2 for calling the Bucket obj's underlying member method code with example usage: obj.flush() without return types