Guide · Open source
How to use pytorch-book: setup, chapters and projects
Updated · written with AI from the project's own documentation and checked against our catalogue data
pytorch-book is the code and Jupyter notebooks that accompany a Chinese book on PyTorch, the deep learning library, and it also works as a standalone beginner's guide. This page explains how to get the repository, what each part covers and which version of PyTorch the code was tested with. By the end you will know where to start, how to run the notebooks, and which chapters to read in order.
Quick start
- 1Check your environment. Confirm you have Python 3 and install PyTorch from pytorch.org. Choose a version in the tested range of 1.6 to 1.8.
- 2Clone the repository. Run the git clone command from the README to download the PyTorch-book code to your machine.
- 3Open Jupyter Notebook. Launch Jupyter in the cloned folder and open the notebook for chapter 2 or 3 to start with the basics.
- 4Work through chapters 3 to 5. Cover Tensor, autograd, the nn module and the tools chapter, editing and rerunning cells as you go.
- 5Try a project. Pick a practical chapter such as poem writing or style transfer and run its code or pretrained demo.
What you need before you start
The README lists Python 3 and PyTorch as the prerequisites. The code was tested with PyTorch 1.6 to 1.8, and the README says newer versions were not tested, so pick a version in that range if you want results to match the book.
The README says to install PyTorch from the official site at pytorch.org, choosing the version you need, and points to the book for other installation methods.
- Python 3 (the README says Python 2 was not tested)
- PyTorch, tested with versions 1.6 to 1.8
- Git, to clone the repository
Clone the repository and open the notebooks
The setup is a clone-and-build style install: you download the repository and run its notebooks. The README gives one clone command. Notebooks are written in Jupyter Notebook, which the README uses as the teaching tool for the basic-usage chapters, so you can change code and rerun it.
- Clone the repo with the command below.
- Open the folder in Jupyter Notebook and run the notebook for the chapter you are reading.
- Edit cells and rerun them to test ideas, which the README encourages.
git clone https://github.com/chenyuntc/PyTorch-book.gitFollow the three parts of the tutorial
The content is split into three parts. Basic usage (chapters 2 to 5) covers PyTorch's main modules: Tensors and autograd, the nn module for layers, activations, loss functions and optimizers, and tools such as data loading, pretrained models, visualization and GPU acceleration.
Advanced extensions (chapters 6 to 8) cover vectorization with broadcasting and indexing, distributed training with torch.distributed and Horovod, and CUDA extensions. Practical applications (chapters 9 to 13) provide complete code and pretrained models as demos.
- Chapters 2-5: installation, Tensor and autograd, nn module (including a ResNet built in under 50 lines), tools
- Chapters 6-8: vectorization, distributed computing, CUDA extension
- Chapter 9: a binary image classification task based on a Kaggle competition, plus debugging
- Chapter 10: building an anime avatar generator with GANs
- Chapter 11: Char RNN and Transformer, with automatic poem writing
- Chapter 12: arbitrary style transfer
- Chapter 13: the CenterNet object detection algorithm
Try the practical projects
The last five chapters are the fun part. Each one implements an application, and the repository provides the full code along with pretrained models you can use as demos. The poem writer, for example, can continue a poem or generate an acrostic (a poem where the first characters spell a phrase). The style transfer network lets you turn any image into the style of a famous painting.
The README does not give run commands for these projects, so check each chapter's notebook or code for instructions.
- Poem writing with a Transformer: continue a poem or write an acrostic
- Anime avatar generation with a GAN
- Arbitrary style transfer: convert a photo into a painting style
- CenterNet object detection
Know the limits before you commit
The README is honest about its limits. The notebook text is an early draft and may contain awkward wording, and it says the book and repo are about 80 percent consistent. The text is in Chinese, so English-speaking readers will need a translator or another resource. The code was tested on PyTorch 1.6 to 1.8, so newer PyTorch features may not work as shown.
The README also says you do not need to buy the book, because the repo contains over 60 percent of the text and over 90 percent of the code. Bug reports and questions go through GitHub issues, and the README welcomes pull requests.
- Notebook text is an early draft that may have awkward wording
- Content is in Chinese
- Tested on PyTorch 1.6 to 1.8 only
- Questions and bugs: open a GitHub issue
What people use it for
- Learning Tensors and autograd by running linear regression in a notebook
- Building a small ResNet from the nn module chapter
- Experimenting with a Transformer that writes classical-style poems
- Running a style transfer demo to turn a photo into a painting style
- Studying how CenterNet detects objects, as a reference for computer vision study
Frequently asked questions
Is pytorch-book free?
The repository is released under the MIT licence, according to its listing. The README says buying the printed book is optional because the repo contains over 60 percent of the text and over 90 percent of the code.
What version of PyTorch does pytorch-book need?
The README says the code was tested with Python 3 and PyTorch 1.6 to 1.8, and that the second edition was written for PyTorch 1.8. Newer versions were not tested, so results may differ.
How do I install pytorch-book?
Clone the repository with git clone https://github.com/chenyuntc/PyTorch-book.git, then install PyTorch from pytorch.org. The README does not describe a separate install step for the code itself.
Is pytorch-book in English?
No. The README and the course text are in Chinese, so English-speaking readers will need a translation tool or an English resource such as the PyTorch official tutorials.
Can a beginner use pytorch-book without knowing PyTorch?
Yes, the README says it can be read on its own as a beginner's guide. Basic knowledge of Python is helpful, since the README describes the tutorial as an introduction to PyTorch concepts.
What are good alternatives to pytorch-book?
Comparable resources include the PyTorch official tutorials, d2l.ai (Dive into Deep Learning) and fast.ai course materials. Choose pytorch-book if you want Chinese-language notebooks with small projects like poem writing and style transfer.
New agent skills, repos and AI tools — every week
The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.
Our verdict
Use pytorch-book if you read Chinese, are new to PyTorch, and want runnable notebooks with small projects such as style transfer and poem generation. Skip it if you need English material, the newest PyTorch features, or polished prose, and consider the PyTorch official tutorials or d2l.ai instead.
Install options & downloads