






'''simple docstring'''



import collections.abc
from typing import Optional, Tuple, Union

import torch
import torch.utils.checkpoint
from torch import nn
from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss

from ...activations import ACTaFN
from ...modeling_outputs import BaseModelOutputWithNoAttention, ImageClassifierOutputWithNoAttention
from ...modeling_utils import PreTrainedModel
from ...utils import add_code_sample_docstrings, add_start_docstrings, add_start_docstrings_to_model_forward, logging
from .configuration_poolformer import PoolFormerConfig


SCREAMING_SNAKE_CASE							=						logging.get_logger(__name__)

# General docstring
SCREAMING_SNAKE_CASE							=						'PoolFormerConfig'

# Base docstring
SCREAMING_SNAKE_CASE							=						'sail/poolformer_s12'
SCREAMING_SNAKE_CASE							=						[1, 512, 7, 7]

# Image classification docstring
SCREAMING_SNAKE_CASE							=						'sail/poolformer_s12'
SCREAMING_SNAKE_CASE							=						'tabby, tabby cat'

SCREAMING_SNAKE_CASE							=						[
    'sail/poolformer_s12',
    # See all PoolFormer models at https://huggingface.co/models?filter=poolformer
]


def 				lowercase_					(     __A			:							Optional[Any]       ,   __A			:							float = 0.0       ,   __A			:							bool = False      )							->   Tuple:



 """simple docstring"""




 if drop_prob == 0.0 or not training:
  return input
 lowercase       : str						=1 - drop_prob
 lowercase       : int						=(input.shape[0],) + (1,) * (input.ndim - 1)  # work with diff dim tensors, not just 2D ConvNets
 lowercase       : int						=keep_prob + torch.rand(__A       ,   dtype=input.dtype       ,   device=input.device      )
 random_tensor.floor_()  # binarize
 lowercase       : int						=input.div(__A      ) * random_tensor
 return output
class UpperCAmelCase_       (     nn.Module					):




      """simple docstring"""




      def __init__(			self      :		Dict  ,   UpperCAmelCase      :		Optional[float] = None		)	->	None:


       '''simple docstring'''

       super().__init__()
       lowercase       : Optional[Any]						=drop_prob






      def 					A__   (			self      :		Optional[Any]  ,   UpperCAmelCase      :		torch.Tensor		)	->	torch.Tensor:


       '''simple docstring'''

       return drop_path(UpperCAmelCase  ,   self.drop_prob  ,   self.training		)






      def 					A__   (			self      :		List[Any]		)	->	str:


       '''simple docstring'''

       return "p={}".format(self.drop_prob		)





class UpperCAmelCase_       (     nn.Module					):




      """simple docstring"""




      def __init__(			self      :		Tuple  ,   UpperCAmelCase      :		Union[str, Any]  ,   UpperCAmelCase      :		Optional[int]  ,   UpperCAmelCase      :		int  ,   UpperCAmelCase      :		Union[str, Any]  ,   UpperCAmelCase      :		Optional[Any]  ,   UpperCAmelCase      :		Union[str, Any]=None		)	->	Union[str, Any]:


       '''simple docstring'''

       super().__init__()
       lowercase       : Union[str, Any]						=patch_size if isinstance(UpperCAmelCase  ,   collections.abc.Iterable		) else (patch_size, patch_size)
       lowercase       : Optional[Any]						=stride if isinstance(UpperCAmelCase  ,   collections.abc.Iterable		) else (stride, stride)
       lowercase       : Dict						=padding if isinstance(UpperCAmelCase  ,   collections.abc.Iterable		) else (padding, padding)

       lowercase       : Tuple						=nn.Convad(UpperCAmelCase  ,   UpperCAmelCase  ,   kernel_size=UpperCAmelCase  ,   stride=UpperCAmelCase  ,   padding=UpperCAmelCase		)
       lowercase       : Tuple						=norm_layer(UpperCAmelCase		) if norm_layer else nn.Identity()






      def 					A__   (			self      :		Union[str, Any]  ,   UpperCAmelCase      :		List[Any]		)	->	int:


       '''simple docstring'''

       lowercase       : Optional[Any]						=self.projection(UpperCAmelCase		)
       lowercase       : Dict						=self.norm(UpperCAmelCase		)
       return embeddings





class UpperCAmelCase_       (     nn.GroupNorm					):




      """simple docstring"""




      def __init__(			self      :		int  ,   UpperCAmelCase      :		List[str]  ,   **UpperCAmelCase      :		int		)	->	List[Any]:


       '''simple docstring'''

       super().__init__(1  ,   UpperCAmelCase  ,   **UpperCAmelCase		)





class UpperCAmelCase_       (     nn.Module					):




      """simple docstring"""




      def __init__(			self      :		List[str]  ,   UpperCAmelCase      :		List[str]		)	->	Tuple:


       '''simple docstring'''

       super().__init__()
       lowercase       : Optional[Any]						=nn.AvgPoolad(UpperCAmelCase  ,   stride=1  ,   padding=pool_size // 2  ,   count_include_pad=UpperCAmelCase		)






      def 					A__   (			self      :		Union[str, Any]  ,   UpperCAmelCase      :		Optional[Any]		)	->	int:


       '''simple docstring'''

       return self.pool(UpperCAmelCase		) - hidden_states





class UpperCAmelCase_       (     nn.Module					):




      """simple docstring"""




      def __init__(			self      :		Union[str, Any]  ,   UpperCAmelCase      :		Union[str, Any]  ,   UpperCAmelCase      :		List[str]  ,   UpperCAmelCase      :		List[Any]  ,   UpperCAmelCase      :		List[str]		)	->	Optional[Any]:


       '''simple docstring'''

       super().__init__()
       lowercase       : List[str]						=nn.Convad(UpperCAmelCase  ,   UpperCAmelCase  ,   1		)
       lowercase       : List[str]						=nn.Convad(UpperCAmelCase  ,   UpperCAmelCase  ,   1		)
       lowercase       : int						=PoolFormerDropPath(UpperCAmelCase		)
       if isinstance(config.hidden_act  ,   UpperCAmelCase		):
        lowercase       : List[str]						=ACTaFN[config.hidden_act]
       else:
        lowercase       : str						=config.hidden_act






      def 					A__   (			self      :		str  ,   UpperCAmelCase      :		Optional[int]		)	->	Tuple:


       '''simple docstring'''

       lowercase       : int						=self.conva(UpperCAmelCase		)
       lowercase       : str						=self.act_fn(UpperCAmelCase		)
       lowercase       : str						=self.drop(UpperCAmelCase		)
       lowercase       : Optional[int]						=self.conva(UpperCAmelCase		)
       lowercase       : List[str]						=self.drop(UpperCAmelCase		)

       return hidden_states





class UpperCAmelCase_       (     nn.Module					):




      """simple docstring"""




      def __init__(			self      :		List[str]  ,   UpperCAmelCase      :		Union[str, Any]  ,   UpperCAmelCase      :		str  ,   UpperCAmelCase      :		List[Any]  ,   UpperCAmelCase      :		Optional[Any]  ,   UpperCAmelCase      :		Optional[Any]  ,   UpperCAmelCase      :		int		)	->	str:


       '''simple docstring'''

       super().__init__()
       lowercase       : Tuple						=PoolFormerPooling(UpperCAmelCase		)
       lowercase       : Dict						=PoolFormerOutput(UpperCAmelCase  ,   UpperCAmelCase  ,   UpperCAmelCase  ,   UpperCAmelCase		)
       lowercase       : Optional[Any]						=PoolFormerGroupNorm(UpperCAmelCase		)
       lowercase       : Union[str, Any]						=PoolFormerGroupNorm(UpperCAmelCase		)

       # Useful for training neural nets
       lowercase       : Dict						=PoolFormerDropPath(UpperCAmelCase		) if drop_path > 0.0 else nn.Identity()
       lowercase       : Any						=config.use_layer_scale
       if config.use_layer_scale:
        lowercase       : Dict						=nn.Parameter(
            config.layer_scale_init_value * torch.ones((UpperCAmelCase)		)  ,   requires_grad=UpperCAmelCase		)
        lowercase       : Dict						=nn.Parameter(
            config.layer_scale_init_value * torch.ones((UpperCAmelCase)		)  ,   requires_grad=UpperCAmelCase		)






      def 					A__   (			self      :		Tuple  ,   UpperCAmelCase      :		str		)	->	int:


       '''simple docstring'''

       if self.use_layer_scale:
        lowercase       : Dict						=self.pooling(self.before_norm(UpperCAmelCase		)		)
        lowercase       : Any						=self.layer_scale_a.unsqueeze(-1		).unsqueeze(-1		) * pooling_output
        # First residual connection
        lowercase       : int						=hidden_states + self.drop_path(UpperCAmelCase		)
        lowercase       : Optional[Any]						=()

        lowercase       : Optional[Any]						=self.output(self.after_norm(UpperCAmelCase		)		)
        lowercase       : List[str]						=self.layer_scale_a.unsqueeze(-1		).unsqueeze(-1		) * layer_output
        # Second residual connection
        lowercase       : Optional[int]						=hidden_states + self.drop_path(UpperCAmelCase		)

        lowercase       : Dict						=(output,) + outputs
        return outputs

       else:
        lowercase       : List[Any]						=self.drop_path(self.pooling(self.before_norm(UpperCAmelCase		)		)		)
        # First residual connection
        lowercase       : Optional[Any]						=pooling_output + hidden_states
        lowercase       : int						=()

        # Second residual connection inside the PoolFormerOutput block
        lowercase       : Tuple						=self.drop_path(self.output(self.after_norm(UpperCAmelCase		)		)		)
        lowercase       : List[Any]						=hidden_states + layer_output

        lowercase       : Dict						=(output,) + outputs
        return outputs





class UpperCAmelCase_       (     nn.Module					):




      """simple docstring"""




      def __init__(			self      :		Union[str, Any]  ,   UpperCAmelCase      :		Optional[int]		)	->	Tuple:


       '''simple docstring'''

       super().__init__()
       lowercase       : Tuple						=config
       # stochastic depth decay rule
       lowercase       : Optional[Any]						=[x.item() for x in torch.linspace(0  ,   config.drop_path_rate  ,   sum(config.depths		)		)]

       # patch embeddings
       lowercase       : Union[str, Any]						=[]
       for i in range(config.num_encoder_blocks		):
        embeddings.append(
            PoolFormerEmbeddings(
                patch_size=config.patch_sizes[i]  ,   stride=config.strides[i]  ,   padding=config.padding[i]  ,   num_channels=config.num_channels if i == 0 else config.hidden_sizes[i - 1]  ,   hidden_size=config.hidden_sizes[i]  ,   )		)
       lowercase       : Union[str, Any]						=nn.ModuleList(UpperCAmelCase		)

       # Transformer blocks
       lowercase       : Any						=[]
       lowercase       : Any						=0
       for i in range(config.num_encoder_blocks		):
        # each block consists of layers
        lowercase       : Tuple						=[]
        if i != 0:
         cur += config.depths[i - 1]
        for j in range(config.depths[i]		):
         layers.append(
             PoolFormerLayer(
                 UpperCAmelCase  ,   num_channels=config.hidden_sizes[i]  ,   pool_size=config.pool_size  ,   hidden_size=config.hidden_sizes[i]  ,   intermediate_size=int(config.hidden_sizes[i] * config.mlp_ratio		)  ,   drop_path=dpr[cur + j]  ,   )		)
        blocks.append(nn.ModuleList(UpperCAmelCase		)		)

       lowercase       : Union[str, Any]						=nn.ModuleList(UpperCAmelCase		)






      def 					A__   (			self      :		List[Any]  ,   UpperCAmelCase      :		Union[str, Any]  ,   UpperCAmelCase      :		Dict=False  ,   UpperCAmelCase      :		Optional[int]=True		)	->	List[Any]:


       '''simple docstring'''

       lowercase       : List[str]						=() if output_hidden_states else None

       lowercase       : int						=pixel_values
       for idx, layers in enumerate(zip(self.patch_embeddings  ,   self.block		)		):
        lowercase	,		lowercase       : List[Any]						=layers
        # Get patch embeddings from hidden_states
        lowercase       : List[Any]						=embedding_layer(UpperCAmelCase		)
        # Send the embeddings through the blocks
        for _, blk in enumerate(UpperCAmelCase		):
         lowercase       : str						=blk(UpperCAmelCase		)
         lowercase       : Dict						=layer_outputs[0]

        if output_hidden_states:
         lowercase       : int						=all_hidden_states + (hidden_states,)

       if not return_dict:
        return tuple(v for v in [hidden_states, all_hidden_states] if v is not None		)

       return BaseModelOutputWithNoAttention(last_hidden_state=UpperCAmelCase  ,   hidden_states=UpperCAmelCase		)





class UpperCAmelCase_       (     __A					):




      """simple docstring"""




      UpperCamelCase_             =      PoolFormerConfig
      UpperCamelCase_             =      '''poolformer'''
      UpperCamelCase_             =      '''pixel_values'''
      UpperCamelCase_             =      True






      def 					A__   (			self      :		str  ,   UpperCAmelCase      :		Any		)	->	Any:


       '''simple docstring'''

       if isinstance(UpperCAmelCase  ,   (nn.Linear, nn.Convad)		):
        module.weight.data.normal_(mean=0.0  ,   std=self.config.initializer_range		)
        if module.bias is not None:
         module.bias.data.zero_()
       elif isinstance(UpperCAmelCase  ,   nn.LayerNorm		):
        module.bias.data.zero_()
        module.weight.data.fill_(1.0		)






      def 					A__   (			self      :		Dict  ,   UpperCAmelCase      :		Tuple  ,   UpperCAmelCase      :		Optional[int]=False		)	->	int:


       '''simple docstring'''

       if isinstance(UpperCAmelCase  ,   UpperCAmelCase		):
        lowercase       : Optional[int]						=value





SCREAMING_SNAKE_CASE							=						r'\n    This model is a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) sub-class. Use\n    it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and\n    behavior.\n\n    Parameters:\n        config ([`PoolFormerConfig`]): Model configuration class with all the parameters of the model.\n            Initializing with a config file does not load the weights associated with the model, only the\n            configuration. Check out the [`~PreTrainedModel.from_pretrained`] method to load the model weights.\n'

SCREAMING_SNAKE_CASE							=						r'\n    Args:\n        pixel_values (`torch.FloatTensor` of shape `(batch_size, num_channels, height, width)`):\n            Pixel values. Pixel values can be obtained using [`AutoImageProcessor`]. See\n            [`PoolFormerImageProcessor.__call__`] for details.\n'
@add_start_docstrings(
    '''The bare PoolFormer Model transformer outputting raw hidden-states without any specific head on top.'''					,							__A					,							)
class UpperCAmelCase_       (     __A					):




      """simple docstring"""




      def __init__(			self      :		str  ,   UpperCAmelCase      :		Union[str, Any]		)	->	Any:


       '''simple docstring'''

       super().__init__(UpperCAmelCase		)
       lowercase       : str						=config

       lowercase       : str						=PoolFormerEncoder(UpperCAmelCase		)

       # Initialize weights and apply final processing
       self.post_init()






      def 					A__   (			self      :		str		)	->	Tuple:


       '''simple docstring'''

       return self.embeddings.patch_embeddings






      @add_start_docstrings_to_model_forward(UpperCAmelCase		)
      @add_code_sample_docstrings(
          checkpoint=_CHECKPOINT_FOR_DOC  ,   output_type=UpperCAmelCase  ,   config_class=_CONFIG_FOR_DOC  ,   modality='''vision'''  ,   expected_output=_EXPECTED_OUTPUT_SHAPE  ,   )
      def 					A__   (			self      :		Any  ,   UpperCAmelCase      :		Optional[torch.FloatTensor] = None  ,   UpperCAmelCase      :		Optional[bool] = None  ,   UpperCAmelCase      :		Optional[bool] = None  ,   )	->	Union[Tuple, BaseModelOutputWithNoAttention]:


       '''simple docstring'''

       lowercase       : List[Any]						=(
           output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
       )
       lowercase       : int						=return_dict if return_dict is not None else self.config.use_return_dict

       if pixel_values is None:
        raise ValueError('''You have to specify pixel_values'''		)

       lowercase       : Optional[int]						=self.encoder(
           UpperCAmelCase  ,   output_hidden_states=UpperCAmelCase  ,   return_dict=UpperCAmelCase  ,   )
       lowercase       : Dict						=encoder_outputs[0]

       if not return_dict:
        return (sequence_output, None) + encoder_outputs[1:]

       return BaseModelOutputWithNoAttention(
           last_hidden_state=UpperCAmelCase  ,   hidden_states=encoder_outputs.hidden_states  ,   )





class UpperCAmelCase_       (     nn.Module					):




      """simple docstring"""




      def __init__(			self      :		Tuple  ,   UpperCAmelCase      :		Dict		)	->	int:


       '''simple docstring'''

       super().__init__()
       lowercase       : int						=nn.Linear(config.hidden_size  ,   config.hidden_size		)






      def 					A__   (			self      :		str  ,   UpperCAmelCase      :		List[str]		)	->	Tuple:


       '''simple docstring'''

       lowercase       : Tuple						=self.dense(UpperCAmelCase		)
       return output





@add_start_docstrings(
    '''
    PoolFormer Model transformer with an image classification head on top
    '''					,							__A					,							)
class UpperCAmelCase_       (     __A					):




      """simple docstring"""




      def __init__(			self      :		int  ,   UpperCAmelCase      :		Optional[int]		)	->	List[Any]:


       '''simple docstring'''

       super().__init__(UpperCAmelCase		)
       lowercase       : List[Any]						=config.num_labels
       lowercase       : str						=PoolFormerModel(UpperCAmelCase		)

       # Final norm
       lowercase       : Dict						=PoolFormerGroupNorm(config.hidden_sizes[-1]		)
       # Classifier head
       lowercase       : List[str]						=(
           nn.Linear(config.hidden_sizes[-1]  ,   config.num_labels		) if config.num_labels > 0 else nn.Identity()
       )

       # Initialize weights and apply final processing
       self.post_init()






      @add_start_docstrings_to_model_forward(UpperCAmelCase		)
      @add_code_sample_docstrings(
          checkpoint=_IMAGE_CLASS_CHECKPOINT  ,   output_type=UpperCAmelCase  ,   config_class=_CONFIG_FOR_DOC  ,   expected_output=_IMAGE_CLASS_EXPECTED_OUTPUT  ,   )
      def 					A__   (			self      :		Tuple  ,   UpperCAmelCase      :		Optional[torch.FloatTensor] = None  ,   UpperCAmelCase      :		Optional[torch.LongTensor] = None  ,   UpperCAmelCase      :		Optional[bool] = None  ,   UpperCAmelCase      :		Optional[bool] = None  ,   )	->	Union[Tuple, ImageClassifierOutputWithNoAttention]:


       '''simple docstring'''

       lowercase       : int						=return_dict if return_dict is not None else self.config.use_return_dict

       lowercase       : Tuple						=self.poolformer(
           UpperCAmelCase  ,   output_hidden_states=UpperCAmelCase  ,   return_dict=UpperCAmelCase  ,   )

       lowercase       : Optional[Any]						=outputs[0]

       lowercase       : Tuple						=self.classifier(self.norm(UpperCAmelCase		).mean([-2, -1]		)		)

       lowercase       : List[Any]						=None
       if labels is not None:
        if self.config.problem_type is None:
         if self.num_labels == 1:
          lowercase       : int						='''regression'''
         elif self.num_labels > 1 and (labels.dtype == torch.long or labels.dtype == torch.int):
          lowercase       : int						='''single_label_classification'''
         else:
          lowercase       : Optional[Any]						='''multi_label_classification'''

        if self.config.problem_type == "regression":
         lowercase       : Optional[Any]						=MSELoss()
         if self.num_labels == 1:
          lowercase       : Dict						=loss_fct(logits.squeeze()  ,   labels.squeeze()		)
         else:
          lowercase       : List[Any]						=loss_fct(UpperCAmelCase  ,   UpperCAmelCase		)
        elif self.config.problem_type == "single_label_classification":
         lowercase       : List[Any]						=CrossEntropyLoss()
         lowercase       : List[str]						=loss_fct(logits.view(-1  ,   self.num_labels		)  ,   labels.view(-1		)		)
        elif self.config.problem_type == "multi_label_classification":
         lowercase       : Union[str, Any]						=BCEWithLogitsLoss()
         lowercase       : Union[str, Any]						=loss_fct(UpperCAmelCase  ,   UpperCAmelCase		)

       if not return_dict:
        lowercase       : str						=(logits,) + outputs[2:]
        return ((loss,) + output) if loss is not None else output

       return ImageClassifierOutputWithNoAttention(loss=UpperCAmelCase  ,   logits=UpperCAmelCase  ,   hidden_states=outputs.hidden_states		)





import warnings
from typing import List, Optional, Union

from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding, PaddingStrategy, PreTokenizedInput, TextInput, TruncationStrategy
from ...utils import TensorType




class        _SCREAMING_SNAKE_CASE	(   __UpperCamelCase			):
      _A    :		Optional[int]     						=  ['image_processor', 'tokenizer']
      _A    :		List[Any]     						=  'LayoutLMv2ImageProcessor'
      _A    :		Dict     						=  ('LayoutXLMTokenizer', 'LayoutXLMTokenizerFast')
      def __init__(      self		,						lowerCamelCase=None		,						lowerCamelCase=None		,						**lowerCamelCase			):
          if "feature_extractor" in kwargs:
              warnings.warn(
                  "The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`"
                  " instead."		,						lowerCamelCase		,						)
              snake_case__    =					kwargs.pop("feature_extractor"			)

          snake_case__    =					image_processor if image_processor is not None else feature_extractor
          if image_processor is None:
              raise ValueError("You need to specify an `image_processor`."			)
          if tokenizer is None:
              raise ValueError("You need to specify a `tokenizer`."			)

          super().__init__(lowerCamelCase		,						lowerCamelCase			)
      def __call__(      self		,						lowerCamelCase		,						lowerCamelCase = None		,						lowerCamelCase = None		,						lowerCamelCase = None		,						lowerCamelCase = None		,						lowerCamelCase = True		,						lowerCamelCase = False		,						lowerCamelCase = None		,						lowerCamelCase = None		,						lowerCamelCase = 0		,						lowerCamelCase = None		,						lowerCamelCase = None		,						lowerCamelCase = None		,						lowerCamelCase = False		,						lowerCamelCase = False		,						lowerCamelCase = False		,						lowerCamelCase = False		,						lowerCamelCase = True		,						lowerCamelCase = None		,						**lowerCamelCase		,						):
          # verify input
          if self.image_processor.apply_ocr and (boxes is not None):
              raise ValueError(
                  "You cannot provide bounding boxes "
                  "if you initialized the image processor with apply_ocr set to True."			)

          if self.image_processor.apply_ocr and (word_labels is not None):
              raise ValueError(
                  "You cannot provide word labels if you initialized the image processor with apply_ocr set to True."			)

          if return_overflowing_tokens is True and return_offsets_mapping is False:
              raise ValueError("You cannot return overflowing tokens without returning the offsets mapping."			)

          # first, apply the image processor
          snake_case__    =					self.image_processor(images=lowerCamelCase		,						return_tensors=lowerCamelCase			)

          # second, apply the tokenizer
          if text is not None and self.image_processor.apply_ocr and text_pair is None:
              if isinstance(lowerCamelCase		,						lowerCamelCase			):
                  snake_case__    =					[text]  # add batch dimension (as the image processor always adds a batch dimension)
              snake_case__    =					features["words"]

          snake_case__    =					self.tokenizer(
              text=text if text is not None else features["words"]		,						text_pair=text_pair if text_pair is not None else None		,						boxes=boxes if boxes is not None else features["boxes"]		,						word_labels=lowerCamelCase		,						add_special_tokens=lowerCamelCase		,						padding=lowerCamelCase		,						truncation=lowerCamelCase		,						max_length=lowerCamelCase		,						stride=lowerCamelCase		,						pad_to_multiple_of=lowerCamelCase		,						return_token_type_ids=lowerCamelCase		,						return_attention_mask=lowerCamelCase		,						return_overflowing_tokens=lowerCamelCase		,						return_special_tokens_mask=lowerCamelCase		,						return_offsets_mapping=lowerCamelCase		,						return_length=lowerCamelCase		,						verbose=lowerCamelCase		,						return_tensors=lowerCamelCase		,						**lowerCamelCase		,						)

          # add pixel values
          snake_case__    =					features.pop("pixel_values"			)
          if return_overflowing_tokens is True:
              snake_case__    =					self.get_overflowing_images(lowerCamelCase		,						encoded_inputs["overflow_to_sample_mapping"]			)
          snake_case__    =					images

          return encoded_inputs
      def A_      (      self		,						lowerCamelCase		,						lowerCamelCase			):
          # in case there's an overflow, ensure each `input_ids` sample is mapped to its corresponding image
          snake_case__    =					[]
          for sample_idx in overflow_to_sample_mapping:
              images_with_overflow.append(images[sample_idx]			)

          if len(lowerCamelCase			) != len(lowerCamelCase			):
              raise ValueError(
                  "Expected length of images to be the same as the length of `overflow_to_sample_mapping`, but got"
                  F""" {len(lowerCamelCase			)} and {len(lowerCamelCase			)}"""			)

          return images_with_overflow
      def A_      (      self		,						*lowerCamelCase		,						**lowerCamelCase			):
          return self.tokenizer.batch_decode(*lowerCamelCase		,						**lowerCamelCase			)
      def A_      (      self		,						*lowerCamelCase		,						**lowerCamelCase			):
          return self.tokenizer.decode(*lowerCamelCase		,						**lowerCamelCase			)
      @property
      def A_      (      self			):
          return ["input_ids", "bbox", "attention_mask", "image"]
      @property
      def A_      (      self			):
          warnings.warn(
              "`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead."		,						lowerCamelCase		,						)
          return self.image_processor_class



      @property
      def A_      (      self			):
          warnings.warn(
              "`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead."		,						lowerCamelCase		,						)
          return self.image_processor



