class_docstr: Contains the environment for the current dataloader within the current training process.
  
  Args:
      world_size: The number of dataloader workers for the current training process
      rank: The rank of the current worker within the number of workers
class_docstr_tok: ["Contains","the","environment","for","the","current","dataloader","within","the","current","training","process",".","Args",":","world_size",":","The","number","of","dataloader","workers","for","the","current","training","process","rank",":","The","rank","of","the","current","worker","within","the","number","of","workers"]
docstr: Automatically detects the number of workers and the current rank.
  
  Note:
      This only works reliably within a dataloader worker as otherwise the necessary information won't be present.
      In such a case it will default to 1 worker
docstr_tok: ["Automatically","detects","the","number","of","workers","and","the","current","rank",".","Note",":","This","only","works","reliably","within","a","dataloader","worker","as","otherwise","the","necessary","information","wo","n't","be","present",".","In","such","a","case","it","will","default","to","1","worker"]
code: def detect(
      cls, get_worker_info_fn: Optional[Callable] = None
  ) -> "_WorkerEnv":
      """Automatically detects the number of workers and the current rank.
  
      Note:
          This only works reliably within a dataloader worker as otherwise the necessary information won't be present.
          In such a case it will default to 1 worker
  
      """
      get_worker_info = get_worker_info_fn or torch_get_worker_info
      worker_info = get_worker_info()
      num_workers = (
          worker_info.num_workers if worker_info is not None else 1
      )
      current_worker_rank = (
          worker_info.id if worker_info is not None else 0
      )
  
      return cls(world_size=num_workers, rank=current_worker_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 _WorkerEnv obj's underlying member method code with example usage: obj.detect(cls, get_worker_info_fn) and returns: cls