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