Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions src/transformers/models/qwen2_5_vl/modeling_qwen2_5_vl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1578,13 +1578,10 @@ def prepare_inputs_for_generation(
delta = delta.repeat_interleave(position_ids.shape[1] // delta.shape[0], dim=0)
vision_positions = position_ids + delta.expand_as(position_ids)
vision_positions = vision_positions.expand(3, vision_positions.shape[1], -1)

# Concatenate "text + vision" positions into [4, bs, seq-len]
if "position_ids" not in model_inputs:
text_positions = torch.arange(input_ids, device=input_ids.device)[None, None, :]
else:
text_positions = model_inputs["position_ids"][None, ...]
model_inputs["position_ids"] = torch.cat([text_positions, vision_positions], dim=0)
raise ValueError("position_ids not found in model_inputs")

model_inputs["position_ids"] = vision_positions

if cache_position[0] != 0:
model_inputs["pixel_values"] = None
Expand Down
9 changes: 3 additions & 6 deletions src/transformers/models/qwen2_5_vl/modular_qwen2_5_vl.py
Original file line number Diff line number Diff line change
Expand Up @@ -823,13 +823,10 @@ def prepare_inputs_for_generation(
delta = delta.repeat_interleave(position_ids.shape[1] // delta.shape[0], dim=0)
vision_positions = position_ids + delta.expand_as(position_ids)
vision_positions = vision_positions.expand(3, vision_positions.shape[1], -1)

# Concatenate "text + vision" positions into [4, bs, seq-len]
if "position_ids" not in model_inputs:
text_positions = torch.arange(input_ids, device=input_ids.device)[None, None, :]
else:
text_positions = model_inputs["position_ids"][None, ...]
model_inputs["position_ids"] = torch.cat([text_positions, vision_positions], dim=0)
raise ValueError("position_ids not found in model_inputs")

model_inputs["position_ids"] = vision_positions

if cache_position[0] != 0:
model_inputs["pixel_values"] = None
Expand Down