transformers icon indicating copy to clipboard operation
transformers copied to clipboard

🐛 Saving TF model : Expected Operation, Variable, or Tensor, got None

Open astariul opened this issue 6 years ago • 4 comments

🐛 Bug

I'm training TFElectraModel. Training goes well, but when I try to save the model, I met the following error :

TypeError: Expected Operation, Variable, or Tensor, got None

Minimal reproducible example

!pip install transformers

from transformers import TFElectraModel

model = TFElectraModel.from_pretrained("google/electra-base-discriminator")
!mkdir swag
model.save("swag")

Related

#2336 https://github.com/tensorflow/tensorflow/issues/35432

astariul avatar Apr 28 '20 07:04 astariul

Hi! We prefer using our own API for this, using from_pretrained which also takes care of the configuration:

from transformers import TFElectraModel

model = TFElectraModel.from_pretrained("google/electra-base-discriminator")
!mkdir swag
model.save_pretrained("swag")

Is there a reason why you would rather use .save rather than .save_pretrained?

LysandreJik avatar Apr 28 '20 13:04 LysandreJik

I was using .save() because I made a custom model, with additional layers on top of Electra, and I want to save these layers as well.

Finally, I simply sub-classed TFElectraPreTrainedModel and add my custom layers there, so I can use .save_pretrained.

Thanks for the help !

astariul avatar Apr 28 '20 23:04 astariul

I am also facing similar issue. The reason for using save method is i want to host the saved model using tensorflow model server

nirajkale avatar Aug 02 '20 19:08 nirajkale

@nirajkale did you manage to solve this? I'm facing the same issue with other pre-trained.

erlichsefisalesforce avatar Mar 19 '23 08:03 erlichsefisalesforce