class_docstr: Collective operations using `torch.distributed <https://pytorch.org/docs/stable/distributed.html>`__.
  
  .. warning:: This is an :ref:`experimental <versioning:Experimental API>` feature which is still in development.
class_docstr_tok: ["Collective","operations","using","`","torch.distributed","<","https",":","\/\/pytorch.org\/docs\/stable\/distributed.html",">","`","__",".","..","warning",":",":","This","is","an",":","ref",":","`","experimental","<","versioning",":","Experimental","API",">","`","feature","which","is","still","in","development","."]
code: def teardown(self) -> Self:
      group_member = self.group != dist.GroupMember.NON_GROUP_MEMBER
      super().teardown()  # will destroy its own group
      # try to destroy the default group. this should only be done by a group member to avoid race conditions,
      # and only if the class is managing it
      if (
          group_member
          and TorchCollective.manages_default_group
          and (default_group := dist.GroupMember.WORLD)
          is not None  # not destroyed already
          and len(dist.distributed_c10d._pg_map)
          == 1  # only the default group is left
      ):
          self.destroy_group(default_group)
          TorchCollective.manages_default_group = False
      elif (
          TorchCollective.manages_default_group
          and dist.GroupMember.WORLD is None
      ):
          TorchCollective.manages_default_group = False
      return self
  
imports: import datetime
  import os
  from typing import Any, List, Optional, Union
  import torch
  import torch.distributed
  from torch import Tensor
  from typing_extensions import Self, override
  from lightning.fabric.plugins.collectives.collective import Collective
  from lightning.fabric.utilities.imports import _TORCH_GREATER_EQUAL_1_13
  from lightning.fabric.utilities.types import CollectibleGroup, RedOpType, ReduceOp
label_desc: Use image node_id 22 for calling the TorchCollective obj's underlying member method code with example usage: obj.teardown() and returns: self