DDPStrategy
- class lightning.pytorch.strategies.DDPStrategy(accelerator=None, parallel_devices=None, cluster_environment=None, checkpoint_io=None, precision_plugin=None, ddp_comm_state=None, ddp_comm_hook=None, ddp_comm_wrapper=None, model_averaging_period=None, process_group_backend=None, timeout=datetime.timedelta(seconds=1800), start_method='popen', **kwargs)[source]
Bases:
ParallelStrategy
Strategy for multi-process single-device training on one or multiple nodes.
- barrier(*args, **kwargs)[source]
Synchronizes all processes which blocks processes until the whole group enters this function.
- Parameters:
- Return type:
- broadcast(obj, src=0)[source]
Broadcasts an object to all processes.
- on_exception(exception)[source]
Called when the trainer execution is interrupted by an exception.
- Return type:
- optimizer_step(optimizer, closure, model=None, **kwargs)[source]
Performs the actual optimizer step.
- Parameters:
- Return type:
- reduce(tensor, group=None, reduce_op='mean')[source]
Reduces a tensor from several distributed processes to one aggregated tensor.
- Parameters:
tensor (
Tensor
) – the tensor to sync and reducegroup (
Optional
[Any
]) – the process group to gather results from. Defaults to all processes (world)reduce_op (
Union
[ReduceOp
,str
,None
]) – the reduction operation. Defaults to ‘mean’/’avg’. Can also be a string ‘sum’ to calculate the sum during reduction.
- Return type:
- Returns:
reduced value, except when the input was not a tensor the output remains is unchanged
- setup(trainer)[source]
Sets up the accelerator, plugins and initializes the optimizers (if needed).
- setup_environment()[source]
Setup any processes or distributed connections.
This is called before the LightningModule/DataModule setup hook which allows the user to access the accelerator environment before setup is complete.
- Return type:
- teardown()[source]
This method is called to teardown the training process.
It is the right place to release memory and free other resources.
- Return type:
- property is_distributed: bool
Legacy property kept for backwards compatibility.
- property root_device: device
Return the root device.