Closed xduan7 closed 1 month ago
Thank you for providing such a detailed script to reproduce certain issues with monkeypatch
. In fact, the use of monkeypatch
can be traced back to the official implementation of MEND: https://github.com/eric-mitchell/mend/blob/main/algs/mend.py#L230.
However, in past experiments, we have observed successful editing of Llama-7B with MEND (Edit success = 1.0). Therefore, monkeypatch is unlikely to cause logits to stop changing. Please rest assured that I will attempt to reproduce this asap.
Hi, do you have any further issues?
@zxlzr Sorry for the late reply but my question is not answered yet.
I understand @pengzju 's statement that MEND
worked fine in your evaluations. So I'm wondering if you could reproduce the results in my script.
If so, my guess would be that it is an issue of package versioning. Otherwise, I'm wondering if monkeypatch
is necessary for MEND
. From what I know, make_functional
actually does nothing other than wrapping up the stateless model with its forward
function. I'm thinking since other knowledge editing methods are not using it, it might not be necessary for MEND
as well.
Sorry, we are busy in the rebuttal stage, we will handle this issue in the next few days.
No worries. Take your time. Hope your rebuttal goes well.
@xduan7
Thank you so much for providing detailed code to tackle this tricky bug. As I mentioned before, many past experiments have shown that MEND can effectively modify weights.
I did manage to reproduce your issue, but the problem isn't that "it doesn't work on LLaMA"; rather, the monkeypatch
loses its effectiveness when the model is run in parallel. In the code you provided, simply changing device
to 'cpu' or a single GPU instead of 'auto' allows all tests to pass.
I guess that the underlying issue is an incompatibility between the HuggingFace Transformers
parallel model logic and the monkeypatch
. This means that as long as you ensure the model runs on a single GPU, you can avoid the issue. That said, we probably can't completely eliminate this issue, but I’ve provided a way to avoid the bug.
I really enjoy our discussion and hope this resolves your problem.
hi, do you have any further questions?
@pengzju @zxlzr Thank you for the reply. This is very helpful and I can confirm that using a single GPU solves the problem. Before we close the issue, I would like to extend the discussion a little bit. The purpose of monkey patch seems to be making the model stateless and wrapped to prevent further modification, so removing it should not impact the knowledge editing results. Do you think it's a good idea to simply remove monkey patch in MEND?
I think this is a good idea. In my previous experience, external patch
and model parallelism have often conflicted. I would also encourage you to try directly modifying the model's weights. I'd welcome your feedback or a PR submission if you can get it to work on multiple GPUs.
Thanks again!
Thank you for everything.
Hi. Thank you for the awesome package. I found something strange when I was trying to use MEND with llama 2 7b. Specifically, the monkey patched llama 2 model is producing different results compared to the original (un-patched) model. Here is a script that demonstrates the problem:
Basically, this script demonstrated that llama 2 model's forward changed after the monkey patch. After a llama 2 model is monkey-patched, weight changes to the model does not lead to output (logits) change. However, by either (1) casting the modified model back to its original class (not monkey-patched), or (2) using the original class forward method (in this case,
LlamaForCausalLM.__class__.forward
) with the modified model, I was able to generate the correct output (logits) corresponding to the weight changes. This implies that the forward method for monkey-patched llama models are probably not working as intended.However, it seems that monkey patch works with gpt 2 xl. You can simply swap the
model_name
in the script to"openai-community/gpt2-xl"
for verification that it is only a problem with llama.I'm wondering if it is absolutely necessary to stick to monkey-patched models in MEND? If so, is there any workaround? And just FYI, I'm using transformers version 4.42.4 and higher version 0.2.1.
Thank you.