Skip to content

[AIR] <Part 1> Add LightningTrainer to support Pytorch Lightning DDP training. - #33161

Merged
gjoliver merged 19 commits into
ray-project:masterfrom
woshiyyya:air/lightning_base_trainer
Mar 15, 2023
Merged

[AIR] <Part 1> Add LightningTrainer to support Pytorch Lightning DDP training.#33161
gjoliver merged 19 commits into
ray-project:masterfrom
woshiyyya:air/lightning_base_trainer

Conversation

@woshiyyya

@woshiyyya woshiyyya commented Mar 9, 2023

Copy link
Copy Markdown
Member

Why are these changes needed?

There will be a list of PRs for PyTorch Lightning Integration. This is the first one.

  • LightningTrainer + Test
  • Logging and Checkpointing + Test
  • Predictor + Batch Prediction + Test
  • Integrate with Tune + Test

Content for this PR:

  • LightningTrainer Interface design
  • Support DDP Training
  • Examples and docstrings

Related issue number

Checks

  • I've signed off every commit(by using the -s flag, i.e., git commit -s) in this PR.
  • I've run scripts/format.sh to lint the changes in this PR.
  • I've included any doc changes needed for https://docs.ray.io/en/master/.
  • I've made sure the tests are passing. Note that there might be a few flaky tests, see the recent failures at https://flakey-tests.ray.io/
  • Testing Strategy
    • Unit tests
    • Release tests
    • This PR is not tested :(

Signed-off-by: woshiyyya <xiaoyunxuan1998@gmail.com>
Signed-off-by: woshiyyya <xiaoyunxuan1998@gmail.com>
@woshiyyya woshiyyya changed the title [AIR] Add LightningTrainer to support Pytorch Lightning DDP training. [AIR] <Part 1> Add LightningTrainer to support Pytorch Lightning DDP training. Mar 9, 2023
Signed-off-by: woshiyyya <xiaoyunxuan1998@gmail.com>
Signed-off-by: woshiyyya <xiaoyunxuan1998@gmail.com>
@woshiyyya
woshiyyya force-pushed the air/lightning_base_trainer branch from 14e3ee3 to 01f9461 Compare March 9, 2023 06:18
@woshiyyya
woshiyyya marked this pull request as ready for review March 9, 2023 17:08
Signed-off-by: woshiyyya <xiaoyunxuan1998@gmail.com>
Signed-off-by: woshiyyya <xiaoyunxuan1998@gmail.com>
@woshiyyya woshiyyya added air train Ray Train Related Issue labels Mar 9, 2023
Signed-off-by: woshiyyya <xiaoyunxuan1998@gmail.com>
Signed-off-by: woshiyyya <xiaoyunxuan1998@gmail.com>
Comment thread python/ray/train/lightning/_lightning_utils.py Outdated
Comment thread python/ray/train/lightning/__init__.py Outdated
Comment thread python/ray/train/lightning/_lightning_utils.py Outdated
Comment thread python/ray/train/lightning/_lightning_utils.py Outdated
Comment thread python/ray/train/lightning/_lightning_utils.py
Comment thread python/ray/train/lightning/lightning_trainer.py
Comment thread python/ray/train/lightning/lightning_trainer.py
Comment thread python/ray/train/lightning/lightning_trainer.py Outdated
Comment thread python/ray/train/tests/_lightning_utils.py
Comment thread python/ray/train/tests/test_lightning_trainer.py
@amogkam

amogkam commented Mar 11, 2023

Copy link
Copy Markdown
Contributor

great work @woshiyyya!

@justinvyu justinvyu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks very good!

Comment thread python/ray/train/lightning/_lightning_utils.py Outdated
Comment thread python/ray/train/lightning/_lightning_utils.py Outdated
Comment thread python/ray/train/lightning/lightning_trainer.py Outdated
Comment thread python/ray/train/lightning/lightning_trainer.py
Comment thread python/ray/train/lightning/lightning_trainer.py Outdated
Comment thread python/ray/train/lightning/lightning_trainer.py Outdated
Comment thread python/ray/train/lightning/lightning_trainer.py
Comment thread python/ray/train/lightning/lightning_trainer.py
Comment thread python/ray/train/lightning/lightning_trainer.py Outdated
Comment thread python/ray/train/tests/test_lightning_trainer.py Outdated
Comment thread python/ray/train/lightning/_lightning_utils.py
Comment thread python/ray/train/lightning/_lightning_utils.py
Comment thread python/ray/train/lightning/lightning_trainer.py Outdated
Comment thread python/ray/train/lightning/lightning_trainer.py Outdated
Comment thread python/ray/train/tests/_lightning_utils.py
woshiyyya and others added 2 commits March 12, 2023 19:01
Co-authored-by: Amog Kamsetty <amogkam@users.noreply.github.com>
Co-authored-by: Justin Yu <justinvyu@anyscale.com>
Signed-off-by: Yunxuan Xiao <xiaoyunxuan1998@gmail.com>
Signed-off-by: woshiyyya <xiaoyunxuan1998@gmail.com>
Signed-off-by: woshiyyya <xiaoyunxuan1998@gmail.com>
Signed-off-by: woshiyyya <xiaoyunxuan1998@gmail.com>
Signed-off-by: woshiyyya <xiaoyunxuan1998@gmail.com>
Signed-off-by: woshiyyya <xiaoyunxuan1998@gmail.com>
Signed-off-by: woshiyyya <xiaoyunxuan1998@gmail.com>

@gjoliver gjoliver left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks quite solid. only a few minor comments.

Comment thread python/ray/train/lightning/_lightning_utils.py
Comment thread python/ray/train/lightning/_lightning_utils.py Outdated
def _train_dataloader() -> TRAIN_DATALOADERS:
assert train_dataset
ds = RayIterableDataset(train_dataset, dataset_iter_config)
return DataLoader(ds, batch_size=1, collate_fn=lambda x: x[0])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why would iter_torch_batches() add an extra dim of 1 here???

``pytorch_lightning.Trainer.fit``.

Example:
.. code-block:: python

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok. add a TODO?

Comment thread python/ray/train/lightning/lightning_trainer.py
Comment thread python/ray/train/lightning/lightning_trainer.py
Comment thread python/ray/train/tests/test_lightning_trainer.py Outdated
Signed-off-by: woshiyyya <xiaoyunxuan1998@gmail.com>
Signed-off-by: woshiyyya <xiaoyunxuan1998@gmail.com>
@woshiyyya
woshiyyya requested a review from gjoliver March 15, 2023 02:22

@gjoliver gjoliver left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amogkam let us know if you have any more comments. we are gonna merge this now, which is just a start.

@amogkam amogkam left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm overall

  1. now that the api is finalized, can we test the docstring?
  2. Can we add a multi-node, multi-gpu release test as the next followup PR? We want to validate that multi node gpu training is working as soon as possible. We can just rewrite the existing ray Lightning release test.

"""Configuration Class to pass into LightningTrainer.

Example:
.. code-block:: python

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we test this code snippet now that the api has been finalized?

@amogkam amogkam Mar 15, 2023

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just replace code-block with test-code, and I think that should work

@woshiyyya woshiyyya Mar 15, 2023

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing. My plan is to create a separate PR for release tests. I've tested on workspace that multi-node multi-machine training works. Also I wrote some ci tests with single-node multi-gpu setting which also work. I'll post a PR tomorrow to address these testing issues.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the code in docstring, I'll test it as well, together with the release test PR.

@gjoliver
gjoliver merged commit 0574620 into ray-project:master Mar 15, 2023
ProjectsByJackHe pushed a commit to ProjectsByJackHe/ray that referenced this pull request Mar 21, 2023
…<Part 1>. (ray-project#33161)

* init Lightning Trainer with ci tests

Signed-off-by: woshiyyya <xiaoyunxuan1998@gmail.com>
Signed-off-by: Jack He <jackhe2345@gmail.com>
edoakes pushed a commit to edoakes/ray that referenced this pull request Mar 22, 2023
…<Part 1>. (ray-project#33161)

* init Lightning Trainer with ci tests

Signed-off-by: woshiyyya <xiaoyunxuan1998@gmail.com>
Signed-off-by: Edward Oakes <ed.nmi.oakes@gmail.com>
peytondmurray pushed a commit to peytondmurray/ray that referenced this pull request Mar 22, 2023
…<Part 1>. (ray-project#33161)

* init Lightning Trainer with ci tests

Signed-off-by: woshiyyya <xiaoyunxuan1998@gmail.com>
elliottower pushed a commit to elliottower/ray that referenced this pull request Apr 22, 2023
…<Part 1>. (ray-project#33161)

* init Lightning Trainer with ci tests

Signed-off-by: woshiyyya <xiaoyunxuan1998@gmail.com>
Signed-off-by: elliottower <elliot@elliottower.com>
ProjectsByJackHe pushed a commit to ProjectsByJackHe/ray that referenced this pull request May 4, 2023
…<Part 1>. (ray-project#33161)

* init Lightning Trainer with ci tests

Signed-off-by: woshiyyya <xiaoyunxuan1998@gmail.com>
Signed-off-by: Jack He <jackhe2345@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

train Ray Train Related Issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants