tracel-ai/burn · error
Error while reading data: use `try_execute` to handle error
Error message
Error while reading data: use `try_execute` to handle error at runtime
What it means
Transaction::execute() blocks on execute_async() and unwraps with this message; if any registered tensor read failed (backend read error, device error, cancelled read), block_on returns None and the process panics. try_execute() is the Result-returning variant the library recommends for runtime error handling.
Source
Thrown at crates/burn-tensor/src/tensor/api/transaction.rs:68
/// Crate-internal owning extraction of the underlying transaction primitive.
pub(crate) fn into_op(self) -> TransactionPrimitive<Dispatch> {
self.opaque.into_inner()
}
/// Add a [tensor](Tensor) to the transaction to be read.
pub fn register<const D: usize, K: crate::kind::Transaction>(
mut self,
tensor: Tensor<D, K>,
) -> Self {
K::register_transaction(self.as_op_mut(), tensor.primitive);
self
}
/// Executes the transaction synchronously and returns the [data](TensorData) in the same order
/// in which they were [registered](Self::register).
pub fn execute(self) -> Vec<TensorData> {
burn_std::future::block_on(self.execute_async())
.expect("Error while reading data: use `try_execute` to handle error at runtime")
}
/// Executes the transaction synchronously and returns the [data](TensorData) in the same
/// order in which they were [registered](Self::register).
///
/// # Returns
///
/// Any error that might have occurred since the last time the device was synchronized.
pub fn try_execute(self) -> Result<Vec<TensorData>, ExecutionError> {
burn_std::future::block_on(self.execute_async())
}
/// Executes the transaction asynchronously and returns the [data](TensorData) in the same order
/// in which they were [registered](Self::register).
pub async fn execute_async(self) -> Result<Vec<TensorData>, ExecutionError> {
self.into_op().execute_async().await
}
}View on GitHub (pinned to d16f7ba2ed)
Solutions
- Switch to `transaction.try_execute()` and handle the Err case
- Ensure execute() is not called inside an async runtime; use execute_async().await instead
- Check device health / backend logs for the underlying read failure
- Retry the read after re-registering the tensors if the failure was transient
Example fix
// before
let data = txn.execute();
// after
match txn.try_execute() {
Ok(data) => data,
Err(e) => { log::error!("txn read failed: {e:?}"); Vec::new() }
} Defensive patterns
Strategy: try-catch
Validate before calling
// check async context before blocking assert!(!tokio::runtime::Handle::try_current().is_ok(), "use execute_async in async context");
Try / catch
match txn.try_execute() {
Ok(data) => handle(data),
Err(e) => log::error!("transaction read failed: {e:?}"),
} Prevention
- Prefer try_execute() in production code
- Use execute_async() inside async runtimes instead of blocking execute()
- Monitor device health before large multi-tensor reads
When it happens
Trigger: Calling `transaction.execute()` when one of the registered tensors cannot be read back (device error, async read failure on WGPU, cancelled operation); executing a transaction in an async context where block_on cannot resolve.
Common situations: Multi-tensor result collection on GPU backends after a kernel failure; reading results inside tokio runtimes (block_on panics/deadlocks); batch metric extraction at end of training steps on WebGPU.
Related errors
- Failed to read tensor data synchronously. Try using nonzero_
- Failed to read tensor data synchronously. Try using argwhere
- Failed to convert tensor data to a scalar: {err}
- todo!("Quantization not supported yet")
- Can read the data without error
AI-assisted analysis of tracel-ai/burn@d16f7ba2ed (2026-09-05).
Data as JSON: /api/errors/4cfd4bf3944906c1.
Report an issue: GitHub.