From 3640116397125123594bcac08f9f63a0b6c2152d Mon Sep 17 00:00:00 2001 From: AndyLi429 <68410213+AndyLi429@users.noreply.github.com> Date: Thu, 14 May 2026 14:21:11 +0800 Subject: [PATCH] [NPU]Bugfix:Set default values for npu_wrapper_preprocess parameters (#25130) --- .../npu/attention/ascend_gdn_backend.py | 2 +- .../npu/modules/qwen_vl_processor.py | 27 ++++++++----------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/python/sglang/srt/hardware_backend/npu/attention/ascend_gdn_backend.py b/python/sglang/srt/hardware_backend/npu/attention/ascend_gdn_backend.py index 7c481e0f3..cdb1dadb7 100644 --- a/python/sglang/srt/hardware_backend/npu/attention/ascend_gdn_backend.py +++ b/python/sglang/srt/hardware_backend/npu/attention/ascend_gdn_backend.py @@ -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, ) diff --git a/python/sglang/srt/hardware_backend/npu/modules/qwen_vl_processor.py b/python/sglang/srt/hardware_backend/npu/modules/qwen_vl_processor.py index e761bf1b4..5dadafac6 100644 --- a/python/sglang/srt/hardware_backend/npu/modules/qwen_vl_processor.py +++ b/python/sglang/srt/hardware_backend/npu/modules/qwen_vl_processor.py @@ -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], )