





"""simple docstring"""




import torch
from transformers import PreTrainedModel, XLMRobertaConfig, XLMRobertaModel


class  __UpperCamelCase       (		a__		):
							lowerCamelCase     :      int         ="""M-CLIP"""






							def __init__(     self   ,      lowerCAmelCase__=1024   ,      lowerCAmelCase__=768   ,      **lowerCAmelCase__   )			->				Optional[Any]:
								a   :	str			=       transformerDimSize
								a   :	Any			=       imageDimSize
								super().__init__(**lowerCAmelCase__   )


class  __UpperCamelCase       (		a__		):
							lowerCamelCase     :      str         =MCLIPConfig






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






							def 					__a     (     self   ,      lowerCAmelCase__   ,      lowerCAmelCase__   )			->				str:
								a   :	int			=       self.transformer(input_ids=lowerCAmelCase__   ,      attention_mask=lowerCAmelCase__   )[0]
								a   :	str			=       (embs * attention_mask.unsqueeze(2   )).sum(dim=1   ) / attention_mask.sum(dim=1   )[:, None]
								return self.LinearTransformation(lowerCAmelCase__   ), embs









"""simple docstring"""




from ..utils import DummyObject, requires_backends


class  __UpperCamelCase       (		metaclass=a__		):
							lowerCamelCase     :      Optional[Any]         =["""transformers""", """torch""", """note_seq"""]






							def __init__(     self   ,      *lowerCAmelCase__   ,      **lowerCAmelCase__   )			->				Union[str, Any]:
								requires_backends(self   ,      ["transformers", "torch", "note_seq"]   )






							@classmethod
							def 					__a     (     cls   ,      *lowerCAmelCase__   ,      **lowerCAmelCase__   )			->				Any:
								requires_backends(cls   ,      ["transformers", "torch", "note_seq"]   )






							@classmethod
							def 					__a     (     cls   ,      *lowerCAmelCase__   ,      **lowerCAmelCase__   )			->				int:
								requires_backends(cls   ,      ["transformers", "torch", "note_seq"]   )


