


'''simple docstring'''



import torch
from transformers import PreTrainedModel, XLMRobertaConfig, XLMRobertaModel



class      a    (		_a	):


     """simple docstring"""






     SCREAMING_SNAKE_CASE	:			Optional[int]							       =       "M-CLIP"

     def __init__(    self					:		Dict							,			snake_case					:		str=1024							,			snake_case					:		Any=768							,			**snake_case					:		Union[str, Any]      )						->							Union[str, Any]:
          __UpperCAmelCase     :			Any  							=      transformerDimSize
          __UpperCAmelCase     :			Optional[int]  							=      imageDimSize
          super().__init__(**snake_case      )



class      a    (		_a	):


     """simple docstring"""






     SCREAMING_SNAKE_CASE	:			Tuple							       =       MCLIPConfig

     def __init__(    self					:		List[Any]							,			snake_case					:		str							,			*snake_case					:		List[Any]							,			**snake_case					:		int      )						->							Optional[int]:
          super().__init__(snake_case							,			*snake_case							,			**snake_case      )
          __UpperCAmelCase     :			Tuple  							=      XLMRobertaModel(snake_case      )
          __UpperCAmelCase     :			str  							=      torch.nn.Linear(
              in_features=config.transformerDimensions							,			out_features=config.numDims      )






     def 			lowerCamelCase__			(    self					:		int							,			snake_case					:		Dict							,			snake_case					:		Any      )						->							Dict:
          __UpperCAmelCase     :			List[str]  							=      self.transformer(input_ids=snake_case							,			attention_mask=snake_case      )[0]
          __UpperCAmelCase     :			Optional[int]  							=      (embs * attention_mask.unsqueeze(2      )).sum(dim=1      ) / attention_mask.sum(dim=1      )[:, None]
          return self.LinearTransformation(snake_case      ), embs



'''simple docstring'''



from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


__UpperCAmelCase      :List[Any]			    =       {
    "configuration_lxmert": ["LXMERT_PRETRAINED_CONFIG_ARCHIVE_MAP", "LxmertConfig"],
    "tokenization_lxmert": ["LxmertTokenizer"],
}

try:
      if not is_tokenizers_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      __UpperCAmelCase      :List[Any]			    =       ["LxmertTokenizerFast"]

try:
      if not is_torch_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      __UpperCAmelCase      :List[Any]			    =       [
          "LxmertEncoder",
          "LxmertForPreTraining",
          "LxmertForQuestionAnswering",
          "LxmertModel",
          "LxmertPreTrainedModel",
          "LxmertVisualFeatureEncoder",
          "LxmertXLayer",
      ]

try:
      if not is_tf_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      __UpperCAmelCase      :List[str]			    =       [
          "TF_LXMERT_PRETRAINED_MODEL_ARCHIVE_LIST",
          "TFLxmertForPreTraining",
          "TFLxmertMainLayer",
          "TFLxmertModel",
          "TFLxmertPreTrainedModel",
          "TFLxmertVisualFeatureEncoder",
      ]


if TYPE_CHECKING:
      from .configuration_lxmert import LXMERT_PRETRAINED_CONFIG_ARCHIVE_MAP, LxmertConfig
      from .tokenization_lxmert import LxmertTokenizer

      try:
            if not is_tokenizers_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .tokenization_lxmert_fast import LxmertTokenizerFast

      try:
            if not is_torch_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_lxmert import (
                LxmertEncoder,
                LxmertForPreTraining,
                LxmertForQuestionAnswering,
                LxmertModel,
                LxmertPreTrainedModel,
                LxmertVisualFeatureEncoder,
                LxmertXLayer,
            )

      try:
            if not is_tf_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_tf_lxmert import (
                TF_LXMERT_PRETRAINED_MODEL_ARCHIVE_LIST,
                TFLxmertForPreTraining,
                TFLxmertMainLayer,
                TFLxmertModel,
                TFLxmertPreTrainedModel,
                TFLxmertVisualFeatureEncoder,
            )

else:
      import sys

      __UpperCAmelCase      :int			    =       _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)