zjunlp / EasyEdit

[ACL 2024] An Easy-to-use Knowledge Editing Framework for LLMs.
https://zjunlp.github.io/project/KnowEdit
MIT License
1.88k stars 232 forks source link

Issue with KN batch editing #338

Closed xduan7 closed 3 months ago

xduan7 commented 3 months ago

First of all, thank you for this awesome toolkit.

I have encountered an issue when I was trying to batch edit with KN on GPT 2:

hparams = KNHyperParams.from_hparams("edit.yaml")
editor = BaseEditor.from_hparams(hparams)

prompts = ['Who is the architect for Toodyay Fire Station?', 'Who is Claire Clairmont\'s sister?',
           'Which fictional universe is Chlorophyll Kid part of?']
ground_truth = ['Ken Duncan', 'Mary Shelley', 'DC Universe']
target_new = ['Wong Tung & Sons', 'Clairmont-Mayer', 'Image Universe']

metrics, edited_model, _ = editor.batch_edit(
    prompts=prompts,
    ground_truth=ground_truth,
    target_new=target_new,
    keep_original_weight=False,
)

I got the following message:

  File ".../experiments/kn/gpt-2-xl/edit.py", line 29, in <module>
    metrics, edited_model, _ = editor.batch_edit(
  File ".../easyeditor/editors/editor.py", line 225, in batch_edit
    for k, v in weights_copy.items():
AttributeError: 'function' object has no attribute 'items'

It seems that the error comes from this line, where the function returns a function instead of a copied weight in dict format like the other methods, e.g. the fine-tuning method.

Is there any solution to this issue? Thank you in advance.

littlefive5 commented 3 months ago

Hello, KN does not support batch editing. It requires the location of the knowledge neurons for each input and editing it correspondingly. So we don't recommend you conduct batch editing with KN.

xduan7 commented 3 months ago

Thank you for the explanation. It makes perfect sense.

I was asking because according to the is_batchable_method method, KN is a capable of batch editing. Again, thank you for the rapid reply.