float16 normalization problem with numpy >= 1.21
See original GitHub issueDescribe the bug
Hi!
I think sklearn.preprocessing.normalize doesn’t work properly on float16 for the latest versions of numpy. I am not sure if this is a bug with numpy or sklearn, but figured folks might want to know. I think for dense matrices, np.einsum
is used to compute norms, so the instability might be there. Regardless…
Steps/Code to Reproduce
import numpy as np
import sklearn
print(sklearn.__version__)
## if numpy is 1.20.3 or below, this works
## if numpy is 1.21.X or above, this breaks
print(np.__version__)
import sklearn.preprocessing
np.random.seed(1)
test = np.random.random((1,512)).astype(np.float16)
test_norm = sklearn.preprocessing.normalize(test)
print(np.linalg.norm(test_norm))
#output for sklearn 1.0.1 and numpy 1.21.2 (anything 1.21.+)
#1.0.1
#1.21.2
#13.25
#output for sklearn 1.0.1 and numpy 1.20.3
#1.0.1
#1.20.3
#1.0
Expected Results
regardless of numpy version, np.linalg.norm
should be close to 1 after normalization
Actual Results
the norm is 13 for any numpy 1.21.+
Versions
see above — I’m using the latest sklearn, but if i also use the latest numpy, float16 normalization no longer seems to work.
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (7 by maintainers)
Top Results From Across the Web
NumPy 1.21.0 Release Notes
There are unresolved problems compiling NumPy 1.20.0 with gcc-11.1. ... is strongly discouraged and will now enforce a normalized type tuple if done....
Read more >NumPy 1.21.5 Release Notes
NumPy 1.21.5 is a maintenance release that fixes a few bugs discovered after the 1.21.4 ... #20462: BUG: Fix float16 einsum fastpaths using...
Read more >NumPy 1.21.4 Release Notes
Previously, the header files only worked for M1 and this caused problems for folks building x86_64 extensions. This problem was not seen before...
Read more >NumPy 1.21.2 Release Notes
The 1.21.x series is compatible with Python 3.10.0rc1 and Python 3.10 will be officially supported after it is released. The previous problems with...
Read more >NumPy 1.21.1 Release Notes
3.17 to deal with problems on arm64. The Python versions supported for this release are 3.7-3.9. The 1.21.x series is compatible with development...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Closing because this issue was fixed in NumPy.
We can keep it open just to track the regression.