I modified the code from the notebook provided in this course.(Fine-tuning a model with the Trainer API).The following code produces validation loss while training and uses the compute metric when I am not using PEFT. But when I am using PEFT, it is showing “no log” as validation loss and skips the compute metric. what can be the problem?
from peft import LoraConfig , prepare_model_for_kbit_training , get_peft_model
lora_config = LoraConfig(
r=8,
target_modules=["query", "key","value"],
bias="none",
lora_alpha=16,
lora_dropout=0.1
)
from transformers import AutoModelForSequenceClassification
model = AutoModelForSequenceClassification.from_pretrained(checkpoint, num_labels=2)
model = prepare_model_for_kbit_training(model,use_gradient_checkpointing=False)
model = get_peft_model(model, lora_config)
def compute_metrics(eval_preds):
metric = evaluate.load("glue", "mrpc")
logits, labels = eval_preds
predictions = np.argmax(logits, axis=-1)
return metric.compute(predictions=predictions, references=labels)
training_args = TrainingArguments("test-trainer",
report_to = 'wandb',
evaluation_strategy="epoch",
disable_tqdm=False,
per_device_train_batch_size=4,
per_device_eval_batch_size=4,
gradient_accumulation_steps=16,
save_steps=10,
logging_steps=10,
max_grad_norm=0.3,
num_train_epochs=3,
warmup_ratio=0.03,
)
trainer = Trainer(
model,
training_args,
train_dataset=tokenized_datasets["train"],
eval_dataset=tokenized_datasets["validation"],
data_collator=data_collator,
tokenizer=tokenizer,
compute_metrics=compute_metrics,
)