← Open Source
prabhuomkar

pytorch-cpp

C++ Implementation of PyTorch Tutorials for Everyone.

TutorialsML/AI fundamentalsC++
Open on GitHub
Momentum
+0stars in 24 hours0.0%
2.14k
Stars
272
Forks
+2
This week
4
Contributors
Created 2019-11-05 · Updated 2026-10-15 · #8930 today
Top developers

prabhuomkar/pytorch-cpp is ranked 8,930 with 2,142 stars.

Same-category comparison

prabhuomkar/pytorch-cpp is ranked 8,930 among these 8 peers; luispedro/BuildingMachineLearningSystemsWithPython is ranked 8,933.

Same-category comparison
NameRankMetrics
dabochen/spreadsheet-is-all-you-need8,916
Stars:
2,158
Forks:
130
Description:
A nanoGPT pipeline packed in a spreadsheet.
codenihar/ml8,920
Stars:
2,154
Forks:
61
Description:
This repo contains all the resources related to the massive mass coders machine learning series.
greshake/llm-security8,924
Language:
Jupyter Notebook
Stars:
2,149
Forks:
160
Description:
New ways of breaking app-integrated LLMs.
SharifiZarchi/Introduction_to_Machine_Learning8,925
Language:
Jupyter Notebook
Stars:
2,146
Forks:
410
Description:
Machine Learning Course, Sharif University of Technology.
luispedro/BuildingMachineLearningSystemsWithPython8,933
Language:
Python
Stars:
2,137
Forks:
1,406
Description:
Source Code for the book Building Machine Learning Systems with Python.
ZJU4HealthCare/Foundations-of-Medical-LLMs8,945
Stars:
2,129
Forks:
352
Description:
Foundations of Medical Large Language Model Learning.
golbin/TensorFlow-Tutorials8,954
Language:
Python
Stars:
2,122
Forks:
972
microsoft/PromptCraft-Robotics8,960
Language:
Python
Stars:
2,119
Forks:
219
Description:
Community for applying LLMs to robotics and a robot simulator with ChatGPT integration.
Key parameters and specifications
Key parameters and specifications
ParameterValue
LanguageC++
CategoryTutorials
SubcategoryML/AI fundamentals
KeywordsEducation
Stars2,142
Forks272
Contributors4
Created date2019-11-05
Updated date2026-10-15
Stars in 1 day0
Stars in 7 days2
Rank8,930
Previous rank8,988
Rank change58
7-day stars rank7,844
Previous 7-day stars rank7,866
7-day stars rank change22
Total stars rank6,003
Previous total stars rank5,993
Total stars rank change-10
CountryIndia
README summary

Section 1 to 3)_ **Python Tutorial**: 1. Basics PyTorch Basics Linear Regression Logistic Regression Feedforward Neural Network 2. Intermediate Convolutional Neural Network Deep Residual Network Recurrent Neural Network Bidirectional Recurrent Neural Network Language Model (RNN-LM) 3. Advanced Generative Adversarial Networks Variational Auto-Encoder Neural Style Transfer Image Captioning (CNN-AttentionRNN) 4. Other Popular Tutorials Deep Learning with PyTorch: A 60 Minute Blitz Getting Started Requirements 1. 0 and **_Note for Windows users:_** Libtorch only supports 64bit Windows and an

x64 generator needs to be specified. For Visual Studio this can be done by appending to the above command. | | | | Determines which libtorch build type version to download (only relevant on **Windows**). | | | | Download required datasets during build (only if they do not already exist in ). | | | | Create all required scriptmodule files for prelearned models / weights during build. Requires installed python3 with pytorch and torchvision. | | | | Skip the downloading of LibTorch and use your own local version (see Requirements) instead. | | | | Determines the CMake build

-type for single-configuration generators (see CMake docs). | Example Linux Aim Use existing Python, PyTorch (see Requirements) and torchvision installation. Download all datasets and create all necessary scriptmodule files. Command Example Windows Aim Automatically download LibTorch for CUDA 11. 8 (Release version) and all necessary datasets. Command Build >**_Note for Windows (Visual Studio) users:_** >The CMake script downloads the *Release* version of LibTorch, so has to be appended to the build command. **How dataset download and scriptmodule creation work:** If

is , the datasets required by the tutorials you choose to build will be downloaded to (if they do not already exist there). If is , the scriptmodule files for the prelearned models / weights required by the tutorials you choose to build will be created in the folder of the respective tutorial's source folder (if they do not already exist). All tutorials To build all tutorials use All tutorials in a category You can choose to only build tutorials in one of

the categories , , or . For example, if you are only interested in the tutorials: Single tutorial You can also choose to only build a single tutorial. For example to build the language model tutorial only: >**_Note_**: The target argument is the tutorial's foldername with all underscores replaced by hyphens. >**_Tip for users of CMake version >= 3. 15_**: You can specify several targets separated by spaces, for example: Run Tutorials 1. **) First change into the tutorial's directory within . For example, assuming you

are in the directory and want to change to the pytorch basics tutorial folder: 2. Note that the executable's name is the tutorial's foldername with all underscores replaced with hyphens (e. for tutorial folder: -> executable name: (or on Windows)). For example, to run the pytorch basics tutorial: Using Docker Find the latest and previous version images on Docker Hub. You can build and run the tutorials (on CPU) in a Docker container using the provided and files: 1. From the

root directory of the cloned repo build the image: 2. Now start the container and build the tutorials using: License

Frequently asked questions

How many stars and forks are recorded?

prabhuomkar/pytorch-cpp has 2,142 stars and 272 forks.

What is the repository rank?

prabhuomkar/pytorch-cpp is ranked 8,930.

What language and category are recorded?

prabhuomkar/pytorch-cpp has 2,142 stars, uses C++ and belongs to Tutorials.

Which repository is closest in rank?

prabhuomkar/pytorch-cpp is compared with luispedro/BuildingMachineLearningSystemsWithPython, ranked 8,933 with 2,137 stars.

README
 ![](images/pytorch_cpp.jpg) 




C++ Implementation of PyTorch Tutorials for Everyone

OS (Compiler)\LibTorch 2.14.0
macOS (clang 16)
Linux (gcc 14, 16)
Windows (msvc 2025)

Table of Contents

This repository provides tutorial code in C++ for deep learning researchers to learn PyTorch (i.e. Section 1 to 3)
Python Tutorial: https://github.com/yunjey/pytorch-tutorial

1. Basics

2. Intermediate

3. Advanced

4. Interactive Tutorials

5. Other Popular Tutorials

Getting Started

Requirements

  1. C++-17 compatible compiler
  2. CMake (minimum version 3.28.6)
  3. LibTorch version >= 1.12.0 and <= 2.14.0
  4. Conda

For Interactive Tutorials

Note: Interactive Tutorials are currently running on LibTorch Nightly Version.
So there are some tutorials which can break when working with nightly version.

conda create --name pytorch-cpp
conda activate pytorch-cpp
conda install xeus-cling notebook -c conda-forge

Clone, build and run tutorials

In Google Colab

On Local Machine

git clone https://github.com/prabhuomkar/pytorch-cpp.git
cd pytorch-cpp

Generate build system

cmake -B build #

Note for Windows users:

Libtorch only supports 64bit Windows and an x64 generator needs to be specified. For Visual Studio this can be done by appending -A x64 to the above command.

Some useful options:

Option Default Description
-D CUDA_V=(11.8|12.4|12.6|12.8|12.9|13.0|13.2|none) none Download LibTorch for a CUDA version (none = download CPU version).
-D LIBTORCH_DOWNLOAD_BUILD_TYPE=(Release|Debug) Release Determines which libtorch build type version to download (only relevant on Windows).
-D DOWNLOAD_DATASETS=(OFF|ON) ON Download required datasets during build (only if they do not already exist in pytorch-cpp/data).
-D CREATE_SCRIPTMODULES=(OFF|ON) OFF Create all required scriptmodule files for prelearned models / weights during build. Requires installed python3 with pytorch and torchvision.
-D CMAKE_PREFIX_PATH=path/to/libtorch/share/cmake/Torch `` Skip the downloading of LibTorch and use your own local version (see Requirements) instead.
-D CMAKE_BUILD_TYPE=(Release|Debug|...) `` Determines the CMake build-type for single-configuration generators (see CMake docs).

Example Linux

Aim
  • Use existing Python, PyTorch (see Requirements) and torchvision installation.
  • Download all datasets and create all necessary scriptmodule files.
Command
cmake -B build \
-D CMAKE_BUILD_TYPE=Release \
-D CMAKE_PREFIX_PATH=/path/to/libtorch/share/cmake/Torch \
-D CREATE_SCRIPTMODULES=ON 

Example Windows

Aim
  • Automatically download LibTorch for CUDA 11.8 (Release version) and all necessary datasets.
  • Do not create scriptmodule files.
Command
cmake -B build \
-A x64 \
-D CUDA_V=11.8

Build

Note for Windows (Visual Studio) users:

The CMake script downloads the Release version of LibTorch, so --config Release has to be appended to the build command.

How dataset download and scriptmodule creation work:

  • If DOWNLOAD_DATASETS is ON, the datasets required by the tutorials you choose to build will be downloaded to pytorch-cpp/data (if they do not already exist there).
  • If CREATE_SCRIPTMODULES is ON, the scriptmodule files for the prelearned models / weights required by the tutorials you choose to build will be created in the model folder of the respective tutorial's source folder (if they do not already exist).

All tutorials

To build all tutorials use

cmake --build build

All tutorials in a category

You can choose to only build tutorials in one of the categories basics, intermediate, advanced or popular. For example, if you are only interested in the basics tutorials:

cmake --build build --target basics
# In general: cmake --build build --target {category}

Single tutorial

You can also choose to only build a single tutorial. For example to build the language model tutorial only:

cmake --build build --target language-model
# In general: cmake --build build --target {tutorial-name}

Note:
The target argument is the tutorial's foldername with all underscores replaced by hyphens.

Tip for users of CMake version >= 3.15:
You can specify several targets separated by spaces, for example:

cmake --build build --target language-model image-captioning

Run Tutorials

  1. (IMPORTANT!) First change into the tutorial's directory within build/tutorials. For example, assuming you are in the pytorch-cpp directory and want to change to the pytorch basics tutorial folder:

    cd build/tutorials/basics/pytorch_basics
    # In general: cd build/tutorials/{basics|intermediate|advanced|popular/blitz}/{tutorial_name}
    
  2. Run the executable. Note that the executable's name is the tutorial's foldername with all underscores replaced with hyphens (e.g. for tutorial folder: pytorch_basics -> executable name: pytorch-basics (or pytorch-basics.exe on Windows)). For example, to run the pytorch basics tutorial:

    Linux/Mac

    ./pytorch-basics
    # In general: ./{tutorial-name}
    

    Windows

    .\pytorch-basics.exe
    # In general: .\{tutorial-name}.exe
    

Using Docker

Find the latest and previous version images on Docker Hub.

You can build and run the tutorials (on CPU) in a Docker container using the provided Dockerfile and docker-compose.yml files:

  1. From the root directory of the cloned repo build the image:
    docker-compose build --build-arg USER_ID=$(id -u) --build-arg GROUP_ID=$(id -g)
    

    Note:
    When you run the Docker container, the host repo directory is mounted as a volume in the Docker container in order to cache build and downloaded dependency files so that it is not necessary to rebuild or redownload everything when a container is restarted. In order to have correct file permissions it is necessary to provide your user and group ids as build arguments when building the image on Linux.

  2. Now start the container and build the tutorials using:
    docker-compose run --rm pytorch-cpp
    
    This fetches all necessary dependencies and builds all tutorials. After the build is done, by default the container starts bash in interactive mode in the build/tutorials folder.
    As with the local build, you can choose to only build tutorials of a category (basics, intermediate, advanced, popular):
    docker-compose run --rm pytorch-cpp {category}
    
    In this case the container is started in the chosen category's base build directory.
    Alternatively, you can also directly run a tutorial by instead invoking the run command with a tutorial name as additional argument, for example:
    docker-compose run --rm pytorch-cpp pytorch-basics
    # In general: docker-compose run --rm pytorch-cpp {tutorial-name} 
    
    This will - if necessary - build the pytorch-basics tutorial and then start the executable in a container.

License

This repository is licensed under MIT as given in LICENSE.

Nearby in the ranking
Similar items