DistributedContext#
- class deepinv.distributed.DistributedContext(backend=None, cleanup=True, seed=None, seed_offset=True, deterministic=False, device_mode=None)[source]#
Bases:
objectContext manager for distributed computing.
- Handles:
Initialization/destruction of the process group (if
RANK/WORLD_SIZEenvironment variables exist)Backend choice: NCCL when one-GPU-per-process per node, else Gloo.
Device selection based on
LOCAL_RANKand visible GPUsSharding helpers and tiny communication helpers
- Parameters:
backend (str | None) – backend to use for distributed communication. If
None(default), automatically selects NCCL for GPU or Gloo for CPU.cleanup (bool) – whether to clean up the process group on exit. Default is
True.seed (int | None) – random seed for reproducible results. If provided, behavior depends on
seed_offset. Default isNone.seed_offset (bool) – whether to add rank offset to seed (each rank gets
seed + rank). Default isTrue. WhenTrue: each process uses a unique seed for diverse random sequences. WhenFalse: all processes share the same seed for synchronized randomness.deterministic (bool) – whether to use deterministic cuDNN operations. Default is
False.device_mode (str | None) – device selection mode. Options are
'cpu','gpu', orNonefor automatic. Default isNone.