burn-derive 0.22.0

Derive crate for the Burn framework
Documentation

Burn Derive

Derive macros for Burn

Current Crates.io Version Documentation license

Use these through burn, which re-exports them; this crate is not meant to be a direct dependency.

  • #[derive(Module)] implements Module for a struct or enum of modules, parameters and constants. #[module(skip)] excludes a field.
  • #[derive(Config)] makes a struct a serializable configuration with a generated new constructor and with_* setters for optional fields and fields marked #[config(default = ...)].
  • #[derive(RecordState)] decomposes an optimizer or scheduler state into named tensors and scalars for the burnpack format.

The crate also implements the assert_shape!, debug_assert_shape! and einsum! tensor macros.

use burn::prelude::*;

#[derive(Config, Debug)]
pub struct MlpConfig {
    hidden: usize,
    #[config(default = 0.1)]
    dropout: f64,
}

#[derive(Module, Debug)]
pub struct Mlp {
    linear: nn::Linear,
    dropout: nn::Dropout,
}

Part of the Burn deep learning framework. See the Burn Book and the API documentation.