




import warnings
from typing import List, Optional, Union

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






class     __lowerCAmelCase (       A__ ):
			snake_case_      : int      =     ["image_processor", "tokenizer"]
			snake_case_      : List[Any]      =     "FlavaImageProcessor"
			snake_case_      : Union[str, Any]      =     ("BertTokenizer", "BertTokenizerFast")







			def __init__(       self    :			Optional[Any]    ,    snake_case__    :			Tuple=None    ,    snake_case__    :			Optional[Any]=None    ,    **snake_case__    :			List[str]      ):




									"""simple docstring"""


									_UpperCAmelCase													=     None
									if "feature_extractor" in kwargs:
															warnings.warn(
															    "The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`"
															    " instead."    ,    _a    ,    )
															_UpperCAmelCase													=     kwargs.pop("feature_extractor"      )

									_UpperCAmelCase													=     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__(_a    ,    _a      )
									_UpperCAmelCase													=     self.image_processor







			def __call__(       self    :			List[str]    ,    snake_case__    :			Optional[ImageInput] = None    ,    snake_case__    :			Optional[Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]]] = None    ,    snake_case__    :			bool = True    ,    snake_case__    :			Union[bool, str, PaddingStrategy] = False    ,    snake_case__    :			Union[bool, str, TruncationStrategy] = False    ,    snake_case__    :			Optional[int] = None    ,    snake_case__    :			int = 0    ,    snake_case__    :			Optional[int] = None    ,    snake_case__    :			Optional[bool] = None    ,    snake_case__    :			Optional[bool] = None    ,    snake_case__    :			Optional[bool] = None    ,    snake_case__    :			Optional[bool] = None    ,    snake_case__    :			bool = False    ,    snake_case__    :			bool = False    ,    snake_case__    :			bool = False    ,    snake_case__    :			bool = False    ,    snake_case__    :			bool = True    ,    snake_case__    :			Optional[Union[str, TensorType]] = None    ,    **snake_case__    :			str    ,    ):




									"""simple docstring"""


									if text is None and images is None:
															raise ValueError("You have to specify either text or images. Both cannot be none."      )

									if text is not None:
															_UpperCAmelCase													=     self.tokenizer(
															    text=_a    ,    add_special_tokens=_a    ,    padding=_a    ,    truncation=_a    ,    max_length=_a    ,    stride=_a    ,    pad_to_multiple_of=_a    ,    return_token_type_ids=_a    ,    return_attention_mask=_a    ,    return_overflowing_tokens=_a    ,    return_special_tokens_mask=_a    ,    return_offsets_mapping=_a    ,    return_length=_a    ,    verbose=_a    ,    return_tensors=_a    ,    **_a    ,    )
									if images is not None:
															_UpperCAmelCase													=     self.image_processor(
															    _a    ,    return_image_mask=_a    ,    return_codebook_pixels=_a    ,    return_tensors=_a    ,    **_a    ,    )

									if text is not None and images is not None:
															encoding.update(_a      )
															return encoding
									elif text is not None:
															return encoding
									else:
															return BatchEncoding(data=dict(**_a      )    ,    tensor_type=_a      )







			def UpperCamelCase			(       self    :			Dict    ,    *snake_case__    :			Optional[Any]    ,    **snake_case__    :			Tuple      ):




									"""simple docstring"""


									return self.tokenizer.batch_decode(*_a    ,    **_a      )







			def UpperCamelCase			(       self    :			List[str]    ,    *snake_case__    :			Optional[Any]    ,    **snake_case__    :			List[Any]      ):




									"""simple docstring"""


									return self.tokenizer.decode(*_a    ,    **_a      )







			@property
			def UpperCamelCase			(       self    :			Any      ):




									"""simple docstring"""


									_UpperCAmelCase													=     self.tokenizer.model_input_names
									_UpperCAmelCase													=     self.image_processor.model_input_names
									return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names      )      )







			@property
			def UpperCamelCase			(       self    :			Optional[int]      ):




									"""simple docstring"""


									warnings.warn(
									    "`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead."    ,    _a    ,    )
									return self.image_processor_class







			@property
			def UpperCamelCase			(       self    :			Optional[Any]      ):




									"""simple docstring"""


									warnings.warn(
									    "`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead."    ,    _a    ,    )
									return self.image_processor







'''simple docstring'''
from typing import Optional, Union

import torch
from torch import nn

from ...configuration_utils import ConfigMixin, register_to_config
from ...models.modeling_utils import ModelMixin







class 							A__    (       A__     ,   A__  ):





  @register_to_config
  def __init__(		self      :	Dict							,					_a      :	int = 768							,					)	->    Union[str, Any]:





       '''simple docstring'''






       super().__init__()

       _SCREAMING_SNAKE_CASE							    =nn.Parameter(torch.zeros(1							,					_a ) )
       _SCREAMING_SNAKE_CASE							    =nn.Parameter(torch.ones(1							,					_a ) )





  def 						A  (		self      :	Tuple							,					_a      :	Optional[Union[str, torch.device]] = None							,					_a      :	Optional[torch.dtype] = None							,					)	->    List[Any]:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							    =nn.Parameter(self.mean.to(_a ).to(_a ) )
       _SCREAMING_SNAKE_CASE							    =nn.Parameter(self.std.to(_a ).to(_a ) )
       return self





  def 						A  (		self      :	Tuple							,					_a      :	str )	->    str:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							    =(embeds - self.mean) * 1.0 / self.std
       return embeds





  def 						A  (		self      :	List[str]							,					_a      :	Optional[Any] )	->    Tuple:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							    =(embeds * self.std) + self.mean
       return embeds
