Home

Awesome

Future development of this binding has been moved to nexus-torch (https://github.com/ctongfei/nexus/tree/master/torch), serving as a computation backend of nexus, a typesafe deep learning engine.

JTorch: JVM bindings for Torch (PyTorch C/C++ core)

Corresponding PyTorch version: 0.4.0

🚧 Ongoing project 🚧 Status: Not ready for use 🚧

WindowsLinuxMacOS
CPU✓
CUDA✓

Installation

Step 1: Install PyTorch from source.

Locate the headers (*.h) and shared libraries (*.so / *.dylib / *.dll)

Step 2: Build SWIG bindings and publish to local Ivy repository.

./build-{mac/linux}.sh

You probably need to modify something in the script to make it work.

[TODO] Will be refactored into a Makefile.

Step 3: Use!

    <dependency>
      <groupId>me.tongfei</groupId>
      <artifactId>jtorch-java</artifactId>
      <version>0.1-TH0.4-SNAPSHOT</version>
    </dependency>

When starting a JVM, add -Djava.library.path=/usr/local/lib (or where your libATen.dylib is), or set $LD_LIBRARY_PATH to include that directory, so that JVM can properly load native the binary.

Package mappings

Torch has several C packages, to which each is mapped to the following Java package:

Torch packageMapped Java package
THjtorch
THNNjtorch.nn
THSjtorch.sparse
THCjtorch.cuda
THCUNNjtorch.cuda.nn
THCSjtorch.cuda.sparse

Type mappings

Torch has the following Storage/Tensor types, which are mapped to the Java corresponding types on the right.

Torch typeElement type (C)BitsMapped element type (Java)Java type
THHalfTensorTHHalf16floatHalfTensor
THFloatTensorfloat32floatFloatTensor
THDoubleTensordouble64doubleDoubleTensor
THByteTensoruint8_t8shortUByteTensor
THCharTensorint8_t8byteByteTensor
THShortTensorint16_t16shortShortTensor
THIntTensorint32_t32intIntTensor
THLongTensorint64_t64longLongTensor