I created my model with:
#Load of the model
model_checkpoint = 'microsoft/deberta-v3-large'
# model_checkpoint = 'roberta-base' # you can alternatively use roberta-base but this model is bigger thus training will take longer
# Define label maps specific to your task
id2label = {0: "Human", 1: "AI"}
label2id = {"Human": 0, "AI": 1}
# Generate classification model from model_checkpoint with the defined labels
model = AutoModelForSequenceClassification.from_pretrained(
model_checkpoint, num_labels=2, id2label=id2label, label2id=label2id)
peft_config = LoraConfig(task_type="SEQ_CLS",
r=1,
lora_alpha=16,
lora_dropout=0.2) model = get_peft_model(model, peft_config)
This works ok, and I call trainer.train() to train my model
When I finish, I want to save the model to export it to another machine, with
model_path = "./deberta-v3-large-5"
model.save_pretrained(model_path)
And reload the model with
reloaded_model = original_model.from_pretrained(model_path)
Must be something super simple, but I can figure it out.
If I run tests on my reloaded_model, I get much worse accuracy than on the original model which was trained
I have also tried, with no luck:
# Save the model and the tokenizer
model_path = "./deberta-v3-large-4"
trainer.save_model(model_path)
tokenizer.save_pretrained(model_path, set_lower_case=False)
from transformers import AutoModelForSequenceClassification, AutoTokenizer
# Path where the model and tokenizer were saved
model_path = "./deberta-v3-large-4"
# Define label maps specific to your task
id2label = {0: "Human", 1: "AI"}
label2id = {"Human": 0, "AI": 1}
# Generate classification model from model_checkpoint with the defined labels
model_regenerate = AutoModelForSequenceClassification.from_pretrained(
model_path, num_labels=2, id2label=id2label, label2id=label2id)
tokenizer_reloaded = AutoTokenizer.from_pretrained(model_path)
peft_config = LoraConfig(task_type="SEQ_CLS",
r=1,
lora_alpha=16,
lora_dropout=0.2)
model_full_regenerate = get_peft_model(model_regenerate, peft_config)
model_full_regenerate.print_trainable_parameters()
In all cases, when I load the model, i get
Some weights of DebertaV2ForSequenceClassification were not initialized from the model checkpoint at microsoft/deberta-v3-large and are newly initialized: ['classifier.bias', 'classifier.weight', 'pooler.dense.bias', 'pooler.dense.weight']
Thanks