[MM] Keep raw pixels through dp-sharded ViT path (#56872)
Signed-off-by: cjackal <44624812+cjackal@users.noreply.github.com>
This commit is contained in:
@@ -1441,7 +1441,7 @@ class Qwen2_5_VLForConditionalGeneration(
|
|||||||
if self.use_data_parallel:
|
if self.use_data_parallel:
|
||||||
return run_dp_sharded_mrope_vision_model(
|
return run_dp_sharded_mrope_vision_model(
|
||||||
self.visual,
|
self.visual,
|
||||||
pixel_values.type(self.visual.dtype),
|
pixel_values,
|
||||||
grid_thw_list,
|
grid_thw_list,
|
||||||
rope_type="rope_3d",
|
rope_type="rope_3d",
|
||||||
)
|
)
|
||||||
@@ -1501,7 +1501,7 @@ class Qwen2_5_VLForConditionalGeneration(
|
|||||||
if self.use_data_parallel:
|
if self.use_data_parallel:
|
||||||
return run_dp_sharded_mrope_vision_model(
|
return run_dp_sharded_mrope_vision_model(
|
||||||
self.visual,
|
self.visual,
|
||||||
pixel_values_videos.type(self.visual.dtype),
|
pixel_values_videos,
|
||||||
grid_thw_list,
|
grid_thw_list,
|
||||||
rope_type="rope_3d",
|
rope_type="rope_3d",
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1379,7 +1379,7 @@ class Qwen2VLForConditionalGeneration(
|
|||||||
if self.use_data_parallel:
|
if self.use_data_parallel:
|
||||||
return run_dp_sharded_mrope_vision_model(
|
return run_dp_sharded_mrope_vision_model(
|
||||||
self.visual,
|
self.visual,
|
||||||
pixel_values.type(self.visual.dtype),
|
pixel_values,
|
||||||
grid_thw.tolist(),
|
grid_thw.tolist(),
|
||||||
rope_type="rope_3d",
|
rope_type="rope_3d",
|
||||||
)
|
)
|
||||||
@@ -1404,7 +1404,7 @@ class Qwen2VLForConditionalGeneration(
|
|||||||
if self.use_data_parallel:
|
if self.use_data_parallel:
|
||||||
return run_dp_sharded_mrope_vision_model(
|
return run_dp_sharded_mrope_vision_model(
|
||||||
self.visual,
|
self.visual,
|
||||||
pixel_values_videos.type(self.visual.dtype),
|
pixel_values_videos,
|
||||||
grid_thw.tolist(),
|
grid_thw.tolist(),
|
||||||
rope_type="rope_3d",
|
rope_type="rope_3d",
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -481,6 +481,7 @@ def run_dp_sharded_mrope_vision_model(
|
|||||||
# to work
|
# to work
|
||||||
max_len_per_rank = max(grouped_pixel_values_len) // embed_dim_reduction_factor
|
max_len_per_rank = max(grouped_pixel_values_len) // embed_dim_reduction_factor
|
||||||
local_grid_thw_list = [grid_thw_list[i] for i in image_idxs_local]
|
local_grid_thw_list = [grid_thw_list[i] for i in image_idxs_local]
|
||||||
|
embed_dtype = next(vision_model.parameters()).dtype
|
||||||
|
|
||||||
# Run the vision model on the local pixel_values_local
|
# Run the vision model on the local pixel_values_local
|
||||||
if rope_type == "rope_2d":
|
if rope_type == "rope_2d":
|
||||||
@@ -495,7 +496,7 @@ def run_dp_sharded_mrope_vision_model(
|
|||||||
image_embeds_local = torch.empty(
|
image_embeds_local = torch.empty(
|
||||||
(0, embed_dim_reduction_factor, out_dim),
|
(0, embed_dim_reduction_factor, out_dim),
|
||||||
device=pixel_values.device,
|
device=pixel_values.device,
|
||||||
dtype=pixel_values.dtype,
|
dtype=embed_dtype,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
if pixel_values_local.shape[0] > 0:
|
if pixel_values_local.shape[0] > 0:
|
||||||
@@ -505,7 +506,7 @@ def run_dp_sharded_mrope_vision_model(
|
|||||||
image_embeds_local = torch.empty(
|
image_embeds_local = torch.empty(
|
||||||
(0, vision_model.out_hidden_size),
|
(0, vision_model.out_hidden_size),
|
||||||
device=pixel_values.device,
|
device=pixel_values.device,
|
||||||
dtype=pixel_values.dtype,
|
dtype=embed_dtype,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Pad the output based on max_len_per_rank
|
# Pad the output based on max_len_per_rank
|
||||||
|
|||||||
Reference in New Issue
Block a user