huggingface / transformers

🤗 Transformers: State-of-the-art Machine Learning for Pytorch, TensorFlow, and JAX.
https://huggingface.co/transformers
Apache License 2.0
134.62k stars 26.92k forks source link

ValueError: You have to specify either decoder_inputs or decoder_inputs_embeds #9000

Closed rk0033 closed 3 years ago

rk0033 commented 3 years ago

Environment info

Who can help

@patrickvonplaten @patil-suraj @jplu

Information

I refer to the URL below and want to run the fine-tuning on mT5. https://huggingface.co/transformers/training.html https://huggingface.co/transformers/model_doc/mt5.html

Model I am using (mT5):

from transformers import MT5Model, T5Tokenizer, TFMT5Model
model = TFMT5Model.from_pretrained("google/mt5-base")
tokenizer = T5Tokenizer.from_pretrained("google/mt5-base")
from transformers import BertTokenizer, glue_convert_examples_to_features
import tensorflow as tf
import tensorflow_datasets as tfds

data = tfds.load('glue/mrpc')
train_dataset = glue_convert_examples_to_features(data['train'], tokenizer, max_length=128, task='mrpc')
train_dataset = train_dataset.shuffle(100).batch(32).repeat(2)
optimizer = tf.keras.optimizers.Adam(learning_rate=3e-5)
loss = tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True)
model.compile(optimizer=optimizer, loss=loss)
model.fit(train_dataset, epochs=2, steps_per_epoch=115)

the output produced :

ValueError                                Traceback (most recent call last)
<ipython-input-9-650f77977ac3> in <module>()
      3 loss = tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True)
      4 model.compile(optimizer=optimizer, loss=loss)
----> 5 model.fit(train_dataset, epochs=2, steps_per_epoch=115)
      6 # model.fit({"inputs": train_dataset},epochs=2, steps_per_epoch=115)
      7 # model.fit(train_dataset)

10 frames
/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/func_graph.py in wrapper(*args, **kwargs)
    971           except Exception as e:  # pylint:disable=broad-except
    972             if hasattr(e, "ag_error_metadata"):
--> 973               raise e.ag_error_metadata.to_exception(e)
    974             else:
    975               raise

ValueError: in user code:

    /usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:806 train_function  *
        return step_function(self, iterator)
    /usr/local/lib/python3.6/dist-packages/transformers/models/t5/modeling_tf_t5.py:1094 call  *
        decoder_outputs = self.decoder(
    /usr/local/lib/python3.6/dist-packages/transformers/models/t5/modeling_tf_t5.py:642 call  *
        raise ValueError(f"You have to specify either {err_msg_prefix}inputs or {err_msg_prefix}inputs_embeds")

    ValueError: You have to specify either decoder_inputs or decoder_inputs_embeds
patrickvonplaten commented 3 years ago

analogs to #8923

stas00 commented 3 years ago

this one is probably safe to close - probably your link was satisfactory, @patrickvonplaten