NVIDIA / framework-reproducibility

Providing reproducibility in deep learning frameworks
Apache License 2.0
423 stars 40 forks source link

non-determinism on tf.keras.layers.UpSampling2D(..., interpolation='nearest') #24

Closed emiliocoutinho closed 4 years ago

emiliocoutinho commented 4 years ago

I believe there is a source of non-determinism on tf.keras.layers.UpSampling2D with interpolation='nearest', as you suggest on Other Possible GPU-Specific Sources of Non-Determinism.

In my case, I was building an auto-encoder, and on the decoder part, there were some procedures that I was not satisfied with and I was just waiting for the right time to change them. Turns out that this part was responsible for the non-deterministic behavior and as in #12, I replaced:

tf.keras.layers.UpSampling2D(..., interpolation='nearest')
ReflectionPadding2D()  # that is nothing more than a tf.pad(..., mode='REFLECT')
tf.keras.layers.Conv2D(..., padding='valid')

by:

tf.keras.layers.Conv2DTranspose(...,padding='same')

and now I have reproducible results on GPU and on CPU.

Thanks for the effort in building this package, it is very useful.

Best Regards.

duncanriach commented 4 years ago

Awesome work. Thanks Emilio. I'm going to move this source up into the confirmed list and review its priority relative to other ops, given that it's probably going to be a similar solution to that for bilinear filtering (referencing TF PR 39243). Thanks also for reporting the work-around.

duncanriach commented 4 years ago

With this commit, I have updated README.md to reflect all of this. I have also added fixing nearest neighbor resizing to my to-do list. This feature addition is in the pipeline to get added to TensorFlow. I'm going to close this issue now.

duncanriach commented 4 years ago

Closing.