{"record":{"id":"a667cabf98bf79b6","repo":"tracel-ai/burn","slug":"svd-fallback-failed-err","errorCode":null,"errorMessage":"SVD fallback failed: {err}","messagePattern":"SVD fallback failed: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-backend/src/backend/ops/tensor.rs","lineNumber":152,"sourceCode":"    /// * `swap` - Whether `tensor` is the transpose of the matrix being decomposed.\n    ///\n    /// # Panics\n    ///\n    /// The default implementation panics if the input cannot be read\n    /// synchronously or if the QR iteration does not converge within the\n    /// requested sweep budget.\n    fn float_svd(\n        tensor: FloatTensor<B>,\n        sweeps: usize,\n        swap: bool,\n    ) -> (FloatTensor<B>, FloatTensor<B>, FloatTensor<B>) {\n        let device = tensor.device();\n        let msg = \"SVD fallback failed to synchronously read tensor data\";\n        let data = try_read_sync(Self::float_into_data(tensor))\n            .expect(msg)\n            .expect(msg);\n        let (u, s, vt) = super::svd::svd_host_data(data, sweeps, swap)\n            .unwrap_or_else(|err| panic!(\"SVD fallback failed: {err}\"));\n\n        (\n            Self::float_from_data(u, &device),\n            Self::float_from_data(s, &device),\n            Self::float_from_data(vt, &device),\n        )\n    }\n\n    /// Moves the tensor to the given device.\n    ///\n    /// # Arguments\n    ///\n    /// * `tensor` - The tensor.\n    /// * `device` - The device to move the tensor to.\n    ///\n    /// # Returns\n    ///\n    /// The tensor on the given device.","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-backend/src/backend/ops/tensor.rs#L134-L170","documentation":"In `float_svd`, when the backend cannot compute SVD on-device, a CPU host fallback (`svd_host_data`) is used. If the host fallback's decomposition routine fails (e.g. the Jacobi sweep iteration fails to converge or produces invalid data), the code panics with `SVD fallback failed: {err}`. The preceding synchronous data read is also guarded with related expect panics.","triggerScenarios":"Calling `tensor.svd()` (float_svd primitive) on a backend without native SVD, where `svd::svd_host_data(data, sweeps, swap)` returns Err — e.g. non-converging Jacobi sweeps, degenerate/NaN/Inf input matrices, or an unsupported matrix shape.","commonSituations":"Computing SVD on ill-conditioned matrices or matrices containing NaN/Inf; very large matrices exceeding sweep limits; GPU tensors whose sync read returns None; numerically unstable random initialization causing non-convergence.","solutions":["Inspect the embedded `{err}` message to see why svd_host_data failed (convergence vs data issue).","Sanitize the input: remove/replace NaN and Inf values and ensure the matrix is finite before calling svd().","Increase `sweeps` (iteration budget) or adjust `swap` to give the Jacobi fallback more room to converge.","Use a backend with native SVD support or compute SVD via a CPU/linalg library (e.g. ndarray/nalgebra) for pathological inputs."],"exampleFix":"// before\nlet (u, s, vt) = tensor.svd();\n\n// after\nassert!(tensor.clone().into_data().to_vec().iter().all(|v| v.is_finite()));\nlet (u, s, vt) = tensor.svd(); // or fall back to a CPU linalg crate on error","handlingStrategy":"fallback","validationCode":"// check input finiteness before SVD\nlet data = tensor.clone().into_data();\nassert!(data.value.iter().all(|x: &f32| x.is_finite()), \"SVD input has NaN/Inf\");","typeGuard":"fn svd_safe(t: &burn::tensor::Tensor<burn::tensor::backend::Backend, 2>) -> bool {\n    // finite, non-degenerate 2D input\n    t.dims()[0] > 0 && t.dims()[1] > 0\n}","tryCatchPattern":"// burn panics rather than returning Result; isolate with catch_unwind if SVD may fail\nlet result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| tensor.svd()));\nmatch result {\n    Ok(usv) => { /* use u, s, vt */ }\n    Err(_) => { /* fall back to a CPU linalg crate (nalgebra/ndarray) */ }\n}","preventionTips":["Sanitize tensors (NaN/Inf) before decomposition ops.","Prefer backends with native SVD for heavy linear-algebra workloads.","Log matrix shape/conditioning before calling svd() on ill-conditioned inputs."],"tags":["svd","linear-algebra","panic","numerical","burn"],"backgroundTag":"svd-fallback-failed","analyzedSha":"d16f7ba2ed0d41408189384044cc886fb4c8f957","analyzedAt":"2026-09-05T13:19:14.260Z","contentChangedAt":"2026-09-05T13:19:14.260Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}