class_docstr: The environment of the distributed training.
  
  Args:
      world_size: The number of total distributed training processes
      global_rank: The rank of the current process within this pool of training processes
class_docstr_tok: ["The","environment","of","the","distributed","training",".","Args",":","world_size",":","The","number","of","total","distributed","training","processes","global_rank",":","The","rank","of","the","current","process","within","this","pool","of","training","processes"]
docstr: Tries to automatically detect the distributed environment paramters.
  
  Note:
      This detection may not work in processes spawned from the distributed processes (e.g. DataLoader workers)
      as the distributed framework won't be initialized there.
      It will default to 1 distributed process in this case.
docstr_tok: ["Tries","to","automatically","detect","the","distributed","environment","paramters",".","Note",":","This","detection","may","not","work","in","processes","spawned","from","the","distributed","processes","(","e.g",".","DataLoader","workers",")","as","the","distributed","framework","wo","n't","be","initialized","there",".","It","will","default","to","1","distributed","process","in","this","case","."]
code: def detect(cls) -> "_DistributedEnv":
      """Tries to automatically detect the distributed environment paramters.
  
      Note:
          This detection may not work in processes spawned from the distributed processes (e.g. DataLoader workers)
          as the distributed framework won't be initialized there.
          It will default to 1 distributed process in this case.
  
      """
      if (
          torch.distributed.is_available()
          and torch.distributed.is_initialized()
      ):
          world_size = torch.distributed.get_world_size()
          global_rank = torch.distributed.get_rank()
      else:
          world_size = None
          global_rank = 0
  
      if world_size is None or world_size == -1:
          world_size = 1
  
      return cls(world_size=world_size, global_rank=global_rank)
  
file_path: pytorch-lightning/src/lightning/data/utilities/env.py
imports: from typing import Callable, Optional
  import torch
  from torch.utils.data import get_worker_info
label_desc: Use image node_id 2 for calling the _DistributedEnv obj's underlying member method code with example usage: obj.detect(cls) and returns: cls