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

make_distribute_tutorial_work_in_google_colab #3022

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
10 changes: 8 additions & 2 deletions intermediate_source/dist_tuto.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ the following template.
"""run.py:"""
#!/usr/bin/env python
import os
import sys
import torch
import torch.distributed as dist
import torch.multiprocessing as mp
Expand All @@ -66,7 +67,11 @@ the following template.
if __name__ == "__main__":
size = 2
processes = []
mp.set_start_method("spawn")
if "google.colab" in sys.modules:
print("Running in Google Colab")
mp.get_context("spawn")
else:
mp.set_start_method("spawn")
for rank in range(size):
p = mp.Process(target=init_process, args=(rank, size, run))
p.start()
Expand Down Expand Up @@ -156,7 +161,8 @@ we should not modify the sent tensor nor access the received tensor before ``req
In other words,

- writing to ``tensor`` after ``dist.isend()`` will result in undefined behaviour.
- reading from ``tensor`` after ``dist.irecv()`` will result in undefined behaviour.
- reading from ``tensor`` after ``dist.irecv()`` will result in undefined
behaviour, until ``req.wait()`` has been executed.

However, after ``req.wait()``
has been executed we are guaranteed that the communication took place,
Expand Down