Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 0 additions & 3 deletions src/transformers/models/aimv2/modeling_aimv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
from ...modeling_utils import ALL_ATTENTION_FUNCTIONS, PreTrainedModel
from ...processing_utils import Unpack
from ...utils import ModelOutput, TransformersKwargs, auto_docstring, can_return_tuple, filter_out_non_signature_kwargs
from ...utils.deprecation import deprecate_kwarg
from ...utils.generic import check_model_inputs
from .configuration_aimv2 import Aimv2Config, Aimv2TextConfig, Aimv2VisionConfig

Expand Down Expand Up @@ -444,13 +443,11 @@ def __init__(self, config: Aimv2VisionConfig):
def get_input_embeddings(self) -> nn.Module:
return self.embeddings.patch_embed

@deprecate_kwarg("attention_mask", version="v4.58.0")
@check_model_inputs(tie_last_hidden_states=False)
@auto_docstring
def forward(
self,
pixel_values,
Comment thread
zucchini-nlp marked this conversation as resolved.
attention_mask: Optional[torch.Tensor] = None,
**kwargs: Unpack[TransformersKwargs],
) -> BaseModelOutputWithPooling:
r"""
Expand Down
3 changes: 0 additions & 3 deletions src/transformers/models/aimv2/modular_aimv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
auto_docstring,
can_return_tuple,
)
from ...utils.deprecation import deprecate_kwarg
from ...utils.generic import check_model_inputs
from ..clip.modeling_clip import CLIPModel, CLIPTextEmbeddings, _get_vector_norm
from ..llama.modeling_llama import LlamaMLP, LlamaRMSNorm
Expand Down Expand Up @@ -487,13 +486,11 @@ def __init__(self, config: Aimv2VisionConfig):
def get_input_embeddings(self) -> nn.Module:
return self.embeddings.patch_embed

@deprecate_kwarg("attention_mask", version="v4.58.0")
@check_model_inputs(tie_last_hidden_states=False)
@auto_docstring
def forward(
self,
pixel_values,
attention_mask: Optional[torch.Tensor] = None,
**kwargs: Unpack[TransformersKwargs],
) -> BaseModelOutputWithPooling:
r"""
Expand Down
2 changes: 0 additions & 2 deletions src/transformers/models/altclip/processing_altclip.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"""

from ...processing_utils import ProcessorMixin
from ...utils.deprecation import deprecate_kwarg


class AltCLIPProcessor(ProcessorMixin):
Expand All @@ -39,7 +38,6 @@ class AltCLIPProcessor(ProcessorMixin):
image_processor_class = ("CLIPImageProcessor", "CLIPImageProcessorFast")
tokenizer_class = ("XLMRobertaTokenizer", "XLMRobertaTokenizerFast")

@deprecate_kwarg(old_name="feature_extractor", version="5.0.0", new_name="image_processor")
def __init__(self, image_processor=None, tokenizer=None):
super().__init__(image_processor, tokenizer)

Expand Down
23 changes: 0 additions & 23 deletions src/transformers/models/beit/modeling_beit.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import collections.abc
import math
import warnings
from dataclasses import dataclass
from typing import Optional, Union

Expand Down Expand Up @@ -163,14 +162,7 @@ def forward(
self,
pixel_values: torch.Tensor,
bool_masked_pos: Optional[torch.BoolTensor] = None,
interpolate_pos_encoding: Optional[bool] = None,
) -> torch.Tensor:
if self.position_embeddings is not None and interpolate_pos_encoding is not None:
warnings.warn(
"`interpolate_pos_encoding` argument has no effect for BEiTEmbeddings, embeddings are always "
"interpolated to the input image size. The argument will be removed in transformers v4.51.0."
)

_, _, height, width = pixel_values.shape
embeddings, (patch_height, patch_width) = self.patch_embeddings(pixel_values)
batch_size, seq_len, _ = embeddings.size()
Expand Down Expand Up @@ -323,21 +315,6 @@ def forward(
interpolate_pos_encoding: bool = False,
resolution: Optional[tuple[int]] = None,
) -> Union[tuple[torch.Tensor], tuple[torch.Tensor, torch.Tensor]]:
if output_attentions:
logger.warning_once(
"`BeitSdpaSelfAttention` is used but `torch.nn.functional.scaled_dot_product_attention` does not "
"support `output_attentions=True`. Falling back to the manual attention implementation, "
"but specifying the manual implementation will be required from Transformers version v5.0.0 onwards. "
'This warning can be removed using the argument `attn_implementation="eager"` when loading the model.'
)
return super().forward(
hidden_states=hidden_states,
output_attentions=output_attentions,
relative_position_bias=relative_position_bias,
interpolate_pos_encoding=interpolate_pos_encoding,
resolution=resolution,
)

Comment thread
zucchini-nlp marked this conversation as resolved.
batch_size, seq_length, _ = hidden_states.shape
query_layer = (
self.query(hidden_states)
Expand Down
32 changes: 3 additions & 29 deletions src/transformers/models/blip_2/modeling_blip_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"""PyTorch BLIP-2 model."""

import math
import warnings
from collections.abc import Callable
from dataclasses import dataclass
from typing import Any, Optional, Union
Expand Down Expand Up @@ -1088,7 +1087,6 @@ def get_text_features(
decoder_input_ids: Optional[torch.Tensor] = None,
decoder_attention_mask: Optional[torch.Tensor] = None,
labels: Optional[torch.Tensor] = None,
legacy_output: bool = True,
) -> Union[torch.FloatTensor, CausalLMOutputWithPast]:
r"""
decoder_input_ids (`torch.LongTensor` of shape `(batch_size, target_sequence_length)`, *optional*):
Expand Down Expand Up @@ -1127,13 +1125,6 @@ def get_text_features(
... text_features = model.get_text_features(**inputs)
```"""

if legacy_output:
warnings.warn(
"Deprecation notice: In Transformers v4.59, the default return value of `get_text_features` will change. "
"Currently, this method returns a model output object, but starting in v4.59, it will return a tensor instead. "
"To opt in to the new behavior now, set `legacy_output=False`."
)

if self.config.use_decoder_only_language_model:
text_outputs: CausalLMOutputWithPast = self.language_model(
input_ids=input_ids,
Expand All @@ -1151,15 +1142,14 @@ def get_text_features(
return_dict=True,
)

return text_outputs if legacy_output else text_outputs.logits
return text_outputs.logits

@filter_out_non_signature_kwargs()
@auto_docstring
def get_image_features(
self,
pixel_values: torch.FloatTensor,
interpolate_pos_encoding: bool = False,
legacy_output: bool = True,
) -> Union[torch.FloatTensor, CausalLMOutputWithPast]:
r"""
legacy_output (`bool`, *optional*, defaults to `True`):
Expand All @@ -1185,28 +1175,20 @@ def get_image_features(
>>> with torch.inference_mode():
... image_outputs = model.get_image_features(**inputs)
```"""
if legacy_output:
warnings.warn(
"Deprecation notice: In Transformers v4.59, the default return value of `get_text_features` will change. "
"Currently, this method returns a model output object, but starting in v4.59, it will return a tensor instead. "
"To opt in to the new behavior now, set `legacy_output=False`."
)

vision_outputs = self.vision_model(
pixel_values=pixel_values,
interpolate_pos_encoding=interpolate_pos_encoding,
return_dict=True,
)

return vision_outputs if legacy_output else vision_outputs.pooler_output
return vision_outputs.pooler_output

@filter_out_non_signature_kwargs()
@auto_docstring
def get_qformer_features(
self,
pixel_values: torch.FloatTensor,
interpolate_pos_encoding: bool = False,
legacy_output: bool = True,
) -> Union[torch.FloatTensor, BaseModelOutputWithPooling]:
r"""
legacy_output (`bool`, *optional*, defaults to `True`):
Expand All @@ -1233,14 +1215,6 @@ def get_qformer_features(
>>> with torch.inference_mode():
... qformer_outputs = model.get_qformer_features(**inputs)
```"""

if legacy_output:
warnings.warn(
"Deprecation notice: In Transformers v4.59, the default return value of `get_qformer_features` will change. "
"Currently, this method returns a model output object, but starting in v4.59, it will return a tensor instead. "
"To opt in to the new behavior now, set `legacy_output=False`."
)

vision_outputs: BaseModelOutputWithPooling = self.vision_model(
pixel_values=pixel_values,
interpolate_pos_encoding=interpolate_pos_encoding,
Expand All @@ -1260,7 +1234,7 @@ def get_qformer_features(
return_dict=True,
)

return query_outputs if legacy_output else query_outputs.last_hidden_state
return query_outputs.last_hidden_state

def get_placeholder_mask(self, input_ids: torch.LongTensor, inputs_embeds: torch.FloatTensor):
"""
Expand Down
50 changes: 2 additions & 48 deletions src/transformers/models/bloom/modeling_bloom.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"""PyTorch BLOOM model."""

import math
import warnings
from typing import Optional, Union

import torch
Expand Down Expand Up @@ -491,7 +490,6 @@ def forward(
output_hidden_states: Optional[bool] = None,
return_dict: Optional[bool] = None,
cache_position: Optional[torch.LongTensor] = None,
**deprecated_arguments,
) -> Union[tuple[torch.Tensor, ...], BaseModelOutputWithPastAndCrossAttentions]:
r"""
input_ids (`torch.LongTensor` of shape `(batch_size, input_ids_length)`):
Expand All @@ -506,16 +504,6 @@ def forward(

[What are input IDs?](../glossary#input-ids)
"""
if deprecated_arguments.pop("position_ids", False) is not False:
# `position_ids` could have been `torch.Tensor` or `None` so defaulting pop to `False` allows to detect if users were passing explicitly `None`
warnings.warn(
"`position_ids` have no functionality in BLOOM and will be removed in v5.0.0. You can safely ignore"
" passing `position_ids`.",
FutureWarning,
)
if len(deprecated_arguments) > 0:
raise ValueError(f"Got unexpected arguments: {deprecated_arguments}")

output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
output_hidden_states = (
output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
Expand Down Expand Up @@ -823,7 +811,7 @@ def forward(
output_hidden_states: Optional[bool] = None,
return_dict: Optional[bool] = None,
cache_position: Optional[torch.LongTensor] = None,
**deprecated_arguments,
**kwargs,
) -> Union[tuple[torch.Tensor], CausalLMOutputWithCrossAttentions]:
r"""
input_ids (`torch.LongTensor` of shape `(batch_size, input_ids_length)`):
Expand All @@ -842,18 +830,6 @@ def forward(
`labels = input_ids` Indices are selected in `[-100, 0, ..., config.vocab_size]` All labels set to `-100`
are ignored (masked), the loss is only computed for labels in `[0, ..., config.vocab_size]`
"""
# Bloom has deprecated kwargs, so we need to pop num_items_in_batch explicitly
num_items_in_batch = deprecated_arguments.pop("num_items_in_batch", None)
if deprecated_arguments.pop("position_ids", False) is not False:
# `position_ids` could have been `torch.Tensor` or `None` so defaulting pop to `False` allows to detect if users were passing explicitly `None`
warnings.warn(
"`position_ids` have no functionality in BLOOM and will be removed in v5.0.0. You can safely ignore"
" passing `position_ids`.",
FutureWarning,
)
if len(deprecated_arguments) > 0:
raise ValueError(f"Got unexpected arguments: {deprecated_arguments}")

return_dict = return_dict if return_dict is not None else self.config.use_return_dict

transformer_outputs = self.transformer(
Expand All @@ -880,7 +856,7 @@ def forward(
lm_logits,
labels,
vocab_size=self.config.vocab_size,
num_items_in_batch=num_items_in_batch,
num_items_in_batch=kwargs["num_items_in_batch"],
)

if not return_dict:
Expand Down Expand Up @@ -932,7 +908,6 @@ def forward(
output_attentions: Optional[bool] = None,
output_hidden_states: Optional[bool] = None,
return_dict: Optional[bool] = None,
**deprecated_arguments,
) -> Union[tuple[torch.Tensor], SequenceClassifierOutputWithPast]:
r"""
input_ids (`torch.LongTensor` of shape `(batch_size, input_ids_length)`):
Expand All @@ -951,16 +926,6 @@ def forward(
config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
`config.num_labels > 1` a classification loss is computed (Cross-Entropy).
"""
if deprecated_arguments.pop("position_ids", False) is not False:
# `position_ids` could have been `torch.Tensor` or `None` so defaulting pop to `False` allows to detect if users were passing explicitly `None`
warnings.warn(
"`position_ids` have no functionality in BLOOM and will be removed in v5.0.0. You can safely ignore"
" passing `position_ids`.",
FutureWarning,
)
if len(deprecated_arguments) > 0:
raise ValueError(f"Got unexpected arguments: {deprecated_arguments}")

return_dict = return_dict if return_dict is not None else self.config.use_return_dict

transformer_outputs = self.transformer(
Expand Down Expand Up @@ -1066,7 +1031,6 @@ def forward(
output_attentions: Optional[bool] = None,
output_hidden_states: Optional[bool] = None,
return_dict: Optional[bool] = None,
**deprecated_arguments,
) -> Union[tuple[torch.Tensor], TokenClassifierOutput]:
r"""
input_ids (`torch.LongTensor` of shape `(batch_size, input_ids_length)`):
Expand All @@ -1085,16 +1049,6 @@ def forward(
config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
`config.num_labels > 1` a classification loss is computed (Cross-Entropy).
"""
if deprecated_arguments.pop("position_ids", False) is not False:
# `position_ids` could have been `torch.Tensor` or `None` so defaulting pop to `False` allows to detect if users were passing explicitly `None`
warnings.warn(
"`position_ids` have no functionality in BLOOM and will be removed in v5.0.0. You can safely ignore"
" passing `position_ids`.",
FutureWarning,
)
if len(deprecated_arguments) > 0:
raise ValueError(f"Got unexpected arguments: {deprecated_arguments}")

return_dict = return_dict if return_dict is not None else self.config.use_return_dict

transformer_outputs = self.transformer(
Expand Down
30 changes: 1 addition & 29 deletions src/transformers/models/clap/processing_clap.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,8 @@
Audio/Text processor class for CLAP
"""

from typing import Optional, Union

from ...audio_utils import AudioInput
from ...processing_utils import ProcessingKwargs, ProcessorMixin, Unpack
from ...tokenization_utils_base import PreTokenizedInput, TextInput
from ...processing_utils import ProcessorMixin
from ...utils import logging
from ...utils.deprecation import deprecate_kwarg


logger = logging.get_logger(__name__)
Expand All @@ -48,28 +43,5 @@ class ClapProcessor(ProcessorMixin):
def __init__(self, feature_extractor, tokenizer):
super().__init__(feature_extractor, tokenizer)

@deprecate_kwarg("audios", version="v4.59.0", new_name="audio")
def __call__(
self,
text: Optional[Union[TextInput, PreTokenizedInput, list[TextInput], list[PreTokenizedInput]]] = None,
audios: Optional[AudioInput] = None,
audio: Optional[AudioInput] = None,
**kwargs: Unpack[ProcessingKwargs],
):
"""
Forwards the `audio` and `sampling_rate` arguments to [`~ClapFeatureExtractor.__call__`] and the `text`
argument to [`~RobertaTokenizerFast.__call__`]. Please refer to the docstring of the above two methods for more
information.
"""
# The `deprecate_kwarg` will not work if the inputs are passed as arguments, so we check
# again that the correct naming is used
if audios is not None and audio is None:
logger.warning(
"Using `audios` keyword argument is deprecated when calling ClapProcessor, instead use `audio`."
)
audio = audios

return super().__call__(text=text, audio=audio, **kwargs)


__all__ = ["ClapProcessor"]
Loading
Loading