Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Train/docs] Deduplicate Train examples & move from ray.air to ray.train #29667

Merged
merged 12 commits into from
Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/ray-air/doc_code/tuner.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
# __torch_start__
from ray import tune
from ray.tune import Tuner
from ray.air.examples.pytorch.torch_linear_example import (
from ray.train.examples.pytorch.torch_linear_example import (
train_func as linear_train_func,
)
from ray.train.torch import TorchTrainer
Expand Down
20 changes: 10 additions & 10 deletions doc/source/ray-overview/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,23 +201,23 @@ This example shows how you can use Ray Train with PyTorch.

First, set up your dataset and model.

```{literalinclude} /../../python/ray/train/examples/torch_quick_start.py
```{literalinclude} /../../python/ray/train/examples/pytorch/torch_quick_start.py
:language: python
:start-after: __torch_setup_begin__
:end-before: __torch_setup_end__
```

Now define your single-worker PyTorch training function.

```{literalinclude} /../../python/ray/train/examples/torch_quick_start.py
```{literalinclude} /../../python/ray/train/examples/pytorch/torch_quick_start.py
:language: python
:start-after: __torch_single_begin__
:end-before: __torch_single_end__
```

This training function can be executed with:

```{literalinclude} /../../python/ray/train/examples/torch_quick_start.py
```{literalinclude} /../../python/ray/train/examples/pytorch/torch_quick_start.py
:language: python
:start-after: __torch_single_run_begin__
:end-before: __torch_single_run_end__
Expand All @@ -231,7 +231,7 @@ easily setup your model & data for distributed training.
This will automatically wrap your model with ``DistributedDataParallel``
and place it on the right device, and add ``DistributedSampler`` to your DataLoaders.

```{literalinclude} /../../python/ray/train/examples/torch_quick_start.py
```{literalinclude} /../../python/ray/train/examples/pytorch/torch_quick_start.py
:language: python
:start-after: __torch_distributed_begin__
:end-before: __torch_distributed_end__
Expand All @@ -240,7 +240,7 @@ and place it on the right device, and add ``DistributedSampler`` to your DataLoa
Then, instantiate a ``Trainer`` that uses a ``"torch"`` backend
with 4 workers, and use it to run the new training function!

```{literalinclude} /../../python/ray/train/examples/torch_quick_start.py
```{literalinclude} /../../python/ray/train/examples/pytorch/torch_quick_start.py
:language: python
:start-after: __torch_trainer_begin__
:end-before: __torch_trainer_end__
Expand All @@ -254,23 +254,23 @@ with Keras <https://www.tensorflow.org/tutorials/distribute/multi_worker_with_ke

First, set up your dataset and model.

```{literalinclude} /../../python/ray/train/examples/tensorflow_quick_start.py
```{literalinclude} /../../python/ray/train/examples/tf/tensorflow_quick_start.py
:language: python
:start-after: __tf_setup_begin__
:end-before: __tf_setup_end__
```

Now define your single-worker TensorFlow training function.

```{literalinclude} /../../python/ray/train/examples/tensorflow_quick_start.py
```{literalinclude} /../../python/ray/train/examples/tf/tensorflow_quick_start.py
:language: python
:start-after: __tf_single_begin__
:end-before: __tf_single_end__
```

This training function can be executed with:

```{literalinclude} /../../python/ray/train/examples/tensorflow_quick_start.py
```{literalinclude} /../../python/ray/train/examples/tf/tensorflow_quick_start.py
:language: python
:start-after: __tf_single_run_begin__
:end-before: __tf_single_run_end__
Expand All @@ -284,7 +284,7 @@ All you need to do is:
2. Choose your TensorFlow distributed training strategy. In this example
we use the ``MultiWorkerMirroredStrategy``.

```{literalinclude} /../../python/ray/train/examples/tensorflow_quick_start.py
```{literalinclude} /../../python/ray/train/examples/tf/tensorflow_quick_start.py
:language: python
:start-after: __tf_distributed_begin__
:end-before: __tf_distributed_end__
Expand All @@ -293,7 +293,7 @@ All you need to do is:
Then, instantiate a ``Trainer`` that uses a ``"tensorflow"`` backend
with 4 workers, and use it to run the new training function!

```{literalinclude} /../../python/ray/train/examples/tensorflow_quick_start.py
```{literalinclude} /../../python/ray/train/examples/tf/tensorflow_quick_start.py
:language: python
:start-after: __tf_trainer_begin__
:end-before: __tf_trainer_end__
Expand Down
10 changes: 5 additions & 5 deletions doc/source/train/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ General Examples
PyTorch
~~~~~~~

* :doc:`/train/examples/torch_fashion_mnist_example`:
* :doc:`/train/examples/pytorch/torch_fashion_mnist_example`:
End-to-end example for PyTorch.

* :doc:`/train/examples/transformers/transformers_example`:
Expand All @@ -24,7 +24,7 @@ PyTorch
TensorFlow
~~~~~~~~~~

* :doc:`/train/examples/tensorflow_mnist_example`:
* :doc:`/train/examples/tf/tensorflow_mnist_example`:
End-to-end example for TensorFlow

Horovod
Expand All @@ -43,10 +43,10 @@ Logger/Callback Examples
Ray Tune Integration Examples
-----------------------------

* :doc:`/train/examples/tune_tensorflow_mnist_example`:
* :doc:`/train/examples/tf/tune_tensorflow_mnist_example`:
End-to-end example for tuning a TensorFlow model.

* :doc:`/train/examples/tune_cifar_torch_pbt_example`:
* :doc:`/train/examples/pytorch/tune_cifar_torch_pbt_example`:
End-to-end example for tuning a PyTorch model with PBT.

..
Expand All @@ -66,6 +66,6 @@ Ray Tune Integration Examples
Benchmarks
----------

* :doc:`/train/examples/torch_data_prefetch_benchmark/benchmark_example`:
* :doc:`/train/examples/pytorch/torch_data_prefetch_benchmark/benchmark_example`:
Benchmark example for the PyTorch data transfer auto pipeline.

Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ The auto pipeline functionality offers more speed improvement when the model siz
========== =================== ======================== ========================


.. literalinclude:: /../../python/ray/train/examples/torch_data_prefetch_benchmark/auto_pipeline_for_host_to_device_data_transfer.py
.. literalinclude:: /../../python/ray/train/examples/pytorch/torch_data_prefetch_benchmark/auto_pipeline_for_host_to_device_data_transfer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
:orphan:

torch_fashion_mnist_example
===========================

.. literalinclude:: /../../python/ray/train/examples/pytorch/torch_fashion_mnist_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
:orphan:

torch_regression_example
========================

.. literalinclude:: /../../python/ray/train/examples/pytorch/torch_regression_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
:orphan:

tune_cifar_torch_pbt_example
============================

.. literalinclude:: /../../python/ray/train/examples/pytorch/tune_cifar_torch_pbt_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
:orphan:

tune_torch_regression_example
=============================

.. literalinclude:: /../../python/ray/train/examples/pytorch/tune_torch_regression_example.py
6 changes: 0 additions & 6 deletions doc/source/train/examples/tensorflow_mnist_example.rst

This file was deleted.

6 changes: 0 additions & 6 deletions doc/source/train/examples/tensorflow_regression_example.rst

This file was deleted.

6 changes: 6 additions & 0 deletions doc/source/train/examples/tf/tensorflow_mnist_example.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
:orphan:

tensorflow_mnist_example
========================

.. literalinclude:: /../../python/ray/train/examples/tf/tensorflow_mnist_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
:orphan:

tensorflow_regression_example
=============================

.. literalinclude:: /../../python/ray/train/examples/tf/tensorflow_regression_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
:orphan:

tune_tensorflow_mnist_example
=============================

.. literalinclude:: /../../python/ray/train/examples/tf/tune_tensorflow_mnist_example.py
6 changes: 0 additions & 6 deletions doc/source/train/examples/torch_fashion_mnist_example.rst

This file was deleted.

6 changes: 0 additions & 6 deletions doc/source/train/examples/torch_regression_example.rst

This file was deleted.

6 changes: 0 additions & 6 deletions doc/source/train/examples/tune_cifar_torch_pbt_example.rst

This file was deleted.

6 changes: 0 additions & 6 deletions doc/source/train/examples/tune_tensorflow_mnist_example.rst

This file was deleted.

6 changes: 0 additions & 6 deletions doc/source/train/examples/tune_torch_regression_example.rst

This file was deleted.

20 changes: 10 additions & 10 deletions doc/source/train/getting-started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -88,22 +88,22 @@ Here are examples for some of the commonly used trainers:

First, set up your dataset and model.

.. literalinclude:: /../../python/ray/train/examples/torch_quick_start.py
.. literalinclude:: /../../python/ray/train/examples/pytorch/torch_quick_start.py
:language: python
:start-after: __torch_setup_begin__
:end-before: __torch_setup_end__


Now define your single-worker PyTorch training function.

.. literalinclude:: /../../python/ray/train/examples/torch_quick_start.py
.. literalinclude:: /../../python/ray/train/examples/pytorch/torch_quick_start.py
:language: python
:start-after: __torch_single_begin__
:end-before: __torch_single_end__

This training function can be executed with:

.. literalinclude:: /../../python/ray/train/examples/torch_quick_start.py
.. literalinclude:: /../../python/ray/train/examples/pytorch/torch_quick_start.py
:language: python
:start-after: __torch_single_run_begin__
:end-before: __torch_single_run_end__
Expand All @@ -116,15 +116,15 @@ Here are examples for some of the commonly used trainers:
This will automatically wrap your model with ``DistributedDataParallel``
and place it on the right device, and add ``DistributedSampler`` to your DataLoaders.

.. literalinclude:: /../../python/ray/train/examples/torch_quick_start.py
.. literalinclude:: /../../python/ray/train/examples/pytorch/torch_quick_start.py
:language: python
:start-after: __torch_distributed_begin__
:end-before: __torch_distributed_end__

Then, instantiate a ``TorchTrainer``
with 4 workers, and use it to run the new training function!

.. literalinclude:: /../../python/ray/train/examples/torch_quick_start.py
.. literalinclude:: /../../python/ray/train/examples/pytorch/torch_quick_start.py
:language: python
:start-after: __torch_trainer_begin__
:end-before: __torch_trainer_end__
Expand All @@ -138,21 +138,21 @@ Here are examples for some of the commonly used trainers:

First, set up your dataset and model.

.. literalinclude:: /../../python/ray/train/examples/tensorflow_quick_start.py
.. literalinclude:: /../../python/ray/train/examples/tf/tensorflow_quick_start.py
:language: python
:start-after: __tf_setup_begin__
:end-before: __tf_setup_end__

Now define your single-worker TensorFlow training function.

.. literalinclude:: /../../python/ray/train/examples/tensorflow_quick_start.py
.. literalinclude:: /../../python/ray/train/examples/tf/tensorflow_quick_start.py
:language: python
:start-after: __tf_single_begin__
:end-before: __tf_single_end__

This training function can be executed with:

.. literalinclude:: /../../python/ray/train/examples/tensorflow_quick_start.py
.. literalinclude:: /../../python/ray/train/examples/tf/tensorflow_quick_start.py
:language: python
:start-after: __tf_single_run_begin__
:end-before: __tf_single_run_end__
Expand All @@ -165,15 +165,15 @@ Here are examples for some of the commonly used trainers:
2. Choose your TensorFlow distributed training strategy. In this example
we use the ``MultiWorkerMirroredStrategy``.

.. literalinclude:: /../../python/ray/train/examples/tensorflow_quick_start.py
.. literalinclude:: /../../python/ray/train/examples/tf/tensorflow_quick_start.py
:language: python
:start-after: __tf_distributed_begin__
:end-before: __tf_distributed_end__

Then, instantiate a ``TensorflowTrainer`` with 4 workers,
and use it to run the new training function!

.. literalinclude:: /../../python/ray/train/examples/tensorflow_quick_start.py
.. literalinclude:: /../../python/ray/train/examples/tf/tensorflow_quick_start.py
:language: python
:start-after: __tf_trainer_begin__
:end-before: __tf_trainer_end__
Expand Down
Loading