Skip to content

[Train][Doc] LightningTrainer end-2-end starter example [no_early_kickoff]#33494

Merged
richardliaw merged 58 commits into
ray-project:masterfrom
woshiyyya:air/lightning_e2e_example
Mar 24, 2023
Merged

[Train][Doc] LightningTrainer end-2-end starter example [no_early_kickoff]#33494
richardliaw merged 58 commits into
ray-project:masterfrom
woshiyyya:air/lightning_e2e_example

Conversation

@woshiyyya
Copy link
Copy Markdown
Member

@woshiyyya woshiyyya commented Mar 21, 2023

Why are these changes needed?

We need to provide end-to-end examples for users to onboard LightningTrainer. This is a starter example which uses

  • simple linear model for MNIST dataset
  • pl.LightningDataModule as input data source
  • pl.Trainer.test() for evaluation

We'll also have an advanced example using Ray Data + BatchPredictor + Ray Tune later.

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 added any new APIs to the API Reference. For example, if I added a
      method in Tune, I've added it in doc/source/tune/api/ under the
      corresponding .rst file.
  • 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 :(

woshiyyya and others added 30 commits March 8, 2023 17:48
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>
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>
Signed-off-by: woshiyyya <xiaoyunxuan1998@gmail.com>
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>
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>
@woshiyyya woshiyyya requested review from a team, Yard1, matthewdeng and maxpumperla as code owners March 22, 2023 01:20
@woshiyyya woshiyyya changed the title [AIR/Doc] LightningTrainer end-2-end example [Train][Doc] LightningTrainer end-2-end starter example Mar 22, 2023
Copy link
Copy Markdown
Contributor

@justinvyu justinvyu left a comment

Choose a reason for hiding this comment

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

Looks good!

Can we also add usage of the LightningPredictor at the end? As a separate path to trainer.test.

Comment thread doc/BUILD
Comment on lines 250 to +261
args = ["--path", "doc/source/train/examples/pytorch/pytorch_resnet_finetune.ipynb"]
)

py_test(
name = "lightning_mnist_example",
size = "large",
main = "test_myst_doc.py",
srcs = ["test_myst_doc.py"],
tags = ["exclusive", "team:ml", "gpu", "ray_air"],
data = ["//doc/source/train/examples/lightning:lightning_mnist_example"],
args = ["--path", "doc/source/train/examples/lightning/lightning_mnist_example.ipynb"]
)
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 use py_test_run_all_notebooks for these two?

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.

Actually these two ipynb files are in different folders. We can't aggregate them in a single build object.

Comment thread doc/source/conf.py Outdated
Comment thread doc/source/train/examples.rst
Comment thread doc/source/train/examples/lightning/lightning_mnist_example.ipynb
Comment thread doc/source/train/examples/lightning/lightning_mnist_example.ipynb Outdated
Comment thread doc/source/train/examples/lightning/lightning_mnist_example.ipynb Outdated
Comment thread doc/source/train/examples/lightning/lightning_mnist_example.ipynb Outdated
Comment thread doc/source/train/examples/lightning/lightning_mnist_example.ipynb Outdated
Comment thread doc/source/train/examples/lightning/lightning_mnist_example.ipynb
Comment thread doc/source/train/examples/lightning/lightning_mnist_example.ipynb Outdated
woshiyyya and others added 5 commits March 23, 2023 14:08
Co-authored-by: Justin Yu <justinvyu@anyscale.com>
Signed-off-by: Yunxuan Xiao <xiaoyunxuan1998@gmail.com>
Signed-off-by: Yunxuan Xiao <xiaoyunxuan1998@gmail.com>
@woshiyyya
Copy link
Copy Markdown
Member Author

woshiyyya commented Mar 24, 2023

Can we also add usage of the LightningPredictor at the end? As a separate path to trainer.test.

@justinvyu Seems that it's much complex to use LightningPredictor than Trainer.test(). Is it better to use the BatchPredictor in the advanced example?

from ray.train.lightning import LightningPredictor
predictor = LightningPredictor.from_checkpoint(checkpoint, MNISTClassifier, use_gpu=False)

def accuracy(logits, labels):
    preds = np.argmax(logits, axis=1)
    correct_preds = np.sum(preds == labels)
    return correct_preds

corrects = total = 0
for batch in test_dataloader:
    inputs, labels = batch
    inputs, labels = inputs.numpy(), labels.numpy()
    logits = predictor.predict(inputs)["predictions"]
    total += labels.size
    corrects += accuracy(logits, labels)
    
print("Accuracy: ", corrects / total)

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>
Comment thread doc/source/train/examples/lightning/lightning_mnist_example.ipynb
Copy link
Copy Markdown
Contributor

@richardliaw richardliaw left a comment

Choose a reason for hiding this comment

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

looks good!

@woshiyyya woshiyyya changed the title [Train][Doc] LightningTrainer end-2-end starter example [Train][Doc] LightningTrainer end-2-end starter example [no_early_kickoff] Mar 24, 2023
@richardliaw richardliaw merged commit cd8ce7f into ray-project:master Mar 24, 2023
elliottower pushed a commit to elliottower/ray that referenced this pull request Apr 22, 2023
…koff] (ray-project#33494)

Co-authored-by: Amog Kamsetty <amogkam@users.noreply.github.com>
Co-authored-by: Justin Yu <justinvyu@anyscale.com>
Signed-off-by: elliottower <elliot@elliottower.com>
ProjectsByJackHe pushed a commit to ProjectsByJackHe/ray that referenced this pull request May 4, 2023
…koff] (ray-project#33494)

Co-authored-by: Amog Kamsetty <amogkam@users.noreply.github.com>
Co-authored-by: Justin Yu <justinvyu@anyscale.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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants