Hey I am building a sentiment classifier app which uses hugging faces Finbert model and few other transformer models. Would the model download the weights from hugging face every time I run the app in spaces. If yes then how do i upload the models to spaces?
If you are using a model you created yourself or a very old model, you will need to use HfApi to download it, but in that case, you can download it when you need it by simply writing it as shown below.
from transformers import AutoTokenizer, AutoModelForSequenceClassification
model = AutoModelForSequenceClassification.from_pretrained("ProsusAI/finbert") # this line downloads model weight
tokenizer = AutoTokenizer.from_pretrained("ProsusAI/finbert") # this line downloads tokenizer configuration
or
from transformers import pipeline
pipe = pipeline("text-classification", model="ProsusAI/finbert") # this line downloads whole model weights and settings
I get how to download these models. I have a query about if I launch my gradio app in spaces. It would download the models every time it loads. How should I upload my model to spaces ?
If you do from_pretrained once, it should be cached, so there should be no problem even if you don’t think about it. If you really want to put the file on the Spaces disk, you can use snapshot_download.
It used to be possible for us to put the model in the Spaces repository itself, but now you can only put up to a total of 1GB in the repository, so I don’t recommend uploading to the repository.
They say the disk space is ephemeral here. Meaning it would restart everytime I refresh the app ?
Meaning it would restart everytime I refresh the app ?
Yes.