OpenAI's Free AI Now Does Your Email
This could save you 3 hours a week and make your inbox stress-free.
PyTorch's linalg.lstsq was handing degenerate shapes straight to the backend, so each case inherited LAPACK's quick-return behavior β and those behaviors disagreed with each other and with the math. gels zeroed B when min(m, n, nrhs) == 0, so for n == 0 the CPU reported zero residuals instead of ||B||^2, and the backward pass, which assumes the true residual, disagreed with them. gelsy set rank = 0 when nrhs == 0, even though the rank of A doesn't depend on B. gelsd/gelss only quick-returned when m or n was 0; with nrhs == 0 they went on to access B, which has no storage, and segfaulted on CPU.
The fix: linalg_lstsq_out_info now handles these cases before calling the backend. With min(m, n) == 0 it skips the backend entirely β the solution is zero, the rank is 0, and B stays in the buffer, so the existing residual code reports ||B||^2. With no right-hand sides it runs the backend against a single zero column, which yields the rank and singular values without passing LAPACK an empty B. The MPS kernel's own empty-input check from the previous commit becomes unreachable, so it is removed.
Testing that through out= exposed a separate bug: when the provided out= tensors can be used directly (an empty solution with a wrong shape still qualifies), outputs the driver doesn't produce were returned with whatever shape they came in with. residuals (when not computed), rank (gels) and singular_values (gels, gelsy) are now resized to empty, as in the functional variant.
User-visible changes on CPU: gels residuals for n == 0 are ||B||^2 rather than 0, gelsy reports the rank of A when there are no right-hand sides, gelsd/gelss no longer segfault without right-hand sides, and unused out= tensors come back empty. This PR was authored with the help of Claude Code. Co-Authored-By: Claude Opus 5.5. Pull Request resolved: #199696. Approved by: https://github.com/Skylion007
- OpenAI's new free AI reads your emails and drafts replies, saving you time.
- It works with Gmail and Outlook, but your data goes to OpenAI's servers.
- The AI can make mistakes, so always review before sending.
Why It Matters
This could save you hours each week and reduce email stress, but privacy trade-offs exist.