All Projects → davidbau → How To Read Pytorch

davidbau / How To Read Pytorch

Quick, visual, principled introduction to pytorch code through five colab notebooks.

Projects that are alternatives of or similar to How To Read Pytorch

Psi4numpy
Combining Psi4 and Numpy for education and development.
Stars: ✭ 170 (-22.02%)
Mutual labels:  jupyter-notebook, tutorial
Tutorials
AI-related tutorials. Access any of them for free → https://towardsai.net/editorial
Stars: ✭ 204 (-6.42%)
Mutual labels:  jupyter-notebook, tutorial
Astropy Tutorials
Tutorials for the Astropy Project
Stars: ✭ 174 (-20.18%)
Mutual labels:  jupyter-notebook, tutorial
Interspeech2019 Tutorial
INTERSPEECH 2019 Tutorial Materials
Stars: ✭ 160 (-26.61%)
Mutual labels:  jupyter-notebook, tutorial
Rl Tutorial Jnrr19
Stable-Baselines tutorial for Journées Nationales de la Recherche en Robotique 2019
Stars: ✭ 204 (-6.42%)
Mutual labels:  jupyter-notebook, tutorial
Learnpythonforresearch
This repository provides everything you need to get started with Python for (social science) research.
Stars: ✭ 163 (-25.23%)
Mutual labels:  jupyter-notebook, tutorial
Gans From Theory To Production
Material for the tutorial: "Deep Diving into GANs: from theory to production"
Stars: ✭ 182 (-16.51%)
Mutual labels:  jupyter-notebook, tutorial
Anomaly detection tuto
Anomaly detection tutorial on univariate time series with an auto-encoder
Stars: ✭ 144 (-33.94%)
Mutual labels:  jupyter-notebook, tutorial
Bayesian Modelling In Python
A python tutorial on bayesian modeling techniques (PyMC3)
Stars: ✭ 2,332 (+969.72%)
Mutual labels:  jupyter-notebook, tutorial
Trump Lies
Tutorial: Web scraping in Python with Beautiful Soup
Stars: ✭ 201 (-7.8%)
Mutual labels:  jupyter-notebook, tutorial
Gasyori100knock
image processing codes to understand algorithm
Stars: ✭ 1,988 (+811.93%)
Mutual labels:  jupyter-notebook, tutorial
Sc17
SuperComputing 2017 Deep Learning Tutorial
Stars: ✭ 211 (-3.21%)
Mutual labels:  jupyter-notebook, tutorial
Pytorch Question Answering
Important paper implementations for Question Answering using PyTorch
Stars: ✭ 154 (-29.36%)
Mutual labels:  jupyter-notebook, tutorial
Shape Detection
🟣 Object detection of abstract shapes with neural networks
Stars: ✭ 170 (-22.02%)
Mutual labels:  jupyter-notebook, tutorial
Autonomousdrivingcookbook
Scenarios, tutorials and demos for Autonomous Driving
Stars: ✭ 1,939 (+789.45%)
Mutual labels:  jupyter-notebook, tutorial
Deeptoxic
top 1% solution to toxic comment classification challenge on Kaggle.
Stars: ✭ 180 (-17.43%)
Mutual labels:  jupyter-notebook, tutorial
Scipy con 2019
Tutorial Sessions for SciPy Con 2019
Stars: ✭ 142 (-34.86%)
Mutual labels:  jupyter-notebook, tutorial
Digital video introduction
A hands-on introduction to video technology: image, video, codec (av1, vp9, h265) and more (ffmpeg encoding).
Stars: ✭ 12,184 (+5488.99%)
Mutual labels:  jupyter-notebook, tutorial
Imodels
Interpretable ML package 🔍 for concise, transparent, and accurate predictive modeling (sklearn-compatible).
Stars: ✭ 194 (-11.01%)
Mutual labels:  jupyter-notebook, tutorial
Dlsys Course.github.io
Deep learning system course
Stars: ✭ 207 (-5.05%)
Mutual labels:  jupyter-notebook, tutorial

David's Tips on How to Read Pytorch

Figure thumbnails

These five python notebooks are an illustrated introduction to core pytorch idioms. Click below to run them on Colab.

  1. Tensor arithmetic: the notation for manipulating n-dimensional arrays of numbers on CPU or GPU.
  2. Autograd: how to get derivatives of any scalar with respect to any tensor input.
  3. Optimization: ways to update tensor parameters to reduce any computed objective, using autograd gradients.
  4. Network modules: how pytorch represents neural networks for convenient composition, training, and saving.
  5. Datasets and Dataloaders: for efficient multithreaded prefetching of large streams of data.

Pytorch is a numerical library that makes it very convenient to train deep networks on GPU hardware. It introduces a new programming vocabulary that takes a few steps beyond regular numerical python code. Although pytorch code can look simple and concrete, much of of the subtlety of what happens is invisible, so when working with pytorch code it helps to thoroughly understand the runtime model.

For example, consider this code:

torch.nn.cross_entropy(model(images.cuda()), labels.cuda()).backward()
optimizer.step()

It looks like it computes some function of images and labels without storing the answer. But actually the purpose of this code is to update some hidden parameters that are not explicit in this formula. This line of code moves batches of image and label data from CPU to the GPU; runs a neural network to make a prediction; constructs a computation graph describing how the loss depends on the network parameters; annotates every network parameter with a gradient; then finally it runs one step of optimization to adjust every parameter of the model. During all this, the CPU does not see any of the actual answers. That is intentional for speed reasons. All the numerical computation is done on the GPU asynchronously and kept there.

The berevity of the code is what makes pytorch code fun to write. But it also reflects why pytorch can be so fast even though the python interpreter is so slow. Although the main python logic slogs along sequentially in a single very slow CPU thread, just a few python instructions can load a huge amount of work into the GPU. That means the program can keep the GPU busy churning through massive numerical computations, for most part, without waiting for the python interpreter.

Is is worth understanding five idioms that work together to make this possible. The five notebooks in this directory are a quick overview of these idioms.

The key ideas are illustrated with small, runnable, tweakable examples, and there are links to other reference material and resources.

All the notebooks can be run on Google Colab where GPUs can be used for free. Or they can be run on your own local Jupyter notebook server. The examples should all work with python 3.5 or newer and pytorch 1.0 or newer.

Start with the first notebook here!

--- David Bau, July 2020

(David is a PhD student at MIT and former Google engineer. His research pursues transparency in deep networks.)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].