Skip to content

Improve eig tests in preparation for new eig backends#166322

Closed
johannesz-codes wants to merge 2 commits intopytorch:mainfrom
johannesz-codes:eig-tests
Closed

Improve eig tests in preparation for new eig backends#166322
johannesz-codes wants to merge 2 commits intopytorch:mainfrom
johannesz-codes:eig-tests

Conversation

@johannesz-codes
Copy link
Contributor

Summary

Improves validation of torch.linalg.eig results by verifying the eigen decomposition identity A v − v λ = 0.

Motivation

Eigenvectors are not unique, and numerical differences between backends (cuSOLVER, MAGMA, CPU)
can cause false test failures. This PR replaces direct elementwise comparisons with a mathematical
identity check, improving robustness across devices.

Details

  • Introduces fulfills_eigen_decomposition_identity() in test_eig_compare_backends() to validate the eigen equation.
  • Uses CPU matmul for high-precision verification.
  • Handles zero-sized matrices explicitly.
  • Tolerances derived from numerical comparisons between cuSOLVER and NumPy.
    See discussion: dev-discuss.pytorch.org link

Impact

  • Improves test stability and correctness across eig backends.
  • No change to public API.
  • All tests pass; lintrunner reports no issues.
  • Enables introduction of new eig backends without false test failures.

@pytorch-bot
Copy link

pytorch-bot bot commented Oct 27, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/166322

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit 1e3010e with merge base 6ecd6b2 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@pytorch-bot pytorch-bot bot added the topic: not user facing topic category label Oct 27, 2025
@johannesz-codes
Copy link
Contributor Author

https://dev-discuss.pytorch.org/t/cusolver-dnxgeev-faster-cuda-eigenvalue-calculations/3248/6

Since I forgot to add the link in the original PR

- Verify validity of eigenvectors using the eigen decomposition identity
  for improved robustness, as eigenvectors are not unique.
- Increases test reliability across backends (cuSOLVER, MAGMA, CPU).
- Tolerances derived from numerical comparisons between cuSOLVER and NumPy. See discussion: https://dev-discuss.pytorch.org/t/cusolver-dnxgeev-faster-cuda-eigenvalue-calculations/3248/6
Copy link
Collaborator

@lezcano lezcano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few things:

  1. Could you inline the function you just wrote?
  2. Don't move things to CPU unnecessarily. Those computations can be performed on the device.
  3. Use assertEqual(a@v, v - w) rather than rolling out your own comparison (let alone printing unconditionally)

Copy link
Collaborator

@lezcano lezcano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Thank you for the clean-up!

@lezcano
Copy link
Collaborator

lezcano commented Oct 28, 2025

@pytorchbot merge

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Oct 28, 2025
@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request Merged open source topic: not user facing topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants