code: def pl_worker_init_function(
      worker_id: int, rank: Optional[int] = None
  ) -> None:  # pragma: no cover
      r"""The worker_init_fn that Lightning automatically adds to your dataloader if you previously set the seed with
      ``seed_everything(seed, workers=True)``.
  
      See also the PyTorch documentation on
      `randomness in DataLoaders <https://pytorch.org/docs/stable/notes/randomness.html#dataloader>`_.
  
      """
      # implementation notes: https://github.com/pytorch/pytorch/issues/5059#issuecomment-817392562
      global_rank = rank if rank is not None else rank_zero_only.rank
      process_seed = torch.initial_seed()
      # back out the base seed so we can use all the bits
      base_seed = process_seed - worker_id
      log.debug(
          f"Initializing random number generators of process {global_rank} worker {worker_id} with base seed {base_seed}"
      )
      ss = np.random.SeedSequence([base_seed, worker_id, global_rank])
      # use 128 bits (4 x 32-bit words)
      np.random.seed(ss.generate_state(4))
      # Spawn distinct SeedSequences for the PyTorch PRNG and the stdlib random module
      torch_ss, stdlib_ss = ss.spawn(2)
      torch.manual_seed(torch_ss.generate_state(1, dtype=np.uint64)[0])
      # use 128 bits expressed as an integer
      stdlib_seed = (
          stdlib_ss.generate_state(2, dtype=np.uint64).astype(object)
          * [1 << 64, 1]
      ).sum()
      random.seed(stdlib_seed)
  
file_path: pytorch-lightning/src/lightning/fabric/utilities/seed.py
imports: import logging
  import os
  import random
  from random import getstate
  from random import setstate
  from typing import Any, Dict, Optional
  import numpy
  import torch
  from lightning.fabric.utilities.rank_zero import _get_rank, rank_prefixed_message, rank_zero_only, rank_zero_warn
label_desc: Use image node_id 3 for calling a global function with example usage: pl_worker_init_function(worker_id, rank) without return types