Skip to content

model generate with different batch size but get different results #23017

Description

@Alwin4Zhang

System Info

I'm using MT5ForConditionalGeneration by transformers to generate summaries,but when I use the arguments below,I will get different results when using beam search + do_sample + top_k + top_p。Only use beam search or do_sample can not cause this phenomenon。But why?

Who can help?

No response

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

self.model = MT5ForConditionalGeneration.from_pretrained(model_dir)
results = conditional_generation_summarizer.batch_summarize(
            documents=temp,
            # max_length=MAX_LENGTH,
            # bad_words=bad_words,
            max_new_tokens=MAX_LENGTH,
            num_beams=6,
            # num_beam_groups=3,
            # temperature=4.0,
            # diversity_penalty=2.0,
            # max_new_tokens=30,
            no_repeat_ngram_size=2,
            do_sample=True,
            top_k=20,
            # top_k=1,
            top_p=0.9,
            repetition_penalty=4.0,
            length_penalty=20.0,
            early_stopping=True,
            # num_return_sequences=6
        )

result = self.model.generate(
            input_ids,
            # attention_mask=attention_mask,
            decoder_start_token_id=self.tokenizer.cls_token_id,
            eos_token_id=self.tokenizer.sep_token_id,
            # max_length=max_length,
            # early_stopping=True,
            # num_beams=num_beams,
            **kwargs
        )

Pasted Graphic 20

Pasted Graphic 21

Expected behavior

I think different batch_size should not do effect on generation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions