[Misc] Remove unnecessary Transformers version guards (#57556)
Signed-off-by: DarkLight1337 <tlleungac@connect.ust.hk>
This commit is contained in:
@@ -36,9 +36,7 @@ import numpy as np
|
||||
import torch
|
||||
import torch.nn as nn
|
||||
import torch.nn.functional as F
|
||||
import transformers
|
||||
from einops import rearrange
|
||||
from packaging.version import Version
|
||||
from transformers import BatchFeature, Glm4vProcessor
|
||||
from transformers.image_processing_base import ImageProcessingMixin
|
||||
from transformers.models.glm4v.configuration_glm4v import (
|
||||
@@ -132,8 +130,6 @@ logger = init_logger(__name__)
|
||||
# For profile run
|
||||
_MAX_FRAMES_PER_VIDEO = 600
|
||||
|
||||
TRANSFORMERS_WITH_GA = Version(transformers.__version__) >= Version("5.10.0.dev0")
|
||||
|
||||
|
||||
def _to_video_metadata(metadata: Mapping[str, Any]) -> VideoMetadata:
|
||||
return VideoMetadata(
|
||||
@@ -1389,17 +1385,6 @@ class Glm4vProcessingInfo(BaseProcessingInfo):
|
||||
timestamps_list = full_second_idxs[::2]
|
||||
return list(timestamps_list)
|
||||
|
||||
def _get_video_frame_embed_token_id(self, hf_processor: object) -> int:
|
||||
attr = (
|
||||
"image_token_id"
|
||||
if isinstance(hf_processor, Glm4vProcessor) or TRANSFORMERS_WITH_GA
|
||||
else "video_token_id"
|
||||
)
|
||||
token_id = getattr(hf_processor, attr, None)
|
||||
if not isinstance(token_id, int):
|
||||
raise ValueError(f"Processor has no valid {attr}")
|
||||
return token_id
|
||||
|
||||
def _construct_video_placeholder(
|
||||
self,
|
||||
video_array: np.ndarray,
|
||||
@@ -1437,7 +1422,7 @@ class Glm4vProcessingInfo(BaseProcessingInfo):
|
||||
num_tokens_per_frame = int(H * W) // merge_length
|
||||
placeholder = []
|
||||
placeholder.append(bov_token_id)
|
||||
frame_embed_token_id = self._get_video_frame_embed_token_id(hf_processor)
|
||||
frame_embed_token_id = hf_processor.image_token_id
|
||||
for frame_idx in frames_idx_token:
|
||||
placeholder.append(boi_token_id)
|
||||
placeholder.extend([frame_embed_token_id] * num_tokens_per_frame)
|
||||
@@ -1601,10 +1586,7 @@ class Glm4vMultiModalProcessor(BaseMultiModalProcessor[Glm4vProcessingInfo]):
|
||||
|
||||
processor = self.info.get_hf_processor(**hf_kwargs)
|
||||
|
||||
use_direct_path = (
|
||||
not isinstance(processor, Glm4vProcessor) and TRANSFORMERS_WITH_GA
|
||||
)
|
||||
if use_direct_path:
|
||||
if not isinstance(processor, Glm4vProcessor):
|
||||
prepared_data, prepared_kwargs = self._get_direct_path_inputs(
|
||||
hf_data, hf_kwargs
|
||||
)
|
||||
@@ -1627,8 +1609,6 @@ class Glm4vMultiModalProcessor(BaseMultiModalProcessor[Glm4vProcessingInfo]):
|
||||
del hf_data["videos"]
|
||||
video_grid_thw_lst = []
|
||||
pixel_values_videos_lst = []
|
||||
frame_embed_token_id = self.info._get_video_frame_embed_token_id(processor)
|
||||
swap_video_frame_tokens = frame_embed_token_id == processor.image_token_id
|
||||
for item in videos:
|
||||
video_array, metadata = item
|
||||
|
||||
@@ -1651,10 +1631,10 @@ class Glm4vMultiModalProcessor(BaseMultiModalProcessor[Glm4vProcessingInfo]):
|
||||
video_mm_kwargs,
|
||||
)
|
||||
input_ids = video_outputs.pop("input_ids")
|
||||
if swap_video_frame_tokens:
|
||||
input_ids[input_ids == processor.image_token_id] = (
|
||||
processor.video_token_id
|
||||
)
|
||||
|
||||
input_ids[input_ids == processor.image_token_id] = (
|
||||
processor.video_token_id
|
||||
)
|
||||
video_placeholder = processor.tokenizer.batch_decode(input_ids)[0]
|
||||
prompt_text = prompt_text.replace(
|
||||
"<|begin_of_video|><|video|><|end_of_video|>",
|
||||
@@ -1670,17 +1650,15 @@ class Glm4vMultiModalProcessor(BaseMultiModalProcessor[Glm4vProcessingInfo]):
|
||||
)
|
||||
else:
|
||||
video_outputs = dict()
|
||||
swap_video_frame_tokens = False
|
||||
|
||||
processed_data = self.info.ctx.call_hf_processor(
|
||||
self.info.get_hf_processor(**hf_kwargs),
|
||||
dict(text=prompt_text, **hf_data),
|
||||
hf_kwargs,
|
||||
)
|
||||
if swap_video_frame_tokens:
|
||||
input_ids = processed_data["input_ids"]
|
||||
input_ids[input_ids == processor.video_token_id] = processor.image_token_id
|
||||
processed_data["input_ids"] = input_ids
|
||||
input_ids = processed_data["input_ids"]
|
||||
input_ids[input_ids == processor.video_token_id] = processor.image_token_id
|
||||
processed_data["input_ids"] = input_ids
|
||||
|
||||
processed_data.update(video_outputs)
|
||||
return self._finalize_hf_mm_data(
|
||||
@@ -1728,7 +1706,7 @@ class Glm4vMultiModalProcessor(BaseMultiModalProcessor[Glm4vProcessingInfo]):
|
||||
)
|
||||
return PromptUpdateDetails.select_token_id(
|
||||
placeholder,
|
||||
embed_token_id=self.info._get_video_frame_embed_token_id(hf_processor),
|
||||
embed_token_id=hf_processor.image_token_id,
|
||||
)
|
||||
|
||||
return [
|
||||
|
||||
@@ -1228,18 +1228,6 @@ class Qwen3OmniMoeThinkerMultiModalProcessor(
|
||||
) -> HFMultiModalInputs:
|
||||
hf_inputs = super()._get_hf_mm_inputs(mm_items, hf_kwargs)
|
||||
|
||||
if mm_items.get_count("audio", strict=False):
|
||||
# TODO(Isotr0py): Remove this patch after upstream fix PR
|
||||
# released and Transformers version update:
|
||||
# https://github.com/huggingface/transformers/pull/41473
|
||||
hf_inputs = hf_inputs._replace(
|
||||
hf_kwargs={
|
||||
**hf_inputs.hf_kwargs,
|
||||
"audio_kwargs": dict(hf_inputs.hf_kwargs.get("audio_kwargs") or {}),
|
||||
"text_kwargs": dict(hf_inputs.hf_kwargs.get("text_kwargs") or {}),
|
||||
}
|
||||
)
|
||||
|
||||
audios = hf_inputs.hf_data.get("audio")
|
||||
if audios:
|
||||
feature_extractor = self.info.get_feature_extractor()
|
||||
|
||||
Reference in New Issue
Block a user