InvalidArgumentError: Exception encountered when calling layer 'encoder' (type TFMarianEncoder)

I am fine-tuning a translation model which translates English to Swahili with my own datasets. Everything goes well during training but when I try to use the pre-trained model i run into the
following error. Any help will be highly appreciated.
If the problem is with my data please provide a step-by-step way in which I could solve it because am a beginner. Thanks

InvalidArgumentError Traceback (most recent call last)
in <cell line: 5>()
3 # Replace this with your own checkpoint
4 model_checkpoint = “KigenCHESS/new-en-to-sw”
----> 5 translaton = pipeline(“translation”, model=model_checkpoint)

10 frames
/usr/local/lib/python3.9/dist-packages/transformers/models/marian/ in call(self, input_ids, inputs_embeds, attention_mask, head_mask, output_attentions, output_hidden_states, return_dict, training)
789 ),
790 )
→ 791 inputs_embeds = self.embed_tokens(input_ids) * self.embed_scale
793 embed_pos = self.embed_positions(input_shape)

InvalidArgumentError: Exception encountered when calling layer ‘encoder’ (type TFMarianEncoder).

cannot compute Mul as input #1(zero-based) was expected to be a half tensor but is a float tensor [Op:Mul]

Call arguments received by layer ‘encoder’ (type TFMarianEncoder):
• input_ids=tf.Tensor(shape=(3, 5), dtype=int32)
• inputs_embeds=None
• attention_mask=tf.Tensor(shape=(3, 5), dtype=int32)
• head_mask=None
• output_attentions=False
• output_hidden_states=False
• return_dict=True
• training=False

1 Like

Same problem, replying to get notified

I found the solution by commenting out this code tf.keras.mixed_precision.set_global_policy(“mixed_float16”)

1 Like

that worked for me too, thanks a lot!

I’m having the same issue. In which part of the code did you comment out tf.keras.mixed_precision.set_global_policy(“mixed_float16”) ?