mirror of https://github.com/tracel-ai/burn.git
0d17cde1cc | ||
---|---|---|
.. | ||
src | ||
Cargo.toml | ||
LICENSE-APACHE | ||
LICENSE-MIT | ||
README.md |
README.md
Burn Torch Backend
Burn Torch backend
This crate provides a Torch backend for Burn utilizing the tch-rs crate, which offers a Rust interface to the PyTorch C++ API.
The backend supports CPU (multithreaded), CUDA (multiple GPUs), and MPS devices (MacOS).
Usage Example
#[cfg(feature = "tch-gpu")]
mod tch_gpu {
use burn_autodiff::ADBackendDecorator;
use burn_tch::{TchBackend, TchDevice};
use mnist::training;
pub fn run() {
#[cfg(not(target_os = "macos"))]
let device = TchDevice::Cuda(0);
#[cfg(target_os = "macos")]
let device = TchDevice::Mps;
training::run::<ADBackendDecorator<TchBackend<f32>>>(device);
}
}
#[cfg(feature = "tch-cpu")]
mod tch_cpu {
use burn_autodiff::ADBackendDecorator;
use burn_tch::{TchBackend, TchDevice};
use mnist::training;
pub fn run() {
let device = TchDevice::Cpu;
training::run::<ADBackendDecorator<TchBackend<f32>>>(device);
}
}