• Stars
    star
    237
  • Rank 164,351 (Top 4 %)
  • Language
    Go
  • License
    Other
  • Created about 5 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

LibTorch (PyTorch) bindings for Golang

EVERYHING IS REALLY OUT-OF-DATE. FOR A MORE UP-TO-DATE BINDINGS I RECOMMEND CHECKING OUT https://github.com/wangkuiyi/gotorch OR OTHER PACKAGES AVAILABLE.

WORK IN PROGRESS... USE AT OWN RISK :-)

Build Status GoDoc

go-torch

LibTorch (PyTorch) bindings for Golang. Library is first and foremost designed for running inference against serialized models exported from Python version of PyTorch. Library can also be used to compile TorchScript applications directly from Go.

Installing

$ go get github.com/orktes/go-torch

Usage

go-torch depends on the LibTorch shared library to be available. For more information refer to https://pytorch.org/cppdocs/. The is also an example Dockerfile which is used for executing tests for the library.

import (
    "github.com/orktes/go-torch"
)

Creating Tensors

Supported scalar types:

  • torch.Byte uint8
  • torch.Char int8
  • torch.Int int32
  • torch.Long int64
  • torch.Float float32
  • torch.Double float64
matrix := []float32{
    []float32{1,2,3},
    []float32{4,5,6},
}
tensor, _ := torch.NewTensor(matrix)
tensor.Shape() // [2, 3]
tensor.DType() // torch.Float

Using serialized PyTorch models

For instructions on how to export models for PyTorch refer to the PyTorch documentation

// Load model
module, _ := torch.LoadJITModule("model.pt")

// Create an input tensor
inputTensor, _ := torch.NewTensor([][]float32{
    []float32{1, 2, 3},
})

// Forward propagation
res, _ := module.Forward(inputTensor)

Using TorchScript

TorchScript documentation

Currently supported input and output types

  • Tensor
  • Tuple (of Tensor and/or nested Tuples)
sumScript = `
def sum(a, b):
    return a + b
`

// Compile TorchScript
module, _ := torch.CompileTorchScript(sumScript)

// Create inputs
a, _ := torch.NewTensor([]float32{1})
b, _ := torch.NewTensor([]float32{2})

res, _ := module.RunMethod("sum", a, b)
fmt.Printf("[1] + [2] = %+v\n", res.(*torch.Tensor).Value())
// output: [1] + [2] = [3]

Acknowledgements

Lots of the functionality related to converting Golang types to PyTorch Tensors are a shameless copy on what Google is doing with their Go Tensorflow bindings. Therefore big part of the credit definetely goes to The TensorFlow Authors.

LICENSE

See here

More Repositories

1

atom-react

ReactJS Support for atom (syntax, snippets)
CoffeeScript
477
star
2

node-jsxcs

JavaScript Code Style checker with JSX (React) support
JavaScript
10
star
3

go-alexa-smarthome

Handler for alexa smarthome v3 directives for golang
Go
10
star
4

babel-plugin-transform-react-native-style-optimizer

Optimize inline style attributes in react-native. Removes duplicate style definitions and moves styles to a StyleSheet.
JavaScript
9
star
5

go-vowpal-wabbit

Vowpal Wabbit bindings for Golang
Go
9
star
6

orlang

My toy programming language, parser and compiler to play around with different ideas for a perfect (IMO) language
Go
9
star
7

captainhub

Github Hook server
Go
7
star
8

rjss

Style sheet language for creating inlineable style objects for react-native and react-canvas
JavaScript
6
star
9

jsxformat

JSX formatting tool
JavaScript
6
star
10

influunt

Dataflow programming for Golang and Python
Go
5
star
11

huealexa

Fake hue server (for using with Amazon echo and Apple HomeKit) scriptable with javascript (written in golang)
JavaScript
3
star
12

mongache

Golang implementation of the mongodb server protocol. Useful for creating read only endpoints that used the mongodb wire protocol.
Go
3
star
13

go-tensorboard

go-tensorboard implements a dynamic tensorboard backend in golang
Go
3
star
14

aw-stats

JavaScript
2
star
15

irc-watcher

Ircbot that records and creates thumbnails of conversations
JavaScript
2
star
16

go-blob-filesystem

http.FileSystem implementation that can use any *gocloud.dev/blob.Bucket as the source for the data
Go
2
star
17

irccloud-java

IRCCloud library for java
Java
2
star
18

nodebas

Joke project: ECMA-55 Minimal BASIC Interpreter with http stack
Go
2
star
19

html5video

HTML5 video with flash fallback
JavaScript
2
star
20

homeautomation

* to MQTT bridge and trigger processor with Alexa Smarthome support
Go
1
star
21

xelisaviihde

Elisa Viihde extension for Xtreamer Media Player
PHP
1
star
22

rjss-playground

RJSS playground
JavaScript
1
star
23

rjss-loader

Webpack loader for the RJSS style syntax
JavaScript
1
star
24

protoc-gen-fastergrpc

Package implements a protobuf generator that generates a memory optimized version of the grpc service
Go
1
star