


'''simple docstring'''



import torch
from transformers import PreTrainedModel, XLMRobertaConfig, XLMRobertaModel






class  UpperCamelCase__(     a__ ):
				__magic_name__       :   int							= """M-CLIP"""




				def __init__(	self    :				Optional[int]   ,					lowerCAmelCase    :				List[Any]=1024   ,					lowerCAmelCase    :				Optional[int]=768   ,					**lowerCAmelCase    :				int   )->  Optional[Any]:

										"""simple docstring"""




										UpperCAmelCase         =			transformerDimSize
										UpperCAmelCase         =			imageDimSize
										super().__init__(**lowerCAmelCase__   )







class  UpperCamelCase__(     a__ ):
				__magic_name__       :   str							= MCLIPConfig




				def __init__(	self    :				List[str]   ,					lowerCAmelCase    :				Optional[int]   ,					*lowerCAmelCase    :				Optional[int]   ,					**lowerCAmelCase    :				Tuple   )->  Union[str, Any]:

										"""simple docstring"""




										super().__init__(lowerCAmelCase__   ,					*lowerCAmelCase__   ,					**lowerCAmelCase__   )
										UpperCAmelCase         =			XLMRobertaModel(lowerCAmelCase__   )
										UpperCAmelCase         =			torch.nn.Linear(
										    in_features=config.transformerDimensions   ,					out_features=config.numDims   )





				def   a__(	self    :				List[str]   ,					lowerCAmelCase    :				Any   ,					lowerCAmelCase    :				List[Any]   )->  str:

										"""simple docstring"""




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









'''simple docstring'''



from typing import TYPE_CHECKING

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


_lowercase    :    Any			     =  {
    """configuration_maskformer""": ["""MASKFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP""", """MaskFormerConfig"""],
    """configuration_maskformer_swin""": ["""MaskFormerSwinConfig"""],
}

try:
	if not is_vision_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	_lowercase    :    Any			     =  ["""MaskFormerFeatureExtractor"""]
	_lowercase    :    Dict			     =  ["""MaskFormerImageProcessor"""]


try:
	if not is_torch_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	_lowercase    :    Any			     =  [
	    """MASKFORMER_PRETRAINED_MODEL_ARCHIVE_LIST""",
	    """MaskFormerForInstanceSegmentation""",
	    """MaskFormerModel""",
	    """MaskFormerPreTrainedModel""",
	]
	_lowercase    :    List[Any]			     =  [
	    """MaskFormerSwinBackbone""",
	    """MaskFormerSwinModel""",
	    """MaskFormerSwinPreTrainedModel""",
	]

if TYPE_CHECKING:
	from .configuration_maskformer import MASKFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP, MaskFormerConfig
	from .configuration_maskformer_swin import MaskFormerSwinConfig

	try:
		if not is_vision_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .feature_extraction_maskformer import MaskFormerFeatureExtractor
		from .image_processing_maskformer import MaskFormerImageProcessor
	try:
		if not is_torch_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_maskformer import (
		    MASKFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
		    MaskFormerForInstanceSegmentation,
		    MaskFormerModel,
		    MaskFormerPreTrainedModel,
		)
		from .modeling_maskformer_swin import (
		    MaskFormerSwinBackbone,
		    MaskFormerSwinModel,
		    MaskFormerSwinPreTrainedModel,
		)


else:
	import sys

	_lowercase    :    List[Any]			     =  _LazyModule(__name__, globals()["""__file__"""], _import_structure)





