transformers icon indicating copy to clipboard operation
transformers copied to clipboard

QuickStart code error

Open richwiss opened this issue 6 years ago • 7 comments

In the model2model quickstart example, I'm getting an error here:

outputs = model(question_tensor, answer_tensor, decoder_lm_labels=labels_tensor)

With the following message:

RuntimeError: The size of tensor a (8) must match the size of tensor b (768) at non-singleton dimension 3

Any ideas?

richwiss avatar Feb 04 '20 15:02 richwiss

Hi! Indeed this was an error, it should have been fixed with https://github.com/huggingface/transformers/commit/90ab15cb7a8fcf8bf58c05453ddf1aa6a4fa00c1.

Could you try installing from source:

pip install git+https://github.com/huggingface/transformers

and let me know if it fixes your issue?

LysandreJik avatar Feb 04 '20 16:02 LysandreJik

Install was successful.

But now I get the following:

Traceback (most recent call last): File "model2model.py", line 82, in model = Model2Model.from_pretrained('fine-tuned-weights') File "/path/venvs/nlp/lib/python3.6/site-packages/transformers/modeling_encoder_decoder.py", line 323, in from_pretrained raise ValueError("Only the Bert model is currently supported.") ValueError: Only the Bert model is currently supported.

Traded on error for another.

richwiss avatar Feb 04 '20 16:02 richwiss

model = Model2Model.from_pretrained('fine-tuned-weights')

Do you have a folder called fine-tuned-weights in your directory?

LysandreJik avatar Feb 04 '20 16:02 LysandreJik

To wrap this up: Just to confirm, there is no existing 'fine-tuned-weights' pretrained model.

'fine-tuned-weights' is just a name for a hypothetical pretrained model.

Regularjoe avatar Feb 07 '20 15:02 Regularjoe

Thank you, this commit works fine and fix the issue.

gmftbyGMFTBY avatar Feb 11 '20 09:02 gmftbyGMFTBY

I'm still a bit confused going along with the Quickstart guide and trying to get a fine-tuned Model2Model to work. First of all, as a minor note, the suggested line in the guide model = Model2Model.from_pretrained('fine-tuned-weights') won't work even if a folder with that name exists, as from_pretrained actually checks if this model path or name contains the string "bert" (among other things, see here). I understand that this is more of a placeholder name than anything else, but it might still be confusing.

Then, let's assume I saved a fine-tuned Model2Model instance via model.save_pretrained(PATH) (where this PATH now contains the string "bert"). The suggested loading of this via from_pretrainedwill still fail: A saved Model2Model is actually split into encoder and decoder, so simply using the top directory containing both for loading will obviously fail. Thus, I only have the option of either loading the encoder or decoder model, which will then, in the newly loaded Model2Model instance, be used as both the encoder and decoder, as this is how Model2Model is loaded: a single (BERT-)model used as encoder and decoder. But that can't be correct for fine-tuned versions of this model, can it? Or am I just missing something obvious here?

redfarg avatar Feb 25 '20 09:02 redfarg

Hi @redfarg, thanks for you comment. This is misleading indeed. We're in the process of adding BART to the library (@sshleifer), improving the experience with encoder-decoder architectures/Model2Model is part of the roadmap.

LysandreJik avatar Feb 25 '20 15:02 LysandreJik