what is pytorch?on-demand.gputechconf.com/gtc/2018/presentation/s... ·...

69

Upload: others

Post on 07-Aug-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural
Page 2: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

Adam Paszke, Sam Gross, Soumith Chintala, Francisco Massa, Adam Lerer, James Bradbury, Gregory Chanan, Trevor Killeen, Zeming Lin, Natalia Gimelshein, Alban Desmaison, Andreas Kopf, Edward Yang, Zach Devito, Martin Raison, Alykhan Tejani, Sasank Chilamkurthy & Team

Page 3: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

What is PyTorch?

Page 4: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

What is PyTorch?

Ndarray library with GPU support

automatic differentiation engine

gradient based optimization package

Deep Learning

Reinforcement LearningNumpy-alternative

Utilities (data loading, etc.)

Page 5: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

ndarray library•np.ndarray <-> torch.Tensor •200+ operations, similar to numpy •very fast acceleration on NVIDIA GPUs

Page 6: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

ndarray library

Numpy PyTorch

Page 7: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

ndarray / Tensor library

Page 8: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

ndarray / Tensor library

Page 9: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

ndarray / Tensor library

Page 10: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

ndarray / Tensor library

Page 11: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

NumPy bridge

Page 12: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

NumPy bridge

Zero memory-copy very efficient

Page 13: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

NumPy bridge

Page 14: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

NumPy bridge

Page 15: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

Seamless GPU Tensors

Page 16: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

automatic differentiation enginefor deep learning and reinforcement learning

Page 17: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

PyTorch Autogradfrom torch.autograd import Variable

Page 18: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

from torch.autograd import Variable

x = Variable(torch.randn(1, 10)) prev_h = Variable(torch.randn(1, 20)) W_h = Variable(torch.randn(20, 20)) W_x = Variable(torch.randn(20, 10))

PyTorch Autograd

Page 19: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

from torch.autograd import Variable

x = Variable(torch.randn(1, 10)) prev_h = Variable(torch.randn(1, 20)) W_h = Variable(torch.randn(20, 20)) W_x = Variable(torch.randn(20, 10))

i2h = torch.mm(W_x, x.t()) h2h = torch.mm(W_h, prev_h.t())

MMMM

PyTorch Autograd

Page 20: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

from torch.autograd import Variable

x = Variable(torch.randn(1, 10)) prev_h = Variable(torch.randn(1, 20)) W_h = Variable(torch.randn(20, 20)) W_x = Variable(torch.randn(20, 10))

i2h = torch.mm(W_x, x.t()) h2h = torch.mm(W_h, prev_h.t()) next_h = i2h + h2h

MMMM

PyTorch Autograd

Page 21: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

from torch.autograd import Variable

x = Variable(torch.randn(1, 10)) prev_h = Variable(torch.randn(1, 20)) W_h = Variable(torch.randn(20, 20)) W_x = Variable(torch.randn(20, 10))

i2h = torch.mm(W_x, x.t()) h2h = torch.mm(W_h, prev_h.t()) next_h = i2h + h2h

Add

MMMM

PyTorch Autograd

Page 22: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

from torch.autograd import Variable

x = Variable(torch.randn(1, 10)) prev_h = Variable(torch.randn(1, 20)) W_h = Variable(torch.randn(20, 20)) W_x = Variable(torch.randn(20, 10))

i2h = torch.mm(W_x, x.t()) h2h = torch.mm(W_h, prev_h.t()) next_h = i2h + h2h next_h = next_h.tanh()

Add

MMMM

Tanh

PyTorch Autograd

Page 23: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

from torch.autograd import Variable

x = Variable(torch.randn(1, 10)) prev_h = Variable(torch.randn(1, 20)) W_h = Variable(torch.randn(20, 20)) W_x = Variable(torch.randn(20, 10))

i2h = torch.mm(W_x, x.t()) h2h = torch.mm(W_h, prev_h.t()) next_h = i2h + h2h next_h = next_h.tanh()

next_h.backward(torch.ones(1, 20))

Add

MMMM

Tanh

PyTorch Autograd

Page 24: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

Neural Networks

Page 25: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

Neural Networks

Page 26: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

Neural Networks

Page 27: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

Optimization packageSGD, Adagrad, RMSProp, LBFGS, etc.

Page 28: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

Work items in practice

Writing Dataset loaders

Building models Implementing Training loop

Checkpointing models

Interfacing with environments

Dealing with GPUsBuilding optimizers Building

Baselines

Page 29: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

Work items in practice

Writing Dataset loaders

Building models Implementing Training loop

Checkpointing models

Interfacing with environments

Dealing with GPUsBuilding optimizers Building

Baselines

Python + PyTorch - an environment to do all of this

Page 30: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

Writing Data Loaders

• every dataset is slightly differently formatted

Page 31: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

Writing Data Loaders

• every dataset is slightly differently formatted • have to be preprocessed and normalized differently

Page 32: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

• every dataset is slightly differently formatted • have to be preprocessed and normalized differently • need a multithreaded Data loader to feed GPUs fast enough

Writing Data Loaders

Page 33: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

PyTorch solution: • share data loaders across the community!

Writing Data Loaders

Page 34: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

PyTorch solution: • share data loaders across the community!

Writing Data Loaders

Page 35: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

PyTorch solution: • use regular Python to write Datasets:

leverage existing Python code

Writing Data Loaders

Page 36: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

PyTorch solution: • use regular Python to write Datasets:

leverage existing Python code Example: ParlAI

Writing Data Loaders

Page 37: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

PyTorch solution: •Code in practice

Writing Data Loaders

Page 38: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

PyTorch solution: •Code in practice

Core Philisophy Upcoming Features

Pain PointsResearch Workflows

Writing Data Loaders

Page 39: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

PyTorch solution: •Code in practice

Core Philisophy Upcoming Features

Pain PointsResearch Workflows

Writing Data Loaders

Page 40: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

Interfacing with environments

Cars Video gamesInternet

Page 41: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

Interfacing with environments

Cars Video gamesPretty much every environment provides a Python API

Page 42: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

Interfacing with environments

Cars Video gamesNatively interact with the environment directly

Page 43: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

Debugging• PyTorch is a Python extension

Page 44: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

Debugging• PyTorch is a Python extension • Use your favorite Python debugger

Page 45: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

Debugging• PyTorch is a Python extension • Use your favorite Python debugger

Page 46: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

Debugging• PyTorch is a Python extension • Use your favorite Python debugger • Use the most popular debugger:

Page 47: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

Debugging• PyTorch is a Python extension • Use your favorite Python debugger • Use the most popular debugger:

print(foo)

Page 48: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

Identifying bottlenecks• PyTorch is a Python extension • Use your favorite Python profiler

Page 49: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

Identifying bottlenecks• PyTorch is a Python extension • Use your favorite Python profiler: Line_Profiler

Page 50: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

Compilation Time• PyTorch is written for the impatient

Page 51: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

Compilation Time• PyTorch is written for the impatient • Absolutely no compilation time when writing your scripts whatsoever

Page 52: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

Compilation Time• PyTorch is written for the impatient • Absolutely no compilation time when writing your scripts whatsoever

• All core kernels are pre-compiled

Page 53: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

Distributed PyTorch• MPI style distributed communication • Broadcast Tensors to other nodes • Reduce Tensors among nodes - for example: sum gradients among all nodes

Page 54: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

VisualizationTensorBoard-PyTorch Visdom

https://github.com/lanpa/tensorboard-pytorchhttps://github.com/facebookresearch/visdom

Page 55: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

Ecosystem• Use the entire Python ecosystem at your will

Page 56: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

Ecosystem• Use the entire Python ecosystem at your will • Including SciPy, Scikit-Learn, etc.

Page 57: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

Ecosystem• Use the entire Python ecosystem at your will • Including SciPy, Scikit-Learn, etc.

Page 58: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

Ecosystem• A shared model-zoo:

Page 59: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

Ecosystem• A shared model-zoo:

Page 60: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

Ecosystem•Probabilistic Programming

http://pyro.ai/

github.com/probtorch/probtorch

Page 61: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

Ecosystem•Gaussian Processes

https://github.com/cornellius-gp/gpytorch

Page 62: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

Ecosystem•QRNN - 2x to 17x faster than LSTM

https://github.com/salesforce/pytorch-qrnn

Page 63: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

Ecosystem•CycleGAN, pix2pix

https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix

Page 64: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

Ecosystem•Machine Translation

https://github.com/OpenNMT/OpenNMT-py https://github.com/facebookresearch/fairseq-py

Page 65: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

Ecosystem•AllenNLP http://allennlp.org/

Page 66: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

Ecosystem•Pix2PixHD

https://github.com/NVIDIA/pix2pixHD

Page 67: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

Ecosystem•Sentiment Discovery

https://github.com/NVIDIA/sentiment-discovery

Page 68: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

Ecosystem•FlowNet2: Optical Flow Estimation with Deep Networks

https://github.com/NVIDIA/flownet2-pytorch

Page 69: What is PyTorch?on-demand.gputechconf.com/gtc/2018/presentation/s... · next_h.backward(torch.ones(1, 20)) Add MM MM Tanh PyTorch Autograd. Neural Networks. Neural Networks. Neural

http://pytorch.org

With ❤ from