Convert a bert model trained in pytorch into a Hugginface Model

Hello everyone :grinning:.

I trained a BERT model using pure PyTorch for a project.
My project aims to use SHAP for model interpretability. However, the SHAP website only provides examples for running it with BERT models that use the Hugging Face API.
To solve this problem, I trained a new model using the Hugging Face API. I am wondering if it is possible to train a BERT model in Pytorch, save it using torch.save(model.state_dict(‘model_weights.pth’)), and then load it using either AutoConfig.from_pretrained() or AutoModelForSequenceClassification.from_pretrained() by passing the .pth file.

Thank you :slightly_smiling_face: