fix(cpu): name the right routine in LUF and SVD error messages - #4167
Merged
zcbenz merged 1 commit intoAug 11, 2026
Merged
Conversation
Both messages hardcoded the float32 routine name even though the ops dispatch float32 and float64 (and complex64 for SVD), so a float64 failure reported a routine that never ran. SVD was also naming the wrong routine entirely: it calls gesdd, not gesvdx. Its two messages used a 'svd_impl:' prefix as well, while every other message in the same file uses '[SVD::eval_cpu]'. Describe the operation instead of naming the routine, which is what Cholesky, Eig, Eigh and Inverse already do.
zcbenz
approved these changes
Aug 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed changes
What's broken. Two CPU linalg error messages name a LAPACK routine that did not run.
LUF::eval_cpudispatchesfloat32andfloat64, but the failure message hardcodes the float32 routine, so afloat64failure reportssgetrf_whendgetrf_is what actually ran:ss << "[LUF::eval_cpu] sgetrf_ failed with code " << infoSVDis wrong on three counts. It dispatchesfloat32,float64andcomplex64, but the message hardcodes the float32 prefix; it namesgesvdx, which the file never calls (run()callsgesdd<T>); and it uses asvd_impl:prefix while every other message in the same file uses[SVD::eval_cpu], including one two lines above it:ss << "svd_impl: sgesvdx_ failed with code " << info;Observed on a CPU-only build, same wrong routine name for both dtypes:
For contrast, LAPACK itself reports the routine per dtype —
mx.linalg.eigon the same input printsOn entry to SHSEQRfor float32 andDHSEQRfor float64.The fix. Describe the operation rather than naming a routine, which is what the other CPU linalg messages already do (
Cholesky::eval_cpu"Cholesky decomposition failed",Eig/Eigh::eval_cpu"Eigenvalue decomposition failed",Inverse::eval_cpu"LU factorization failed"). That keeps the messages correct for every dtype without duplicating the dispatch. Thesvd_impl:prefix becomes[SVD::eval_cpu]to match its own file.After:
On tests. These are message-only changes on error paths that cannot be reached from Python without terminating the process, so there is no test to add. The
info < 0branch inLUFmeans LAPACK got an illegal argument, which MLX never passes. TheSVDbranch is reachable (the repro above), but the throw happens insideencoder.dispatch, so it escapes the worker thread and callsstd::terminateinstead of surfacing as a Python exception —assertRaisescannot catch it.python/tests/test_linalg.pyandtest_ops.pyare green (168 passed, 575 subtests).That thread-propagation behaviour looks like a separate bug worth its own fix —
mx.linalg.invon a singular matrix aborts the interpreter the same way — but it needs a design decision about where to capture and rethrow, so I have left it out of this PR. Happy to file it as an issue if that is useful.No benchmark: string literals only, no change to any code path.
Checklist
pre-commit run --all-filesto format my code / installed pre-commit prior to committing changes