GitRead 中文社区
首页趋势排行榜原创文章严选周刊
更多资源
新手训练营
精选专题热门话题GitHub 文档资源精选实战指南

pytorch-cpp

C++ Implementation of PyTorch Tutorials for Everyone

  • 语言C++
  • 默认分支master
  • 大小501 KB
  • 更新6 天前
  • Issues2
在 GitHub 打开
avatarprabhuomkar

项目介绍

prabhuomkar/pytorch-cpp 是一个托管在 GitHub 上的开源项目,主要使用 C++ 编写,采用 MIT License 许可证,目前获得 2.1k 个 Star、267 次 Fork。

仓库全名
prabhuomkar/pytorch-cpp

README 摘要

C++ Implementation of PyTorch Tutorials for Everyone OS (Compiler)\\LibTorch | 2.14.0 | :--------------------- | :--------------------------------------------------------------------------------------------------- | 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…

完整内容见 GitHub 原始 README 或本页 。

常见问题

pytorch-cpp 用什么语言开发?

主要使用 C++ 编写,采用 MIT License 许可证,目前有 2.1k 个 Star。

pytorch-cpp 可以免费商用吗?

仓库采用 MIT License 许可证,可免费使用与修改,商业使用请遵守许可证条款(例如保留版权声明与许可声明)。

如何获取 pytorch-cpp 的源码?

可以直接克隆仓库:git clone https://github.com/prabhuomkar/pytorch-cpp.git,默认分支为 master;安装与运行步骤见仓库 README。

pytorch-cpp 最近还在维护吗?

仓库最近一次更新为 6 天前,当前有 2 个未关闭 Issue;Star 数为 2.1k,可作为社区活跃度的参考。

本页面展示项目元数据与原始 README,GitRead 中文社区 编辑团队负责选题收录。

相关仓库

tensorflow/tensorflow avatar
tensorflowtensorflow
3 小时前
201.4k
78.2k
3.4k

面向所有人的开源机器学习框架

deep-learningdeep-neural-networksdistributed+5
C++
1.4 GB
0
详情
ggml-org/llama.cpp avatar
llama.cppggml-org
3 小时前
133.8k
25.3k
2.6k

C/C++ 中的大语言模型推理

ggml
C++
479.1 MB
3
详情
react/react-native avatar
react-nativereact
2 小时前
126.9k
25.5k
1.4k

使用 React 构建原生应用的框架

androidapp-frameworkcross-platform+5
C++
970.4 MB
0
详情
electron/electron avatar
electronelectron
3 小时前
123.8k
17.9k
780

使用 JavaScript、HTML 和 CSS 构建跨平台桌面应用

electronjavascriptc-plus-plus+6
C++
227.6 MB
0
详情
godotengine/godot avatar
godotgodotengine
2 天前
119.9k
26.8k
13.4k

Godot Engine – 多平台 2D 和 3D 游戏引擎

game-developmentgame-enginegamedev+4
C++
1.8 GB
0
详情
microsoft/terminal avatar
terminalmicrosoft
2 天前
105.4k
9.6k
1.7k

新的 Windows Terminal 和原始的 Windows 控制台主机,全都集中在这里!

cmdcommand-lineconsole+8
C++
177.4 MB
0
详情
opencv/opencv avatar
opencvopencv
5 小时前
91.5k
57.1k
2.9k

开源计算机视觉库

opencvc-plus-pluscomputer-vision+2
C++
558.2 MB
0
详情
bitcoin/bitcoin avatar
bitcoinbitcoin
5 小时前
90.6k
30.0k
345

Bitcoin Core 集成/暂存树

bitcoinc-plus-pluscryptocurrency+2
C++
324.5 MB
0
详情

关于

artificial-intelligenceautogradcolabconvolutional-neural-networkcplusplusdatasetsgenerative-adversarial-networkinteractive-tutorialslanguage-modellibtorchmachine-learningneural-networkpytorchrecurrent-neural-networkscriptmodule-filestensorstorchtutorial
  • MIT License
  • 2.1k Stars
  • 267 Forks
  • 50 Watching

简要分析

热度分
2725
价值分
1369
活跃状态
活跃
GitHub

语言占比

C++
CMake
Dockerfile
Jupyter Notebook
Python
Shell

Release

  • PyTorch 2.14.09月13日
  • PyTorch 2.8.02025年8月25日
  • PyTorch 2.6.02025年8月25日
  • PyTorch 2.3.02025年8月25日
  • PyTorch 2.1.12024年5月5日

贡献者

prabhuomkarprabhuomkarmfl28mfl28amirtronixamirtronixMithil467Mithil467vishesh9131vishesh9131

C++ Implementation of PyTorch Tutorials for Everyone

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

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

  • 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. Interactive Tutorials

  • Tensor Slicing

5. Other Popular Tutorials

  • Deep Learning with PyTorch: A 60 Minute Blitz

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

Open In Colab

On Local Machine

git clone https://github.com/prabhuomkar/pytorch-cpp.git
cd pytorch-cpp
Generate build system
cmake -B build #<options>

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 <empty> Skip the downloading of LibTorch and use your own local version (see Requirements) instead.
-D CMAKE_BUILD_TYPE=(Release|Debug|...) <empty> 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.

评论

登录 后发表评论
暂无评论
GitRead 中文社区
深度解读 · 趋势洞察 · 价值精选

关于

关于我们联系我们编辑准则收录标准赞赏人员

发现

技术趋势新手训练营资源精选实战指南精选专题热门话题GitHub 文档

条款

隐私政策服务条款网站地图
26.9万收录项目
5.2万中文话题
155精选专题
发现技术价值,连接开源智慧
© 2026 GitRead · GitHub 中文社区 本站与 GitHub, Inc. 无隶属关系;GitHub 是 GitHub, Inc. 的商标。