JTorch
Java/JVM bindings for Torch: A Tensor Computation Library
Install / Use
/learn @ctongfei/JTorchREADME
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 🚧
| | Windows | Linux | MacOS | |:----:|:-------:|:-----:|:-----:| | 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 package | Mapped Java package |
|---------------|---------------------|
|TH |jtorch |
|THNN |jtorch.nn |
|THS |jtorch.sparse |
|THC |jtorch.cuda |
|THCUNN |jtorch.cuda.nn |
|THCS |jtorch.cuda.sparse |
Type mappings
Torch has the following Storage/Tensor types, which are mapped to the Java corresponding types on the right.
| Torch type | Element type (C) | Bits | Mapped element type (Java) | Java type |
|-----------------|------------------|------|-----------------------------|---------------|
|THHalfTensor |THHalf | 16 |float |HalfTensor |
|THFloatTensor |float | 32 |float |FloatTensor |
|THDoubleTensor |double | 64 |double |DoubleTensor |
|THByteTensor |uint8_t | 8 |short |UByteTensor |
|THCharTensor |int8_t | 8 |byte |ByteTensor |
|THShortTensor |int16_t | 16 |short |ShortTensor |
|THIntTensor |int32_t | 32 |int |IntTensor |
|THLongTensor |int64_t | 64 |long |LongTensor |
Related Skills
node-connect
343.1kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
90.0kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
343.1kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
343.1kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
