Skip to content

[android][recipe] Making android native app using torchscript model with custom op #1041

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 7 commits into from
Jul 2, 2020
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ beginner
intermediate
advanced
pytorch_basics
recipes

#data things
_data/
Expand Down Expand Up @@ -31,6 +32,7 @@ __pycache__/
*.so

# Distribution / packaging
src/
.Python
env/
build/
Expand Down
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ docs:
touch docs/.nojekyll

html-noplot:
make clean
$(SPHINXBUILD) -D plot_gallery=0 -b html $(SPHINXOPTS) "$(SOURCEDIR)" "$(BUILDDIR)/html"
# bash .jenkins/remove_invisible_code_block_batch.sh "$(BUILDDIR)/html"
@echo
Expand Down
15 changes: 13 additions & 2 deletions conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import glob
import shutil
from custom_directives import IncludeDirective, GalleryItemDirective, CustomGalleryItemDirective, CustomCalloutItemDirective, CustomCardItemDirective
import distutils.file_util
import re


try:
Expand Down Expand Up @@ -63,10 +65,19 @@
'examples_dirs': ['beginner_source', 'intermediate_source',
'advanced_source', 'recipes_source'],
'gallery_dirs': ['beginner', 'intermediate', 'advanced', 'recipes'],
'filename_pattern': os.environ.get('GALLERY_PATTERN', r'tutorial.py'),
'backreferences_dir': False
}

if os.getenv('GALLERY_PATTERN'):
# GALLERY_PATTERN is to be used when you want to work on a single
# tutorial. Previously this was fed into filename_pattern, but
# if you do that, you still end up parsing all of the other Python
# files which takes a few seconds. This strategy is better, as
# ignore_pattern also skips parsing.
# See https://github.com/sphinx-gallery/sphinx-gallery/issues/721
# for a more detailed description of the issue.
sphinx_gallery_conf['ignore_pattern'] = r'/(?!' + re.escape(os.getenv('GALLERY_PATTERN')) + r')[^/]+$'

for i in range(len(sphinx_gallery_conf['examples_dirs'])):
gallery_dir = sphinx_gallery_conf['gallery_dirs'][i]
source_dir = sphinx_gallery_conf['examples_dirs'][i]
Expand All @@ -78,7 +89,7 @@

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


# Add any paths that contain templates here, relative to this directory.
Expand Down
45 changes: 22 additions & 23 deletions intermediate_source/dist_tuto.rst
Original file line number Diff line number Diff line change
Expand Up @@ -394,29 +394,28 @@ using point-to-point collectives.

""" Implementation of a ring-reduce with addition. """
def allreduce(send, recv):
rank = dist.get_rank()
size = dist.get_world_size()
send_buff = th.zeros(send.size())
recv_buff = th.zeros(send.size())
accum = th.zeros(send.size())
accum[:] = send[:]

left = ((rank - 1) + size) % size
right = (rank + 1) % size

for i in range(size - 1):
if i % 2 == 0:
# Send send_buff
send_req = dist.isend(send_buff, right)
dist.recv(recv_buff, left)
accum[:] += recv[:]
else:
# Send recv_buff
send_req = dist.isend(recv_buff, right)
dist.recv(send_buff, left)
accum[:] += send[:]
send_req.wait()
recv[:] = accum[:]
rank = dist.get_rank()
size = dist.get_world_size()
send_buff = send.clone()
recv_buff = send.clone()
accum = send.clone()

left = ((rank - 1) + size) % size
right = (rank + 1) % size

for i in range(size - 1):
if i % 2 == 0:
# Send send_buff
send_req = dist.isend(send_buff, right)
dist.recv(recv_buff, left)
accum[:] += recv_buff[:]
else:
# Send recv_buff
send_req = dist.isend(recv_buff, right)
dist.recv(send_buff, left)
accum[:] += send_buff[:]
send_req.wait()
recv[:] = accum[:]

In the above script, the ``allreduce(send, recv)`` function has a
slightly different signature than the ones in PyTorch. It takes a
Expand Down
Loading