• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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# ==============================================================================
15"""Tests for Grappler Arithmetic Optimizer."""
16
17from __future__ import absolute_import
18from __future__ import division
19from __future__ import print_function
20
21from tensorflow.python.eager import context
22from tensorflow.python.eager import def_function
23from tensorflow.python.ops import array_ops
24from tensorflow.python.ops import math_ops
25from tensorflow.python.platform import test
26
27
28class ArithmeticOptimizerTest(test.TestCase):
29
30  # See b/146524878.
31  def testFunctionArgShapeInference(self):
32
33    @def_function.function
34    def f(x, y):
35      return math_ops.matmul(
36          x, array_ops.reshape(array_ops.transpose(y), [384, 1536]))
37
38    with context.eager_mode():
39      x = array_ops.ones((1, 384))
40      y = array_ops.ones((1536, 384))
41      with context.collect_graphs(optimized=True) as graphs:
42        f(x, y).numpy()
43      self.assertLen(graphs, 1)
44      self.assertLen(graphs[0].node, 4)
45      self.assertEqual(graphs[0].node[2].name,
46                       'ArithmeticOptimizer/FoldTransposeIntoMatMul_MatMul')
47
48
49if __name__ == '__main__':
50  test.main()
51