tch-rs is a Rust bindings library for PyTorch's C++ API.
The library solves the problem of using PyTorch from Rust by providing thin wrappers around libtorch, the C++ implementation of PyTorch. Rather than creating idiomatic Rust abstractions, the project deliberately stays close to the original C++ API, allowing more ergonomic Rust bindings to be built on top if needed. This approach means developers work with familiar PyTorch concepts while accessing them through Rust.
Developers should choose this library if they need to integrate PyTorch into Rust applications and prefer direct access to the C++ API surface. It suits projects that require deep learning capabilities in Rust without the overhead of language translation layers. The library requires libtorch to be available on the system, which can be obtained through a system-wide installation, manual setup, a Python PyTorch installation, or automatic download via the download-libtorch feature. On Windows, the MSVC Rust toolchain is recommended over MinGW due to PyTorch compatibility issues, and debug and release builds are not ABI-compatible, requiring careful version matching.
The project maintains active engagement with its codebase through regular updates and refinements. The maintainer responds to issues and pull requests, indicating ongoing stewardship of the library. Documentation is available on docs.rs and includes practical examples demonstrating tensor operations and model training. The project includes examples covering basic tensor operations and gradient descent training, providing starting points for new users.