Git Product home page Git Product logo

pytorch-cpp's Introduction

C++ Implementation of PyTorch Tutorials for Deep Learning Researchers

OS (Compiler)\libtorch 1.5 nightly
macOS (clang 9.1) Status
macOS (clang 10.0) Status
macOS (clang 11.0) Status
Linux (gcc 5) Status
Linux (gcc 6) Status
Linux (gcc 7) Status
Linux (gcc 8) Status
Windows (msvc 2017) Status

This repository provides tutorial code in C++ for deep learning researchers to learn PyTorch.
Python Tutorial: https://github.com/yunjey/pytorch-tutorial

Getting Started

Requirements

  1. C++
  2. CMake
  3. LibTorch v1.5.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

Fork/Clone and Build

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=(9.2|10.1|10.2|none) none Download libtorch for a CUDA version (none = download CPU version).
-D DOWNLOAD_DATASETS=(OFF|ON) ON Download all datasets used in the tutorials.
-D CMAKE_PREFIX_PATH=path/to/libtorch/share/cmake/Torch Skip the downloading of libtorch and use your own local version instead.

Build

cmake --build build

Note for Windows users:
The CMake script downloads the Release version of libtorch, so --config Release has to be appended to the build command.

General Note:
By default all tutorials will be built. If you only want to build one specific tutorial, specify the target parameter for the build command. For example to only build the language model tutorial, append --target language-model (target name = tutorial foldername with all underscores replaced with hyphens).

Running 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}/{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

Table of Contents

1. Basics

2. Intermediate

3. Advanced

4. Interactive Tutorials

License

This repository is licensed under MIT as given in LICENSE.

pytorch-cpp's People

Contributors

prabhuomkar avatar mfl28 avatar arrufat avatar mithil467 avatar

Stargazers

Ramakant Gadhewal avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.