





import torch
from transformers import PreTrainedModel, XLMRobertaConfig, XLMRobertaModel





class      lowercase__    (							__A  ):
  __UpperCamelCase	     =  """M-CLIP"""







  def __init__(	self    ,						_lowercase=1_024    ,						_lowercase=768    ,						**_lowercase						):
       lowerCAmelCase_					:       Tuple    =		transformerDimSize
       lowerCAmelCase_					:       Optional[Any]    =		imageDimSize
       super().__init__(**_lowercase						)





class      lowercase__    (							__A  ):
  __UpperCamelCase	     =  MCLIPConfig







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







  def 	UpperCAmelCase__		(	self    ,						_lowercase    ,						_lowercase						):
       lowerCAmelCase_					:       Optional[int]    =		self.transformer(input_ids=_lowercase    ,						attention_mask=_lowercase						)[0]
       lowerCAmelCase_					:       Any    =		(embs * attention_mask.unsqueeze(2						)).sum(dim=1						) / attention_mask.sum(dim=1						)[:, None]
       return self.LinearTransformation(_lowercase						), embs







from typing import TYPE_CHECKING

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


UpperCAmelCase_					:   int 							=						{"""configuration_plbart""": ["""PLBART_PRETRAINED_CONFIG_ARCHIVE_MAP""", """PLBartConfig"""]}

try:
      if not is_sentencepiece_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      UpperCAmelCase_					:   Optional[int] 							=						["""PLBartTokenizer"""]

try:
      if not is_torch_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      UpperCAmelCase_					:   Union[str, Any] 							=						[
          """PLBART_PRETRAINED_MODEL_ARCHIVE_LIST""",
          """PLBartForCausalLM""",
          """PLBartForConditionalGeneration""",
          """PLBartForSequenceClassification""",
          """PLBartModel""",
          """PLBartPreTrainedModel""",
      ]


if TYPE_CHECKING:
      from .configuration_plbart import PLBART_PRETRAINED_CONFIG_ARCHIVE_MAP, PLBartConfig

      try:
            if not is_sentencepiece_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .tokenization_plbart import PLBartTokenizer

      try:
            if not is_torch_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_plbart import (
                PLBART_PRETRAINED_MODEL_ARCHIVE_LIST,
                PLBartForCausalLM,
                PLBartForConditionalGeneration,
                PLBartForSequenceClassification,
                PLBartModel,
                PLBartPreTrainedModel,
            )


else:
      import sys

      UpperCAmelCase_					:   List[str] 							=						_LazyModule(__name__, globals()["""__file__"""], _import_structure)
