Repository navigation
Closed
Labels
Description
Describe the issue:
At one PC, starting with numpy version 1.23.*, I have noticed that linalg.inv gives wrong result. We have tried to reproduce it on few more PCs, but we didn't succeed. Even on this PC older versions of numpy are working fine. In the code example, you can find matrices. Matrix p_inv_exp is result got with older numpy versions, while p_inv_wrong is matrix got with 1.23.* version.
PC is equipped with 12th Gen Intel(R) Core(TM) i5-12400 2.50 GHz processor.
Does anyone have an idea what the problem could be? Which PC specifics you need to know?
Reproduce the code example:
import numpy as np
p = np.array([[-1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
[0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 330.0, 0.0],
[0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0],
[0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2700.0, 0.0],
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0]])
p_inv_exp = [[-1.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0],
[-0.0, -0.8910891089108911, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, 0.10891089108910891, -0.0],
[-0.0, -0.0, -1.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0],
[-0.0, -0.0, -0.0, -1.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0],
[-0.0, -0.0, -0.0, -0.0, -1.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0],
[-0.0, -0.0, -0.0, -0.0, -0.0, -1.0, -0.0, -0.0, -0.0, -0.0, -0.0],
[-0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -1.0, -0.0, -0.0, -0.0, -0.0],
[-0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -1.0, -0.0, -0.0, -0.0],
[-0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -1.0, -0.0, -0.0],
[0.0, 0.00033003300330033004, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.00033003300330033004, 0.0],
[-0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -1.0]]
p_inv_wrong = [[-1.00000000e+00, -0.00000000e+00, -0.00000000e+00, -0.00000000e+00, -0.00000000e+00, -0.00000000e+00, -0.00000000e+00, -0.00000000e+00, -0.00000000e+00, -0.00000000e+00, -0.00000000e+00],
[-0.00000000e+00, -1.00000000e+00, -0.00000000e+00, -0.00000000e+00, -0.00000000e+00, -0.00000000e+00, -0.00000000e+00, -0.00000000e+00, -0.00000000e+00, -0.00000000e+00, -3.30000000e+02],
[-0.00000000e+00, -0.00000000e+00, -1.00000000e+00, -0.00000000e+00, -0.00000000e+00, -0.00000000e+00, -0.00000000e+00, -0.00000000e+00, -0.00000000e+00, -0.00000000e+00, -0.00000000e+00],
[-0.00000000e+00, -0.00000000e+00, -0.00000000e+00, -1.00000000e+00, -0.00000000e+00, -0.00000000e+00, -0.00000000e+00, -0.00000000e+00, -0.00000000e+00, -0.00000000e+00, -0.00000000e+00],
[-0.00000000e+00, -0.00000000e+00, -0.00000000e+00, -0.00000000e+00, -1.00000000e+00, -0.00000000e+00, -0.00000000e+00, -0.00000000e+00, -0.00000000e+00, -0.00000000e+00, -0.00000000e+00],
[-0.00000000e+00, -0.00000000e+00, -0.00000000e+00, -0.00000000e+00, -0.00000000e+00, -1.00000000e+00, -0.00000000e+00, -0.00000000e+00, -0.00000000e+00, -0.00000000e+00, -0.00000000e+00],
[-0.00000000e+00, -0.00000000e+00, -0.00000000e+00, -0.00000000e+00, -0.00000000e+00, -0.00000000e+00, -1.00000000e+00, -0.00000000e+00, -0.00000000e+00, -0.00000000e+00, -0.00000000e+00],
[-0.00000000e+00, -0.00000000e+00, -0.00000000e+00, -0.00000000e+00, -0.00000000e+00, -0.00000000e+00, -0.00000000e+00, -1.00000000e+00, -0.00000000e+00, -0.00000000e+00, -0.00000000e+00],
[-0.00000000e+00, -0.00000000e+00, -0.00000000e+00, -0.00000000e+00, -0.00000000e+00, -0.00000000e+00, -0.00000000e+00, -0.00000000e+00, -1.00000000e+00, -0.00000000e+00, -0.00000000e+00],
[ 0.00000000e+00, 3.30033003e-04, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 3.30033003e-04, 0.00000000e+00],
[-0.00000000e+00, -0.00000000e+00, -0.00000000e+00, -0.00000000e+00, -0.00000000e+00, -0.00000000e+00, -0.00000000e+00, -0.00000000e+00, -0.00000000e+00, -0.00000000e+00, -1.00000000e+00]]
print(p@p_inv_wrong)Error message:
No response
NumPy/Python version information:
1.23.4 3.8.4 (tags/v3.8.4:dfa645a, Jul 13 2020, 16:46:45) [MSC v.1924 64 bit (AMD64)]
Context for the issue:
No response
Activity
charris commentedon Oct 31, 2022
Same MSC version on all machines? How did you install NumPy?
seberg commentedon Nov 1, 2022
Another piece (additionally to the two what @charris asked), can you report what:
reports? (requires installing threadpoolctl) That should tell us what BLAS/lapack backend you are using.
mmiletic95 commentedon Nov 1, 2022
UPDATE: We found one more PC with the same processor and it behaves exactly the same.
Yes, on most of the machines we are using same MSC version. At these PCs (that are not working well) we tried different python versions and different MSCs, and it is still not working with numpy 1.23.*. Earlier numpy versions are working correctly.
Some MSCs we also tried: 3.10.0 (tags/v3.10.0:b494f59, Oct 4 2021, 19:00:18) [MSC v.1929 64 bit (AMD64)], 3.10.8 (tags/v3.10.8:aaaf517, Oct 11 2022, 16:50:38) [MSC v.1933 64 bit (AMD64)],
NumPy is installed using pip install procedure
With NumPy 1.23 - not working
with NumPy 1.20 - working:
seberg commentedon Nov 1, 2022
@mmiletic95 , thanks. It might be a problem related to the Copperlake kernels in OpenBLAS,. Just to be sure, there is nothing like a virtual machines or so involved here, right?
Could you try on the bad machine after first setting the environment variable:
(you can rerun the
threadpoolctlcommand to confirm that it saysarchitecture=SkylakeXafterwards, rather thanCopperLake).mmiletic95 commentedon Nov 1, 2022
@seberg Thank you! If we set OPENBLAS_CORETYPE=SkylakeX at bad machine, everything works as expected.
seberg commentedon Nov 1, 2022
Ok, cool. So it has to do with the Copperlake. But, one thing I am not yet certain about is whether this is actually a bug, and not just bad input plus fluctuations in numerical accuracy. Looking at:
The matrix seems rather badly conditioned, so you may just be expecting too much and should maybe use the pseudo-inverse
pinvinstead?mmiletic95 commentedon Nov 1, 2022
Thank you @seberg. Probably it is candidate for pseudo-inverse. But, the difference in results is really significant. Shouldn't result be the "same" at all "architectures"? I mean, at the same processor with just two different setups, we are getting completely different results. Shouldn't we get deterministic result even if it is hard to be computed?
mattip commentedon Nov 1, 2022
I wonder if this is solved on OpenBLAS 0.3.21. I didn't see anything relevant in the release notes but maybe I am not reading close enough.
We should probably update anyway, that version was released in August.
seberg commentedon Nov 1, 2022
No, unfortunatly you cannot expect the same results, you can expect the same results within numerical accuracy, but that may be tricky thing often...
That is a problem clearly, since it means that it can be very hard to reproduce work-flows precisely, but identical software versions are just as important as hardware here.
OTOH, it is very possible that this is a bug (and eveven that it is long fixed). I have not thought about whether this is within the expected numerical accuracy range.
mmiletic95 commentedon Nov 2, 2022
@seberg "No, unfortunatly you cannot expect the same results, you can expect the same results within numerical accuracy, but that may be tricky thing often..." Yes, that is exactly what I wanted to say. I mean, we tested this at like 50+ PCs and everything works fine except specific PCs. Then, on these PCs, every version of NumPy except 1.23.* works fine. Furthermore, even if we just change architecture in OpenBLAS, everything works fine even on these PCs even with 1.23.*. For me, it is hard to believe that somehow magically behavior is changed in this corner case, while in all other cases everything is the same (ofc, with small differences - in range of 1e-18), meanwhile keeping all calculations under numerical tolerance. What are probabilities that we can hit exactly that behavior with certain settings and that everything stays within tolerance?
However, we are here if we can anyhow help to pinpont exact issue, or prove that everything is withing expected numerical tolerance. Will some live debugging help?
seberg commentedon Nov 2, 2022
@martin-frbg, do you think this is an issue with the Cooperlake kernels or rather just bad numerics here? I think
invis usingdgesvin the background here.martin-frbg commentedon Nov 2, 2022
Cooperlake kernels and parameters in OpenBLAS should be identical to SkylakeX ones except for the added BFLOAT16 GEMM.
I'd like to see how 0.3.21 fares before investigating further (and I do not have Cooperlake hardware currently)
martin-frbg commentedon Nov 3, 2022
Actually there is a small, unwanted difference in the kernel selection - both ?ASUM and ?ROT kernels employ an assembly microkernel when the target is SKYLAKEX, but fall back to C code for Cooperlake. (Somebody forgot to expand the
ifdef SKYLAKEXto its successors that use the same source file.) Not checked yet if this matters for yourinvproblem, but the difference in numerical accuracy is apparent in the LAPACK testsuite when I build for either TARGET on my SkylakeXmartin-frbg commentedon Nov 3, 2022
Nevertheless, I cannot reproduce the "p_inv_wrong" result with 0.3.21 on my hardware. (Compiler version /options may play a role here of course)
mattip commentedon Nov 17, 2022
There are wheels available at the bottom of https://github.com/numpy/numpy/actions/runs/3485912390 with OpenBLAS 0.3.21. @mmiletic95 could you give the new build a go?
mmiletic95 commentedon Nov 17, 2022
@mattip Tested at 3 "bad" machines, it seems it works. Thank you!
elliot-kulakow-ent commentedon Apr 17, 2023
I am getting this same behavior on Sapphire Rapids with numpy 1.23.5 - which version includes the openBLAS 0.23.1 upgrade? I'm seeing the PR was merged in November but can't see if it was included in 1.24.x
SamZhangQingChuan commentedon Nov 20, 2023
Hi everyone,
I seem to have encountered the same issue on my box and it can be replicated consistently
1.23.4Intel(R) Xeon(R) Platinum 8488C(Sapphire Rapids)m7i.large0.3.20Replicate method:
A few ways to fix(from my observations):
1.24.0and the openblas will be upgraded to0.3.21seberg commentedon Nov 21, 2023
Thanks for the note, not sieving through the full discussion, but if 0.3.21 of openblas fixed it, there seems nothing actionable to do here anymore (we are not going to release new 1.23 wheeels for sure).
[XPU] Remove stale expectedFailure for linalg.tensorinv test_numpy_re…
[XPU] Remove stale expectedFailure for linalg.tensorinv test_numpy_re…