From the course: Rust LLMOps

Unlock this course with a free trial

Join today to access over 23,400 courses taught by industry experts.

Rust-PyTorch hello world

Rust-PyTorch hello world - Rust Tutorial

From the course: Rust LLMOps

Rust-PyTorch hello world

- [Instructor] Rust bindings for the C++ API of PyTorch are very exciting, because it allows you to just get right into the low level parts of PyTorch in a elegant language like Rust. So let's go ahead and take a look at what this looks like. First up, here's a Hello World example here. But before we run it, let's dive into what's necessary. So first, you would need to say Cargo New to create a new skeleton structure. But look at this. We have the dependencies here and I need to actually have what version of PyTorch is the latest. One of the nice things about Cargo is it's easy to check exactly what the latest versions are, and we can see here, oh good, I've got the latest one. Next up here, if I go to the main.rs, I've got Hello World Tensor, and then I'm able to just go ahead and use that and then make a main function. So really, only a couple lines of code to get started here, and let's go ahead and walk through it. So we say let t, so it's going to be a type of tensor, and we say,…

Contents