[NPU]Bugfix:Set default values for npu_wrapper_preprocess parameters (#25130)
This commit is contained in:
@@ -414,7 +414,7 @@ class AscendGDNAttnBackend(AscendMambaAttnBackendBase):
|
||||
nv=num_value_heads,
|
||||
intermediate_state=intermediate_state,
|
||||
cache_indices=cache_indices,
|
||||
num_accept_tokens=num_accept_tokens,
|
||||
num_accepted_tokens=num_accept_tokens,
|
||||
g=g,
|
||||
)
|
||||
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
from typing import Optional
|
||||
|
||||
import torch
|
||||
import torchvision.transforms.v2.functional as tvF
|
||||
from transformers.image_processing_utils import BatchFeature
|
||||
from transformers.image_processing_utils_fast import (
|
||||
group_images_by_shape,
|
||||
reorder_images,
|
||||
)
|
||||
from transformers.image_transforms import group_images_by_shape, reorder_images
|
||||
from transformers.image_utils import (
|
||||
ChannelDimension,
|
||||
PILImageResampling,
|
||||
@@ -63,8 +58,8 @@ def transform_patches_to_flatten(
|
||||
return flatten_patches
|
||||
|
||||
|
||||
# Func refers to transformers.models.qwen2_vl.image_processing_qwen2_vl_fast.py
|
||||
# Qwen2VLImageProcessorFast._preprocess
|
||||
# Func refers to transformers.models.qwen2_vl.image_processing_qwen2_vl.py
|
||||
# Qwen2VLImageProcessor._preprocess
|
||||
def npu_wrapper_preprocess(func):
|
||||
|
||||
def _preprocess(
|
||||
@@ -72,7 +67,7 @@ def npu_wrapper_preprocess(func):
|
||||
images: list["torch.Tensor"],
|
||||
do_resize: bool,
|
||||
size: SizeDict,
|
||||
interpolation: Optional["tvF.InterpolationMode"],
|
||||
resample: "PILImageResampling | tvF.InterpolationMode | int | None",
|
||||
do_rescale: bool,
|
||||
rescale_factor: float,
|
||||
do_normalize: bool,
|
||||
@@ -97,13 +92,13 @@ def npu_wrapper_preprocess(func):
|
||||
height,
|
||||
width,
|
||||
factor=patch_size * merge_size,
|
||||
min_pixels=size["shortest_edge"],
|
||||
max_pixels=size["longest_edge"],
|
||||
min_pixels=size.shortest_edge,
|
||||
max_pixels=size.longest_edge,
|
||||
)
|
||||
stacked_images = self.resize(
|
||||
image=stacked_images,
|
||||
size=SizeDict(height=resized_height, width=resized_width),
|
||||
interpolation=interpolation,
|
||||
resample=resample,
|
||||
)
|
||||
resized_images_grouped[shape] = stacked_images
|
||||
resized_images = reorder_images(resized_images_grouped, grouped_images_index)
|
||||
@@ -173,7 +168,7 @@ def npu_wrapper_preprocess(func):
|
||||
|
||||
|
||||
# Func refers to transformers.models.qwen3_vl.video_processing_qwen3_vl.py
|
||||
# Qwen3VLVideoProcessorFast._preprocess
|
||||
# Qwen3VLVideoProcessor._preprocess
|
||||
def npu_wrapper_video_preprocess(func):
|
||||
|
||||
def _preprocess(
|
||||
@@ -182,7 +177,7 @@ def npu_wrapper_video_preprocess(func):
|
||||
do_convert_rgb: bool = True,
|
||||
do_resize: bool = True,
|
||||
size: SizeDict | None = None,
|
||||
interpolation: PILImageResampling = PILImageResampling.BICUBIC,
|
||||
resample: "PILImageResampling | tvF.InterpolationMode | int | None" = PILImageResampling.BICUBIC,
|
||||
do_rescale: bool = True,
|
||||
rescale_factor: float = 1 / 255.0,
|
||||
do_normalize: bool = True,
|
||||
@@ -214,7 +209,7 @@ def npu_wrapper_video_preprocess(func):
|
||||
stacked_videos = self.resize(
|
||||
stacked_videos,
|
||||
size=SizeDict(height=resized_height, width=resized_width),
|
||||
interpolation=interpolation,
|
||||
resample=resample,
|
||||
)
|
||||
stacked_videos = stacked_videos.view(
|
||||
B, T, C, resized_height, resized_width
|
||||
@@ -297,7 +292,7 @@ def npu_apply_qwen_image_preprocess_patch():
|
||||
if _npu_preprocess_patched:
|
||||
return
|
||||
apply_module_patch(
|
||||
"transformers.models.qwen2_vl.image_processing_qwen2_vl_fast.Qwen2VLImageProcessorFast",
|
||||
"transformers.models.qwen2_vl.image_processing_qwen2_vl.Qwen2VLImageProcessor",
|
||||
"_preprocess",
|
||||
[npu_wrapper_preprocess],
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user