Skip to content
Navigation Menu
{{ message }}
-
Notifications
You must be signed in to change notification settings - Fork 75.3k
Add tests for TF_CUDNN_DETERMINISTIC #25796
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
tensorflow-copybara
merged 1 commit into
tensorflow:master
from
duncanriach:cudnn_deterministic_testing
Feb 23, 2019
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
tensorflow/python/kernel_tests/cudnn_determinism_test.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| # Copyright 2019 The TensorFlow Authors. All Rights Reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # ============================================================================== | ||
| """Tests for TF_CUDNN_DETERMINISTIC=true""" | ||
|
|
||
| from __future__ import absolute_import | ||
| from __future__ import division | ||
| from __future__ import print_function | ||
|
|
||
| import os | ||
| from collections import namedtuple | ||
| import numpy as np | ||
|
|
||
| from tensorflow.python.framework import constant_op | ||
| from tensorflow.python.framework import dtypes | ||
| from tensorflow.python.framework import test_util | ||
| from tensorflow.python.platform import test | ||
| from tensorflow.python.ops import nn_ops | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sort alphabetically.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it. Thanks. |
||
|
|
||
| # The TF_CUDNN_DETERMINISTIC flag disables autotuning of cuDNN algorithms and | ||
| # causes deterministic cuDNN algorithms to be selected when both deterministic | ||
| # and non-deterministic algorithms are available. These tests are intended to | ||
| # confirm that deterministic algorithms are chosen when | ||
| # TF_CUDNN_DETERMINISTIC=true. The configurations tested were confirmed to | ||
| # produce non-deterministic results without setting TF_CUDNN_DETERMINISTIC=true | ||
|
|
||
| _PADDING = "SAME" | ||
| _STRIDES = [1, 1, 1, 1] | ||
|
|
||
| LayerShape = namedtuple('LayerShape', 'batch, height, width, channels') | ||
| FilterShape = namedtuple( | ||
| 'FilterShape', 'height, width, in_channels, out_channels') | ||
|
|
||
| class ConvolutionTest(test.TestCase): | ||
|
|
||
| def _random_data_op(self, shape): | ||
| # np.random.random_sample can properly interpret either tf.TensorShape or | ||
| # namedtuple as a list. | ||
| return constant_op.constant(2 * np.random.random_sample(shape) - 1, | ||
|
chsigg marked this conversation as resolved.
|
||
| dtype=dtypes.float32) | ||
|
|
||
| def _random_out_op(self, in_shape, filter_shape): | ||
| # Choosing not to use array_op.zeros() to prevent possible removal by | ||
| # optimization | ||
| in_op = self._random_data_op(in_shape) | ||
| filter_op = self._random_data_op(filter_shape) | ||
| # Use the forward op's shape-inference | ||
| conv_op = nn_ops.conv2d(in_op, filter_op, | ||
| strides=_STRIDES, padding=_PADDING) | ||
| out_shape = conv_op.get_shape() | ||
| out_op = self._random_data_op(out_shape) | ||
| return out_op | ||
|
|
||
| def _assert_reproducible(self, operation): | ||
| with self.cached_session(force_gpu=True): | ||
| result_1 = self.evaluate(operation) | ||
| result_2 = self.evaluate(operation) | ||
| self.assertAllEqual(result_1, result_2) | ||
|
|
||
| @test_util.run_cuda_only | ||
| def testBackwardFilterGradient(self): | ||
| np.random.seed(1) | ||
| in_shape = LayerShape(batch=8, height=128, width=128, channels=8) | ||
| filter_shape = FilterShape(height=3, width=3, in_channels=8, out_channels=8) | ||
| in_op = self._random_data_op(in_shape) | ||
| out_op = self._random_out_op(in_shape, filter_shape) | ||
| filter_gradient_op = nn_ops.conv2d_backprop_filter( | ||
| in_op, filter_shape, out_op, strides=_STRIDES, padding=_PADDING) | ||
| self._assert_reproducible(filter_gradient_op) | ||
|
|
||
| @test_util.run_cuda_only | ||
| def testBackwardInputGradient(self): | ||
| np.random.seed(2) | ||
| in_shape = LayerShape(batch=8, height=32, width=32, channels=8) | ||
| filter_shape = FilterShape(height=7, width=7, | ||
| in_channels=8, out_channels=128) | ||
| filter_op = self._random_data_op(filter_shape) | ||
| out_op = self._random_out_op(in_shape, filter_shape) | ||
| input_gradient_op = nn_ops.conv2d_backprop_input( | ||
| in_shape, filter_op, out_op, strides=_STRIDES, padding=_PADDING) | ||
| self._assert_reproducible(input_gradient_op) | ||
|
|
||
| # TODO(duncanriach-nvidia): (1) add test to confirm that forward autotuning | ||
| # is disabled for cuDNN convolution; (2) add test for deterministic cuDNN | ||
| # max-pooling | ||
|
|
||
| if __name__ == "__main__": | ||
| os.environ['TF_CUDNN_DETERMINISTIC'] = 'true' | ||
| test.main() | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
You can’t perform that action at this time.

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please import entire module and then do collections.namedtuple below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. Thanks for catching that.