Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Installing and first use

Add the dependency

cargo add bunsen

bunsen is versioned on its own semver line, released by release-plz; its version is not tied to burn’s. Each release builds against one burn version, and bunsen re-exports it as bunsen::public::burn, so you can use the same burn without pinning it twice. bunsen requires a recent stable Rust; its minimum supported version is the rust-version on its crates.io page.

Pick features as described in Features, backends and the network. The defaults build offline and include the common modules.

A first program

This builds a block from its config, runs it, and checks the shape of its output with a shape contract. It is compiled and run by cargo test as part of the workspace, so it can’t drift from the API:

    use bunsen::{
        blocks::transformers::mlp::{
            Mlp,
            MlpConfig,
        },
        prelude::*,
        support::testing::cpu_device,
    };
    use burn::tensor::Tensor;

    let device = cpu_device();

    // `init` comes from `ModuleInit`; the binding's type names the module.
    let mlp: Mlp = MlpConfig::new(16).init(&device);

    let x = Tensor::<3>::zeros([2, 5, 16], &device);
    let y = mlp.forward(x);

    // Check the output's shape, and name its dimensions while doing it.
    let [batch, time, embed] = unpack_shape_contract!(["batch", "time", "embed"], &y.dims());
    assert_eq!((batch, time, embed), (2, 5, 16));

Three things to notice, each with its own chapter:

Next

  • The bunsen crate: what’s in the library, and where things go.
  • Kits: whole models you can load by name.
  • The API docs for everything else.