tracel-ai/burn · error
svd requires a float tensor
Error message
svd requires a float tensor
What it means
The float bridge's svd only computes singular value decomposition for float dtypes; any other tensor kind reaching the svd entry point panics with 'svd requires a float tensor'. It is a dtype precondition check inside the bridge's match over element kinds.
Source
Thrown at crates/burn-tensor/src/bridge/ops/float.rs:40
/// Singular value decomposition of a float tensor, dispatched to the active
/// backend (`FloatTensorOps::float_svd`). Returns the three factors as
/// tensors on the same device as the input.
pub(crate) fn svd(
tensor: BridgeTensor,
sweeps: usize,
swap: bool,
) -> (BridgeTensor, BridgeTensor, BridgeTensor) {
let (kind, tensor) = tensor.into_parts();
match kind {
BridgeKind::Float => {
let (u, s, vt) = Dispatch::float_svd(tensor, sweeps, swap);
(
BridgeTensor::float(u),
BridgeTensor::float(s),
BridgeTensor::float(vt),
)
}
_ => panic!("svd requires a float tensor"),
}
}
macro_rules! q_bin_ops {
($lhs:ident, $rhs:ident, $op:ident, $q_op:ident) => {{
let (lkind, lhs) = $lhs.into_parts();
let (rkind, rhs) = $rhs.into_parts();
match (lkind, rkind) {
(BridgeKind::Float, BridgeKind::Float) => BridgeTensor::float(Dispatch::$op(lhs, rhs)),
(BridgeKind::QFloat, BridgeKind::QFloat) => from_q_primitive(Dispatch::$q_op(lhs, rhs)),
(BridgeKind::QFloat, BridgeKind::Float) => {
let dtype = rhs.dtype();
BridgeTensor::float(Dispatch::$op(Dispatch::dequantize(lhs, dtype.into()), rhs))
}
(BridgeKind::Float, BridgeKind::QFloat) => {
let dtype = lhs.dtype();
BridgeTensor::float(Dispatch::$op(lhs, Dispatch::dequantize(rhs, dtype.into())))
}View on GitHub (pinned to d16f7ba2ed)
Solutions
- Convert the tensor to a float dtype before calling svd: tensor.float() / .to_dtype(FLOAT32)
- Fix upstream code so the matrix stays Float (f32/f64) — e.g. convert loaded data with TensorData::convert::<f32>()
- Verify the tensor type parameter is Tensor<B, D, Float>, not Int or QFloat, at the SVD call site
Example fix
// before let (u, s, vt) = int_matrix.svd(); // after let (u, s, vt) = int_matrix.float().svd();
Defensive patterns
Strategy: validation
Validate before calling
fn svd_checked<B: Backend, const D: usize>(m: Tensor<B, D, Float>) -> (Tensor<B, D, Float>, Tensor<B, D, Float>, Tensor<B, D, Float>) {
m.svd() // only call on Float-typed tensors; convert ints first with .float()
} Type guard
fn ensure_float<B: Backend, const D: usize>(t: Tensor<B, D, Int>) -> Tensor<B, D, Float> { t.float() } Try / catch
std::panic::catch_unwind(|| matrix.svd())
.map_err(|_| "svd requires a float tensor; call .float() first")?; Prevention
- Only invoke svd on Tensor<B, D, Float> values
- Convert integer-loaded matrices to float at ingestion time
- Add dtype assertions before linear-algebra calls (svd, qr, eig) in shared numerics code
When it happens
Trigger: Calling tensor.svd() on a tensor whose dtype/kind is not a floating-point type (e.g. Int or quantized) — such as running SVD on integer matrices without converting to float first.
Common situations: Loading integer data (e.g. image arrays, index tables) and computing SVD directly; dtype changes from quantization or checkpoint loading leaving matrices in Int form; generic code losing the Float type parameter.
Related errors
- SVD fallback failed: {err}
- Data should have the same element type as the tensor {err:?}
- Not a valid float kind
- Expected bool data type, got {dtype:?}
- only float tensors may use an autodiff primitive
AI-assisted analysis of tracel-ai/burn@d16f7ba2ed (2026-09-05).
Data as JSON: /api/errors/b24166befbb77488.
Report an issue: GitHub.