Practical overview
When it fits
Use it when a Rust application needs access to PyTorch’s C++ operations and you can provide the required libtorch dependency.
Who it is for
- Rust developers building machine-learning or deep-learning programs with PyTorch operations.
- Developers prototyping tensor-based models or training loops in Rust.
- Rust library authors building more idiomatic bindings on top of the crate.
Documented uses
- Perform PyTorch tensor operations from a Rust program.
- Define neural-network modules and use automatic differentiation.
- Build a model-training loop with a variable store, loss calculation and optimizer steps.
Requirements & limits
The project is open source under the Apache-2.0 license. Its repository specifies libtorch v2.13.0 as a dependency.
- The crate wraps the C++ API rather than presenting a wholly different interface; its stated aim is to stay close to that API.
- A libtorch installation or another documented way to provide libtorch is required.
- The README describes system-wide, manually configured, Python-installed and optional prebuilt-download routes for supplying libtorch.
- Windows users should account for the documented debug/release ABI difference and the recommendation to use the MSVC Rust toolchain.
Check current requirements in the official documentation. Source-based guidance does not mean OpenViST has run or independently tested this project.
Configure a manual libtorch installation
Make a manually installed libtorch location available to a Tch Rs build.
Before you start
- A Rust project using Tch Rs.
- The required libtorch C++ library, specified by the repository as v2.13.0.
- A manual libtorch installation extracted on the system.
Steps
Set the LIBTORCH environment variable to the extracted libtorch directory.
On Linux or macOS, add that setting to the shell configuration file or equivalent.
On Windows, set LIBTORCH to the extracted directory and append its lib subdirectory to Path.
Use the repository's example command, cargo run --example basics, to run an example.
Expected outcome
The build process can locate the manually installed libtorch, and the documented example command can be used to run a crate example.
Guide limitations
- The repository specifies libtorch v2.13.0.
- On Windows, PyTorch debug and release builds are not ABI-compatible; the README recommends the MSVC Rust toolchain rather than MinGW.
Sources & review
Source record details
- Source availability
- Active
- Sources checked
- 10 October 2026
- Original website title
- LaurentMazare/tch-rs · Official homepage title · retained in its source language

