



from ..utils import DummyObject, requires_backends



class        lowercase_   (					metaclass=_UpperCAmelCase		):
							_lowerCamelCase						=		['flax', 'transformers']



							def __init__(						self				,    *lowercase_				,    **lowercase_    ):
													requires_backends(self				,    ["flax", "transformers"]    )



							@classmethod
							def 	UpperCamelCase	(						cls				,    *lowercase_				,    **lowercase_    ):
													requires_backends(cls				,    ["flax", "transformers"]    )



							@classmethod
							def 	UpperCamelCase	(						cls				,    *lowercase_				,    **lowercase_    ):
													requires_backends(cls				,    ["flax", "transformers"]    )




class        lowercase_   (					metaclass=_UpperCAmelCase		):
							_lowerCamelCase						=		['flax', 'transformers']



							def __init__(						self				,    *lowercase_				,    **lowercase_    ):
													requires_backends(self				,    ["flax", "transformers"]    )



							@classmethod
							def 	UpperCamelCase	(						cls				,    *lowercase_				,    **lowercase_    ):
													requires_backends(cls				,    ["flax", "transformers"]    )



							@classmethod
							def 	UpperCamelCase	(						cls				,    *lowercase_				,    **lowercase_    ):
													requires_backends(cls				,    ["flax", "transformers"]    )




class        lowercase_   (					metaclass=_UpperCAmelCase		):
							_lowerCamelCase						=		['flax', 'transformers']



							def __init__(						self				,    *lowercase_				,    **lowercase_    ):
													requires_backends(self				,    ["flax", "transformers"]    )



							@classmethod
							def 	UpperCamelCase	(						cls				,    *lowercase_				,    **lowercase_    ):
													requires_backends(cls				,    ["flax", "transformers"]    )



							@classmethod
							def 	UpperCamelCase	(						cls				,    *lowercase_				,    **lowercase_    ):
													requires_backends(cls				,    ["flax", "transformers"]    )




class        lowercase_   (					metaclass=_UpperCAmelCase		):
							_lowerCamelCase						=		['flax', 'transformers']



							def __init__(						self				,    *lowercase_				,    **lowercase_    ):
													requires_backends(self				,    ["flax", "transformers"]    )



							@classmethod
							def 	UpperCamelCase	(						cls				,    *lowercase_				,    **lowercase_    ):
													requires_backends(cls				,    ["flax", "transformers"]    )



							@classmethod
							def 	UpperCamelCase	(						cls				,    *lowercase_				,    **lowercase_    ):
													requires_backends(cls				,    ["flax", "transformers"]    )
import torch
from transformers import PreTrainedModel, XLMRobertaConfig, XLMRobertaModel



class        lowercase_   (					__snake_case		):
							_lowerCamelCase						=		'M-CLIP'



							def __init__(						self				,    lowercase_=1_024				,    lowercase_=768				,    **lowercase_    ):
													_snake_case						:					str    =   transformerDimSize
													_snake_case						:					Union[str, Any]    =   imageDimSize
													super().__init__(**lowercase_    )




class        lowercase_   (					__snake_case		):
							_lowerCamelCase						=		MCLIPConfig



							def __init__(						self				,    lowercase_				,    *lowercase_				,    **lowercase_    ):
													super().__init__(lowercase_				,    *lowercase_				,    **lowercase_    )
													_snake_case						:					List[Any]    =   XLMRobertaModel(lowercase_    )
													_snake_case						:					int    =   torch.nn.Linear(
													    in_features=config.transformerDimensions				,    out_features=config.numDims    )



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