Skip to content

Commit 1ba8dbb

Browse files
fchollettensorflower-gardener
authored andcommitted
Remove experimental.PeepholeLSTMCell from the API.
PiperOrigin-RevId: 429503438
1 parent 4924fd3 commit 1ba8dbb

File tree

7 files changed

+1
-84
lines changed

7 files changed

+1
-84
lines changed

tensorflow_model_optimization/python/core/clustering/keras/cluster_integration_test.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -463,30 +463,6 @@ def testClusterGRU(self):
463463

464464
self._train(stripped_model)
465465

466-
@keras_parameterized.run_all_keras_modes
467-
def testClusterPeepholeLSTM(self):
468-
model = keras.models.Sequential()
469-
model.add(
470-
keras.layers.Embedding(self.max_features, 16, input_length=self.maxlen))
471-
model.add(keras.layers.RNN(tf.keras.experimental.PeepholeLSTMCell(16)))
472-
model.add(keras.layers.Dense(1))
473-
model.add(keras.layers.Activation("sigmoid"))
474-
475-
self._clusterTrainStrip(model)
476-
477-
self._assertNbUniqueWeights(
478-
weight=model.layers[1].cell.kernel,
479-
expected_unique_weights=self.params_clustering["number_of_clusters"],
480-
)
481-
self._assertNbUniqueWeights(
482-
weight=model.layers[1].cell.recurrent_kernel,
483-
expected_unique_weights=self.params_clustering["number_of_clusters"],
484-
)
485-
self._assertNbUniqueWeights(
486-
weight=model.layers[0].embeddings,
487-
expected_unique_weights=self.params_clustering["number_of_clusters"],
488-
)
489-
490466
@keras_parameterized.run_all_keras_modes
491467
def testClusterBidirectional(self):
492468
model = keras.models.Sequential()

tensorflow_model_optimization/python/core/clustering/keras/clustering_registry.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ class ClusteringRegistry(object):
8989
tf.compat.v2.keras.layers.SimpleRNNCell,
9090
tf.compat.v1.keras.layers.StackedRNNCells,
9191
tf.compat.v2.keras.layers.StackedRNNCells,
92-
tf.keras.experimental.PeepholeLSTMCell,
9392
})
9493

9594
_SUPPORTED_RNN_LAYERS = frozenset([

tensorflow_model_optimization/python/core/clustering/keras/clustering_registry_test.py

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -472,19 +472,6 @@ def testMakeClusterableWorksOnKerasRNNLayerWithRNNCellsParams(self):
472472
layer.cell.cells[0].recurrent_kernel)]
473473
self.assertEqual(expected_weights[0], layer.get_clusterable_weights()[0])
474474

475-
def testMakeClusterableWorksOnKerasStackedRNNLayerWithPeepholeLSTMCell(self):
476-
"""Test stacked RNN layer with peephole LSTM cell.
477-
478-
Verifies that make_clusterable() works as expected on a built-in
479-
RNN layer with a PeepholeLSTMCell
480-
"""
481-
cell1 = layers.LSTMCell(10)
482-
cell2 = keras.experimental.PeepholeLSTMCell(10)
483-
cell_list = tf.keras.layers.StackedRNNCells([cell1, cell2])
484-
layer = layers.RNN(cell_list)
485-
with self.assertRaises(AttributeError):
486-
layer.get_clusterable_weights()
487-
488475
ClusterRegistry.make_clusterable(layer)
489476
keras.Sequential([layer]).build(input_shape=(2, 3, 4))
490477

@@ -511,27 +498,6 @@ def testMakeClusterableWorksOnKerasBidirectionalLayerWithLSTM(self):
511498
layer.forward_layer.cell.recurrent_kernel)]
512499
self.assertEqual(expected_weights[0], layer.get_clusterable_weights()[0])
513500

514-
def testMakeClusterableWorksOnRNNLayerWithPeepholeLSTMCell(self):
515-
"""Test RNN with peephole LSTM cell.
516-
517-
Verifies that make_clusterable() works as expected on a built-in
518-
RNN layer with a PeepholeLSTMCell
519-
"""
520-
cell1 = layers.LSTMCell(10)
521-
cell2 = keras.experimental.PeepholeLSTMCell(10)
522-
layer = layers.RNN([cell1, cell2])
523-
524-
with self.assertRaises(AttributeError):
525-
layer.get_clusterable_weights()
526-
527-
ClusterRegistry.make_clusterable(layer)
528-
keras.Sequential([layer]).build(input_shape=(2, 3, 4))
529-
530-
expected_weights = [('kernel/0', layer.cell.cells[0].kernel),
531-
('recurrent_kernel/0',
532-
layer.cell.cells[0].recurrent_kernel)]
533-
self.assertEqual(expected_weights[0], layer.get_clusterable_weights()[0])
534-
535501
def testMakeClusterableDoesNotWorksOnKerasRNNLayerWithClusterableCell(self):
536502
"""A built-in RNN layer with custom clusterable RNN cell is not clusterable."""
537503
cell1 = layers.LSTMCell(10)

tensorflow_model_optimization/python/core/sparsity/keras/prune_integration_test.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,6 @@ def testRNNLayersWithRNNCellParams_ReachesTargetSparsity(self):
469469
keras.layers.RNN([
470470
layers.LSTMCell(10),
471471
layers.GRUCell(10),
472-
tf.keras.experimental.PeepholeLSTMCell(10),
473472
layers.SimpleRNNCell(10)
474473
]),
475474
input_shape=(3, 4),

tensorflow_model_optimization/python/core/sparsity/keras/prune_registry.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,6 @@ class PruneRegistry(object):
112112
tf.compat.v2.keras.layers.GRUCell: ['kernel', 'recurrent_kernel'],
113113
tf.compat.v1.keras.layers.LSTMCell: ['kernel', 'recurrent_kernel'],
114114
tf.compat.v2.keras.layers.LSTMCell: ['kernel', 'recurrent_kernel'],
115-
tf.compat.v1.keras.experimental.PeepholeLSTMCell: [
116-
'kernel', 'recurrent_kernel'
117-
],
118-
tf.compat.v2.keras.experimental.PeepholeLSTMCell: [
119-
'kernel', 'recurrent_kernel'
120-
],
121115
tf.compat.v1.keras.layers.SimpleRNNCell: ['kernel', 'recurrent_kernel'],
122116
tf.compat.v2.keras.layers.SimpleRNNCell: ['kernel', 'recurrent_kernel'],
123117
}

tensorflow_model_optimization/python/core/sparsity/keras/prune_registry_test.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ class PruneRegistryTest(tf.test.TestCase, parameterized.TestCase):
8383
layers.RNN([
8484
layers.LSTMCell(10),
8585
layers.GRUCell(10),
86-
keras.experimental.PeepholeLSTMCell(10),
8786
layers.SimpleRNNCell(10)
8887
]),
8988
keras.layers.RNN(MinimalRNNCellPrunable(32)),

tensorflow_model_optimization/python/examples/clustering/keras/imdb/imdb_multiple_cells.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
# ==============================================================================
15-
"""End-to-end tests for StackedRNNCells and PeepholeLSTMCell.
15+
"""End-to-end tests for StackedRNNCells.
1616
1717
The dataset is actually too small for LSTM to be of any advantage
1818
compared to simpler, much faster methods such as TF-IDF+LogReg.
@@ -32,22 +32,6 @@
3232

3333
x_train, y_train, x_test, y_test = prepare_dataset()
3434

35-
print("Build a model with the StackedRNNCells with PeepholeLSTMCell...")
36-
model = tf.keras.models.Sequential()
37-
38-
model.add(tf.keras.layers.Embedding(max_features, 128, input_length=maxlen))
39-
model.add(
40-
tf.keras.layers.RNN(
41-
tf.keras.layers.StackedRNNCells(
42-
[tf.keras.experimental.PeepholeLSTMCell(128) for _ in range(2)])))
43-
model.add(tf.keras.layers.Dropout(0.5))
44-
model.add(tf.keras.layers.Dense(1))
45-
model.add(tf.keras.layers.Activation("sigmoid"))
46-
47-
test_case = "StackedRNNCells_PeepholeLSTMCell"
48-
cluster_train_eval_strip(
49-
model, x_train, y_train, x_test, y_test, batch_size, test_case)
50-
5135
print("Build a model with the StackedRNNCells with LSTMCell...")
5236
model = tf.keras.models.Sequential()
5337

0 commit comments

Comments
 (0)