





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 				a			(      _SCREAMING_SNAKE_CASE			):
				SCREAMING_SNAKE_CASE__     :   Any		      =     ['''image_processor''', '''tokenizer''']
				SCREAMING_SNAKE_CASE__     :   List[str]		      =     '''BlipImageProcessor'''
				SCREAMING_SNAKE_CASE__     :   Optional[Any]		      =     ('''BertTokenizer''', '''BertTokenizerFast''')






				def __init__(  self			, _lowerCAmelCase			, _lowerCAmelCase					):

										"""simple docstring"""




										__SCREAMING_SNAKE_CASE:				List[Any]           =   False
										super().__init__(_lowerCAmelCase			, _lowerCAmelCase					)
										__SCREAMING_SNAKE_CASE:				Union[str, Any]           =   self.image_processor






				def __call__(  self			, _lowerCAmelCase = None			, _lowerCAmelCase = None			, _lowerCAmelCase = True			, _lowerCAmelCase = False			, _lowerCAmelCase = None			, _lowerCAmelCase = None			, _lowerCAmelCase = 0			, _lowerCAmelCase = None			, _lowerCAmelCase = None			, _lowerCAmelCase = False			, _lowerCAmelCase = False			, _lowerCAmelCase = False			, _lowerCAmelCase = False			, _lowerCAmelCase = False			, _lowerCAmelCase = True			, _lowerCAmelCase = None			, **_lowerCAmelCase			, ):

										"""simple docstring"""




										if images is None and text is None:
																raise ValueError('''You have to specify either images or text.'''					)

										# Get only text
										if images is None:
																__SCREAMING_SNAKE_CASE:				Union[str, Any]           =   self.tokenizer
																__SCREAMING_SNAKE_CASE:				Any           =   self.tokenizer(
																    text=_lowerCAmelCase			, add_special_tokens=_lowerCAmelCase			, padding=_lowerCAmelCase			, truncation=_lowerCAmelCase			, max_length=_lowerCAmelCase			, stride=_lowerCAmelCase			, pad_to_multiple_of=_lowerCAmelCase			, return_attention_mask=_lowerCAmelCase			, return_overflowing_tokens=_lowerCAmelCase			, return_special_tokens_mask=_lowerCAmelCase			, return_offsets_mapping=_lowerCAmelCase			, return_token_type_ids=_lowerCAmelCase			, return_length=_lowerCAmelCase			, verbose=_lowerCAmelCase			, return_tensors=_lowerCAmelCase			, **_lowerCAmelCase			, )
																return text_encoding

										# add pixel_values
										__SCREAMING_SNAKE_CASE:				Tuple           =   self.image_processor(_lowerCAmelCase			, return_tensors=_lowerCAmelCase					)

										if text is not None:
																__SCREAMING_SNAKE_CASE:				Dict           =   self.tokenizer(
																    text=_lowerCAmelCase			, add_special_tokens=_lowerCAmelCase			, padding=_lowerCAmelCase			, truncation=_lowerCAmelCase			, max_length=_lowerCAmelCase			, stride=_lowerCAmelCase			, pad_to_multiple_of=_lowerCAmelCase			, return_attention_mask=_lowerCAmelCase			, return_overflowing_tokens=_lowerCAmelCase			, return_special_tokens_mask=_lowerCAmelCase			, return_offsets_mapping=_lowerCAmelCase			, return_token_type_ids=_lowerCAmelCase			, return_length=_lowerCAmelCase			, verbose=_lowerCAmelCase			, return_tensors=_lowerCAmelCase			, **_lowerCAmelCase			, )
										else:
																__SCREAMING_SNAKE_CASE:				Optional[Any]           =   None

										if text_encoding is not None:
																encoding_image_processor.update(_lowerCAmelCase					)

										return encoding_image_processor






				def 			snake_case_    (  self			, *_lowerCAmelCase			, **_lowerCAmelCase					):

										"""simple docstring"""




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






				def 			snake_case_    (  self			, *_lowerCAmelCase			, **_lowerCAmelCase					):

										"""simple docstring"""




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






				@property
				def 			snake_case_    (  self					):

										"""simple docstring"""




										__SCREAMING_SNAKE_CASE:				Dict           =   self.tokenizer.model_input_names
										__SCREAMING_SNAKE_CASE:				Optional[Any]           =   self.image_processor.model_input_names
										return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names					)					)









import torch
from transformers import PreTrainedModel, XLMRobertaConfig, XLMRobertaModel





class 			lowerCamelCase_				( _SCREAMING_SNAKE_CASE   ):


 '''simple docstring'''







 lowercase_							       =       "M-CLIP"



 def __init__(				self    :						Tuple							,							_lowerCAmelCase    :						List[str]=1_024							,							_lowerCAmelCase    :						str=768							,							**_lowerCAmelCase    :						Union[str, Any]		):
       SCREAMING_SNAKE_CASE_      		=     transformerDimSize
       SCREAMING_SNAKE_CASE_      		=     imageDimSize
       super().__init__(**_lowerCAmelCase		)





class 			lowerCamelCase_				( _SCREAMING_SNAKE_CASE   ):


 '''simple docstring'''







 lowercase_							       =       MCLIPConfig



 def __init__(				self    :						Dict							,							_lowerCAmelCase    :						Union[str, Any]							,							*_lowerCAmelCase    :						str							,							**_lowerCAmelCase    :						str		):
       super().__init__(_lowerCAmelCase							,							*_lowerCAmelCase							,							**_lowerCAmelCase		)
       SCREAMING_SNAKE_CASE_      		=     XLMRobertaModel(_lowerCAmelCase		)
       SCREAMING_SNAKE_CASE_      		=     torch.nn.Linear(
           in_features=config.transformerDimensions							,							out_features=config.numDims		)




 def  lowerCAmelCase_    (				self    :						List[Any]							,							_lowerCAmelCase    :						Any							,							_lowerCAmelCase    :						Union[str, Any]		):
       SCREAMING_SNAKE_CASE_      		=     self.transformer(input_ids=_lowerCAmelCase							,							attention_mask=_lowerCAmelCase		)[0]
       SCREAMING_SNAKE_CASE_      		=     (embs * attention_mask.unsqueeze(2		)).sum(dim=1		) / attention_mask.sum(dim=1		)[:, None]
       return self.LinearTransformation(_lowerCAmelCase		), embs