



import torch
from transformers import PreTrainedModel, XLMRobertaConfig, XLMRobertaModel

class 				snake_case__(_UpperCamelCase      ):

     """simple docstring"""






     lowercase_								=		"""M-CLIP"""







     def __init__(							self :     Union[str, Any]				,       SCREAMING_SNAKE_CASE :     Tuple=1_024				,       SCREAMING_SNAKE_CASE :     Optional[int]=768				,       **SCREAMING_SNAKE_CASE :     Union[str, Any]					):
         lowercase__					:   Union[str, Any]													=					transformerDimSize
         lowercase__					:   Dict													=					imageDimSize
         super().__init__(**SCREAMING_SNAKE_CASE					)






class 				snake_case__(_UpperCamelCase      ):

     """simple docstring"""






     lowercase_								=		MCLIPConfig







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







     def 			snake_case					(							self :     List[Any]				,       SCREAMING_SNAKE_CASE :     Optional[Any]				,       SCREAMING_SNAKE_CASE :     Tuple					):
         lowercase__					:   List[str]													=					self.transformer(input_ids=SCREAMING_SNAKE_CASE				,       attention_mask=SCREAMING_SNAKE_CASE					)[0]
         lowercase__					:   Optional[Any]													=					(embs * attention_mask.unsqueeze(2					)).sum(dim=1					) / attention_mask.sum(dim=1					)[:, None]
         return self.LinearTransformation(SCREAMING_SNAKE_CASE					), embs









from typing import TYPE_CHECKING

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


lowerCAmelCase__					  =  {}

try:
				if not is_sentencepiece_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				lowerCAmelCase__					  =  ['''NllbTokenizer''']

try:
				if not is_tokenizers_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				lowerCAmelCase__					  =  ['''NllbTokenizerFast''']


if TYPE_CHECKING:
				try:
								if not is_sentencepiece_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .tokenization_nllb import NllbTokenizer

				try:
								if not is_tokenizers_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .tokenization_nllb_fast import NllbTokenizerFast

else:
				import sys

				lowerCAmelCase__					  =  _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)




