PyTorch is officially binded with Rust (tch-rs)

The rust community has grown so much over the years, a library ‘tch-rs’ (https://docs.rs/tch/0.2.0/tch/) has had a successful build (https://travis-ci.org/LaurentMazare/tch-rs) to bind C++ API of PyTorch.

I am posting this to have the PyTorch community expand and self aware if anyone else has experience with rust and open to hear if anyone has tried to deploy PyTorch algorithms with tch-rs.

5 Likes

what is the benefit for binding with rust language ?

2 Likes

Right now Libtorch C++ API deployment is somewhat difficult unless you have an open source library/software (i.e. torchserve) than can wrap serialize model’s into production instead of python web frameworks (flask/django/fastapi). Torchserve is nice for it has an RFC for a high performance Cpp PyTorch serving platform

If you look at the techempower benchmarks, you see in the top 10 we have 4/10 libraries made in rust. This site is used to measure who has the fastest request done for web frameworks.

Right now two popular web frameworks from rust, Rocket and Actix, are gaining traction in the web community. Once you finish creating your algorithms in pytorch using pytorch library, torchscript the model to be loaded up using tch-rs.

2 Likes

I have a GUI application which was written in Python + Java. Both the GUI and deep learning models are handled by Python and some core logics was written in Java. It has some performance issues and I’m trying to rewrite it using Rust. Basically, I want rewrite the GUI using Rust and load the trained models into Rust using tch-rs.

1 Like

So you’re writing you’re client side (front end) using Rust, assuming the framework is yew ( GitHub - yewstack/yew: Rust / Wasm framework for building client web apps ), to load up you’re PyTorch models using tch-rs?

I’m learning and trying to use Tauri to build the GUI, using Rust to re-implement some core logic which was originally implemented in Java. And yes, use tch-rs to load trained models.

1 Like

i made something like this but it’s more readable like PyTorch

1 Like