Skip to content

Commit a79c227

Browse files
author
Jessica Lin
authored
Merge branch 'master' into recipe_aarlink_customop
2 parents 8e4e379 + 43e3eb7 commit a79c227

File tree

4 files changed

+37
-26
lines changed

4 files changed

+37
-26
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

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)