0

I am trying to store a hugging face transformer ai model for each individual user locally instead of storing it in a database.

model = BertForSequenceClassification.from_pretrained('bert-base-uncased',num_labels=2)
model.save_pretrained("locallystored")

I then would like to train that users model that I stored locally. I send a websocket to backend to train the model stored in the users local machine.

socketio.on("willtraintheusersmodel")
    model = BertForSequenceClassification.from_pretrained('locallystored')
    *training*
    model.train() 
    model.save_pretrained("locallystored")
    #then I update the changes made

How can I save a model in the users computer locally and retrieve it anytime i need to train or make predictions? I am trying to make this work in production with multiple users.

I have a python-socketio backend with react frontend

Any help would be extremely appreciated thanks.

  • `model.save_pretrained("CustomModel")` CustumModel is a path in your current working directory. Why don't you specify an absolute path? – cronoik Mar 22 '23 at 20:10
  • Not sure how I can get the absolute path of user though – tidekis doritos Mar 22 '23 at 20:52
  • also if I do will it necessarily get stored in the users local file? – tidekis doritos Mar 22 '23 at 21:03
  • https://stackoverflow.com/questions/64001128/load-a-pre-trained-model-from-disk-with-huggingface-transformers – alvas Mar 22 '23 at 22:28
  • 1
    @tidekisdoritos You said in your question that you want to store the stuff locally. Maybe I can provide a better suggestion when you share more details. – cronoik Mar 23 '23 at 10:08
  • @cronoik Hello, I've updated the post a bit, does that clears up some things? – tidekis doritos Mar 23 '23 at 16:30
  • @cronoik hello can u please suggest me a way, running out of ideas. – tidekis doritos Mar 26 '23 at 17:01
  • 1
    Well, as far as I understood I would go for a different setup. I think you should store all your models in your backend and only copy them to your users (but never pull from there). Whenever you fine-tune a user's model, you do that in your backend and push the trained model afterward to the user by overriding the previous version. – cronoik Mar 26 '23 at 18:36
  • thanks for the suggestion however im not too sure how I can push the trained model the the user. Should I send the file to the frontend and save it from there? Or maybe I misunderstood and u mean I should store save the users trained model in my backend with a unique identifier and I retrieve it from there. In that case, im not sure how that would work out in production. – tidekis doritos Mar 26 '23 at 20:33

0 Answers0