← Back to Pull requests

Default to QR iteration for the SVD of a matrix #3571

Closed
unknown closed this pull request without merging on Nov 17, 2026 12:32 UTC
View on GitHub
unknown unknown commented on Nov 12, 2026 07:39 UTC
Author

svd and svdvals of a CuMatrix default to cuSOLVER's one-sided Jacobi method (gesvdj). QR iteration (gesvd, through the 64-bit Xgesvd) is faster in double precision: 13–45× for the ComplexF64 matrices of size 512 and 1466 below, and faster in every double-precision case measured. Its singular vectors are also closer to orthonormal: 10–20× at n = 64 and 90–400× at n = 512–1466. This PR makes it the default for matrices. Batches (3-D arrays) keep the Jacobi method, since gesvdjBatched is the only batched routine that computes the full decomposition.

QRAlgorithm() also threw an ArgumentError for wide matrices, because gesvd requires m ≥ n. Making it the default meant fixing that first. The adapter that decomposes Aᴴ already existed, but was only used when Jacobi's 32-bit workspace overflowed; now it implements QRAlgorithm for svd, svd!, svdvals and svdvals!, compact and full.

svd(A) and svdvals(A) on an RTX 5080 (CUDA 13.5), minimum of ≥ 3 runs. "main" is Jacobi with tol = eps; "Jacobi" is the previous PR's tolerance; "QR" is this PR's default. Orthogonality is the larger of ‖UᴴU − I‖ and ‖VᴴV − I‖ (Frobenius norm):

| type | n | spectrum | svd: main / Jacobi / QR | svdvals: main / Jacobi / QR | orthogonality: Jacobi / QR |
|---|---|---|---|---|---|
| ComplexF64 | 64 | 1 → 1e-3 | 37.9 / 37.3 / 3.2 ms | 37.9 / 37.2 / 1.3 ms | 2e-13 / 2e-14 |
| ComplexF64 | 64 | 1 → 1e-20 | 91.5 / 70.0 / 2.8 ms | 91.6 / 69.8 / 1.3 ms | 3e-13 / 1e-14 |
| ComplexF64 | 512 | 1 → 1e-3 | 1.01 s / 990 / 77 ms | 1.01 s / 988 / 28 ms | 1e-11 / 1e-13 |
| ComplexF64 | 512 | 1 → 1e-20 | 5.34 / 2.08 s / 57 ms | 5.34 / 2.08 s / 27 ms | 1e-11 / 9e-14 |
| ComplexF64 | 1466 | 1 → 1e-3 | 7.85 / 7.69 s / 560 ms | 6.36 / 6.25 s / 168 ms | 7e-11 / 3e-13 |
| ComplexF64 | 1466 | 1 → 1e-20 | 40.0 / 17.6 s / 388 ms | 36.5 / 14.8 s / 158 ms | 9e-11 / 2e-13 |
| ComplexF32 | 64 | 1 → 1e-3 | 1.57 / 1.38 / 1.37 ms | 1.51 / 1.34 / 0.70 ms | 1e-4 / 8e-6 |
| ComplexF32 | 64 | 1 → 1e-20 | 11.5 / 1.30 / 1.20 ms | 11.3 / 1.27 / 0.68 ms | 8e-5 / 7e-6 |
| ComplexF32 | 512 | 1 → 1e-3 | 36.5 / 33.3 / 16.4 ms | 35.3 / 32.7 / 11.1 ms | 6e-3 / 6e-5 |
| ComplexF32 | 512 | 1 → 1e-20 | 211 / 36.5 / 13.4 ms | 208 / 35.8 / 10.2 ms | 4e-3 / 5e-5 |
| ComplexF32 | 1466 | 1 → 1e-3 | 267 / 237 / 86 ms | 219 / 199 / 53 ms | 3e-2 / 2e-4 |
| ComplexF32 | 1466 | 1 → 1e-20 | 1.66 s / 255 / 61 ms | 1.42 s / 224 / 47 ms | 2e-2 / 1e-4 |

A wider comparison on CUDA 13.5 found where Jacobi is still competitive. It covered all four element types, n = 1…1024, 4096×64, 20000×32 and 64×4096, compact, full and values-only, and four spectra, 312 cells per type:

  • Double precision: QR iteration is faster in every cell, by a median 6.3× (Float64) and 18.5× (ComplexF64).

  • Single precision: Jacobi is faster in 52 of 312 cells, by at most 1.9×. These are all vector jobs, mostly tall or wide matrices and Gaussian input at n = 32–128. Values-only is always faster with QR iteration.
  • A smaller sample on CUDA 12.0 and 11.8 (Float32 and ComplexF64; n = 8…1024 and 4096×64; two spectra; compact and values-only):

  • ComplexF64: QR iteration is 4.8–78× faster.

  • Float32: QR iteration with vectors is slower in those cuSOLVER versions, and Jacobi is 2.1–4.1× faster from n = 32 up. This was measured with the old libraries on a Blackwell card, where they run JIT-compiled.
  • Even where Jacobi is faster in single precision, its singular vectors are about 100× less orthogonal (‖VᴴV − I‖ 1.8e-2 vs 1.2e-4 at n = 1024).

    Caveat. On graded matrices whose large columns are not first, the Jacobi method determines the smallest singular values to a much higher relative accuracy: for example 5.6e-10 vs 1.6e-6 for Float64, n = 128, columns scaled 1 → 1e-12 in random order. QR iteration only gives normwise accuracy (error ≈ eps·σ₁/σᵢ).

    Results change with the algorithm. Both are accurate in norm, but singular-vector phases, and the bases for repeated or zero singular values, can differ. alg=JacobiAlgorithm() restores the old route.

    Diff: 506 lines (+379 / -127) across 6 files Reviewer: kshyatt Review duration: 7492m
    All Vouch review confidence checks passed
    Residual risk 0.19 = Change Risk (0.48) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.48 · 506 lines diff across 6 files
    0.48
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    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.373
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #3571"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% 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: 47.6% (MEDIUM) · Higher = larger blast radius
    47.6%
    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: 60.5% · Lower = rushed or shallow review
    60.5%
    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: 18.8% · Safe to merge
    18.8%