Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A significant difference between the results obtained from testing after training and reloading the model after saving. How to save and reload the model correctly for reasoning? #73

Open
FanY1999 opened this issue Aug 7, 2023 · 0 comments

Comments

@FanY1999
Copy link

FanY1999 commented Aug 7, 2023

I don't understand why the reasoning effect of reloading the trained model is very poor. Did I write something wrong? Looking forward to your reply.

the key code is as follows:

train mode

  • some codes of train mode(in main())
model=BertForSequenceClassification.from_pretrained(config.bert_path, return_dict=True,num_labels=config.num_classes).to(device)
delta_config = AutoDeltaConfig.from_dict({"delta_type":"adapter"})
delta = AdapterModel.from_config(delta_config, backbone_model=model)
delta.freeze_module()
delta.log()
train(config, model, train_iter, dev_iter, test_iter,delta)
  • train() part
for i, (trains, labels) in enumerate(train_iter):
    batch={'input_ids':trains[0],'attention_mask':trains[2],'labels':labels}
    outputs=model(**batch)
    loss=outputs.loss
    model.zero_grad()
    loss.backward()
    optimizer.step()
    ……
    ……
    dev_acc, dev_loss = evaluate(config, model, dev_iter)
    if dev_loss < dev_best_loss:
        dev_best_loss = dev_loss
        delta.save_finetuned(config.save_path)
test(config, model, test_iter)    # test after training finished
  • result
    acc=0.7735

resoning/test mode

  • some codes of reasoning/test mode(in main())
model=BertForSequenceClassification.from_pretrained(config.bert_path, return_dict=True,num_labels=config.num_classes).to(device)
delta=AdapterModel.from_finetuned(config.save_path,backbone_model=model)
test(config, model, test_iter)
  • result
    acc=0.5713
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant