Refine the code of Universal Assisted Generation - #34823
Merged
Merged
Conversation
Contributor
|
cc @mosheber |
Contributor
Author
|
The usage: from transformers import AutoModelForCausalLM, AutoTokenizer
prompt = "Alice and Bob"
checkpoint = "google/gemma-2-9b"
assistant_checkpoint = "double7/vicuna-68m"
assistant_tokenizer = AutoTokenizer.from_pretrained(assistant_checkpoint)
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
inputs = tokenizer(prompt, return_tensors="pt")
model = AutoModelForCausalLM.from_pretrained(checkpoint)
assistant_model = AutoModelForCausalLM.from_pretrained(assistant_checkpoint)
# assistant_model.generation_config.assistant_lookbehind = 10 # the default value
# assistant_model.generation_config.target_lookbehind = 10 # the default value
outputs = model.generate(**inputs, assistant_model=assistant_model, tokenizer=tokenizer, assistant_tokenizer=assistant_tokenizer)
tokenizer.batch_decode(outputs, skip_special_tokens=True) |
xinpengzz
marked this pull request as ready for review
November 22, 2024 02:58
Contributor
Contributor
Author
|
I have tested these changes on 2000 samples in the alpaca-cleaned dataset, and the output is identical to those without assistant decoding. main model is Qwen1.5-0.5B and draft model is vicuna-68m. |
Contributor
Author
|
Hi @ArthurZucker 👋 , Would it be convenient to review the code? |
Collaborator
|
Hey yeah sorry reviewing now! |
ArthurZucker
approved these changes
Nov 28, 2024
ArthurZucker
left a comment
Collaborator
There was a problem hiding this comment.
Nice and simple, thanks for adding the arg descriptions! 🤗
4 tasks
BernardZach
pushed a commit
to BernardZach/transformers
that referenced
this pull request
Dec 5, 2024
* removed the useless attritbutes * add configs for window size * fixed the wrong kwargs * added docstring
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
co-Authors: @WenjingKangIntel
Universal Assisted Generation(UAG) allowed the assisted generation with any assistant model regardless of its tokenizer.
This work is awesome and makes the different models work together possible !
This PR is to refine its code.
The code of the Universal Assisted Generation (UAG) contains some useless attributes and some processes that need improvement.
I have contacted with the @danielkorat, the one of authors of UAG, about it, and he suggested me to create a pull request to discuss it conveniently and detailedly.
Code changes:
self.prev_tokens,self.prev_target_ids.start_assistant_look_index < 0.Todo:
Before submitting
This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).Pull Request section?
Was this discussed/approved via a Github issue or the forum? Please add a link.to it if that's the case
Did you make sure to update the documentation with your changes? Here are thedocumentation guidelines, and
here are tips on formatting docstrings.
Did you write any new necessary tests?Who can review?
@danielkorat
@gante
and anyone interested in the program 😄