oneDNN icon indicating copy to clipboard operation
oneDNN copied to clipboard

Wrong output from lstm layer

Open pranathibl opened this issue 6 years ago • 13 comments

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.

pranathibl avatar Sep 11 '20 06:09 pranathibl

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?

vpirogov avatar Sep 16 '20 23:09 vpirogov

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.

vpirogov avatar Sep 16 '20 23:09 vpirogov

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

pranathibl avatar Sep 18 '20 09:09 pranathibl

Hi @vpirogov, @dzarukin

any update on this issue?

pranathibl avatar Sep 24 '20 11:09 pranathibl

Hi @pranathibl, sorry for a late response. I'll be able to share my analysis the next week. Is it OK with you?

dzarukin avatar Sep 24 '20 22:09 dzarukin

Sure

Thank you.

pranathibl avatar Sep 25 '20 03:09 pranathibl

Hi

any update on this?

pranathibl avatar Oct 05 '20 07:10 pranathibl

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

sbogusev avatar Oct 05 '20 23:10 sbogusev

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

sbogusev avatar Oct 06 '20 22:10 sbogusev

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.

expectedOutput.txt

Thanks Pranathi

pranathibl avatar Oct 07 '20 14:10 pranathibl

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

sbogusev avatar Oct 07 '20 19:10 sbogusev

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

sbogusev avatar Oct 07 '20 23:10 sbogusev

Closing the issue there seems to be no update. Feel free to reopen if there are any concerns.

sbogusev avatar Nov 04 '20 20:11 sbogusev