self.assertEqual(text, new_text)
      self.assertEqual(errors, ["test.py:1: %s requires manual check." % decay])
      self.assertIn("%s has been changed" % decay, report)

  def testEstimatorLossReductionChangege(self):
    text = "tf.estimator.LinearClassifier(a, b)\n"
    _, report, errors, new_text = self._upgrade(text)
    self.assertEqual(text, new_text)
    self.assertEqual(errors, ["test.py:1: %s requires manual check."
                              % "tf.estimator.LinearClassifier"])
    self.assertIn("loss_reduction has been changed", report)


class TestUpgradeFiles(test_util.TensorFlowTestCase):

  def testInplace(self):
    """Check to make sure we don't have a file system race."""
    temp_file = tempfile.NamedTemporaryFile("w", delete=False)
    original = "tf.conj(a)\n"
    upgraded = "tf.math.conj(a)\n"
    temp_file.write(original)
    temp_file.close()
    upgrader = ast_edits.ASTCodeUpgrader(tf_upgrade_v2.TFAPIChangeSpec())
    upgrader.process_file(temp_file.name, temp_file.name)
    self.assertAllEqual(open(temp_file.name).read(), upgraded)
    os.unlink(temp_file.name)


if __name__ == "__main__":
  test_lib.main()
    opts = model_analyzer.TRAINABLE_VARS_PARAMS_STAT_OPTIONS
    opts['dump_to_file'] = os.path.join(test.get_temp_dir(), 'dump')
    opts['account_type_regexes'] = ['.*']
    opts['select'] = [
        'bytes', 'params', 'float_ops', 'num_hidden_ops', 'device', 'op_types'
    ]

    with session.Session() as sess, ops.device('/cpu:0'):
      x = self._BuildSmallModel()

      sess.run(variables.global_variables_initializer())
      run_meta = config_pb2.RunMetadata()
      _ = sess.run(x,
                   options=config_pb2.RunOptions(
                       trace_level=config_pb2.RunOptions.FULL_TRACE),
                   run_metadata=run_meta)

      model_analyzer.print_model_analysis(
          sess.graph, run_meta, tfprof_options=opts)

      with gfile.Open(opts['dump_to_file'], 'r') as f:
        # pylint: disable=line-too-long
        self.assertEqual(
            '_TFProfRoot (0/450 params, 0/10.44k flops, 0B/5.28KB, _kTFScopeParent)\n  Conv2D (0/0 params, 5.83k/5.83k flops, 432B/432B, /job:localhost/replica:0/task:0/cpu:0, /job:localhost/replica:0/task:0/cpu:0|Conv2D)\n  Conv2D_1 (0/0 params, 4.61k/4.61k flops, 384B/384B, /job:localhost/replica:0/task:0/cpu:0, /job:localhost/replica:0/task:0/cpu:0|Conv2D)\n  DW (3x3x3x6, 162/162 params, 0/0 flops, 648B/1.30KB, /job:localhost/replica:0/task:0/cpu:0, /job:localhost/replica:0/task:0/cpu:0|VariableV2|_trainable_variables)\n    DW/Assign (0/0 params, 0/0 flops, 0B/0B, /device:CPU:0, /device:CPU:0|Assign)\n    DW/Initializer (0/0 params, 0/0 flops, 0B/0B, _kTFScopeParent)\n      DW/Initializer/random_normal (0/0 params, 0/0 flops, 0B/0B, Add)\n        DW/Initializer/random_normal/RandomStandardNormal (0/0 params, 0/0 flops, 0B/0B, RandomStandardNormal)\n        DW/Initializer/random_normal/mean (0/0 params, 0/0 flops, 0B/0B, Const)\n        DW/Initializer/random_normal/mul (0/0 params, 0/0 flops, 0B/0B, Mul)\n        DW/Initializer/random_normal/shape (0/0 params, 0/0 flops, 0B/0B, Const)\n        DW/Initializer/random_normal/stddev (0/0 params, 0/0 flops, 0B/0B, Const)\n    DW/read (0/0 params, 0/0 flops, 648B/648B, /job:localhost/replica:0/task:0/cpu:0, /job:localhost/replica:0/task:0/cpu:0|Identity)\n  DW2 (2x2x6x12, 288/288 params, 0/0 flops, 1.15KB/2.30KB, /job:localhost/replica:0/task:0/cpu:0, /job:localhost/replica:0/task:0/cpu:0|VariableV2|_trainable_variables)\n    DW2/Assign (0/0 params, 0/0 flops, 0B/0B, /device:CPU:0, /device:CPU:0|Assign)\n    DW2/Initializer (0/0 params, 0/0 flops, 0B/0B, _kTFScopeParent)\n      DW2/Initializer/random_normal (0/0 params, 0/0 flops, 0B/0B, Add)\n        DW2/Initializer/random_normal/RandomStandardNormal (0/0 params, 0/0 flops, 0B/0B, RandomStandardNormal)\n        DW2/Initializer/random_normal/mean (0/0 params, 0/0 flops, 0B/0B, Const)\n        DW2/Initializer/random_normal/mul (0/0 params, 0/0 flops, 0B/0B, Mul)\n        DW2/Initializer/random_normal/shape (0/0 params, 0/0 flops, 0B/0B, Const)\n        DW2/Initializer/random_normal/stddev (0/0 params, 0/0 flops, 0B/0B, Const)\n    DW2/read (0/0 params, 0/0 flops, 1.15KB/1.15KB, /job:localhost/replica:0/task:0/cpu:0, /job:localhost/replica:0/task:0/cpu:0|Identity)\n  init (0/0 params, 0/0 flops, 0B/0B, /device:CPU:0, /device:CPU:0|NoOp)\n  zeros (0/0 params, 0/0 flops, 864B/864B, /job:localhost/replica:0/task:0/cpu:0, /job:localhost/replica:0/task:0/cpu:0|Const)\n',
            f.read())
        # pylint: enable=line-too-long


if __name__ == '__main__':
  test.main()
Beispiel #3
0
def main(argv=None):  # pylint: disable=function-redefined
  _ops.enable_eager_execution()
  _test.main(argv)
Beispiel #4
0
  parser.add_argument(
      '--num_inputs',
      type=int,
      default=1024,
      help='Dimension of inputs that are fed into each LSTM cell.'
  )
  parser.add_argument(
      '--num_nodes',
      type=int,
      default=1024,
      help='Number of nodes in each LSTM cell.'
  )
  parser.add_argument(
      '--device',
      type=str,
      default='gpu',
      help="""\
      TensorFlow device to assign ops to, e.g. "gpu", "cpu". For details see
      documentation for tf.Graph.device.\
      """
  )
  parser.add_argument(
      '--dump_graph_dir',
      type=str,
      default='',
      help='If non-empty, dump graphs in *.pbtxt format to this directory.'
  )
  global FLAGS  # pylint:disable=global-at-module-level
  FLAGS, unparsed = parser.parse_known_args()
  test.main(argv=[sys.argv[0]] + unparsed)
Beispiel #5
0
def main(argv=None):
  _context.enable_eager_execution()
  _test.main(argv)
      node { name: "random_uniform_1/mul" op: "Mul" input: "random_uniform_1/RandomUniform" input: "random_uniform_1/sub" device: "/device:GPU:0" }
      node { name: "random_uniform_1" op: "Add" input: "random_uniform_1/mul" input: "random_uniform_1/min" device: "/device:GPU:0" }
      node { name: "Variable_1" op: "VariableV2" device: "/device:GPU:0" }
      node { name: "Variable_1/Assign" op: "Assign" input: "Variable_1" input: "random_uniform_1" device: "/device:GPU:0" }
      node { name: "Variable_1/read" op: "Identity" input: "Variable_1" device: "/device:GPU:0" }
      node { name: "MatMul" op: "MatMul" input: "Variable/read" input: "Variable_1/read" device: "/device:GPU:0" }
      node { name: "group_deps" op: "NoOp" input: "^MatMul" device: "/device:GPU:0" }
                             """, self._StripGraph(gd))

  def _VerifyRunGraph(self, n, m, k, transpose_a, transpose_b, dtype):
    benchmark_instance = matmul_benchmark.MatmulBenchmark()
    duration = benchmark_instance.run_graph("gpu", n, m, k, transpose_a,
                                            transpose_b, 1, dtype)
    self.assertTrue(duration > 1e-6)


if __name__ == "__main__":
  dtypes = [np.float32, np.float64]
  index = 0
  for _dtype in dtypes:
    for _n, _m, (_transpose_a, _transpose_b) in itertools.product(
        [512, 1024], [1, 8, 16, 128], [(False, False), (True, False), (False,
                                                                       True)]):
      _k = _n
      setattr(MatmulBenchmarkTest, "testBuildGraph_" + str(index),
              BuildGraphTest(_n, _m, _k, _transpose_a, _transpose_b, _dtype))
      setattr(MatmulBenchmarkTest, "testRunGraph_" + str(index),
              RunGraphTest(_n, _m, _k, _transpose_a, _transpose_b, _dtype))
      index += 1
  googletest.main()
Beispiel #7
0
def main(argv=None):
  _ops.enable_eager_execution()
  _test.main(argv)
    with ops.device("cpu:0"):
      x1 = array_ops.ones([2, 2])
      x2 = array_ops.ones([2, 2])
      y = math_ops.matmul(x1, x2)
    np.testing.assert_array_equal([[2, 2], [2, 2]], y.numpy())

    # `y` is placed on the local CPU as expected.
    self.assertEqual(y.device,
                     "/job:%s/replica:0/task:0/device:CPU:0" % JOB_NAME)


class RemoteExecutionWithoutLazyRemoteInputsCopyTest(RemoteExecutionTest):

  @classmethod
  def setUpClass(cls):
    super(RemoteExecutionWithoutLazyRemoteInputsCopyTest, cls).setUpClass()
    context._reset_context()
    context.context().lazy_remote_inputs_copy = False

  @classmethod
  def tearDownClass(cls):
    super(RemoteExecutionWithoutLazyRemoteInputsCopyTest, cls).tearDownClass()
    context._reset_context()
    context.context().lazy_remote_inputs_copy = True


if __name__ == "__main__":
  ops.enable_eager_execution()
  test.main()
                            b_np.imag = np.random.normal(
                                -5, 5, k * n).astype(dtype).reshape([k, n])
                        for adjoint_a, transpose_a in trans_options:
                            for adjoint_b, transpose_b in trans_options:
                                name = "%s_%s_%s_%s_%s_%s_%s_%s_%s" % (
                                    use_static_shape, dtype.__name__, m, n, k,
                                    adjoint_a, transpose_a, adjoint_b,
                                    transpose_b)
                                _AddTest(
                                    MatMulTest, "MatMulTest", name,
                                    _GetMatMulTest(a_np,
                                                   b_np,
                                                   use_static_shape,
                                                   adjoint_a=adjoint_a,
                                                   transpose_a=transpose_a,
                                                   adjoint_b=adjoint_b,
                                                   transpose_b=transpose_b))
                                _AddTest(
                                    MatMulGradientTest, "MatMulGradientTest",
                                    name,
                                    _GetMatMulGradientTest(
                                        a_np,
                                        b_np,
                                        use_static_shape,
                                        adjoint_a=adjoint_a,
                                        transpose_a=transpose_a,
                                        adjoint_b=adjoint_b,
                                        transpose_b=transpose_b))

    test_lib.main()