← Back to Pull requests

Report SVD failures instead of returning them #3570

Open
unknown opened this pull request with 473 lines diff across 5 files
View on GitHub
unknown unknown commented on Nov 12, 2026 07:39 UTC
Author

gesvdj!, gesvdjBatched! and gesvdaStridedBatched! only threw for info < 0 (invalid arguments), so a solver that did not converge or failed handed back its output as a result. This PR makes them throw a LAPACKException for info > 0, like gesvd! and gesvdp! already do, and gives the Jacobi wrappers a tolerance they can actually reach.

Jacobi tolerance. The wrappers set the tolerance to eps. On matrices with (numerically) zero singular values, the Jacobi residual levels off at about √n·eps, so from n ≈ 64 gesvdj often ran all 100 sweeps and returned info = n+1. Running on past that point sometimes leaves it in a bad state: in 9 of 101 ComplexF64 runs with half the singular values zero (n = 370/512), the reconstruction error was 1.7e-9…1.2e-8. Just throwing on info > 0 would therefore break svd(A; alg=JacobiAlgorithm()) for these matrices. The new default is 2sqrt(max(m, n))eps(real(T)):

| tolerance | grid: cells not converged (F64 / C64 / F32 / C32) | stall test, C64 n = 370/512 | F32/C32 n = 768–2048, 80 runs |
|---|---|---|---|
| eps (old) | 16/56, 24/64, 25/56, 33/64 | 202/202 not converged, 9 bad results | – |
| unset (cuSOLVER's own rule) | 0, 0, 0, 5/64 | 0/240 | 31/80 not converged |
| 2√N·eps (new) | 0, 0, 0, 0 | 0/240, worst error 9e-13 | 0/80 |

The grid covers n = 16…1466 with six input classes (well-conditioned, condition 1e12, decaying to 1e-20, half zero, unitary, Gaussian) plus tall and wide variants. With 2√N·eps, every cell converged with a margin of at least 4× over the measured floor. Accuracy against a 100-sweep run did not change measurably (geometric-mean ratios 0.85–1.02). It also runs faster: ComplexF64 n = 512 decaying to 1e-20 drops from 5.3 s to 2.0 s, and n = 1024 with half the values zero from 17.8 s to 4.1 s. Leaving the tolerance to cuSOLVER doesn't work: in single precision its criterion stays at about 8 eps, below the floor once n ≥ 1024. For gesvdjBatched!, the worst error over the batched test inputs (n ≤ 32, four element types) is within 1.24× of the eps result.

The cost shows on graded matrices, where eps resolves the smallest singular values to a higher relative accuracy. Maximum relative error of the singular values (the unset rule is shown for comparison, Xgesvd for reference):

| input (n = 128 unless noted) | eps | 2√N·eps | unset | Xgesvd |
|---|---|---|---|---|
| F64, columns scaled 1 → 1e-12, random order | 2.7e-11 | 5.6e-10 | 5.7e-8 | 1.6e-6 |
| C64, same | 1.9e-12 | 2.1e-8 | 2.1e-8 | 6.7e-6 |
| F64, columns scaled 1 → 1e-12, reversed | 5.1e-12 | 8.3e-9 | 9.3e-9 | 2.2e-5 |
| C64 n = 32, same | 6.5e-13 | 3.8e-10 | 1.1e-9 | 9.1e-6 |
| F64, rows and columns scaled 1 → 1e-8, sorted | 8.3e-6 | 3.2e-3 | 1.2e-2 | 1.6e-14 |

So alg=JacobiAlgorithm() no longer reproduces the old numbers exactly. Callers who want the old tolerance can pass tol=eps(real(T)) to gesvdj!, and now get an exception where it isn't reached.

Batched routines. NVIDIA documents info[i] = min(m,n)+1 for gesvdjBatched when a matrix doesn't converge, but cuSOLVER 12.4 returns 0 even after a single sweep. The check is in place for when it does. gesvdaStridedBatched! returns NaN columns for the singular vectors of a matrix whose rank is below rank. cuSOLVER 11.7.3 (CUDA 12.8) and later also set a positive info, so that now throws, and svd(A; alg=ApproximateAlgorithm()) with it. cuSOLVER 11.7.1 (CUDA 12.6) and older return info = 0 with the NaNs, so the test is gated on the version. The values-only calls succeeded for the same inputs.

Both Jacobi wrappers now also destroy their gesvdjInfo object when they throw.

Measured on an RTX 5080 with CUDA 13.5 (cuSOLVER 12.4.1). The tests also pass with CUDA 12.0 and 11.8, and on Julia 1.10.

Diff: 473 lines (+354 / -119) across 5 files Reviewer: kshyatt Review duration: 3980m
All Vouch review confidence checks passed
Residual risk 0.27 = Change Risk (0.51) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.51 · 473 lines diff across 5 files
0.51
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
0.02
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
46%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.369
Shallow Review Depth shallow_review_depth
0.344
Ai Authored ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #3570"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 46.7% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 50.7% (MEDIUM) · Higher = larger blast radius
50.7%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 46.7% · Lower = rushed or shallow review
46.7%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 27% · Safe to merge
27%