Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
9ef173b
Build Repair Work: build-fix branch (#564)
brianjo Jul 21, 2019
cae2509
Update PyTorch Cheat.md
jspisak Jul 22, 2019
283d902
Update ptcheat.rst (#570)
brianjo Jul 22, 2019
35480d8
Update cifar10_tutorial.py (#568)
jspisak Jul 22, 2019
6befae3
Update dcgan_faces_tutorial.py (#567)
jspisak Jul 22, 2019
903eae8
Update chatbot_tutorial.py (#573)
brianjo Jul 24, 2019
8110633
Update Super Resolution Tutorial to Use ORT
lara-hdr Jul 17, 2019
996c87c
update index-rst
lara-hdr Jul 17, 2019
5705add
fix custum_directive
lara-hdr Jul 18, 2019
7d4e4bb
adress PR comments
Jul 23, 2019
d7a3b1c
adress remaining comments
Jul 23, 2019
51360b7
add info about the model
Jul 24, 2019
c374b7e
Update index.rst
brianjo Jul 25, 2019
b969e89
Fix some minor issues in Custom C++ and CUDA Extensions (#580)
rgommers Jul 26, 2019
e77477a
remove old audio classifier tutorial.
vincentqb Jul 25, 2019
46d5224
Update build.sh
brianjo Jul 30, 2019
4588203
Update build.sh
brianjo Jul 30, 2019
242af44
initial version
avinassh Jun 20, 2019
55d2726
fix typos
avinassh Jun 20, 2019
fd7a418
Update the tutorial
avinassh Jun 20, 2019
6d75bea
add item to the index
avinassh Jun 20, 2019
77c65fb
fix image path
avinassh Jun 20, 2019
6eae05e
fix relative link
avinassh Jun 20, 2019
044cc11
Fix the header
avinassh Jun 20, 2019
8f7e00a
move to intermediate section
avinassh Jul 3, 2019
b95e2dd
Update main index
avinassh Jul 3, 2019
816cd12
move the file to intermediate directory
avinassh Jul 3, 2019
9a6ee4f
Fix grammar issues and improvements from PR review
avinassh Jul 30, 2019
8eee4ed
some more fixes
avinassh Jul 30, 2019
d5fbeee
update flask deploy URL
avinassh Jul 30, 2019
206392c
Add files via upload
brianjo Aug 2, 2019
03df12d
Update requirements.txt
brianjo Aug 2, 2019
cbda085
Update flask_rest_api_tutorial.py
brianjo Aug 2, 2019
eb28769
Update flask_rest_api_tutorial.py
brianjo Aug 2, 2019
9eccef4
Update flask_rest_api_tutorial.py
brianjo Aug 2, 2019
353f8f1
Add files via upload
brianjo Aug 2, 2019
7008816
Update flask_rest_api_tutorial.py
brianjo Aug 2, 2019
617a094
Update flask_rest_api_tutorial.py
brianjo Aug 2, 2019
9194910
Update flask_rest_api_tutorial.py
brianjo Aug 2, 2019
886473e
Update flask_rest_api_tutorial.py
brianjo Aug 2, 2019
aacab43
Update flask_rest_api_tutorial.py
brianjo Aug 2, 2019
b362ddc
Update seq2seq_translation_tutorial.py
jspisak Aug 5, 2019
9acf280
updated tutorial
Krovatkin Jul 17, 2019
c6ce577
Add beginning of CIFAR Tensorboard tutorial
Jul 30, 2019
d91f7fd
Add CIFAR_10 Tensorboard tutorial
Jul 31, 2019
39a54da
Fix formatting, wording
Jul 31, 2019
4eebe14
Add Tensorboard tutorial to blitz README
Jul 31, 2019
ff4f9b5
Remove captions from images
Jul 31, 2019
7c30d0e
Fix typo
Jul 31, 2019
1e8f2ea
Fix numbering, wording
Jul 31, 2019
50316d2
Fix capitalization, numbering
Jul 31, 2019
8dd4c76
New TensorBoard tutorial
Aug 4, 2019
166136c
New TensorBoard tutorial title
Aug 4, 2019
930bac1
Add TensorBoard tutorial to README
Aug 4, 2019
657b3ff
Add flask tutorial files
Aug 5, 2019
52ed443
Updates to flask tutorial
Aug 5, 2019
80e2974
Remove flask tutorial notebook folder
Aug 5, 2019
2817580
Remove TensorBoard stuff from flask branch
Aug 5, 2019
1d6b666
Remove more TensorBoard stuff from flask branch
Aug 5, 2019
454752b
Remove final TensorBoard stuff
Aug 5, 2019
4456756
Actually remove changes to sphinx theme
Aug 5, 2019
8bd51dd
Changes to get Flask tutorial to run
Aug 5, 2019
44f1e59
Update flask_rest_api_tutorial.py
brianjo Aug 5, 2019
239557f
Update torchvision_tutorial.rst
brianjo Aug 5, 2019
7454c41
Mention a quirk with jupyter notebooks
smessmer Aug 5, 2019
7198f02
please
smessmer Aug 5, 2019
c6262e7
chatbot_tutorial.py: Solve the optimizer cuda call problem
jiangzhonglian Jul 25, 2019
6efe7ad
chatbot_tutorial.py: Solve the optimizer cuda call problem
jiangzhonglian Jul 25, 2019
4fdef1a
Update build.sh
brianjo Aug 6, 2019
811c9db
Update build.sh
brianjo Aug 6, 2019
dfa1951
Intro to TorchScript tutorial (#592)
Aug 7, 2019
9fa7632
Update Deploy Seq2Seq Tutorial with New TorchScript API
wanchaol Aug 7, 2019
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
22 changes: 18 additions & 4 deletions .jenkins/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,44 @@ export PATH=/opt/conda/bin:$PATH
rm -rf src
pip install -r $DIR/../requirements.txt

# For Tensorboard. Until 1.14 moves to the release channel.
pip install tb-nightly

export PATH=/opt/conda/bin:$PATH
conda install -y sphinx==1.8.2 pandas
pip install sphinx==1.8.2 pandas

# install awscli
# pip uninstall awscli
# pip install awscli==1.16.35

# PyTorch Theme
rm -rf src
pip install -e git+git://github.com/pytorch/pytorch_sphinx_theme.git#egg=pytorch_sphinx_theme
# pillow >= 4.2 will throw error when trying to write mode RGBA as JPEG,
# this is a workaround to the issue.
pip install sphinx-gallery tqdm matplotlib ipython pillow==4.1.1
pip install sphinx-gallery==0.3.1 tqdm matplotlib ipython pillow==4.1.1

# Install torchaudio from source
git clone https://github.com/pytorch/audio --quiet
pushd audio
python setup.py install
popd

# Install torchaudio from source
git clone https://github.com/pytorch/text --quiet
pushd text
python setup.py install
popd

aws configure set default.s3.multipart_threshold 5120MB

# Decide whether to parallelize tutorial builds, based on $JOB_BASE_NAME
export NUM_WORKERS=20
if [[ "${JOB_BASE_NAME}" == *worker_* ]]; then
# Step 1: Remove runnable code from tutorials that are not supposed to be run
python $DIR/remove_runnable_code.py beginner_source/aws_distributed_training_tutorial.py beginner_source/aws_distributed_training_tutorial.py
python $DIR/remove_runnable_code.py beginner_source/aws_distributed_training_tutorial.py beginner_source/aws_distributed_training_tutorial.py || true
# TODO: Fix bugs in these tutorials to make them runnable again
python $DIR/remove_runnable_code.py beginner_source/audio_classifier_tutorial.py beginner_source/audio_classifier_tutorial.py
python $DIR/remove_runnable_code.py beginner_source/audio_classifier_tutorial.py beginner_source/audio_classifier_tutorial.py || true

# Step 2: Keep certain tutorials based on file count, and remove runnable code in all other tutorials
# IMPORTANT NOTE: We assume that each tutorial has a UNIQUE filename.
Expand Down
1 change: 1 addition & 0 deletions _static/imagenet_class_index.json

Large diffs are not rendered by default.

Binary file removed _static/img/cat_output1.png
Binary file not shown.
Binary file added _static/img/cat_superres_with_ort.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified _static/img/chatbot/diff.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified _static/img/chatbot/pytorch_workflow.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _static/img/flask.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed _static/img/hybrid.png
Binary file not shown.
Binary file added _static/img/sample_file.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _static/img/torchscript.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions advanced_source/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ Advanced Tutorials
Custom C Extensions for PyTorch
https://pytorch.org/tutorials/advanced/c_extension.html

4. super_resolution_with_caffe2.py
Transfering a Model from PyTorch to Caffe2 and Mobile using ONNX
https://pytorch.org/tutorials/advanced/super_resolution_with_caffe2.html
4. super_resolution_with_onnxruntime.py
Exporting a Model from PyTorch to ONNX and Running it using ONNXRuntime
https://pytorch.org/tutorials/advanced/super_resolution_with_onnxruntime.html
95 changes: 51 additions & 44 deletions advanced_source/cpp_export.rst
Original file line number Diff line number Diff line change
Expand Up @@ -92,28 +92,30 @@ vanilla Pytorch model::

Because the ``forward`` method of this module uses control flow that is
dependent on the input, it is not suitable for tracing. Instead, we can convert
it to a ``ScriptModule`` by subclassing it from ``torch.jit.ScriptModule`` and
adding a ``@torch.jit.script_method`` annotation to the model's ``forward``
method::

import torch

class MyModule(torch.jit.ScriptModule):
def __init__(self, N, M):
super(MyModule, self).__init__()
self.weight = torch.nn.Parameter(torch.rand(N, M))

@torch.jit.script_method
def forward(self, input):
if bool(input.sum() > 0):
output = self.weight.mv(input)
else:
output = self.weight + input
return output

my_script_module = MyModule(2, 3)

Creating a new ``MyModule`` object now directly produces an instance of
it to a ``ScriptModule``.
In order to convert the module to the ``ScriptModule``, one needs to
compile the module with ``torch.jit.script`` as follows::

class MyModule(torch.nn.Module):
def __init__(self, N, M):
super(MyModule, self).__init__()
self.weight = torch.nn.Parameter(torch.rand(N, M))

def forward(self, input):
if input.sum() > 0:
output = self.weight.mv(input)
else:
output = self.weight + input
return output

my_module = MyModule(10,20)
sm = torch.jit.script(my_module)

If you need to exclude some methods in your ``nn.Module``
because they use Python features that TorchScript doesn't support yet,
you could annotate those with ``@torch.jit.ignore``

``my_module`` is an instance of
``ScriptModule`` that is ready for serialization.

Step 2: Serializing Your Script Module to a File
Expand Down Expand Up @@ -152,32 +154,38 @@ do:

.. code-block:: cpp

#include <torch/script.h> // One-stop header.

#include <iostream>
#include <memory>

int main(int argc, const char* argv[]) {
if (argc != 2) {
std::cerr << "usage: example-app <path-to-exported-script-module>\n";
return -1;
#include <torch/script.h> // One-stop header.

#include <iostream>
#include <memory>

int main(int argc, const char* argv[]) {
if (argc != 2) {
std::cerr << "usage: example-app <path-to-exported-script-module>\n";
return -1;
}


torch::jit::script::Module module;
try {
// Deserialize the ScriptModule from a file using torch::jit::load().
module = torch::jit::load(argv[1]);
}
catch (const c10::Error& e) {
std::cerr << "error loading the model\n";
return -1;
}

std::cout << "ok\n";
}

// Deserialize the ScriptModule from a file using torch::jit::load().
std::shared_ptr<torch::jit::script::Module> module = torch::jit::load(argv[1]);

assert(module != nullptr);
std::cout << "ok\n";
}

The ``<torch/script.h>`` header encompasses all relevant includes from the
LibTorch library necessary to run the example. Our application accepts the file
path to a serialized PyTorch ``ScriptModule`` as its only command line argument
and then proceeds to deserialize the module using the ``torch::jit::load()``
function, which takes this file path as input. In return we receive a shared
pointer to a ``torch::jit::script::Module``, the equivalent to a
``torch.jit.ScriptModule`` in C++. For now, we only verify that this pointer is
not null. We will examine how to execute it in a moment.
function, which takes this file path as input. In return we receive a ``torch::jit::script::Module``
object. We will examine how to execute it in a moment.

Depending on LibTorch and Building the Application
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -300,8 +308,7 @@ application's ``main()`` function:
inputs.push_back(torch::ones({1, 3, 224, 224}));

// Execute the model and turn its output into a tensor.
at::Tensor output = module->forward(inputs).toTensor();

at::Tensor output = module.forward(inputs).toTensor();
std::cout << output.slice(/*dim=*/1, /*start=*/0, /*end=*/5) << '\n';

The first two lines set up the inputs to our model. We create a vector of
Expand Down Expand Up @@ -344,7 +351,7 @@ Looks like a good match!

.. tip::

To move your model to GPU memory, you can write ``model->to(at::kCUDA);``.
To move your model to GPU memory, you can write ``model.to(at::kCUDA);``.
Make sure the inputs to a model living in CUDA memory are also in CUDA memory
by calling ``tensor.to(at::kCUDA)``, which will return a new tensor in CUDA
memory.
Expand Down
17 changes: 9 additions & 8 deletions advanced_source/cpp_extension.rst
Original file line number Diff line number Diff line change
Expand Up @@ -147,23 +147,22 @@ For the "ahead of time" flavor, we build our C++ extension by writing a
``setup.py`` script that uses setuptools to compile our C++ code. For the LLTM, it
looks as simple as this::

from setuptools import setup
from torch.utils.cpp_extension import CppExtension, BuildExtension
from setuptools import setup, Extension
from torch.utils import cpp_extension

setup(name='lltm_cpp',
ext_modules=[CppExtension('lltm', ['lltm.cpp'])],
cmdclass={'build_ext': BuildExtension})

ext_modules=[cpp_extension.CppExtension('lltm_cpp', ['lltm.cpp'])],
cmdclass={'build_ext': cpp_extension.BuildExtension})

In this code, :class:`CppExtension` is a convenience wrapper around
:class:`setuptools.Extension` that passes the correct include paths and sets
the language of the extension to C++. The equivalent vanilla :mod:`setuptools`
code would simply be::

setuptools.Extension(
Extension(
name='lltm_cpp',
sources=['lltm.cpp'],
include_dirs=torch.utils.cpp_extension.include_paths(),
include_dirs=cpp_extension.include_paths(),
language='c++')

:class:`BuildExtension` performs a number of required configuration steps and
Expand Down Expand Up @@ -413,7 +412,7 @@ see::
If we call ``help()`` on the function or module, we can see that its signature
matches our C++ code::

In[4] help(lltm.forward)
In[4] help(lltm_cpp.forward)
forward(...) method of builtins.PyCapsule instance
forward(arg0: torch::Tensor, arg1: torch::Tensor, arg2: torch::Tensor, arg3: torch::Tensor, arg4: torch::Tensor) -> List[torch::Tensor]

Expand Down Expand Up @@ -473,6 +472,8 @@ small benchmark to see how much performance we gained from rewriting our op in
C++. We'll run the LLTM forwards and backwards a few times and measure the
duration::

import time

import torch

batch_size = 16
Expand Down
Loading