-
Notifications
You must be signed in to change notification settings - Fork 249
Fix numpy2 natural gradient compatibility #400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
- Replace vectorized np.linalg.solve with sample-wise computation in scores.py - Add robust dimension checking and error handling - Handle singular matrix cases with pseudo-inverse fallback - Add comprehensive test suite for NumPy 2.x compatibility - Fixes GitHub issue #384: dimension mismatch in natural gradient computation The original issue occurred when np.linalg.solve received incompatible dimensions between metric and gradient arrays. The new implementation: 1. Validates dimensions before computation 2. Solves linear systems sample-by-sample for better stability 3. Provides clear error messages for dimension mismatches 4. Handles singular matrices gracefully All existing tests pass and new compatibility tests verify the fix.
- Fix unbalanced tuple unpacking in make_regression call - Replace broad Exception catching with specific ValueError and LinAlgError - All linter checks now pass
- Remove trailing whitespace that was causing GitHub CI to fail - All linter checks now pass on Python 3.11
…tisfy pylint unbalanced-tuple-unpacking across sklearn versions
Nice @ryan-wolbeck. Did you test speed? I'd worry that the sample-wise computation could slow things down a lot but I could be wrong. |
That's a good point to test, looking at build times it looks like it goes from about 12 mins runtime for each version of python to about 22 mins. Do you have ideas of a middle ground? |
Hm... there are python libraries that precompile code that looks like this into C++ which runs very very quickly. Numba is a good example that is very easy to use. Though honestly I'm not sure writing the code the way you did (sample-by-sample) vs the numpy version is more stable in the first place? |
Updated the code to get past the speed issue. To your second point, I don't have a strong opinion. |
The original issue occurred when np.linalg.solve received incompatible
dimensions between metric and gradient arrays. The new implementation:
All existing tests pass and new compatibility tests verify the fix.
closes #384