Skip to content

fix: handle ragged batch inputs in Qwen2_5_VLProcessor mm_token_type_ids computation#44919

Closed
s-zx wants to merge 1 commit intohuggingface:mainfrom
s-zx:fix/qwen2-5-vl-ragged-batch-token-ids
Closed

fix: handle ragged batch inputs in Qwen2_5_VLProcessor mm_token_type_ids computation#44919
s-zx wants to merge 1 commit intohuggingface:mainfrom
s-zx:fix/qwen2-5-vl-ragged-batch-token-ids

Conversation

@s-zx
Copy link
Copy Markdown

@s-zx s-zx commented Mar 21, 2026

What does this PR do?

Fixes a crash in Qwen2_5_VLProcessor.__call__ when processing batched inputs without padding (padding=False).

Root cause: When the tokenizer returns sequences of different lengths (ragged list), np.array(text_inputs["input_ids"]) creates an object array instead of a 2D integer array. The subsequent element-wise comparisons (== image_token_id, == video_token_id) then fail or produce wrong results.

Fix: Detect batch inputs (list-of-lists) and process each sequence individually, which correctly handles both padded (uniform length) and unpadded (ragged) batches.

Before:

array_ids = np.array(text_inputs["input_ids"])  # fails for ragged batches
mm_token_type_ids = np.zeros_like(text_inputs["input_ids"])
mm_token_type_ids[array_ids == self.image_token_id] = 1

After:

if isinstance(input_ids, list) and input_ids and isinstance(input_ids[0], list):
    # process each sequence individually
    for ids in input_ids:
        arr = np.array(ids)
        ...

Fixes #44514

…_ids

When processing batched inputs without padding (padding=False), the
tokenizer returns lists of different lengths. Calling np.array() on
such a ragged list produces an object array, making the subsequent
element-wise comparisons (== image_token_id, == video_token_id) fail.

Fix by detecting batch inputs (list of lists) and processing each
sequence individually, which works for both padded and unpadded batches.

Fixes huggingface#44514
@github-actions
Copy link
Copy Markdown
Contributor

[For maintainers] Suggested jobs to run (before merge)

run-slow: qwen2_5_vl

@zucchini-nlp
Copy link
Copy Markdown
Member

Will close in favor of #44563 (comment) which solves the issue for all models at once

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Qwen2_5_VLProcessor.apply_chat_template crashes on batched input when padding=False

3 participants