"""simple docstring"""





import os
import sys
from contextlib import contextmanager


# Windows only
if os.name == "nt":
			import ctypes
			import msvcrt  # noqa




			class  _snake_case		(    ctypes.Structure ):







							"""simple docstring"""






							a			=						[("size", ctypes.c_int), ("visible", ctypes.c_byte)]



def      lowerCamelCase_()->    Any:
							if os.name == "nt":
														_SCREAMING_SNAKE_CASE		:						List[str]			  =    CursorInfo()
														_SCREAMING_SNAKE_CASE		:						Tuple			  =    ctypes.windll.kernelaa.GetStdHandle(-11  )
														ctypes.windll.kernelaa.GetConsoleCursorInfo(__SCREAMING_SNAKE_CASE     ,	ctypes.byref(__SCREAMING_SNAKE_CASE  )  )
														_SCREAMING_SNAKE_CASE		:						List[str]			  =    False
														ctypes.windll.kernelaa.SetConsoleCursorInfo(__SCREAMING_SNAKE_CASE     ,	ctypes.byref(__SCREAMING_SNAKE_CASE  )  )
							elif os.name == "posix":
														sys.stdout.write("""\033[?25l"""  )
														sys.stdout.flush()



def      lowerCamelCase_()->    Tuple:
							if os.name == "nt":
														_SCREAMING_SNAKE_CASE		:						Union[str, Any]			  =    CursorInfo()
														_SCREAMING_SNAKE_CASE		:						Any			  =    ctypes.windll.kernelaa.GetStdHandle(-11  )
														ctypes.windll.kernelaa.GetConsoleCursorInfo(__SCREAMING_SNAKE_CASE     ,	ctypes.byref(__SCREAMING_SNAKE_CASE  )  )
														_SCREAMING_SNAKE_CASE		:						Optional[Any]			  =    True
														ctypes.windll.kernelaa.SetConsoleCursorInfo(__SCREAMING_SNAKE_CASE     ,	ctypes.byref(__SCREAMING_SNAKE_CASE  )  )
							elif os.name == "posix":
														sys.stdout.write("""\033[?25h"""  )
														sys.stdout.flush()



@contextmanager
def      lowerCamelCase_()->    List[Any]:
							try:
														hide_cursor()
														yield
							finally:
														show_cursor()



"""simple docstring"""





import torch
from transformers import PreTrainedModel, XLMRobertaConfig, XLMRobertaModel




class  _snake_case		(    __snake_case ):







				"""simple docstring"""






				a			=						"M-CLIP"





				def __init__(      self							:							Optional[Any]      ,    _A							:							List[str]=1_0_2_4      ,    _A							:							Union[str, Any]=7_6_8      ,    **_A							:							Optional[Any]):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE		:						Tuple			  =    transformerDimSize
											_SCREAMING_SNAKE_CASE		:						List[str]			  =    imageDimSize
											super().__init__(**_A)




class  _snake_case		(    __snake_case ):







				"""simple docstring"""






				a			=						MCLIPConfig





				def __init__(      self							:							Dict      ,    _A							:							Optional[Any]      ,    *_A							:							Any      ,    **_A							:							Dict):



											"""simple docstring"""







											super().__init__(_A      ,    *_A      ,    **_A)
											_SCREAMING_SNAKE_CASE		:						Tuple			  =    XLMRobertaModel(_A)
											_SCREAMING_SNAKE_CASE		:						List[Any]			  =    torch.nn.Linear(
											    in_features=config.transformerDimensions      ,    out_features=config.numDims)





				def 		_lowerCAmelCase		(      self							:							Union[str, Any]      ,    _A							:							str      ,    _A							:							int):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE		:						str			  =    self.transformer(input_ids=_A      ,    attention_mask=_A)[0]
											_SCREAMING_SNAKE_CASE		:						Optional[Any]			  =    (embs * attention_mask.unsqueeze(2)).sum(dim=1) / attention_mask.sum(dim=1)[:, None]
											return self.LinearTransformation(_A), embs


