-
Notifications
You must be signed in to change notification settings - Fork 28.3k
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
Contrastive decoding "raw" logits and scores are identical #29551
Comments
Hi @dmarx 👋 In theory I agree with the issue -- Regarding the other part of the issue, moving |
This doesn't seem like an issue to me: after applying top_k or top_p, I'd expect the likelihood of tokens below threshold to be 0 (or -inf in log space) or perhaps even NaN. Given that the API currently distinguishes between "raw" For concreteness, here's the relevant API documentation:
|
@dmarx You're right, but let me correct your comment first: none of the processors you mention change the logits in contrastive search, so it's expected that logits == scores if those are the only processors. from transformers import AutoModelForCausalLM, AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("distilgpt2")
model = AutoModelForCausalLM.from_pretrained("distilgpt2")
inputs = tokenizer(["The quick brown"], return_tensors="pt")
gen_out = model.generate(**inputs, do_sample=False, top_k=5, penalty_alpha=0.6, top_p=0.9, max_new_tokens=5)
print(tokenizer.batch_decode(gen_out, skip_special_tokens=True))
# You'll see something like this on your terminal:
# /home/joao/transformers/src/transformers/generation/configuration_utils.py:497: UserWarning: `do_sample` is set to `False`. However, `top_p` is set to `0.9` -- this flag is only used in sample-based generation modes. You should set `do_sample=True` or unset `top_p`.
# warnings.warn(
# Setting `pad_token_id` to `eos_token_id`:50256 for open-end generation.
# ['The quick brownie is a great way'] Nevertheless, our logits processors modify the logits in place, resulting in the incorrect behavior you describe. I'm going to open a PR for it :) |
System Info
transformers
version: 4.38.2Who can help?
@gante @ArthurZucker @younesbelkada
Information
Tasks
examples
folder (such as GLUE/SQuAD, ...)Reproduction
Expected behavior
At the very least, I'd expect
outputs.scores != outputs.logits
. Regarding what specific values should be attached to those attributes, I'm pretty sure the expected behavior would be:outputs.logits
should be the logits of the selected tokens as scored when they were first proposedoutputs.scores
should be the logits of the selected tokens after contrastive penalties and re-ranking have been appliedI think a contributing factor is that the re-ranking logic is currently encapsulated inside the
_ranking_fast()
function, so the penalized scores actually aren't even available to the scope that builds the output. Strongly recommend part of this fix include refactoring theGenerationMixin._contrastive_search
method to add the body of_ranking_fast()
directly rather than invoking it through a single-use function, which could then be eliminated since that is the only place it is used.Issue was uncovered while working on #29545
The text was updated successfully, but these errors were encountered: