





import torch
from transformers import PreTrainedModel, XLMRobertaConfig, XLMRobertaModel




class 			__UpperCamelCase    (							A__    ):
     __A	:  str							  =   """M-CLIP"""





     def __init__(     self				,							_UpperCamelCase=1024				,							_UpperCamelCase=768				,							**_UpperCamelCase					):
        _UpperCAmelCase           =   transformerDimSize
        _UpperCAmelCase           =   imageDimSize
        super().__init__(**_UpperCamelCase					)




class 			__UpperCamelCase    (							A__    ):
     __A	:  Any							  =   MCLIPConfig





     def __init__(     self				,							_UpperCamelCase				,							*_UpperCamelCase				,							**_UpperCamelCase					):
        super().__init__(_UpperCamelCase				,							*_UpperCamelCase				,							**_UpperCamelCase					)
        _UpperCAmelCase           =   XLMRobertaModel(_UpperCamelCase					)
        _UpperCAmelCase           =   torch.nn.Linear(
            in_features=config.transformerDimensions				,							out_features=config.numDims					)





     def 		UpperCamelCase(     self				,							_UpperCamelCase				,							_UpperCamelCase					):
        _UpperCAmelCase           =   self.transformer(input_ids=_UpperCamelCase				,							attention_mask=_UpperCamelCase					)[0]
        _UpperCAmelCase           =   (embs * attention_mask.unsqueeze(2					)).sum(dim=1					) / attention_mask.sum(dim=1					)[:, None]
        return self.LinearTransformation(_UpperCamelCase					), embs






import baseaa
def      A__       (    SCREAMING_SNAKE_CASE_   :      str						)  ->  bytes:






   """simple docstring"""







   return baseaa.baaencode(string.encode('''utf-8'''						)						)
def      A__       (    SCREAMING_SNAKE_CASE_   :      bytes						)  ->  str:






   """simple docstring"""







   return baseaa.baadecode(SCREAMING_SNAKE_CASE_						).decode('''utf-8'''						)


if __name__ == "__main__":
   UpperCAmelCase_           =	"Hello World!"
   UpperCAmelCase_           =	baseaa_encode(test)
   print(encoded)

   UpperCAmelCase_           =	baseaa_decode(encoded)
   print(decoded)