1# Copyright 2020 The TensorFlow Authors. All Rights Reserved. 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14"""Test for tfr mnist training example.""" 15 16from absl.testing import parameterized 17 18from tensorflow.compiler.mlir.tfr.examples.mnist import mnist_train 19from tensorflow.python.distribute import combinations 20from tensorflow.python.distribute import strategy_combinations 21from tensorflow.python.distribute import test_util as distribute_test_util 22from tensorflow.python.framework import test_util 23 24strategies = [ 25 strategy_combinations.one_device_strategy, 26 strategy_combinations.one_device_strategy_gpu, 27 strategy_combinations.tpu_strategy, 28] 29 30 31class MnistTrainTest(test_util.TensorFlowTestCase, parameterized.TestCase): 32 33 @combinations.generate(combinations.combine(strategy=strategies)) 34 def testMnistTrain(self, strategy): 35 accuracy = mnist_train.main(strategy) 36 self.assertGreater(accuracy, 0.7, 'accuracy sanity check') 37 38 39if __name__ == '__main__': 40 distribute_test_util.main() 41