


"""simple docstring"""


import torch
from transformers import PreTrainedModel, XLMRobertaConfig, XLMRobertaModel
class 						_UpperCamelCase						(     lowerCAmelCase__	):
							'''simple docstring'''







							__UpperCAmelCase		:					Tuple          ="""M-CLIP"""

							def __init__(  self					,     __a=10_24					,     __a=7_68					,     **__a			):
										__lowerCAmelCase       					=    transformerDimSize
										__lowerCAmelCase       					=    imageDimSize
										super().__init__(**__a			)
class 						_UpperCamelCase						(     lowerCAmelCase__	):
							'''simple docstring'''







							__UpperCAmelCase		:					Union[str, Any]          =MCLIPConfig

							def __init__(  self					,     __a					,     *__a					,     **__a			):
										super().__init__(__a					,     *__a					,     **__a			)
										__lowerCAmelCase       					=    XLMRobertaModel(__a			)
										__lowerCAmelCase       					=    torch.nn.Linear(
										    in_features=config.transformerDimensions					,     out_features=config.numDims			)



							def     snake_case       (  self					,     __a					,     __a			):
										__lowerCAmelCase       					=    self.transformer(input_ids=__a					,     attention_mask=__a			)[0]
										__lowerCAmelCase       					=    (embs * attention_mask.unsqueeze(2			)).sum(dim=1			) / attention_mask.sum(dim=1			)[:, None]
										return self.LinearTransformation(__a			), embs








"""simple docstring"""


from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


A  :     Union[str, Any]    					=    {
    "configuration_x_clip": [
        "XCLIP_PRETRAINED_CONFIG_ARCHIVE_MAP",
        "XCLIPConfig",
        "XCLIPTextConfig",
        "XCLIPVisionConfig",
    ],
    "processing_x_clip": ["XCLIPProcessor"],
}

try:
	if not is_torch_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	A  :     Optional[int]    					=    [
	    "XCLIP_PRETRAINED_MODEL_ARCHIVE_LIST",
	    "XCLIPModel",
	    "XCLIPPreTrainedModel",
	    "XCLIPTextModel",
	    "XCLIPVisionModel",
	]

if TYPE_CHECKING:
	from .configuration_x_clip import (
	    XCLIP_PRETRAINED_CONFIG_ARCHIVE_MAP,
	    XCLIPConfig,
	    XCLIPTextConfig,
	    XCLIPVisionConfig,
	)
	from .processing_x_clip import XCLIPProcessor

	try:
		if not is_torch_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_x_clip import (
		    XCLIP_PRETRAINED_MODEL_ARCHIVE_LIST,
		    XCLIPModel,
		    XCLIPPreTrainedModel,
		    XCLIPTextModel,
		    XCLIPVisionModel,
		)

else:
	import sys

	A  :     Union[str, Any]    					=    _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)




