class_docstr: A wrapper around ProcessGroup that allows collectives to be issued in a
  consistent fashion regardless of the following scenarios:
  
      pg is None, distributed is initialized:     use WORLD as pg
      pg is None, distributed is not initialized: single process app
      pg is not None:                             use pg
class_docstr_tok: ["A","wrapper","around","ProcessGroup","that","allows","collectives","to","be","issued","in","a","consistent","fashion","regardless","of","the","following","scenarios",":","pg","is","None",",","distributed","is","initialized",":","use","WORLD","as","pg","pg","is","None",",","distributed","is","not","initialized",":","single","process","app","pg","is","not","None",":","use","pg"]
code: def __init__(self, pg: Optional[dist.ProcessGroup]) -> None:
      if pg is None and dist.is_available() and dist.is_initialized():
          self.pg: Optional[dist.ProcessGroup] = dist.group.WORLD
      else:
          self.pg: Optional[dist.ProcessGroup] = pg
  
imports: import os
  import tempfile
  from functools import wraps
  from typing import Any, Callable, cast, List, Optional, TypeVar, Union
  import torch
  import torch.distributed
  import torch.nn.functional
  from torch import Tensor
  from torch.distributed.elastic.utils.distributed import get_free_port
  from typing_extensions import Literal
label_desc: Use image node_id 1 to create a new PGWrapper object  with example: obj = PGWrapper(pg)