Wrong output from lstm layer
Hi,
I am seeing incorrect results in lstm layer for the input attached LSTM layer configuration: input size - 25 sequenceLength - 209 Hidden units - 10.
i have attached the script i used lstm_standalone.zip
i tried using different versions(v1.0, v1.4,v1.6) , output is different for each version.
Thanks, Pranathi.
Thank you for the report, @pranathibl. The reproducer does not include any validation code. How do I see that results are incorrect?
One thing I noticed about your reproducer is that it's using ntc format for input and output tensors. Do you observe the same behavior with tnc, which is the default for LSTM cell?
Please also note that recommended usage model for RNN and other compute primitives relies on format any to let the library choose the format that works best. See LSTM inference example.
Hi @vpirogov
I see the same issue with tnc format as well. I am attaching the script along with the expected output. lstm_standalone.zip
hiddenStateY.txt is the output for last sequence with, whereas expected_hiddenStateY.txt is the expected values for input values in input.txt.
-Pranathi
Hi @vpirogov, @dzarukin
any update on this issue?
Hi @pranathibl, sorry for a late response. I'll be able to share my analysis the next week. Is it OK with you?
Sure
Thank you.
Hi
any update on this?
Hi Pranathi,
Sorry for not getting back to you on this issue. I am currently looking into it, and will reach out back to you with my findings by tomorrow. Thank you for your patience.
Silviu
Hi @pranathibl,
Having looked at the issue, I can confirm that different versions of the library produce different output for your code. It seems that there is some small "error" introduced at first iteration between version, and this "error" grows as the sequence progresses. Also, I have noticed that the hidden states computed using oneDNN v1.6 and v1.7 are identical.
For my analysis to progress further, could you please provide the expected output of the hidden state after one iteration, i.e. using #define SEQ_LEN 1? Below is the result computed by oneDNN v1.7:
0.01202767 0.18950476 -0.03439132 0.10100358 0.08630899 0.01268229 -0.08630899 -0.23024113 -0.01202767 0.40531671
How does it compare to what you expect?
Thank you,
Silviu
hi @sbogusev ,
It is true that the difference between expected and actual output increases as sequence length increases. I am attaching the complete output for all the sequences.
Thanks Pranathi
Thank you, @pranathibl . The complete output will definitely help finding the root cause. The good news is that the output of the first sequence from oneDNN and your output are identical, so algorithmically oneDNN works correctly. I have a suspicion that this difference may be cause by the tanh elementwise operation, but I will look into it in a bit more details and will let you know tomorrow about my findings.
Thank you,
Silviu
Hi @pranathibl . Just wanted to confirm that indeed the results are different between different version of oneDNN because of tanh.
In essence, oneDNN uses a polynomial to approximate the tanh function, and the correctness of this approximation is validated against the tanh implementation from glibc within 4e-5 absolute error. This means that tanh operation will produce some small residual error, however, due to the nature of RNNs and the fact that your example uses multiple sequences (209), this error becomes part of the input for the next iteration, and becomes very significant at the end of the sequence. The reason this error was different between different versions of the library is because of different implementations of tanh that was present in the library during different releases.
Firstly I would like to note that oneDNN does not guarantee numerical reproducibility between different versions of the library. We use reference algorithms (such as math functions from glibc) to validate the numerical accuracy of our optimized algorithms within a degree of tolerance (which is also subject to change). Even using the tanh implementation from glibc for your example does not produce results close to yours. The only way to reproduce your expected output would be using the same tools and the same environment as you did to obtain it, otherwise there will be a difference.
Secondly, and perhaps the bigger question, is whether the difference in output discussed above causes unexpected behavior for your RNN-based model. Or is it mostly an observation that the numbers differ? The numerical errors discussed above are also present in other large models (CNN-based or otherwise). However this error does not necessarily result in the model behaving differently.
Could you please let me know if the behavior of your model is affected in any way by the difference in output? Then we can proceed further.
Thank you,
Silviu
Closing the issue there seems to be no update. Feel free to reopen if there are any concerns.