diff options
author | Alexandre Passos <apassos@google.com> | 2018-09-27 13:18:33 -0700 |
---|---|---|
committer | TensorFlower Gardener <gardener@tensorflow.org> | 2018-09-27 13:23:04 -0700 |
commit | 4cedc8b6e738b7a188c9c091cf667bacafae44b7 (patch) | |
tree | 56de35940e5f9daedd5f39a82d2cd90cf374e4e4 /tensorflow/python/kernel_tests | |
parent | c898e63d07fc63315be98f0772736e5d7f2fb44c (diff) |
Updating the V2 variables API.
PiperOrigin-RevId: 214824023
Diffstat (limited to 'tensorflow/python/kernel_tests')
9 files changed, 59 insertions, 59 deletions
diff --git a/tensorflow/python/kernel_tests/array_ops_test.py b/tensorflow/python/kernel_tests/array_ops_test.py index 2fe85839d0..c5547b19be 100644 --- a/tensorflow/python/kernel_tests/array_ops_test.py +++ b/tensorflow/python/kernel_tests/array_ops_test.py @@ -1001,14 +1001,14 @@ class SliceAssignTest(test_util.TensorFlowTestCase): errors.FailedPreconditionError, "Attempting to use uninitialized value Variable"): with self.cached_session() as sess: - v = variables.Variable([1, 2]) + v = variables.VariableV1([1, 2]) sess.run(v[:].assign([1, 2])) def testTypeError(self): init_val = constant_op.constant([1, 2], dtype=dtypes.int32) too_small_val = constant_op.constant([3, 4], dtype=dtypes.int8) too_large_val = constant_op.constant([3, 4], dtype=dtypes.int64) - v = variables.Variable(init_val) + v = variables.VariableV1(init_val) with self.assertRaises(TypeError): v[:].assign(too_small_val) with self.assertRaises(TypeError): diff --git a/tensorflow/python/kernel_tests/control_flow_ops_py_test.py b/tensorflow/python/kernel_tests/control_flow_ops_py_test.py index fc4d2a3809..083de84775 100644 --- a/tensorflow/python/kernel_tests/control_flow_ops_py_test.py +++ b/tensorflow/python/kernel_tests/control_flow_ops_py_test.py @@ -130,7 +130,7 @@ class ControlFlowTest(test.TestCase): def testRefIdentity(self): with self.cached_session(): - v = variables.Variable(7) + v = variables.VariableV1(7) v = control_flow_ops._Identity(v) op = state_ops.assign(v, 9) @@ -142,7 +142,7 @@ class ControlFlowTest(test.TestCase): def testRefEnter(self): with self.cached_session(): - v = variables.Variable(7) + v = variables.VariableV1(7) enter_v = control_flow_ops._Enter(v, "foo_1", is_constant=True) nine = constant_op.constant(9) @@ -155,7 +155,7 @@ class ControlFlowTest(test.TestCase): def testRefSwitch(self): with self.cached_session(): - v = variables.Variable(7) + v = variables.VariableV1(7) p = constant_op.constant(True) v1 = control_flow_ops._SwitchRefOrTensor(v._ref(), p) # pylint: disable=protected-access @@ -796,7 +796,7 @@ class ControlFlowTest(test.TestCase): def testWhileWithRefs_1(self): with self.cached_session() as sess: - x = variables.Variable(0)._ref() # pylint: disable=protected-access + x = variables.VariableV1(0)._ref() # pylint: disable=protected-access i = constant_op.constant(0) c = lambda i, x: math_ops.less(i, 100) @@ -2317,7 +2317,7 @@ class ControlFlowTest(test.TestCase): def testWhileWithRefsWithGradients_1(self): with self.cached_session() as sess: - x = variables.Variable(0.)._ref() # pylint: disable=protected-access + x = variables.VariableV1(0.)._ref() # pylint: disable=protected-access i = constant_op.constant(0) c = lambda i, x: math_ops.less(i, 10) @@ -2329,7 +2329,7 @@ class ControlFlowTest(test.TestCase): r = control_flow_ops.while_loop(c, body, [i, x], parallel_iterations=5) - grad_ys = [variables.Variable(73)._ref()] # pylint: disable=protected-access + grad_ys = [variables.VariableV1(73)._ref()] # pylint: disable=protected-access grad = gradients_impl.gradients([r[1]], [x], grad_ys=grad_ys) variables.global_variables_initializer().run() @@ -2779,7 +2779,7 @@ class ControlFlowTest(test.TestCase): def testWithOpsDependencies(self): with self.cached_session() as sess: - v = variables.Variable(0.0) + v = variables.VariableV1(0.0) c = constant_op.constant(10) # Fetching v directly will result in an uninitialized error @@ -2802,7 +2802,7 @@ class ControlFlowTest(test.TestCase): def testWithTensorDependencies(self): with self.cached_session(): - v = variables.Variable(0.0) + v = variables.VariableV1(0.0) c1 = constant_op.constant(10) c2 = constant_op.constant(20) @@ -2828,7 +2828,7 @@ class ControlFlowTest(test.TestCase): def testWithIndexedSlicesDependencies(self): with self.cached_session(): - v = variables.Variable( + v = variables.VariableV1( np.array([[0.0, 1.0], [10.0, 11.0], [20.0, 21.0]]).astype(np.float32)) v_at_1 = ops.IndexedSlices(v, constant_op.constant([1])) gather_v_at_1 = array_ops.gather(v_at_1.values, v_at_1.indices) @@ -2851,18 +2851,18 @@ class ControlFlowTest(test.TestCase): with ops.Graph().as_default(): # device set on tensor => same device on dep. with ops.device("/job:ps"): - vd = variables.Variable([0.0]) + vd = variables.VariableV1([0.0]) with_vd_dep = control_flow_ops.with_dependencies([vd.initializer], vd) self.assertTrue("/job:ps" in with_vd_dep.device) # No device set on tensor => no device on dep. - vnod = variables.Variable([0.0]) + vnod = variables.VariableV1([0.0]) with_vnod_dep = control_flow_ops.with_dependencies([vnod.initializer], vnod) self.assertDeviceEqual(None, with_vnod_dep.device) # device set on tensor, default device on graph => default device on dep. - vdef = variables.Variable([0.0], name="vdef") + vdef = variables.VariableV1([0.0], name="vdef") with ops.device("/job:worker/device:GPU:1"): with_vdef_dep = control_flow_ops.with_dependencies([vdef.initializer], vdef) @@ -2872,8 +2872,8 @@ class ControlFlowTest(test.TestCase): def testGroup(self): with self.cached_session() as sess: - v1 = variables.Variable([0.0]) - v2 = variables.Variable([1.0]) + v1 = variables.VariableV1([0.0]) + v2 = variables.VariableV1([1.0]) # Group init1 and init2 and run. init = control_flow_ops.group(v1.initializer, v2.initializer) @@ -2955,29 +2955,29 @@ class ControlFlowTest(test.TestCase): p1 = array_ops.placeholder(dtypes.float32) p2 = array_ops.placeholder(dtypes.float32) p3 = array_ops.placeholder(dtypes.float32) - v1 = variables.Variable(p1, validate_shape=False) - v2 = variables.Variable(p2, validate_shape=False) - v3 = variables.Variable(p3, validate_shape=False) + v1 = variables.VariableV1(p1, validate_shape=False) + v2 = variables.VariableV1(p2, validate_shape=False) + v3 = variables.VariableV1(p3, validate_shape=False) self.assertIs(None, v1.get_shape().ndims) s = control_flow_ops.ref_select(index, [v1, v2, v3]) self.assertIs(None, s.get_shape().ndims) # All inputs known but different. - v1 = variables.Variable([[1, 2]]) - v2 = variables.Variable([[2], [1]]) + v1 = variables.VariableV1([[1, 2]]) + v2 = variables.VariableV1([[2], [1]]) s = control_flow_ops.ref_select(index, [v1, v2]) self.assertIs(None, s.get_shape().ndims) # All inputs known and same. - v1 = variables.Variable([[1, 2]]) - v2 = variables.Variable([[1, 2]]) + v1 = variables.VariableV1([[1, 2]]) + v2 = variables.VariableV1([[1, 2]]) s = control_flow_ops.ref_select(index, [v1, v2]) self.assertEqual([1, 2], s.get_shape()) # Possibly the same but not guaranteed. - v1 = variables.Variable([[1., 2.]]) + v1 = variables.VariableV1([[1., 2.]]) p2 = array_ops.placeholder(dtypes.float32, shape=[None, 2]) - v2 = variables.Variable(p2, validate_shape=False) + v2 = variables.VariableV1(p2, validate_shape=False) s = control_flow_ops.ref_select(index, [v1, v2]) self.assertEqual(None, s.get_shape()) @@ -3160,11 +3160,11 @@ class TupleTest(test.TestCase): def testTensors(self): for v1_first in [True, False]: with self.cached_session(): - v1 = variables.Variable([1.0]) + v1 = variables.VariableV1([1.0]) add1 = math_ops.add( control_flow_ops.with_dependencies([v1.initializer], v1._ref()), # pylint: disable=protected-access 2.0) - v2 = variables.Variable([10.0]) + v2 = variables.VariableV1([10.0]) add2 = math_ops.add( control_flow_ops.with_dependencies([v2.initializer], v2._ref()), # pylint: disable=protected-access 20.0) @@ -3190,14 +3190,14 @@ class TupleTest(test.TestCase): def testIndexedSlices(self): for v1_first in [True, False]: with self.cached_session(): - v1 = variables.Variable( + v1 = variables.VariableV1( np.array([[0.0, 1.0], [10.0, 11.0], [20.0, 21.0]]).astype( np.float32)) v1_at_1 = ops.IndexedSlices( control_flow_ops.with_dependencies([v1.initializer], v1._ref()), # pylint: disable=protected-access constant_op.constant([1])) - v2 = variables.Variable( + v2 = variables.VariableV1( np.array([[0.1, 1.1], [10.1, 11.1], [20.1, 21.1]]).astype( np.float32)) v2_at_1 = ops.IndexedSlices( @@ -3229,7 +3229,7 @@ class TupleTest(test.TestCase): def testAcceptTensorsAsControlInputs(self): with self.cached_session(): - var = variables.Variable(0) + var = variables.VariableV1(0) assign = state_ops.assign(var, 1) t, = control_flow_ops.tuple( [constant_op.constant(0)], control_inputs=[assign]) diff --git a/tensorflow/python/kernel_tests/dense_update_ops_test.py b/tensorflow/python/kernel_tests/dense_update_ops_test.py index 06c3271850..120e10314f 100644 --- a/tensorflow/python/kernel_tests/dense_update_ops_test.py +++ b/tensorflow/python/kernel_tests/dense_update_ops_test.py @@ -87,7 +87,7 @@ class AssignOpTest(test.TestCase): def testAssignNonStrictShapeChecking(self): with self.cached_session(): data = array_ops.fill([1024, 1024], 0) - p = variables.Variable([1]) + p = variables.VariableV1([1]) a = state_ops.assign(p, data, validate_shape=False) a.op.run() self.assertAllEqual(p.eval(), data.eval()) @@ -100,14 +100,14 @@ class AssignOpTest(test.TestCase): def testInitRequiredAssignAdd(self): with self.cached_session(): - p = variables.Variable(array_ops.fill([1024, 1024], 1), dtypes.int32) + p = variables.VariableV1(array_ops.fill([1024, 1024], 1), dtypes.int32) a = state_ops.assign_add(p, array_ops.fill([1024, 1024], 0)) with self.assertRaisesOpError("use uninitialized"): a.op.run() def testInitRequiredAssignSub(self): with self.cached_session(): - p = variables.Variable(array_ops.fill([1024, 1024], 1), dtypes.int32) + p = variables.VariableV1(array_ops.fill([1024, 1024], 1), dtypes.int32) a = state_ops.assign_sub(p, array_ops.fill([1024, 1024], 0)) with self.assertRaisesOpError("use uninitialized"): a.op.run() diff --git a/tensorflow/python/kernel_tests/identity_op_py_test.py b/tensorflow/python/kernel_tests/identity_op_py_test.py index 37f9f716f8..88ea10c22a 100644 --- a/tensorflow/python/kernel_tests/identity_op_py_test.py +++ b/tensorflow/python/kernel_tests/identity_op_py_test.py @@ -61,7 +61,7 @@ class IdentityOpTest(test.TestCase): def testRefIdentityShape(self): with self.cached_session(): shape = [2, 3] - tensor = variables.Variable( + tensor = variables.VariableV1( constant_op.constant( [[1, 2, 3], [6, 5, 4]], dtype=dtypes.int32)) self.assertEquals(shape, tensor.get_shape()) diff --git a/tensorflow/python/kernel_tests/resource_variable_ops_test.py b/tensorflow/python/kernel_tests/resource_variable_ops_test.py index f90545f84c..1365d4b240 100644 --- a/tensorflow/python/kernel_tests/resource_variable_ops_test.py +++ b/tensorflow/python/kernel_tests/resource_variable_ops_test.py @@ -290,7 +290,7 @@ class ResourceVariableOpsTest(test_util.TensorFlowTestCase): self.assertEqual(self.evaluate(read), [[2]]) def testUseResource(self): - v = variables.Variable(1.0, use_resource=True) + v = variables.VariableV1(1.0, use_resource=True) self.assertTrue(isinstance(v, resource_variable_ops.ResourceVariable)) def testEagerNoUseResource(self): diff --git a/tensorflow/python/kernel_tests/scatter_nd_ops_test.py b/tensorflow/python/kernel_tests/scatter_nd_ops_test.py index 86e063cb36..4b92309e4d 100644 --- a/tensorflow/python/kernel_tests/scatter_nd_ops_test.py +++ b/tensorflow/python/kernel_tests/scatter_nd_ops_test.py @@ -136,7 +136,7 @@ class StatefulScatterNdTest(test.TestCase): new = ref.copy() np_scatter(new, indices, updates) # Scatter via tensorflow - ref_var = variables.Variable(ref) + ref_var = variables.VariableV1(ref) ref_var.initializer.run() tf_scatter(ref_var, indices, updates).eval() @@ -258,7 +258,7 @@ class StatefulScatterNdTest(test.TestCase): params = np.array([1, 2, 3, 4, 5, 6]).astype(np.float32) updates = np.array([-3, -4, -5]).astype(np.float32) with self.test_session(use_gpu=False): - ref = variables.Variable(params) + ref = variables.VariableV1(params) ref.initializer.run() # Indices all in range, no problem. diff --git a/tensorflow/python/kernel_tests/scatter_ops_test.py b/tensorflow/python/kernel_tests/scatter_ops_test.py index 1a0fa744ae..527b7daf10 100644 --- a/tensorflow/python/kernel_tests/scatter_ops_test.py +++ b/tensorflow/python/kernel_tests/scatter_ops_test.py @@ -178,7 +178,7 @@ class ScatterTest(test.TestCase): np_scatter = _TF_OPS_TO_NUMPY[tf_scatter] np_scatter(new, indices, updates) # Scatter via tensorflow - ref = variables.Variable(old) + ref = variables.VariableV1(old) ref.initializer.run() tf_scatter(ref, indices, updates).eval() self.assertAllClose(ref.eval(), new) @@ -294,7 +294,7 @@ class ScatterTest(test.TestCase): updates = np.array([-3, -4, -5]).astype(np.float32) if not test.is_gpu_available(): with self.test_session(use_gpu=False): - ref = variables.Variable(params) + ref = variables.VariableV1(params) ref.initializer.run() # Indices all in range, no problem. diff --git a/tensorflow/python/kernel_tests/variable_scope_test.py b/tensorflow/python/kernel_tests/variable_scope_test.py index 401e1ae102..33f464fb90 100644 --- a/tensorflow/python/kernel_tests/variable_scope_test.py +++ b/tensorflow/python/kernel_tests/variable_scope_test.py @@ -394,10 +394,10 @@ class VariableScopeTest(test.TestCase): old = variable_scope._DEFAULT_USE_RESOURCE try: variable_scope.enable_resource_variables() - self.assertTrue(isinstance(variables_lib.Variable(1.0), + self.assertTrue(isinstance(variables_lib.VariableV1(1.0), resource_variable_ops.ResourceVariable)) variable_scope.disable_resource_variables() - self.assertFalse(isinstance(variables_lib.Variable(1.0), + self.assertFalse(isinstance(variables_lib.VariableV1(1.0), resource_variable_ops.ResourceVariable)) finally: variable_scope._DEFAULT_USE_RESOURCE = old diff --git a/tensorflow/python/kernel_tests/variables_test.py b/tensorflow/python/kernel_tests/variables_test.py index 2e7975667c..942ceedc8b 100644 --- a/tensorflow/python/kernel_tests/variables_test.py +++ b/tensorflow/python/kernel_tests/variables_test.py @@ -43,14 +43,14 @@ class VariablesTestCase(test.TestCase): def testInitialization(self): with self.cached_session(): - var0 = variables.Variable(0.0) + var0 = variables.VariableV1(0.0) self.assertEqual("Variable:0", var0.name) self.assertEqual("Variable", var0._shared_name) self.assertEqual([], var0.get_shape()) self.assertEqual([], var0.get_shape()) self.assertEqual([], var0.shape) - var1 = variables.Variable(1.1) + var1 = variables.VariableV1(1.1) self.assertEqual("Variable_1:0", var1.name) self.assertEqual("Variable_1", var1._shared_name) self.assertEqual([], var1.get_shape()) @@ -143,7 +143,7 @@ class VariablesTestCase(test.TestCase): def testZeroSizeStringAssign(self): with self.cached_session() as sess: - array = variables.Variable( + array = variables.VariableV1( initial_value=array_ops.zeros((0,), dtype=dtypes.string), name="foo", trainable=False, @@ -192,7 +192,7 @@ class VariablesTestCase(test.TestCase): # d get the control dep. d = constant_op.constant(2.0) # variables do not. - var_x = variables.Variable(2.0) + var_x = variables.VariableV1(2.0) self.assertEqual([c.op], d.op.control_inputs) self.assertEqual([], var_x.initializer.control_inputs) self.assertEqual([], var_x.value().op.control_inputs) @@ -280,10 +280,10 @@ class VariablesTestCase(test.TestCase): def testCollections(self): with self.cached_session(): - var_x = variables.Variable(2.0) - var_y = variables.Variable(2.0, trainable=False) - var_z = variables.Variable(2.0, trainable=True) - var_t = variables.Variable( + var_x = variables.VariableV1(2.0) + var_y = variables.VariableV1(2.0, trainable=False) + var_z = variables.VariableV1(2.0, trainable=True) + var_t = variables.VariableV1( 2.0, trainable=True, collections=[ @@ -296,9 +296,9 @@ class VariablesTestCase(test.TestCase): def testCollectionsWithScope(self): with self.cached_session(): with ops.name_scope("scope_1"): - var_x = variables.Variable(2.0) + var_x = variables.VariableV1(2.0) with ops.name_scope("scope_2"): - var_y = variables.Variable(2.0) + var_y = variables.VariableV1(2.0) self.assertEqual([var_x, var_y], variables.global_variables()) self.assertEqual([var_x], variables.global_variables("scope_1")) @@ -399,7 +399,7 @@ class VariablesTestCase(test.TestCase): def testColocation(self): with ops.device("/job:ps"): - var = variables.Variable(0, name="v") + var = variables.VariableV1(0, name="v") with ops.device("/job:worker/task:7"): assign_op = var.assign(1) self.assertDeviceEqual("/job:ps", assign_op.device) @@ -522,7 +522,7 @@ class VariablesTestCase(test.TestCase): self.assertAllClose(np.ones((5, 5), np.float32), var.eval()) def testRepr(self): - var = variables.Variable(np.zeros((5, 5), np.float32), name="noop") + var = variables.VariableV1(np.zeros((5, 5), np.float32), name="noop") self.assertEqual( "<tf.Variable 'noop:0' shape=(5, 5) dtype=float32_ref>", repr(var)) @@ -556,8 +556,8 @@ class IsInitializedTest(test.TestCase): def testVariableList(self): with ops.Graph().as_default(), self.cached_session() as sess: - v = variables.Variable([1, 2], name="v") - w = variables.Variable([3, 4], name="w") + v = variables.VariableV1([1, 2], name="v") + w = variables.VariableV1([3, 4], name="w") uninited = variables.report_uninitialized_variables() self.assertAllEqual(np.array([b"v", b"w"]), sess.run(uninited)) sess.run(w.initializer) @@ -593,8 +593,8 @@ class ObsoleteIsInitializedTest(test.TestCase): def testVariables(self): with ops.Graph().as_default(), self.cached_session() as sess: - v = variables.Variable([1, 2]) - w = variables.Variable([3, 4]) + v = variables.VariableV1([1, 2]) + w = variables.VariableV1([3, 4]) _ = v, w inited = variables.assert_variables_initialized() with self.assertRaisesOpError("Attempting to use uninitialized value"): @@ -604,8 +604,8 @@ class ObsoleteIsInitializedTest(test.TestCase): def testVariableList(self): with ops.Graph().as_default(), self.cached_session() as sess: - v = variables.Variable([1, 2]) - w = variables.Variable([3, 4]) + v = variables.VariableV1([1, 2]) + w = variables.VariableV1([3, 4]) inited = variables.assert_variables_initialized([v]) with self.assertRaisesOpError("Attempting to use uninitialized value"): inited.op.run() |