Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from ...processing_utils import ProcessorMixin
from ...tokenization_python import PreTokenizedInput, TextInput
from ...utils import auto_docstring, is_torch_available, logging
from ...utils.deprecation import deprecate_kwarg
from ...utils.import_utils import requires_backends


Expand All @@ -30,9 +31,10 @@

@auto_docstring
class GraniteSpeechProcessor(ProcessorMixin):
@deprecate_kwarg("audio_processor", new_name="feature_extractor", version="v5.20")
def __init__(
self,
audio_processor,
feature_extractor,
tokenizer,
audio_token="<|audio|>",
chat_template=None,
Expand All @@ -44,7 +46,12 @@ def __init__(
audio tokens inserted depends on the audio feature dimensions extracted by the audio processor.
"""
self.audio_token = tokenizer.audio_token if hasattr(tokenizer, "audio_token") else audio_token
super().__init__(audio_processor, tokenizer, chat_template=chat_template)
super().__init__(feature_extractor, tokenizer, chat_template=chat_template)

@property
def audio_processor(self):
logger.warning_once("`audio_processor` is deprecated! Use `feature_extractor` instead!")
return self.feature_extractor

@auto_docstring
def __call__(
Expand All @@ -64,7 +71,7 @@ def __call__(
# text / audio inputs here because some inference engines will
# trigger the conditions due to the way they call multimodal
# processors, e.g., vLLM.
audio_inputs = self.audio_processor(audio, device=device)
audio_inputs = self.feature_extractor(audio, device=device)

# TODO (@alex-jw-brooks); we should add a util to get_num_audio_tokens
# from feature lengths and call it here, rather than returning it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from ...processing_utils import ProcessingKwargs, ProcessorMixin, Unpack
from ...tokenization_utils_base import TextInput
from ...utils import auto_docstring, logging
from ...utils.deprecation import deprecate_kwarg


logger = logging.get_logger(__name__)
Expand All @@ -39,18 +40,24 @@ class Phi4MultimodalProcessorKwargs(ProcessingKwargs, total=False):

@auto_docstring
class Phi4MultimodalProcessor(ProcessorMixin):
@deprecate_kwarg("audio_processor", new_name="feature_extractor", version="v5.20")
def __init__(
self,
image_processor,
audio_processor,
feature_extractor,
tokenizer,
**kwargs,
):
self.image_token = tokenizer.image_token
self.image_token_id = tokenizer.image_token_id
self.audio_token = tokenizer.audio_token
self.audio_token_id = tokenizer.audio_token_id
super().__init__(image_processor, audio_processor, tokenizer, **kwargs)
super().__init__(image_processor, feature_extractor, tokenizer, **kwargs)

@property
def audio_processor(self):
logger.warning_once("`audio_processor` is deprecated! Use `feature_extractor` instead!")
return self.feature_extractor

@auto_docstring
def __call__(
Expand Down Expand Up @@ -78,7 +85,7 @@ def __call__(
audio_kwargs = output_kwargs["audio_kwargs"]

image_inputs = self.image_processor(images, **image_kwargs) if images is not None else {}
audio_inputs = self.audio_processor(audio, **audio_kwargs) if audio is not None else {}
audio_inputs = self.feature_extractor(audio, **audio_kwargs) if audio is not None else {}

# We pop here for images as we don't need it later
num_img_tokens = image_inputs.pop("num_img_tokens", [])
Expand Down