blog.dopana

Back

One of the standout features of Burn is the clean decoupling of model architectural definitions from hardware computation backends.

Defining Neural Networks with the Module Macro#

In Burn, model components implement the Module trait. Thanks to the #[derive(Module)] proc-macro, defining network layers is clean and strongly typed.

The Power of Multi-Backend Abstraction#

You can swap backends seamlessly by altering the generic backend parameter B:

  • WGPU Backend: High performance across Vulkan, Metal, and DirectX.
  • LibTorch Backend: Interoperability with PyTorch C++ bindings.
  • Candle Backend: Lightweight execution based on Hugging Face Candle.
  • NdArray Backend: Pure CPU fallbacks.
src/main.rs
use burn::backend::wgpu::{Wgpu, WgpuDevice};

fn main() {
    let device = WgpuDevice::default();
    let model = Model::<Wgpu>::new(784, 128, 10, &device);
    println!("Model initialized successfully!");
}
rust

References#