Skip to content

documentation: Torchrun gpu support documentation change #3698

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

Merged
merged 11 commits into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
42 changes: 36 additions & 6 deletions doc/frameworks/pytorch/using_pytorch.rst
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ fit Optional Arguments
- ``logs``: Defaults to True, whether to show logs produced by training
job in the Python session. Only meaningful when wait is True.

----

Distributed PyTorch Training
============================
Expand Down Expand Up @@ -262,16 +263,18 @@ during the PyTorch DDP initialization.

.. note::

The SageMaker PyTorch estimator operates ``mpirun`` in the backend.
It doesn’t use ``torchrun`` for distributed training.
The SageMaker PyTorch estimator can operate both ``mpirun`` (for PyTorch 1.12.0 and later)
and ``torchrun`` (for PyTorch 1.13.1 and later) in the backend for distributed training.

For more information about setting up PyTorch DDP in your training script,
see `Getting Started with Distributed Data Parallel
<https://pytorch.org/tutorials/intermediate/ddp_tutorial.html>`_ in the
PyTorch documentation.

The following example shows how to run a PyTorch DDP training in SageMaker
using two ``ml.p4d.24xlarge`` instances:
The following examples show how to set a PyTorch estimator
to run a distributed training job on two ``ml.p4d.24xlarge`` instances.

**Using PyTorch DDP with the mpirun backend**

.. code:: python

Expand All @@ -291,7 +294,34 @@ using two ``ml.p4d.24xlarge`` instances:
}
)

pt_estimator.fit("s3://bucket/path/to/training/data")
**Using PyTorch DDP with the torchrun backend**

.. code:: python

from sagemaker.pytorch import PyTorch

pt_estimator = PyTorch(
entry_point="train_ptddp.py",
role="SageMakerRole",
framework_version="1.13.1",
py_version="py38",
instance_count=2,
instance_type="ml.p4d.24xlarge",
distribution={
"torch_distributed": {
"enabled": True
}
}
)


.. note::

For more information about setting up ``torchrun`` in your training script,
see `torchrun (Elastic Launch) <https://pytorch.org/docs/stable/elastic/run.html>`_ in *the
PyTorch documentation*.

----

.. _distributed-pytorch-training-on-trainium:

Expand Down Expand Up @@ -324,7 +354,7 @@ with the ``torch_distributed`` option as the distribution strategy.

.. note::

SageMaker Debugger is currently not supported with Trn1 instances.
SageMaker Debugger is not compatible with Trn1 instances.

Adapt Your Training Script to Initialize with the XLA backend
-------------------------------------------------------------
Expand Down
10 changes: 6 additions & 4 deletions src/sagemaker/pytorch/estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,10 @@ def __init__(
To learn more, see `Distributed PyTorch Training
<https://sagemaker.readthedocs.io/en/stable/frameworks/pytorch/using_pytorch.html#distributed-pytorch-training>`_.

**To enable Torch Distributed (for Trainium instances only):**
**To enable Torch Distributed:**

This is available for general distributed training on
GPU instances from PyTorch v1.13.1 and later.

.. code:: python

Expand All @@ -181,6 +184,7 @@ def __init__(
}
}

This option also supports distributed training on Trn1.
To learn more, see `Distributed PyTorch Training on Trainium
<https://sagemaker.readthedocs.io/en/stable/frameworks/pytorch/using_pytorch.html#distributed-pytorch-training-on-trainium>`_.

Expand Down Expand Up @@ -210,9 +214,7 @@ def __init__(
To learn more, see `Training with parameter servers
<https://sagemaker.readthedocs.io/en/stable/frameworks/tensorflow/using_tf.html#training-with-parameter-servers>`_.

**To enable distributed training with
`SageMaker Training Compiler <https://docs.aws.amazon.com/sagemaker/latest/dg/training-compiler.html>`_
for PyTorch:**
**To enable distributed training with SageMaker Training Compiler:**

.. code:: python

Expand Down