
import torch
from transformers import PreTrainedModel, XLMRobertaConfig, XLMRobertaModel





class 							UpperCAmelCase				(  __SCREAMING_SNAKE_CASE  ):




	'''simple docstring'''





	snake_case_    =					"M-CLIP"






	def __init__(	self :			str							,A :			List[Any]=10_24							,A :			int=7_68							,**A :			List[Any]			):
					__A             =			transformerDimSize
					__A             =			imageDimSize
					super().__init__(**A			)





class 							UpperCAmelCase				(  __SCREAMING_SNAKE_CASE  ):




	'''simple docstring'''





	snake_case_    =					MCLIPConfig






	def __init__(	self :			Optional[int]							,A :			Dict							,*A :			Optional[Any]							,**A :			Dict			):
					super().__init__(A							,*A							,**A			)
					__A             =			XLMRobertaModel(A			)
					__A             =			torch.nn.Linear(
					    in_features=config.transformerDimensions							,out_features=config.numDims			)







	def     UpperCamelCase_  (	self :			List[Any]							,A :			str							,A :			str			):
					__A             =			self.transformer(input_ids=A							,attention_mask=A			)[0]
					__A             =			(embs * attention_mask.unsqueeze(2			)).sum(dim=1			) / attention_mask.sum(dim=1			)[:, None]
					return self.LinearTransformation(A			), embs


from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tf_available, is_torch_available


SCREAMING_SNAKE_CASE							:Any										=    {
    'configuration_rag': ['RagConfig'],
    'retrieval_rag': ['RagRetriever'],
    'tokenization_rag': ['RagTokenizer'],
}

try:
					if not is_torch_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					SCREAMING_SNAKE_CASE							:List[Any]										=    [
					    'RagModel',
					    'RagPreTrainedModel',
					    'RagSequenceForGeneration',
					    'RagTokenForGeneration',
					]

try:
					if not is_tf_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					SCREAMING_SNAKE_CASE							:Any										=    [
					    'TFRagModel',
					    'TFRagPreTrainedModel',
					    'TFRagSequenceForGeneration',
					    'TFRagTokenForGeneration',
					]


if TYPE_CHECKING:
					from .configuration_rag import RagConfig
					from .retrieval_rag import RagRetriever
					from .tokenization_rag import RagTokenizer

					try:
										if not is_torch_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_rag import RagModel, RagPreTrainedModel, RagSequenceForGeneration, RagTokenForGeneration

					try:
										if not is_tf_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_tf_rag import (
										    TFRagModel,
										    TFRagPreTrainedModel,
										    TFRagSequenceForGeneration,
										    TFRagTokenForGeneration,
										)

else:
					import sys

					SCREAMING_SNAKE_CASE							:int										=    _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)
