forked from vllm-project/vllm
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bugfix] Qwen2.5_VL fix from Qwen Team #2
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -773,8 +773,12 @@ def __init__( | |
dtype: torch.dtype, | ||
mrope_section: Optional[List[int]] = None, | ||
) -> None: | ||
super().__init__(head_size, rotary_dim, max_position_embeddings, base, | ||
is_neox_style, dtype) | ||
# In Qwen2.5-VL, the maximum index value is related to the duration of | ||
# the input video. We enlarge max_position_embeddings to 4 times to get | ||
# a larger the cos and sin cache. | ||
self.cache_max_position_num = max_position_embeddings * 4 | ||
super().__init__(head_size, rotary_dim, self.cache_max_position_num, | ||
base, is_neox_style, dtype) | ||
|
||
self.mrope_section = mrope_section | ||
if self.mrope_section: | ||
|
@@ -835,7 +839,7 @@ def get_input_positions( | |
hf_config: PretrainedConfig, | ||
image_grid_thw: Union[List[List[int]], torch.Tensor], | ||
video_grid_thw: Union[List[List[int]], torch.Tensor], | ||
second_per_grid_ts: Optional[List[float]] = None, | ||
video_second_per_grid_ts: Optional[List[float]] = None, | ||
context_len: int = 0, | ||
seq_len: Optional[int] = None, | ||
) -> Tuple[List[List[int]], int]: | ||
|
@@ -847,7 +851,7 @@ def get_input_positions( | |
hf_config=hf_config, | ||
image_grid_thw=image_grid_thw, | ||
video_grid_thw=video_grid_thw, | ||
second_per_grid_ts=second_per_grid_ts, | ||
video_second_per_grid_ts=video_second_per_grid_ts, | ||
context_len=context_len, | ||
seq_len=seq_len, | ||
) | ||
|
@@ -860,7 +864,7 @@ def get_input_positions_tensor( | |
hf_config: PretrainedConfig, | ||
image_grid_thw: Union[List[List[int]], torch.Tensor], | ||
video_grid_thw: Union[List[List[int]], torch.Tensor], | ||
second_per_grid_ts: Optional[List[float]] = None, | ||
video_second_per_grid_ts: Optional[List[float]] = None, | ||
context_len: int = 0, | ||
seq_len: Optional[int] = None, | ||
) -> Tuple[torch.Tensor, int]: | ||
|
@@ -870,8 +874,8 @@ def get_input_positions_tensor( | |
video_token_id = hf_config.video_token_id | ||
vision_start_token_id = hf_config.vision_start_token_id | ||
spatial_merge_size = hf_config.vision_config.spatial_merge_size | ||
tokens_per_second = getattr(hf_config.vision_config, | ||
"tokens_per_second", None) | ||
video_tokens_per_second = getattr(hf_config.vision_config, | ||
"tokens_per_second", 1.0) | ||
Comment on lines
-873
to
+878
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto |
||
|
||
if isinstance(image_grid_thw, torch.Tensor): | ||
image_grid_thw = image_grid_thw.tolist() | ||
|
@@ -891,6 +895,7 @@ def get_input_positions_tensor( | |
|
||
image_index, video_index = 0, 0 | ||
for _ in range(image_nums + video_nums): | ||
video_second_per_grid_t = 0.0 | ||
if image_token_id in input_tokens and remain_images > 0: | ||
ed_image = input_tokens.index(image_token_id, st) | ||
else: | ||
|
@@ -905,7 +910,6 @@ def get_input_positions_tensor( | |
image_grid_thw[image_index][1], | ||
image_grid_thw[image_index][2], | ||
) | ||
second_per_grid_t = 0.0 | ||
image_index += 1 | ||
remain_images -= 1 | ||
ed = ed_image | ||
|
@@ -915,10 +919,10 @@ def get_input_positions_tensor( | |
video_grid_thw[video_index][1], | ||
video_grid_thw[video_index][2], | ||
) | ||
if second_per_grid_ts: | ||
second_per_grid_t = second_per_grid_ts[video_index] | ||
else: | ||
second_per_grid_t = 1.0 | ||
video_second_per_grid_t = 1.0 | ||
if video_second_per_grid_ts is not None: | ||
video_second_per_grid_t = video_second_per_grid_ts[ | ||
video_index] | ||
video_index += 1 | ||
remain_videos -= 1 | ||
ed = ed_video | ||
|
@@ -932,17 +936,9 @@ def get_input_positions_tensor( | |
llm_pos_ids_list.append( | ||
torch.arange(text_len).view(1, -1).expand(3, -1) + st_idx) | ||
|
||
if tokens_per_second is not None: | ||
range_tensor = torch.arange(llm_grid_t).view(-1, 1) | ||
expanded_range = range_tensor.expand(-1, | ||
llm_grid_h * llm_grid_w) | ||
time_tensor = expanded_range * second_per_grid_t * \ | ||
tokens_per_second | ||
time_tensor_long = time_tensor.long() | ||
t_index = time_tensor_long.flatten() | ||
else: | ||
t_index = torch.arange(llm_grid_t).view(-1, 1).expand( | ||
-1, llm_grid_h * llm_grid_w).flatten() | ||
t_index = (torch.arange(llm_grid_t).view(-1, 1).expand( | ||
-1, llm_grid_h * llm_grid_w) * video_second_per_grid_t * | ||
video_tokens_per_second).long().flatten() | ||
|
||
h_index = torch.arange(llm_grid_h).view(1, -1, 1).expand( | ||
llm_grid_t, -1, llm_grid_w).flatten() | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it okay if we keep it as
second_per_grid_ts
? I think generally speaking it's better if we use the same names as those of the output of theProcessor
class unless there's a strong reason for us to use a different one, what do you think?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The term
second_per_grid_ts
is a video-related parameter, so usingvideo_second_per_grid_ts
would be more appropriate from this perspective. However, if you need to maintain consistency with thetransformer
, that is also acceptable.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good! I'll merge this PR and rename it afterwards!