Skip to content

Inconsistent behavior in generate when output_scores=True #17424

Description

@shijie-wu

System Info

main branch

Who can help?

@patrickvonplaten, @Narsil, @gante

Information

  • The official example scripts
  • My own modified scripts

Tasks

  • An officially supported task in the examples folder (such as GLUE/SQuAD, ...)
  • My own task or dataset (give details below)

Reproduction

In generate when output_scores=True, the behavior is inconsistent. In greedy_search mode, the scores are raw logits

next_token_logits = outputs.logits[:, -1, :]
# Store scores, attentions and hidden_states when required
if return_dict_in_generate:
if output_scores:
scores += (next_token_logits,)

but in sample mode (and various beam search modes), the scores are processed logits

next_token_logits = outputs.logits[:, -1, :]
# pre-process distribution
next_token_scores = logits_processor(input_ids, next_token_logits)
next_token_scores = logits_warper(input_ids, next_token_scores)
# Store scores, attentions and hidden_states when required
if return_dict_in_generate:
if output_scores:
scores += (next_token_scores,)

Expected behavior

In generate when output_scores=True, the returned scores should be consistent. It could either be raw logits or the processed logits. While for my usecase, I only need raw logits. There might be some usecases which require the processed logits. So there're multiple options:

  1. Return raw logits when output_scores=True
  2. Return processed logits when output_scores=True
  3. Return processed logits when output_scores=True, and raw logits when output_raw_scores=True

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions