"""simple docstring"""




def   UpperCAmelCase					(	UpperCamelCase__       ,    UpperCamelCase__				):






							"""simple docstring"""





							A__	     =							0
							while b > 0:
														if b & 1:
																					res += a

														a += a
														b >>= 1

							return res






def   UpperCAmelCase					(	UpperCamelCase__       ,    UpperCamelCase__       ,    UpperCamelCase__				):






							"""simple docstring"""





							A__	     =							0
							while b > 0:
														if b & 1:
																					A__	     =							((res % c) + (a % c)) % c

														a += a
														b >>= 1

							return res






"""simple docstring"""




import torch
from transformers import PreTrainedModel, XLMRobertaConfig, XLMRobertaModel
class     UpperCamelCase__(			__A ):
						lowerCAmelCase__  :						Union[str, Any]													=		'M-CLIP'





						def __init__(       self		,__UpperCAmelCase=10_24		,__UpperCAmelCase=7_68		,**__UpperCAmelCase     )					->				List[str]:
													A__	     =							transformerDimSize
													A__	     =							imageDimSize
													super().__init__(**__UpperCAmelCase     )






class     UpperCamelCase__(			__A ):
						lowerCAmelCase__  :						Union[str, Any]													=		MCLIPConfig





						def __init__(       self		,__UpperCAmelCase		,*__UpperCAmelCase		,**__UpperCAmelCase     )					->				List[Any]:
													super().__init__(__UpperCAmelCase		,*__UpperCAmelCase		,**__UpperCAmelCase     )
													A__	     =							XLMRobertaModel(__UpperCAmelCase     )
													A__	     =							torch.nn.Linear(
													    in_features=config.transformerDimensions		,out_features=config.numDims     )





						def 				snake_case__	(       self		,__UpperCAmelCase		,__UpperCAmelCase     )					->				Tuple:
													A__	     =							self.transformer(input_ids=__UpperCAmelCase		,attention_mask=__UpperCAmelCase     )[0]
													A__	     =							(embs * attention_mask.unsqueeze(2     )).sum(dim=1     ) / attention_mask.sum(dim=1     )[:, None]
													return self.LinearTransformation(__UpperCAmelCase     ), embs





