Upgrade transformers==5.3.0 (#17784)
Signed-off-by: Xinyuan Tong <xinyuantong.cs@gmail.com> Co-authored-by: Kangyan-Zhou <zky314343421@gmail.com> Co-authored-by: Alison Shao <alisonshao@mac.lan> Co-authored-by: Mick <mickjagger19@icloud.com>
This commit is contained in:
@@ -48,6 +48,11 @@ from sglang.srt.distributed.communication_op import tensor_model_parallel_all_ga
|
||||
from sglang.srt.utils import flatten_nested_list
|
||||
|
||||
|
||||
def ensure_numpy(x):
|
||||
"""Convert torch.Tensor to numpy array if needed (v5 compat)."""
|
||||
return x.numpy() if isinstance(x, torch.Tensor) else x
|
||||
|
||||
|
||||
def has_valid_data(data) -> bool:
|
||||
if data is None:
|
||||
return False
|
||||
@@ -237,10 +242,11 @@ def process_anyres_image(image, processor, grid_pinpoints):
|
||||
best_resolution = select_best_resolution(image.size, possible_resolutions)
|
||||
image_padded = resize_and_pad_image(image, best_resolution)
|
||||
|
||||
# For Siglip processor, only have size but no crop size
|
||||
# For Siglip processor, only have size but no crop size.
|
||||
# In transformers v5, crop_size may exist but be None.
|
||||
crop_size = (
|
||||
processor.crop_size["height"]
|
||||
if "crop_size" in processor.__dict__
|
||||
if getattr(processor, "crop_size", None) is not None
|
||||
else processor.size["height"]
|
||||
)
|
||||
shortest_edge = (
|
||||
@@ -257,6 +263,8 @@ def process_anyres_image(image, processor, grid_pinpoints):
|
||||
processor.preprocess(image_patch.convert("RGB"))["pixel_values"][0]
|
||||
for image_patch in image_patches
|
||||
]
|
||||
# In transformers v5, image processors may return torch.Tensor instead of numpy arrays
|
||||
image_patches = [ensure_numpy(p) for p in image_patches]
|
||||
return np.stack(image_patches, axis=0)
|
||||
|
||||
|
||||
|
||||
@@ -16,7 +16,11 @@ from sglang.srt.models.llava import (
|
||||
)
|
||||
from sglang.srt.models.llavavid import LlavaVidForCausalLM
|
||||
from sglang.srt.models.mistral import Mistral3ForConditionalGeneration
|
||||
from sglang.srt.multimodal.mm_utils import expand2square, process_anyres_image
|
||||
from sglang.srt.multimodal.mm_utils import (
|
||||
ensure_numpy,
|
||||
expand2square,
|
||||
process_anyres_image,
|
||||
)
|
||||
from sglang.srt.multimodal.processors.base_processor import BaseMultimodalProcessor
|
||||
from sglang.srt.utils import ImageData, load_image, logger
|
||||
from sglang.utils import get_exception_traceback
|
||||
@@ -50,8 +54,8 @@ class LlavaImageProcessor(BaseMultimodalProcessor):
|
||||
# It is a video with multiple images
|
||||
image_hash = hash(url)
|
||||
pixel_values = image_processor(image)["pixel_values"]
|
||||
for _ in range(len(pixel_values)):
|
||||
pixel_values[_] = pixel_values[_].astype(np.float16)
|
||||
for i in range(len(pixel_values)):
|
||||
pixel_values[i] = ensure_numpy(pixel_values[i]).astype(np.float16)
|
||||
pixel_values = np.stack(pixel_values, axis=0)
|
||||
return pixel_values, image_hash, image_size
|
||||
else:
|
||||
@@ -75,6 +79,7 @@ class LlavaImageProcessor(BaseMultimodalProcessor):
|
||||
else:
|
||||
pixel_values = image_processor(image)["pixel_values"][0]
|
||||
|
||||
pixel_values = ensure_numpy(pixel_values)
|
||||
if isinstance(pixel_values, np.ndarray):
|
||||
pixel_values = pixel_values.astype(np.float16)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user