[Generate] Allow custom config values in generate config#43181
[Generate] Allow custom config values in generate config#43181vasqu merged 4 commits intohuggingface:mainfrom
Generate] Allow custom config values in generate config#43181Conversation
Co-authored-by: Eric Bezzam <ebezzam@users.noreply.github.com>
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
| # (custom entries are carried over). | ||
| global_defaults = self.generation_config._get_default_generation_params() | ||
| generation_config.update(**self.generation_config.to_dict(), defaults_only=True) | ||
| generation_config.update(**self.generation_config.to_dict(), defaults_only=True, allow_custom_entries=True) |
There was a problem hiding this comment.
Ah, that is what you meant earlier. I assumed that generation_config at this point will already be self.generation_config
Btw, if a few lines above we create not generation_config = GenerationConfig() but generation_config = self.generation_config it will be much easier. I can't think of why it is a bad idea. WDYT?
There was a problem hiding this comment.
Nope, not the case, e.g.
from transformers import AutoModelForCausalLM, AutoTokenizer, GenerationConfig
model = AutoModelForCausalLM.from_pretrained(
"meta-llama/Llama-3.2-3B-Instruct",
device_map="auto",
torch_dtype="auto",
attn_implementation="flash_attention_2",
).eval()
tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-3.2-3B-Instruct")
tokenizer.pad_token = tokenizer.eos_token
inputs = tokenizer(
["Hello, how are you?", "is this life?"],
padding=True,
padding_side="left",
return_tensors="pt",
).to(model.device)
outputs = model.generate(**inputs, max_new_tokens=50, generation_config=GenerationConfig(do_sample=False))
print(tokenizer.batch_decode(outputs, skip_special_tokens=True))We will have different generation configs so it's not guaranteed.
There was a problem hiding this comment.
Indeed 🥲
I guess there is no cleaner option then
zucchini-nlp
left a comment
There was a problem hiding this comment.
Also, let's allow loading custom fields when running generation_config.from_pretrained. After the recent changes, there is no need for a _from_model_config private attr and we are guaranteed to get only generation attr at init time. So we could just save all kwargs at __init__ as attributes, criiw
ebezzam
left a comment
There was a problem hiding this comment.
thanks @vasqu and @zucchini-nlp for iterating! I tried these changes in my VibeVoice branch, and they work 👍
zucchini-nlp
left a comment
There was a problem hiding this comment.
Seems like the CI is flaky again 🥲
|
View the CircleCI Test Summary for this PR: https://huggingface.co/spaces/transformers-community/circle-ci-viz?pr=43181&sha=cb4bda |
|
Finally got it |
…ce#43181) * allow custom values to carry over Co-authored-by: Eric Bezzam <ebezzam@users.noreply.github.com> * slightly different version, moving everything to update itself * fix typo --------- Co-authored-by: Eric Bezzam <ebezzam@users.noreply.github.com>
As per title, followup to a series of PRs that address the new config logic
Generation] Fix default overwrite for non-Nonedefaults #42958None#42702tl;dr: custom values in an uploaded generation config are ignored atm