burn_capture/lib.rs
1#![cfg_attr(not(feature = "std"), no_std)]
2#![warn(missing_docs)]
3#![cfg_attr(docsrs, feature(doc_cfg))]
4
5//! A backend that records Burn operation graphs instead of executing them.
6//!
7//! Tensors moved to a [`CaptureDevice`] are recorded rather than computed. Each
8//! [`CaptureDevice::capture_scope`] call delimits one capture: the closure runs ordinary tensor
9//! code, declares the graph's inputs and outputs through [`CaptureScope::complete`], and the
10//! scope returns a [`CapturedGraph`]: the recorded `burn_ir::GraphIr` plus the recorded tensor
11//! data, such as model weights. This is for tools that need a model's computation as a graph,
12//! such as exporters, rather than its results.
13//!
14//! Applications enable the `capture` feature of `burn` and use `Device::capture()` and
15//! `Device::capture_scope`. Inputs and outputs are declared by [`TensorId`]; with the
16//! `extension` feature, `tensor.clone().try_into_primitive::<CaptureBackend>()?.id()` gives a
17//! tensor's ID. A runtime input must come from outside the scope, for example a tensor moved
18//! onto the capture device; tensors created inside the scope are recorded as constants.
19
20extern crate alloc;
21
22mod capture;
23
24pub use burn_ir::TensorId;
25pub use capture::*;