PyTorch tutorials.

PyTorch Tutorials

All the tutorials are now presented as sphinx style documentation at:

https://pytorch.org/tutorials

Contributing

We use sphinx-gallery's notebook styled examples to create the tutorials. Syntax is very simple. In essence, you write a slightly well formatted python file and it shows up as documentation page.

Here's how to create a new tutorial or recipe:

  1. Create a notebook styled python file. If you want it executed while inserted into documentation, save the file with suffix tutorial so that file name is your_tutorial.py.
  2. Put it in one of the beginner_source, intermediate_source, advanced_source based on the level. If it is a recipe, add to recipes_source.
  3. For Tutorials (except if it is a prototype feature), include it in the TOC tree at index.rst
  4. For Tutorials (except if it is a prototype feature), create a thumbnail in the index.rst file using a command like .. customcarditem:: beginner/your_tutorial.html. For Recipes, create a thumbnail in the recipes_index.rst

In case you prefer to write your tutorial in jupyter, you can use this script to convert the notebook to python file. After conversion and addition to the project, please make sure the sections headings etc are in logical order.

Building

  • Start with installing torch, torchvision, and your GPUs latest drivers. Install other requirements using pip install -r requirements.txt

If you want to use virtualenv, make your environment in a venv directory like: virtualenv ./venv, then source ./venv/bin/activate.

  • Then you can build using make docs. This will download the data, execute the tutorials and build the documentation to docs/ directory. This will take about 60-120 min for systems with GPUs. If you do not have a GPU installed on your system, then see next step.
  • You can skip the computationally intensive graph generation by running make html-noplot to build basic html documentation to _build/html. This way, you can quickly preview your tutorial.

If you get ModuleNotFoundError: No module named 'pytorch_sphinx_theme' make: *** [html-noplot] Error 2 from /tutorials/src/pytorch-sphinx-theme or /venv/src/pytorch-sphinx-theme (while using virtualenv), run python setup.py install.

About contributing to PyTorch Documentation and Tutorials

  • You can find information about contributing to PyTorch documentation in the PyTorch Repo README.md file.
  • Additional information can be found in PyTorch CONTRIBUTING.md.
Comments
  •  [HELP WANTED]Tutorial for nn.Transformer with nn.TransformerDecoder

    [HELP WANTED]Tutorial for nn.Transformer with nn.TransformerDecoder

    Hi, The existing tutorials for nn.Transformer e.g. https://pytorch.org/tutorials/beginner/transformer_tutorial.html and https://github.com/pytorch/examples/tree/master/word_language_model both are only use nn.TransformerEncoder. There is no tutorial using nn.TransformerDecoder. I think it is better to add one example that include nn.TransformerDecoder so that users can easy get started with. As for my own experience, I have some troubles using nn.TransfomerDecoder in inference process.

  • Neural-Style tutorial

    Neural-Style tutorial

    PyTorch tutorial explaining how to implement the neural transfer of artistic style developed by Leon Gatys and AL. The code parts of the tutorial can be tested in a whole script available here: https://github.com/alexis-jacq/Pytorch-Tutorials/blob/master/Neural_Style.py.

  • Add nvFuser tutorial for PyTorch 1.12.0

    Add nvFuser tutorial for PyTorch 1.12.0

    Adds an nvFuser tutorial for the PyTorch 1.12.0 release. A separate blog post will be published with this tutorial and we'll add cross references. If preferred, I can remove the placeholder in this PR and follow up with the right link once the blog post is published.

    CC @csarofeen @kevinstephano @mruberry

  • Language Translation with Transformers

    Language Translation with Transformers

    This tutorial show how train a language translation model from scratch using Transformers. The data processing code is taken from RNN translation tutorial. Resolves #719

  • Add new speech command recognition tutorial

    Add new speech command recognition tutorial

    Add command recognition tutorial, see colab.

    • [x] This tutorial runs in about ~~1h~~ ~~10 min using this~~ 5 min.
    • [x] Tutorial is faster on GPU, comment.
    • [x] ~~SpeechCommands as it is currently in torchaudio doesn't have the train/valid/test split. We could decide to add that in before the release to simplify the tutorial. pytorch/audio#966.~~
    • [x] ~~Experiment with MFCC instead of resample only.~~
    • [x] ~~Replace SPEECHCOMMANDS by YESNO dataset, and use torchaudio.transforms.vad to segment audio into utterances.~~

    This pull request complements #572, see also deprecated tutorial.

    cc @brianjo

  • Add a new tutorial: Building a Flask API server with PyTorch

    Add a new tutorial: Building a Flask API server with PyTorch

    I was writing this for my blog, however, I noticed that PyTorch Tutorials does not have one on building an API. So I am submitting here. My apologies, since I did not discuss this here first. I think PyTorch Tutorial could really use this 😄

  • Adding model parallel tutorial

    Adding model parallel tutorial

    I feel model parallel itself already has enough meat to make a separate tutorial page. The DistributedDataParallel wrapping ModelParallel tutorial will come in my next PR. Let me know if I should merge them into one instead.

  • Update audio preprocessing tutorial

    Update audio preprocessing tutorial

    Updating the audio tutorial for the Jan 7 release

    • [x] support for batching in transforms. (pytorch/audio#337, pytorch/audio#327)
    • [x] torchaudio.functional.gain and torchaudio.functional.dither. (pytorch/audio#319, pytorch/audio#360)
    • [x] data augmentations in torchaudio.augmentation: TimeStretch, FrequencyMasking, TimeMasking. (pytorch/audio#285, pytorch/audio#333, pytorch/audio#348)
      • Going to add example in next iteration of tutorial
    • [x] compute deltas: torchaudio.functional.compute_deltas. (pytorch/audio#268, pytorch/audio#326)
    • [x] torchaudio.functional.equalizer_biquad. (pytorch/audio#315, pytorch/audio#340)
    • [x] torchaudio.functional.lowpass_biquad and torchaudio.functional.highpass_biquad. (pytorch/audio#275)
    • [x] torchaudio.kaldi.mfcc (https://pytorch.org/audio/functional.html#mfcc ). (pytorch/audio#228)

    In a following update of the tutorial, we will want:

    • [x] We introduce a backend switch mechanism to replace sox by something else. We currently support soundfile along with sox. The backends are loaded lazily when needed. (pytorch/audio#355)
    • [x] We now have a unified datasets interface with lazy loading of files to memory, new download and extract functions, and new datasets: LibriSpeech and CommonVoice. (pytorch/audio#303, pytorch/audio#316, pytorch/audio#330)

    Lower priority items:

    • [x] We make jit compilation optional for function and use nn.Module where possible. (pytorch/audio#314, pytorch/audio#326, pytorch/audio#342)
  • Web page for Tutorials

    Web page for Tutorials

    Hi,

    I've been working on beautifying/integrating all the tutorials on pytorch into one. see https://github.com/pytorch/pytorch/pull/778. These tutorials are based on sphinx-gallery and tutorials are executed during build time.

    I've created a separate repo for the tutorials and used gh-pages to host them: http://chsasank.github.io/pytorch-tutorials. I also added my own transfer learning tutorial

    After a discussion with @soumith, he suggested we should host these tutorials at tutorials.pytorch.org. He also requested a change:

    • [x] Categorize tutorials by level instead of source

    If indeed this is to be front face of tutorials, we'll need to figure out

    • [x] how to modify the repo
    • [x] how to build the sources and host

    For hosting, we shouldn't probably use github pages as it will mess up the git history with all the html files.

    Since these tutorials are executed at build, we might need a decently powered build environment. Most tutorials take may be 5 min on my macbook air. Except seq2seq tutorial, which took 40 min on CPU/25 min on GPU. Note that a tutorial is re-excuted only if changes are made to the tutorial file.

    Thanks, Sasank.

  • Reinstate torchaudio tutorial

    Reinstate torchaudio tutorial

    Let's see if the tutorial loads correctly with current binaries. pytorch/audio#307

    This partly reverts commit 9cee82507629c5f557dcef0ed508dc973935ad92 from #685.

    CC @SethHWeidman @ezyang

  • export ONNX failed with Transfering a Model from PyTorch to Caffe2 and Mobile using ONNX

    export ONNX failed with Transfering a Model from PyTorch to Caffe2 and Mobile using ONNX

    followed with Transfering a Model from PyTorch to Caffe2 and Mobile using ONNX, when run below code, it appear AssertionError: Arrays are not almost equal to 3 decimals

    import onnx
    import caffe2.python.onnx.backend as onnx_caffe2_backend
    
    # Load the ONNX ModelProto object. model is a standard Python protobuf object
    model = onnx.load("super_resolution.onnx")
    
    # prepare the caffe2 backend for executing the model this converts the ONNX model into a
    # Caffe2 NetDef that can execute it. Other ONNX backends, like one for CNTK will be
    # availiable soon.
    prepared_backend = onnx_caffe2_backend.prepare(model)
    
    # run the model in Caffe2
    
    # Construct a map from input names to Tensor data.
    # The graph of the model itself contains inputs for all weight parameters, after the input image.
    # Since the weights are already embedded, we just need to pass the input image.
    # Set the first input.
    W = {model.graph.input[0].name: x.data.numpy()}
    
    # Run the Caffe2 net:
    c2_out = prepared_backend.run(W)[0]
    
    # Verify the numerical correctness upto 3 decimal places
    np.testing.assert_almost_equal(torch_out.data.cpu().numpy(), c2_out, decimal=3)
    
    print("Exported model has been executed on Caffe2 backend, and the result looks good!")
    
  • [ao] fixing tutorials

    [ao] fixing tutorials

    Stack from ghstack (oldest at bottom):

    • -> #2137

    Summary: fixing tutorial to have example_inputs and QConfigMapping

    Test Plan:

    built tutorials

    for fx_graph_mode_ptq_static.rst and fx_graph_mode_ptq_dynamic.py I pasted and ran the script to verify that it ran, the latter could be run exactly while the former required a slight modification since I had a different version of the imagenet dataset but only the dataloaders had to be modified.

    for the quant_guide no explicit testing was done Reviewers:

    Subscribers:

    Tasks:

    Tags:

  • fix on cifar10 tutorial for windows platform

    fix on cifar10 tutorial for windows platform

    A fix to the cifar10_tutorial.py file is proposed resolving issue #12645 on pytorch repo. This fix will allow the tutorial to run correctly without needing any modification on Windows. For other platforms, there should not be any difference. To keep the structure and flow of the tutorial the same, the necessary if statement was added on top.

    cc @suraj813

  • 自动驾驶更新笔记 Autopilot Updating Notes

    自动驾驶更新笔记 Autopilot Updating Notes

    您好,仓库内容很全面,非常受益, 可否引荐下本人的笔记,把我对自动驾驶的理解分享给大家,希望大家和我一起不断完善相关内容,谢谢您!

    Hello, the content of the repository is very comprehensive and very beneficial. Could you introduce my notes and share my understanding of autopilot with others? I hope you can continue to improve the relevant content with me, thank you!

    Autopilot-Updating-Notes

  • Bump pillow from 9.0.1 to 9.3.0

    Bump pillow from 9.0.1 to 9.3.0

    Bumps pillow from 9.0.1 to 9.3.0.

    Release notes

    Sourced from pillow's releases.

    9.3.0

    https://pillow.readthedocs.io/en/stable/releasenotes/9.3.0.html

    Changes

    ... (truncated)

    Changelog

    Sourced from pillow's changelog.

    9.3.0 (2022-10-29)

    • Limit SAMPLESPERPIXEL to avoid runtime DOS #6700 [wiredfool]

    • Initialize libtiff buffer when saving #6699 [radarhere]

    • Inline fname2char to fix memory leak #6329 [nulano]

    • Fix memory leaks related to text features #6330 [nulano]

    • Use double quotes for version check on old CPython on Windows #6695 [hugovk]

    • Remove backup implementation of Round for Windows platforms #6693 [cgohlke]

    • Fixed set_variation_by_name offset #6445 [radarhere]

    • Fix malloc in _imagingft.c:font_setvaraxes #6690 [cgohlke]

    • Release Python GIL when converting images using matrix operations #6418 [hmaarrfk]

    • Added ExifTags enums #6630 [radarhere]

    • Do not modify previous frame when calculating delta in PNG #6683 [radarhere]

    • Added support for reading BMP images with RLE4 compression #6674 [npjg, radarhere]

    • Decode JPEG compressed BLP1 data in original mode #6678 [radarhere]

    • Added GPS TIFF tag info #6661 [radarhere]

    • Added conversion between RGB/RGBA/RGBX and LAB #6647 [radarhere]

    • Do not attempt normalization if mode is already normal #6644 [radarhere]

    ... (truncated)

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

Minimal tutorials for PyTorch

Minimal tutorials for PyTorch adapted from Alec Radford's Theano tutorials. Tensor multiplication Linear Regression Logistic Regression Neural Network

Oct 25, 2022
Simple PyTorch Tutorials Zero to ALL!

PyTorchZeroToAll Quick 3~4 day lecture materials for HKUST students. Video Lectures: (RNN TBA) Youtube Bilibili Slides Lecture Slides @GoogleDrive If

Nov 25, 2022
PyTorch tutorials and best practices.

Effective PyTorch Table of Contents Part I: PyTorch Fundamentals PyTorch basics Encapsulate your model with Modules Broadcasting the good and the ugly

Nov 28, 2022
A set of examples around pytorch in Vision, Text, Reinforcement Learning, etc.

PyTorch Examples WARNING: if you fork this repo, github actions will run daily on it. To disable this, go to /examples/settings/actions and Disable Ac

Nov 29, 2022
Deep Learning (with PyTorch)

Deep Learning (with PyTorch) This notebook repository now has a companion website, where all the course material can be found in video and textual for

Dec 2, 2022
Open source guides/codes for mastering deep learning to deploying deep learning in production in PyTorch, Python, C++ and more.
Open source guides/codes for mastering deep learning to deploying deep learning in production in PyTorch, Python, C++ and more.

Deep Learning Materials by Deep Learning Wizard Start Learning Now Please head to www.deeplearningwizard.com to start learning! It is mobile/tablet fr

Nov 21, 2022
Simple examples to introduce PyTorch

This repository introduces the fundamental concepts of PyTorch through self-contained examples. At its core, PyTorch provides two main features: An n-

Dec 4, 2022
PyTorch Tutorial for Deep Learning Researchers

This repository provides tutorial code for deep learning researchers to learn PyTorch. In the tutorial, most of the models were implemented with less

Dec 2, 2022
PyTorch Implementation of Fully Convolutional Networks. (Training code to reproduce the original result is available.)
PyTorch Implementation of Fully Convolutional Networks. (Training code to reproduce the original result is available.)

pytorch-fcn PyTorch implementation of Fully Convolutional Networks. Requirements pytorch >= 0.2.0 torchvision >= 0.1.8 fcn >= 6.1.5 Pillow scipy tqdm

Dec 1, 2022
Pytorch implementations of various Deep NLP models in cs-224n(Stanford Univ)

DeepNLP-models-Pytorch Pytorch implementations of various Deep NLP models in cs-224n(Stanford Univ: NLP with Deep Learning) This is not for Pytorch be

Dec 2, 2022
A scalable template for PyTorch projects, with examples in Image Segmentation, Object classification, GANs and Reinforcement Learning.
A scalable template for PyTorch projects, with examples in Image Segmentation, Object classification, GANs and Reinforcement Learning.

PyTorch Project Template is being sponsored by the following tool; please help to support us by taking a look and signing up to a free trial PyTorch P

Nov 27, 2022
Some example scripts on pytorch

pytorch-practice Some example scripts on pytorch CONLL 2000 Chunking task Uses BiLSTM CRF loss with char CNN embeddings. To run use: cd data/conll2000

Nov 29, 2022
Example of network fine-tuning in pytorch for the kaggle competition Dogs vs. Cats Redux: Kernels Edition

Example of network fine-tuning in pytorch for the kaggle competition Dogs vs. Cats Redux: Kernels Edition Currently

Sep 22, 2022
ConvNet training using pytorch

Convolutional networks using PyTorch This is a complete training example for Deep Convolutional Networks on various datasets (ImageNet, Cifar10, Cifar

Nov 4, 2022
simple generative adversarial network (GAN) using PyTorch

Generative Adversarial Networks (GANs) in PyTorch Running Run the sample code by typing: ./gan_pytorch.py ...and you'll train two nets to battle it o

Jun 14, 2020
Torch Containers simplified in PyTorch
Torch Containers simplified in PyTorch

pytorch-containers This repository aims to help former Torchies more seamlessly transition to the "Containerless" world of PyTorch by providing a list

Apr 25, 2022
The Hitchiker's Guide to PyTorch

The Hitchiker's Guide to PyTorch

Nov 2, 2022
Simple tutorials on Pytorch DDP training

pytorch-distributed-training Distribute Dataparallel (DDP) Training on Pytorch Features Easy to study DDP training You can directly copy this code for

Nov 28, 2022
Pytorch tutorials for Neural Style transfert

PyTorch Tutorials This tutorial is no longer maintained. Please use the official version: https://pytorch.org/tutorials/advanced/neural_style_tutorial

Jun 26, 2022
Pytorch Geometric Tutorials

Pytorch Geometric Tutorials

Dec 2, 2022