Move the test with the private symbol variable_scope.EagerVariableStore from Keras to TF.

PiperOrigin-RevId: 342674107
Change-Id: If9b2baf08d720c2dc86708fffcde949a0f57205a
This commit is contained in:
Yanhui Liang 2020-11-16 11:00:54 -08:00 committed by TensorFlower Gardener
parent 00d1dc082e
commit 20cfb32577
2 changed files with 15 additions and 18 deletions

View File

@ -25,7 +25,6 @@ from absl.testing import parameterized
import numpy as np
from tensorflow.python.eager import context
from tensorflow.python.framework import constant_op
from tensorflow.python.framework import dtypes
from tensorflow.python.framework import ops
from tensorflow.python.framework import tensor_shape
@ -290,23 +289,6 @@ class DenseTest(test.TestCase, parameterized.TestCase):
self.assertAllClose(weights['scope/dense/bias'].read_value(), np.zeros(
(2)))
@combinations.generate(combinations.combine(mode=['eager']))
def testEagerExecution(self):
container = variable_scope.EagerVariableStore()
x = constant_op.constant([[2.0]])
with container.as_default():
y = core_layers.dense(
x, 1, name='my_dense',
kernel_initializer=init_ops.ones_initializer())
self.assertAllEqual(y, [[2.0]])
self.assertEqual(len(container.variables()), 2)
# Recreate the layer to test reuse.
with container.as_default():
core_layers.dense(
x, 1, name='my_dense',
kernel_initializer=init_ops.ones_initializer())
self.assertEqual(len(container.variables()), 2)
def testFunctionalDenseWithCustomGetter(self):
called = [0]

View File

@ -279,6 +279,21 @@ class VariableScopeTest(test.TestCase):
self.assertFalse(ops.get_collection(ops.GraphKeys.GLOBAL_VARIABLES))
self.assertFalse(ops.get_collection(ops.GraphKeys.TRAINABLE_VARIABLES))
def testEagerVariableStoreWithFunctionalLayer(self):
with context.eager_mode():
container = variable_scope.EagerVariableStore()
x = constant_op.constant([[2.0]])
with container.as_default():
y = core_layers.dense(x, 1, name="my_dense",
kernel_initializer=init_ops.ones_initializer())
self.assertAllEqual(y, [[2.0]])
self.assertEqual(len(container.variables()), 2)
# Recreate the layer to test reuse.
with container.as_default():
core_layers.dense(x, 1, name="my_dense",
kernel_initializer=init_ops.ones_initializer())
self.assertEqual(len(container.variables()), 2)
# TODO(mihaimaruseac): Not converted to use wrap_function because of
# TypeError: Expected tf.group() expected Tensor arguments not 'None' with
# type '<type 'NoneType'>'.