tracel-ai/burn · error

seeding is not supported during graph capture

Error message

seeding is not supported during graph capture

What it means

The capture backend records operations instead of executing kernels, so it has no real RNG to reseed; calling `seed()` on a capture client panics. Randomness during capture must be handled outside the captured region or on the underlying backend.

Source

Thrown at crates/burn-capture/src/capture.rs:530

    }

    fn register_tensor_data(&self, data: TensorData) -> RouterTensor<Self> {
        let mut state = self.state().lock();
        state.assert_open();
        let id = TensorId::new(TENSOR_COUNTER.fetch_add(1, Ordering::Relaxed));
        let shape = data.shape.clone();
        let dtype = data.dtype;
        state.values.insert(id, data);
        drop(state);
        RouterTensor::new(id, shape, dtype, self.clone())
    }

    fn device(&self) -> Self::Device {
        self.device
    }

    fn seed(&self, _seed: u64) {
        panic!("seeding is not supported during graph capture")
    }

    fn dtype_usage(&self, dtype: DType) -> DTypeUsageSet {
        match dtype {
            // Capture records these operations without executing dtype-specific kernels. The
            // router's quantized operations are not implemented yet, so quantized tensors remain
            // the only dtype family that capture cannot represent through the backend API.
            DType::QFloat(_) => DTypeUsageSet::empty(),
            _ => DTypeUsage::general(),
        }
    }

    fn register_and_execute_graph(
        &self,
        graph_id: GraphId,
        relative_graph: Vec<OperationIr>,
        bindings: GraphBindings,
    ) {

View on GitHub (pinned to d16f7ba2ed)

Solutions

  1. Seed the underlying (real) backend device before entering `capture_scope`, not the capture client.
  2. Remove or gate the seeding call so it is skipped when capture is active.
  3. Generate random tensors before capture and feed them as constant inputs to the captured region.

Example fix

// before
device.capture_scope(|device| {
    client.seed(42); // panic
    let w = Tensor::<CaptureDevice, 2>::random(..., device);
});
// after
real_client.seed(42);
device.capture_scope(|device| {
    let w = Tensor::<CaptureDevice, 2>::random(..., device);
});
Defensive patterns

Strategy: fallback

Validate before calling

// Seed the real backend, not the capture client
if !is_capture_client(&client) {
    client.seed(42);
}

Prevention

When it happens

Trigger: Calling `client.seed(seed)` or any API that reseeds the backend (e.g. seed-based random tensor config, `burn_import` seeding hooks) while the client is a capture client inside `capture_scope`.

Common situations: Reproducing training runs by seeding RNG when capturing a graph; framework code that unconditionally seeds before generating random weights; test harnesses that seed globally per iteration.

Related errors


AI-assisted analysis of tracel-ai/burn@d16f7ba2ed (2026-09-05). Data as JSON: /api/errors/118b643b29c9498c. Report an issue: GitHub.