Skip to content

Commit 4a3efed

Browse files
author
Jessica Lin
authored
Merge branch 'master' into batch
2 parents 0cdb3ac + 43e3eb7 commit 4a3efed

File tree

5 files changed

+41
-30
lines changed

5 files changed

+41
-30
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ beginner
33
intermediate
44
advanced
55
pytorch_basics
6+
recipes
67

78
#data things
89
_data/
@@ -31,6 +32,7 @@ __pycache__/
3132
*.so
3233

3334
# Distribution / packaging
35+
src/
3436
.Python
3537
env/
3638
build/

Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ docs:
108108
touch docs/.nojekyll
109109

110110
html-noplot:
111-
make clean
112111
$(SPHINXBUILD) -D plot_gallery=0 -b html $(SPHINXOPTS) "$(SOURCEDIR)" "$(BUILDDIR)/html"
113112
# bash .jenkins/remove_invisible_code_block_batch.sh "$(BUILDDIR)/html"
114113
@echo

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ All the tutorials are now presented as sphinx style documentation at:
1111

1212
We use sphinx-gallery's [notebook styled examples](https://sphinx-gallery.github.io/stable/tutorials/index.html) to create the tutorials. Syntax is very simple. In essence, you write a slightly well formatted python file and it shows up as documentation page.
1313

14-
Here's how to create a new tutorial:
14+
Here's how to create a new tutorial or recipe:
1515
1. Create a notebook styled python file. If you want it executed while inserted into documentation, save the file with suffix `tutorial` so that file name is `your_tutorial.py`.
16-
2. Put it in one of the beginner_source, intermediate_source, advanced_source based on the level.
17-
2. Include it in the right TOC tree at index.rst
18-
3. Create a thumbnail in the index.rst file using a command like `.. customcarditem:: beginner/your_tutorial.html`. (This is a custom directive. See `custom_directives.py` for more info.)
16+
2. Put it in one of the beginner_source, intermediate_source, advanced_source based on the level. If it is a recipe, add to recipes_source.
17+
2. For Tutorials, include it in the TOC tree at index.rst
18+
3. For Tutorials, create a thumbnail in the [index.rst file](https://github.com/pytorch/tutorials/blob/master/index.rst) using a command like `.. customcarditem:: beginner/your_tutorial.html`. For Recipes, create a thumbnail in the [recipes_index.rst](https://github.com/pytorch/tutorials/blob/master/recipes_source/recipes_index.rst)
1919

2020
In case you prefer to write your tutorial in jupyter, you can use [this script](https://gist.github.com/chsasank/7218ca16f8d022e02a9c0deb94a310fe) to convert the notebook to python file. After conversion and addition to the project, please make sure the sections headings etc are in logical order.
2121

conf.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
import glob
3636
import shutil
3737
from custom_directives import IncludeDirective, GalleryItemDirective, CustomGalleryItemDirective, CustomCalloutItemDirective, CustomCardItemDirective
38+
import distutils.file_util
39+
import re
3840

3941

4042
try:
@@ -63,10 +65,19 @@
6365
'examples_dirs': ['beginner_source', 'intermediate_source',
6466
'advanced_source', 'recipes_source'],
6567
'gallery_dirs': ['beginner', 'intermediate', 'advanced', 'recipes'],
66-
'filename_pattern': os.environ.get('GALLERY_PATTERN', r'tutorial.py'),
6768
'backreferences_dir': False
6869
}
6970

71+
if os.getenv('GALLERY_PATTERN'):
72+
# GALLERY_PATTERN is to be used when you want to work on a single
73+
# tutorial. Previously this was fed into filename_pattern, but
74+
# if you do that, you still end up parsing all of the other Python
75+
# files which takes a few seconds. This strategy is better, as
76+
# ignore_pattern also skips parsing.
77+
# See https://github.com/sphinx-gallery/sphinx-gallery/issues/721
78+
# for a more detailed description of the issue.
79+
sphinx_gallery_conf['ignore_pattern'] = r'/(?!' + re.escape(os.getenv('GALLERY_PATTERN')) + r')[^/]+$'
80+
7081
for i in range(len(sphinx_gallery_conf['examples_dirs'])):
7182
gallery_dir = sphinx_gallery_conf['gallery_dirs'][i]
7283
source_dir = sphinx_gallery_conf['examples_dirs'][i]
@@ -78,7 +89,7 @@
7889

7990
# Copy rst files from source dir to gallery dir
8091
for f in glob.glob(os.path.join(source_dir, '*.rst')):
81-
shutil.copy(f, gallery_dir)
92+
distutils.file_util.copy_file(f, gallery_dir, update=True)
8293

8394

8495
# Add any paths that contain templates here, relative to this directory.

intermediate_source/dist_tuto.rst

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -394,29 +394,28 @@ using point-to-point collectives.
394394
395395
""" Implementation of a ring-reduce with addition. """
396396
def allreduce(send, recv):
397-
rank = dist.get_rank()
398-
size = dist.get_world_size()
399-
send_buff = th.zeros(send.size())
400-
recv_buff = th.zeros(send.size())
401-
accum = th.zeros(send.size())
402-
accum[:] = send[:]
403-
404-
left = ((rank - 1) + size) % size
405-
right = (rank + 1) % size
406-
407-
for i in range(size - 1):
408-
if i % 2 == 0:
409-
# Send send_buff
410-
send_req = dist.isend(send_buff, right)
411-
dist.recv(recv_buff, left)
412-
accum[:] += recv[:]
413-
else:
414-
# Send recv_buff
415-
send_req = dist.isend(recv_buff, right)
416-
dist.recv(send_buff, left)
417-
accum[:] += send[:]
418-
send_req.wait()
419-
recv[:] = accum[:]
397+
rank = dist.get_rank()
398+
size = dist.get_world_size()
399+
send_buff = send.clone()
400+
recv_buff = send.clone()
401+
accum = send.clone()
402+
403+
left = ((rank - 1) + size) % size
404+
right = (rank + 1) % size
405+
406+
for i in range(size - 1):
407+
if i % 2 == 0:
408+
# Send send_buff
409+
send_req = dist.isend(send_buff, right)
410+
dist.recv(recv_buff, left)
411+
accum[:] += recv_buff[:]
412+
else:
413+
# Send recv_buff
414+
send_req = dist.isend(recv_buff, right)
415+
dist.recv(send_buff, left)
416+
accum[:] += send_buff[:]
417+
send_req.wait()
418+
recv[:] = accum[:]
420419
421420
In the above script, the ``allreduce(send, recv)`` function has a
422421
slightly different signature than the ones in PyTorch. It takes a

0 commit comments

Comments
 (0)