Lightning-AI / Lightning-AI/pytorch-lightning

Consolidate collective functions

Open
#7,534 8 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

distributed feature let's do it! refactor
Dominant language
Python
Stars
31.4k
Forks
3.8k
Avg merge
6d 7h
Merged PRs (30d)
6

Description

🚀 Feature

Lightning should offer a central place to use the collective functions provided here: https://pytorch.org/docs/stable/distributed.html#collective-functions

Motivation

LightningModule code is usually agnostic to what device its running on or whether its running in a distributed training environment. However, there are times where the module does need to rely on collective functions.

In Lightning, we currently have many places where these are offered:

Some of these call each other and the dependency isn't very clear now, so it is confusing for users which to go through.

Pitch
  1. Offer these utilities under a central place: pytorch_lightning/utilities/collectives.py for these utilities:
    barrier, all_gather, broadcast, etc

These should be very thin wrappers over the PyTorch distributed functions, checking if torch.distributed is available and initialized. If not, we return what's expected for single-process training.

  1. Update the callsites internally to use to these implementations

  2. Mark existing functions as deprecated and slated for removal in v1.6

cc @borda @awaelchli @rohitgr7 @akihironitta @justusschock

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading pytorch_lightning/utilities/distributed.py, utilities/collectives.py as proposed, distributed/dist.py, accelerators/accelerator.py, plugins/training_type/training_type_plugin.py, and core/lightning.py. Trace the existing collective-function callsites and dependencies; done means centralized thin wrappers exist, internal callsites use them, and the old functions are deprecated for removal in v1.6.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
distributed-systems
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.