Coder Social home page Coder Social logo

pytorch-cpp-example's Introduction

pytorch-cpp-example

Sample scripts for testing PyTorch models in C++. Both CPU & GPU implementations are provided.

Author: Muralikrishnan Gopalakrishnan Meena (Oak Ridge National Laboratory), https://sites.google.com/view/muraligm/

Contributors:

Description

These are sample scripts to load a PyTorch model and run a forward step. These are adapted from PyTorch's docs for loading a Torch Script model in C++. They also have instructions in the doc to convert a PyTorch model to torch script in Python.

There are 2 examples:

  1. CPU implementation example_pytorchNN_cpu.cpp
  2. GPU implementation example_pytorchNN_gpu.cpp

For more details on the PyTorch C++ frontend API used in these scripts, refer to torch_interface.h.

The sample model used here, PyTorch_model_Cpp.pt, is for a fluid flow emulator which takes 36 inputs and gives 4 outputs.

Usage

  1. Go to the build folder
    cd build
    
  2. Activate binaries using environment file corresponding to your machine
    source <machineName>_<cpu/gpu>.env
    
    Example: For running on GPU on Summit
    source summit_gpu.env
    
  3. Compile:
    ./cmakescript
    make -j
    
  4. Run:
    ./example
    
  • Sample output for the GPU usage (example_pytorchNN_gpu.cpp)
    Model loaded succefully!
    Number of CUDA devices: 1
    Sample output (scaled flow properties): -0.95627  4.08107  -2.88555  -0.970117
    

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.