• Docs >
  • lightning.fabric.utilities
Shortcuts

lightning.fabric.utilities

lightning.fabric.utilities.seed.seed_everything(seed=None, workers=False)[source]

Function that sets seed for pseudo-random number generators in: pytorch, numpy, python.random In addition, sets the following environment variables:

  • PL_GLOBAL_SEED: will be passed to spawned subprocesses (e.g. ddp_spawn backend).

  • PL_SEED_WORKERS: (optional) is set to 1 if workers=True.

Parameters:
  • seed (Optional[int]) – the integer value seed for global random state in Lightning. If None, will read seed from PL_GLOBAL_SEED env variable or select it randomly.

  • workers (bool) – if set to True, will properly configure all dataloaders passed to the Trainer with a worker_init_fn. If the user already provides such a function for their dataloaders, setting this argument will have no influence. See also: pl_worker_init_function().

Return type:

int

lightning.fabric.utilities.seed.pl_worker_init_function(worker_id, rank=None)[source]

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.

Return type:

None

lightning.fabric.utilities.data.suggested_max_num_workers(local_world_size)[source]

Suggests an upper bound of num_workers to use in a PyTorch DataLoader based on the number of CPU cores available on the system and the number of distributed processes in the current machine.

Parameters:

local_world_size (int) – The number of distributed processes running on the current machine. Set this to the number of devices configured in Fabric/Trainer.

Return type:

int

lightning.fabric.utilities.distributed.is_shared_filesystem(strategy, path=None, timeout=3)[source]

Checks whether the filesystem under the given path is shared across all processes.

This function should only be used in a context where distributed is initialized.

Parameters:
  • strategy (Strategy) – The strategy being used, either from Fabric (fabric.strategy) or from Trainer (trainer.strategy).

  • path (Union[str, Path, None]) – The path to check. Defaults to the current working directory. The user must have permissions to write to this path or the parent folder, and the filesystem must be writable.

  • timeout (int) – If any of the processes can’t list the file created by rank 0 within this many seconds, the filesystem is determined to be not shared.

Return type:

bool

lightning.fabric.utilities.warnings.disable_possible_user_warnings(module='')[source]

Ignore warnings of the category PossibleUserWarning from Lightning.

For more granular control over which warnings to ignore, use warnings.filterwarnings() directly.

Parameters:

module (str) – Name of the module for which the warnings should be ignored (e.g., 'lightning.pytorch.strategies'). Default: Disables warnings from all modules.

Return type:

None