adapter-hub / adapters

A Unified Library for Parameter-Efficient and Modular Transfer Learning
https://docs.adapterhub.ml
Apache License 2.0
2.59k stars 348 forks source link

fix adapters with `*adapter_attention*` #29

Closed JoPfeiff closed 3 years ago

JoPfeiff commented 4 years ago

šŸ› Bug

Old versions of the adapters initialized *adapter_attention* which were never used but stored. I proposed a two stage fix:

Information

Model I am using (Bert, XLNet ...): e.g. RoBERTa-Base

Language I am using the model on (English, Chinese ...): English

Adapter setup I am using (if any): many but e.g.

model = AutoModel.from_pretrained("roberta-base")
model.load_adapter("comsense/csqa@ukp", "text_task", config="{'using': 'pfeiffer'}")

The problem arises when using:

The tasks I am working on is:

To reproduce

Steps to reproduce the behavior:

  1. load the adapter, you will get a warning for parameters which are not required

Expected behavior

no warning

Environment info

calpt commented 4 years ago

hot fix which does not log the warning that the parameters were not instantiated

can we keep the logging and reduce the log level from "warn" to "info"?

arueckle commented 4 years ago

Can we just remove the weights from the checkpoints?

import sys
from shutil import copyfile

import torch

chckpt_path = sys.argv[1]
copyfile(chckpt_path, chckpt_path + '.backup')
chckpt = torch.load(chckpt_path, map_location=torch.device('cpu'))
chckpt_new = dict()

for k, w in chckpt.items():
    if 'adapter_attention' not in k:
        chckpt_new[k] = w
    else:
        print('unwanted key: {}'.format(k))

torch.save(chckpt_new, chckpt_path)