getting started

Make the leap

Let's get started!

1. Install Rust

Refer to the Rust book's installation page.

2. Create a Rust application

  1. Open your preferred terminal or command prompt.
  2. Use Cargo, Rust's package manager, to create a new Burn application in a specific directory.
  3. Change your current directory to the newly created project.

cargo new my_burn_app && cd my_burn_app/

3. Add the Burn dependency and choose a backend

  1. Cargo simplifies the process of including external libraries. The following command adds the main dependency and specifies the [wgpu] backend.

cargo add burn --features wgpu

4. Start developing with Burn

  1. With Burn successfully installed, you're now ready to start developing your deep learning projects using this powerful framework.

Basic example

1. Now open [src/main.rs] and replace its content with:

use burn::tensor::{Device, Tensor};

fn main() {
    // Run on any device: Device::{wgpu, cuda, rocm, metal, vulkan, flex, cpu}
    let device = Device::wgpu(Default::default());

    let tensor1 = Tensor::<2>::from_data([[2., 3.], [4., 5.]], &device);
    let tensor2 = Tensor::<2>::ones_like(&tensor1);

    // Print the element-wise addition of the two tensors.
    println!("{}", tensor1 + tensor2);
}

2. Run Cargo

cargo run

3. You should now see the result of the addition:

Tensor {
  data:
[[3.0, 4.0],
 [5.0, 6.0]],
  shape:  [2, 2],
  device:  Device<Cube(Wgpu(WgpuDevice { kind: DefaultDevice, backend: Auto }))>,
  kind:  "Float",
  dtype:  "f32",
}

While this example is somewhat trivial, the basic workflow section of the Burn Book will walk you through a much more relevant example for deep learning applications.

Stay connected

Join the mailing list

Join our community! We'd love to keep you in the loop with our newsletter.

unsubscribed