


import torch
from transformers import PreTrainedModel, XLMRobertaConfig, XLMRobertaModel






class _lowerCamelCase(		_a  ):
       lowercase_					:      Any       					=     """M-CLIP"""
       def __init__(   self, lowerCamelCase=10_24, lowerCamelCase=7_68, **lowerCamelCase)			->  Optional[int]:




           """simple docstring"""

           _lowercase			:				Any 						=						transformerDimSize
           _lowercase			:				Union[str, Any] 						=						imageDimSize
           super().__init__(**lowerCamelCase)






class _lowerCamelCase(		_a  ):
       lowercase_					:      Union[str, Any]       					=     MCLIPConfig
       def __init__(   self, lowerCamelCase, *lowerCamelCase, **lowerCamelCase)			->  str:




           """simple docstring"""

           super().__init__(lowerCamelCase, *lowerCamelCase, **lowerCamelCase)
           _lowercase			:				Dict 						=						XLMRobertaModel(lowerCamelCase)
           _lowercase			:				Any 						=						torch.nn.Linear(
               in_features=config.transformerDimensions, out_features=config.numDims)




       def      UpperCamelCase	(   self, lowerCamelCase, lowerCamelCase)			->  Dict:




           """simple docstring"""

           _lowercase			:				Tuple 						=						self.transformer(input_ids=lowerCamelCase, attention_mask=lowerCamelCase)[0]
           _lowercase			:				Union[str, Any] 						=						(embs * attention_mask.unsqueeze(2)).sum(dim=1) / attention_mask.sum(dim=1)[:, None]
           return self.LinearTransformation(lowerCamelCase), embs






from __future__ import annotations



def 							UpperCamelCase_( lowerCamelCase_					)       ->		float:
    if not nums:
        raise ValueError('List is empty'					)
    return sum(lowerCamelCase_					) / len(lowerCamelCase_					)


if __name__ == "__main__":
 import doctest

 doctest.testmod()


