EasyEdit icon indicating copy to clipboard operation
EasyEdit copied to clipboard

Bug about using ROME to edit

Open WanliYoung opened this issue 3 years ago • 3 comments

Hello, when I tried to use ROME to edit gpt2-xl according to the example of ROME from the Docs and Colab, I met some bugs. The code is: from easyeditor import ROMEHyperParams from easyeditor import BaseEditor

hparams = ROMEHyperParams.from_hparams('./hparams/ROME/gpt2-xl')

prompts = ['Ray Charles, the', 'Grant Hill is a professional', 'The law in Ikaalinen declares the language' ] ground_truth = ['piano', 'basketball', 'Finnish' ] target_new = ['violin', 'soccer', 'Swedish' ] subject = ['Ray Charles', 'Grant Hill', 'Ikaalinen' ]

editor = BaseEditor.from_hparams(hparams)

metrics, edited_model, _ = editor.edit( prompts=prompts, ground_truth=ground_truth, target_new=target_new, subject=subject, # locality_inputs=locality_inputs, keep_original_weight=False )

I met a bug: Traceback (most recent call last): File "/home/yangwanli/EasyEdit/test_rome.py", line 25, in metrics, edited_model, _ = editor.edit( File "/home/yangwanli/EasyEdit/easyeditor/editors/editor.py", line 200, in edit edited_model, weights_copy = self.apply_algo( File "/home/yangwanli/EasyEdit/easyeditor/models/rome/rome_main.py", line 41, in apply_rome_to_model deltas = execute_rome(model, tok, request, hparams) File "/home/yangwanli/EasyEdit/easyeditor/models/rome/rome_main.py", line 104, in execute_rome left_vector: torch.Tensor = compute_u( File "/home/yangwanli/EasyEdit/easyeditor/models/rome/compute_u.py", line 112, in compute_u u = get_inv_cov( File "/home/yangwanli/EasyEdit/easyeditor/models/rome/compute_u.py", line 42, in get_inv_cov stat = layer_stats( File "/home/yangwanli/EasyEdit/easyeditor/models/rome/layer_stats.py", line 148, in layer_stats loader = tally( File "/home/yangwanli/EasyEdit/easyeditor/util/runningstats.py", line 104, in tally cached_state = load_cached_state(cache, args, quiet=quiet) File "/home/yangwanli/EasyEdit/easyeditor/util/runningstats.py", line 1485, in load_cached_state print("%s %s changed from %s to %s" % (cachefile, a, dat[a], v)) File "/home/yangwanli/anaconda3/envs/EasyEdit/lib/python3.9/site-packages/numpy/lib/npyio.py", line 249, in getitem raise KeyError("%s is not a file in the archive" % key) KeyError: 'sample_size is not a file in the archive'

I found the bug come from "File "/home/yangwanli/EasyEdit/easyeditor/util/runningstats.py", line 1485, in load_cached_state": if a not in dat or dat[a] != v: if not quiet: print("%s %s changed from %s to %s" % (cachefile, a, dat[a], v)) return None

a was not in dat, but you used dat[a], so it raise the KeyError. But I don't know how to fix the bug. I tried to comment the print codes, but it raise other errors.

WanliYoung avatar Aug 24 '23 15:08 WanliYoung

Here are my two suggestions:

    1. Set mom2_adjustment to false, which avoids calculating second-order momentum, but does not affect overall performance.
    1. When mom2_adjustment is set to True, the wikipedia dataset must be downloaded and the representation calculated, which is time-consuming. You can break points here (or import pdb) to see if the load dataset is correct

pengzju avatar Aug 24 '23 16:08 pengzju

Now that I've set all mom2_adjustment to False by default, please update the easyedit code and try again.

If your problem has been resolved, please help close this issue.

pengzju avatar Aug 24 '23 16:08 pengzju

Thanks for your help! It's correct. Now I can use ROME to edit gpt2-xl successfully. Thanks for your great contributions again!

WanliYoung avatar Aug 24 '23 16:08 WanliYoung