mirror of
https://github.com/huggingface/transformers.git
synced 2025-07-25 23:38:59 +06:00
TF: Add missing cast to GPT-J (#18201)
* Fix TF GPT-J tests * add try/finally block
This commit is contained in:
parent
05ed569c79
commit
ec6cd7633f
@ -222,7 +222,7 @@ class TFGPTJAttention(tf.keras.layers.Layer):
|
|||||||
key = self._split_heads(key, True)
|
key = self._split_heads(key, True)
|
||||||
value = self._split_heads(value, False)
|
value = self._split_heads(value, False)
|
||||||
|
|
||||||
sincos = tf.gather(self.embed_positions, position_ids, axis=0)
|
sincos = tf.cast(tf.gather(self.embed_positions, position_ids, axis=0), hidden_states.dtype)
|
||||||
sincos = tf.split(sincos, 2, axis=-1)
|
sincos = tf.split(sincos, 2, axis=-1)
|
||||||
if self.rotary_dim is not None:
|
if self.rotary_dim is not None:
|
||||||
k_rot = key[:, :, :, : self.rotary_dim]
|
k_rot = key[:, :, :, : self.rotary_dim]
|
||||||
|
@ -274,16 +274,17 @@ class TFCoreModelTesterMixin:
|
|||||||
def test_mixed_precision(self):
|
def test_mixed_precision(self):
|
||||||
tf.keras.mixed_precision.set_global_policy("mixed_float16")
|
tf.keras.mixed_precision.set_global_policy("mixed_float16")
|
||||||
|
|
||||||
config, inputs_dict = self.model_tester.prepare_config_and_inputs_for_common()
|
# try/finally block to ensure subsequent tests run in float32
|
||||||
|
try:
|
||||||
|
config, inputs_dict = self.model_tester.prepare_config_and_inputs_for_common()
|
||||||
|
for model_class in self.all_model_classes:
|
||||||
|
class_inputs_dict = self._prepare_for_class(inputs_dict, model_class)
|
||||||
|
model = model_class(config)
|
||||||
|
outputs = model(class_inputs_dict)
|
||||||
|
|
||||||
for model_class in self.all_model_classes:
|
self.assertIsNotNone(outputs)
|
||||||
class_inputs_dict = self._prepare_for_class(inputs_dict, model_class)
|
finally:
|
||||||
model = model_class(config)
|
tf.keras.mixed_precision.set_global_policy("float32")
|
||||||
outputs = model(class_inputs_dict)
|
|
||||||
|
|
||||||
self.assertIsNotNone(outputs)
|
|
||||||
|
|
||||||
tf.keras.mixed_precision.set_global_policy("float32")
|
|
||||||
|
|
||||||
@slow
|
@slow
|
||||||
def test_train_pipeline_custom_model(self):
|
def test_train_pipeline_custom_model(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user