Unverified Commit 134caef3 authored by Matt's avatar Matt Committed by GitHub
Browse files

Speed up TF tests by reducing hidden layer counts (#24595)

* hidden layers, huh, what are they good for (absolutely nothing)

* Some tests break with 1 hidden layer, use 2

* Use 1 hidden layer in a few slow models

* Use num_hidden_layers=2 everywhere

* Slightly higher tol for groupvit

* Slightly higher tol for groupvit
parent 3441ad7d
...@@ -52,7 +52,7 @@ class TFViTModelTester: ...@@ -52,7 +52,7 @@ class TFViTModelTester:
is_training=True, is_training=True,
use_labels=True, use_labels=True,
hidden_size=32, hidden_size=32,
num_hidden_layers=5, num_hidden_layers=2,
num_attention_heads=4, num_attention_heads=4,
intermediate_size=37, intermediate_size=37,
hidden_act="gelu", hidden_act="gelu",
......
...@@ -60,7 +60,7 @@ class TFViTMAEModelTester: ...@@ -60,7 +60,7 @@ class TFViTMAEModelTester:
is_training=True, is_training=True,
use_labels=True, use_labels=True,
hidden_size=32, hidden_size=32,
num_hidden_layers=5, num_hidden_layers=2,
num_attention_heads=4, num_attention_heads=4,
intermediate_size=37, intermediate_size=37,
hidden_act="gelu", hidden_act="gelu",
......
...@@ -130,7 +130,7 @@ class TFWav2Vec2ModelTester: ...@@ -130,7 +130,7 @@ class TFWav2Vec2ModelTester:
conv_bias=False, conv_bias=False,
num_conv_pos_embeddings=16, num_conv_pos_embeddings=16,
num_conv_pos_embedding_groups=2, num_conv_pos_embedding_groups=2,
num_hidden_layers=4, num_hidden_layers=2,
num_attention_heads=2, num_attention_heads=2,
hidden_dropout_prob=0.1, # this is most likely not correctly set yet hidden_dropout_prob=0.1, # this is most likely not correctly set yet
intermediate_size=20, intermediate_size=20,
......
...@@ -51,7 +51,7 @@ class TFXGLMModelTester: ...@@ -51,7 +51,7 @@ class TFXGLMModelTester:
use_labels=True, use_labels=True,
vocab_size=99, vocab_size=99,
d_model=32, d_model=32,
num_hidden_layers=5, num_hidden_layers=2,
num_attention_heads=4, num_attention_heads=4,
ffn_dim=37, ffn_dim=37,
activation_function="gelu", activation_function="gelu",
......
...@@ -61,7 +61,7 @@ class TFXLMModelTester: ...@@ -61,7 +61,7 @@ class TFXLMModelTester:
self.vocab_size = 99 self.vocab_size = 99
self.n_special = 0 self.n_special = 0
self.hidden_size = 32 self.hidden_size = 32
self.num_hidden_layers = 5 self.num_hidden_layers = 2
self.num_attention_heads = 4 self.num_attention_heads = 4
self.hidden_dropout_prob = 0.1 self.hidden_dropout_prob = 0.1
self.attention_probs_dropout_prob = 0.1 self.attention_probs_dropout_prob = 0.1
......
...@@ -61,7 +61,7 @@ class TFXLNetModelTester: ...@@ -61,7 +61,7 @@ class TFXLNetModelTester:
self.hidden_size = 32 self.hidden_size = 32
self.num_attention_heads = 4 self.num_attention_heads = 4
self.d_inner = 128 self.d_inner = 128
self.num_hidden_layers = 5 self.num_hidden_layers = 2
self.type_sequence_label_size = 2 self.type_sequence_label_size = 2
self.untie_r = True self.untie_r = True
self.bi_data = False self.bi_data = False
......
...@@ -1527,36 +1527,6 @@ class TFModelTesterMixin: ...@@ -1527,36 +1527,6 @@ class TFModelTesterMixin:
if metrics: if metrics:
self.assertTrue(len(accuracy1) == len(accuracy2) > 0, "Missing metrics!") self.assertTrue(len(accuracy1) == len(accuracy2) > 0, "Missing metrics!")
# Make sure fit works with tf.data.Dataset and results are consistent
dataset = tf.data.Dataset.from_tensor_slices(prepared_for_class)
if sample_weight is not None:
# Add in the sample weight
weighted_dataset = dataset.map(lambda x: (x, None, tf.convert_to_tensor(0.5, dtype=tf.float32)))
else:
weighted_dataset = dataset
# Pass in all samples as a batch to match other `fit` calls
weighted_dataset = weighted_dataset.batch(len(dataset))
dataset = dataset.batch(len(dataset))
# Reinitialize to fix batchnorm again
model.set_weights(model_weights)
# To match the other calls, don't pass sample weights in the validation data
history3 = model.fit(
weighted_dataset,
validation_data=dataset,
steps_per_epoch=1,
validation_steps=1,
shuffle=False,
)
val_loss3 = history3.history["val_loss"][0]
self.assertTrue(not isnan(val_loss3))
accuracy3 = {key: val[0] for key, val in history3.history.items() if key.endswith("accuracy")}
self.check_keras_fit_results(val_loss1, val_loss3)
self.assertEqual(history1.history.keys(), history3.history.keys())
if metrics:
self.assertTrue(len(accuracy1) == len(accuracy3) > 0, "Missing metrics!")
def test_int_support(self): def test_int_support(self):
config, inputs_dict = self.model_tester.prepare_config_and_inputs_for_common() config, inputs_dict = self.model_tester.prepare_config_and_inputs_for_common()
for model_class in self.all_model_classes: for model_class in self.all_model_classes:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment