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 ifworkers=True.
- Parameters:
seed¶ (
Optional[int]) – the integer value seed for global random state in Lightning. IfNone, will read seed fromPL_GLOBAL_SEEDenv variable or select it randomly.workers¶ (
bool) – if set toTrue, will properly configure all dataloaders passed to the Trainer with aworker_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:
- 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:
- lightning.fabric.utilities.data.suggested_max_num_workers(local_world_size)[source]¶
Suggests an upper bound of
num_workersto use in a PyTorchDataLoaderbased on the number of CPU cores available on the system and the number of distributed processes in the current machine.
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:
- lightning.fabric.utilities.warnings.disable_possible_user_warnings(module='')[source]¶
Ignore warnings of the category
PossibleUserWarningfrom Lightning.For more granular control over which warnings to ignore, use
warnings.filterwarnings()directly.