-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Decoder-only Attribution Models Support #144
Conversation
In the current state, decoder-only models can be instantiated with |
* origin/main: Python 3.11 CI support (#146) Added Python 3.11 checks
Major (non-breaking) changes in progress:
Example with full attribution: Example constraining same attributions between steps [6, 10): Note how the selected slices attributed in the second case match scores with the same slices in the full attribution. Todos:
|
Some tests are broken at the moment (need checking) but decoder-only attribution seems to be producing the right output. Visualization still doesn't support decoder-only formats, so |
Minor adjustments to viz functions and aggregators to support an empty |
Fixed the issues with positions, and now both seq2seq and decoder-only attribution are working as expected! 🎉 Also added the first test for decoder-only models to the test suite to ensure continued compatibility. Points still needing discussion/fixing:
EDIT: We opted for enforcing a batch size of one (with an info message to inform the user) to handle this case for the moment. The only downside is a slower attribution process, but it is reasonable in the context.
EDIT: Enforcing a batch size of one for the case of multiple texts with custom start-end positions for a decoder-only model. |
This looks amazing! :) When I tested it with the following setup: gpt_model = inseq.load_model("gpt2", "saliency")
gpt_out = gpt_model.attribute(
"The developer argued with the designer because her idea",
show_progress=True,
pretty_progress=True,
generation_args={"max_new_tokens": 10}
)
gpt_out.show() ...I ran into this assertion error: inseq/inseq/models/attribution_model.py Lines 196 to 198 in 27d1a77
It turns out that I could produce this after simply commenting out the three lines: Should I run into this error or should we make the assertion less strict? |
Thanks for spotting this bug @nfelnlp! The texts = texts[0] if len(texts) == 1 else texts from |
…-only attribution
@nfelnlp with the last commit both the case you mentioned and the batched decoder-only attribution should work, documented our choice in the comment above! |
@nfelnlp only some robustness tests are left, then we can proceed with the merge. Could you help with that? 🙂 |
Just tested the latest version and it works flawlessly for the GPT-2 use case I described above. |
Description
This PR introduces support to perform attributions on decoder-only models from Hugging Face (e.g. GPT2) using the
AutoModelForCausalLM
abstraction. The implementation will involve several generalizations of existing classes and methods, notably:Batch
alongside the currentEncoderDecoderBatch
usage.FeatureAttributionSequenceOutput
.ForSeq2SeqLM
(current) andForCausalLM
(to be added) in theHuggingfaceModel
class.The new loading pipeline will also support using pre-loaded models in
inseq.load_model
aiming for compatibility with LLM.int8 (see #141).Related Issue
#128
Type of Change