rachtibat / LRP-eXplains-Transformers

Layer-Wise Relevance Propagation for Large Language Models and Vision Transformers [ICML 2024]
https://lxt.readthedocs.io
Other
100 stars 12 forks source link

Differences when using lxt.models.llama.LlamaForCausalLM vs. transformers.LlamaForCausalLM #16

Closed GenK-ai closed 1 week ago

GenK-ai commented 1 month ago

I recently read your paper on the AttnLRP. I liked it, especially as seemed quite useful for an university project I am working on. However when trying out your code for TinyLLaMA given on https://lxt.readthedocs.io/en/latest/quickstart.html#tinyllama I found out that it does not work when exchanging "TinyLlama/TinyLlama-1.1B-Chat-v1.0" with "meta-llama/Llama-3.2-1B".

In attempt to make it work I tried out to exchange "from lxt.models.llama import LlamaForCausalLM" with "from transformers import LlamaForCausalLM". in the provided code. However that led to different relevance maps for TinyLlama.

With "from lxt.models.llama import LlamaForCausalLM" : heatmap.pdf

With "from transformers import LlamaForCausalLM": heatmap.pdf

I assume this is caused that your version differs from the actual version of modeling_llama.py (https://github.com/huggingface/transformers/blob/main/src/transformers/models/llama/modeling_llama.py).

I therefore wanted to ask if there is any possibility to get it to work with a code similar to https://lxt.readthedocs.io/en/latest/quickstart.html#tinyllama for "TinyLlama/TinyLlama-1.1B-Chat-v1.0" with "meta-llama/Llama-3.2-1B" which I overlooked?

rachtibat commented 4 weeks ago

Hi,

Llama 3.2 is based on an updated transformers library. So, the LXT code doesnt work right now unfortunately. We need to update the code base, we try to do it next week (: and support quantisation for Llama too.

For LXT to work, you must use the lxt.models import. So, what you do now will not work.

Best

GenK-ai commented 3 weeks ago

Thanks for the info. Looking forward to the updates whenever they’re uploaded. Appreciate you making this code base available to everyone.

rachtibat commented 1 week ago

Hey @GenK-ai,

we updated LXT to support the new LlaMA 3.2 LLM family in the new release https://github.com/rachtibat/LRP-eXplains-Transformers/releases/tag/v0.6.1 You can also look at the quantization example in https://github.com/rachtibat/LRP-eXplains-Transformers/tree/main/examples. Of course, without quantization the accuracy and hence explanations of the model should be better.

Good luck for your university project!