Skip to content

Infinite repetition bug still exists #1611

Description

@99991

In some cases, Qwen3-VL and Qwen2.5-VL become stuck in an infinite loop, repeating the same text over and over. Increasing the repetition penalty is not an acceptable solution because it breaks the transcription of naturally repetitive text, for example in tables.

Output

```markdown
# NLP Pipeline

In the following, the NLP pipeline and its components are discussed in depth:

```
Text
  |
  v
Language identification
  |
  v
String -> Tokenization -> Sentence splitter -> POS tagger
  |                     |
  |                     v
  |                Sentences
  |                Tokens
  |
  |-----------------|
  | Segmentation    |
  |                 |
  |                 |
  |                 |
  |                 |
  |                 |
  |                 |
  |                 |
  |                 |
  |                 |
  |                 |
  |                 |
  |                 |
  |                 |
  |                 |
  |                 |
  |                 |
  |                 |
  |                 |
  |                 |
  |                 |
  |                 |
  |                 |
  |                 |
  |                 |
  |                 |
  |                 |
  |                 |
  |                 |
  |                 |
  |                 |
  |                 |
  |                 |
  |                 |
  |                 |
  |                 |
  |                 |
  |                 |
  |                 |
  |                 |
  |                 |
  |                 |
  |                 |
  |

Code

from transformers import Qwen3VLForConditionalGeneration, AutoProcessor
import torch
torch.manual_seed(0)

model = Qwen3VLForConditionalGeneration.from_pretrained(
    "Qwen/Qwen3-VL-4B-Instruct",
    dtype="float16",
    device_map="auto"
)

processor = AutoProcessor.from_pretrained("Qwen/Qwen3-VL-4B-Instruct")

# Download image from github and rename to test.png
image_path = "test.png"

messages = [
    {
        "role": "user",
        "content": [
            {
                "type": "image",
                "image": image_path,
            },
            {
                "type": "text",
                "text": "Transcribe this image as markdown.",
            },
        ],
    }
]

# Preparation for inference
inputs = processor.apply_chat_template(
    messages,
    tokenize=True,
    add_generation_prompt=True,
    return_dict=True,
    return_tensors="pt"
)
inputs = inputs.to(model.device)

# Inference: Generation of the output
generated_ids = model.generate(**inputs, max_new_tokens=256)
generated_ids_trimmed = [
    out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
]
output_text = processor.batch_decode(
    generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
)

print(output_text[0])

test.png

Image

Related

Previous issue: #241 (closed without comment)

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