
from __future__ import annotations


def 							SCREAMING_SNAKE_CASE_      (			UpperCamelCase__ ,		UpperCamelCase__		):
      if b == 0:
            return (1, 0)
      ((UpperCamelCase__)				,(UpperCamelCase__))    :   List[str]					=				extended_euclid(UpperCamelCase__ ,		a % b		)
      UpperCamelCase__    :   str					=				a // b
      return (y, x - k * y)


def 							SCREAMING_SNAKE_CASE_      (			UpperCamelCase__ ,		UpperCamelCase__ ,		UpperCamelCase__ ,		UpperCamelCase__		):
      ((UpperCamelCase__)				,(UpperCamelCase__))    :   int					=				extended_euclid(UpperCamelCase__ ,		UpperCamelCase__		)
      UpperCamelCase__    :   Optional[Any]					=				na * na
      UpperCamelCase__    :   Tuple					=				ra * x * na + ra * y * na
      return (n % m + m) % m


def 							SCREAMING_SNAKE_CASE_      (			UpperCamelCase__ ,		UpperCamelCase__		):
      ((UpperCamelCase__)				,(UpperCamelCase__))    :   Any					=				extended_euclid(UpperCamelCase__ ,		UpperCamelCase__		)
      if b < 0:
            UpperCamelCase__    :   Any					=				(b % n + n) % n
      return b


def 							SCREAMING_SNAKE_CASE_      (			UpperCamelCase__ ,		UpperCamelCase__ ,		UpperCamelCase__ ,		UpperCamelCase__		):
      UpperCamelCase__				,UpperCamelCase__    :   Optional[Any]					=				invert_modulo(UpperCamelCase__ ,		UpperCamelCase__		), invert_modulo(UpperCamelCase__ ,		UpperCamelCase__		)
      UpperCamelCase__    :   Dict					=				na * na
      UpperCamelCase__    :   int					=				ra * x * na + ra * y * na
      return (n % m + m) % m


if __name__ == "__main__":
    from doctest import testmod

    testmod(name="chinese_remainder_theorem", verbose=True)
    testmod(name="chinese_remainder_theorem2", verbose=True)
    testmod(name="invert_modulo", verbose=True)
    testmod(name="extended_euclid", verbose=True)




import torch
from transformers import PreTrainedModel, XLMRobertaConfig, XLMRobertaModel




class 				_lowerCamelCase (      UpperCamelCase_ ):





     """simple docstring"""







     SCREAMING_SNAKE_CASE_		   =  '''M-CLIP'''






     def __init__(							self						,						__SCREAMING_SNAKE_CASE=1_0_2_4						,						__SCREAMING_SNAKE_CASE=7_6_8						,						**__SCREAMING_SNAKE_CASE  )  ->   List[Any]:




           """simple docstring"""







           UpperCamelCase__    :   Dict					=				transformerDimSize
           UpperCamelCase__    :   Any					=				imageDimSize
           super().__init__(**__SCREAMING_SNAKE_CASE  )




class 				_lowerCamelCase (      UpperCamelCase_ ):





     """simple docstring"""







     SCREAMING_SNAKE_CASE_		   =  MCLIPConfig






     def __init__(							self						,						__SCREAMING_SNAKE_CASE						,						*__SCREAMING_SNAKE_CASE						,						**__SCREAMING_SNAKE_CASE  )  ->   Optional[int]:




           """simple docstring"""







           super().__init__(__SCREAMING_SNAKE_CASE						,						*__SCREAMING_SNAKE_CASE						,						**__SCREAMING_SNAKE_CASE  )
           UpperCamelCase__    :   Union[str, Any]					=				XLMRobertaModel(__SCREAMING_SNAKE_CASE  )
           UpperCamelCase__    :   Tuple					=				torch.nn.Linear(
               in_features=config.transformerDimensions						,						out_features=config.numDims  )






     def    __SCREAMING_SNAKE_CASE			(							self						,						__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE  )  ->   List[str]:




           """simple docstring"""







           UpperCamelCase__    :   Tuple					=				self.transformer(input_ids=__SCREAMING_SNAKE_CASE						,						attention_mask=__SCREAMING_SNAKE_CASE  )[0]
           UpperCamelCase__    :   Tuple					=				(embs * attention_mask.unsqueeze(2  )).sum(dim=1  ) / attention_mask.sum(dim=1  )[:, None]
           return self.LinearTransformation(__SCREAMING_SNAKE_CASE  ), embs


