Skip to content

Commit 8eb4e3d

Browse files
Update ddp_tutorial to work on Windows platform (#1182)
* Update ddp_tutorial.rst update ddp_tutorial to work on Windows platform * Update ddp tutorial to contain script for Windows and non-Windows platform together * Resolved code review comments * Wrap init_process_group method since it is too long in built doc * The comment is too long in one line, make it short. * Update Co-authored-by: Joe Zhu <jozh@microsoft.com> Co-authored-by: Brian Johnson <brianjo@fb.com>
1 parent 5c7e38b commit 8eb4e3d

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

intermediate_source/ddp_tutorial.rst

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ Getting Started with Distributed Data Parallel
22
=================================================
33
**Author**: `Shen Li <https://mrshenli.github.io/>`_
44

5+
**Edited by**: `Joe Zhu <https://github.com/gunandrose4u>`_
6+
57
Prerequisites:
68

79
- `PyTorch Distributed Overview <../beginner/dist_overview.html>`__
@@ -68,6 +70,7 @@ be found in
6870
.. code:: python
6971
7072
import os
73+
import sys
7174
import tempfile
7275
import torch
7376
import torch.distributed as dist
@@ -79,12 +82,26 @@ be found in
7982
8083
8184
def setup(rank, world_size):
82-
os.environ['MASTER_ADDR'] = 'localhost'
83-
os.environ['MASTER_PORT'] = '12355'
84-
85-
# initialize the process group
86-
dist.init_process_group("gloo", rank=rank, world_size=world_size)
85+
if sys.platform == 'win32':
86+
# Distributed package only covers collective communications with Gloo
87+
# backend and FileStore on Windows platform. Set init_method parameter
88+
# in init_process_group to a local file.
89+
# Example init_method="file:///f:/libtmp/some_file"
90+
init_method="file:///{your local file path}"
91+
92+
# initialize the process group
93+
dist.init_process_group(
94+
"gloo",
95+
init_method=init_method,
96+
rank=rank,
97+
world_size=world_size
98+
)
99+
else:
100+
os.environ['MASTER_ADDR'] = 'localhost'
101+
os.environ['MASTER_PORT'] = '12355'
87102
103+
# initialize the process group
104+
dist.init_process_group("gloo", rank=rank, world_size=world_size)
88105
89106
def cleanup():
90107
dist.destroy_process_group()

0 commit comments

Comments
 (0)