import torch
from transformers import PreTrainedModel, XLMRobertaConfig, XLMRobertaModel





class UpperCAmelCase						( snake_case__  ):


				'''simple docstring'''






				lowerCamelCase_    = '''M-CLIP'''
				def __init__(						self		,     lowercase=1_0_2_4		,     lowercase=7_6_8		,     **lowercase ):



						"""simple docstring"""





						A_		:    Any         =				transformerDimSize
						A_		:    Union[str, Any]         =				imageDimSize
						super().__init__(**UpperCAmelCase_ )





class UpperCAmelCase						( snake_case__  ):


				'''simple docstring'''






				lowerCamelCase_    = MCLIPConfig
				def __init__(						self		,     lowercase		,     *lowercase		,     **lowercase ):



						"""simple docstring"""





						super().__init__(UpperCAmelCase_		,     *UpperCAmelCase_		,     **UpperCAmelCase_ )
						A_		:    int         =				XLMRobertaModel(UpperCAmelCase_ )
						A_		:    str         =				torch.nn.Linear(
						    in_features=config.transformerDimensions		,     out_features=config.numDims )







				def   lowerCAmelCase_       (						self		,     lowercase		,     lowercase ):



						"""simple docstring"""





						A_		:    Optional[Any]         =				self.transformer(input_ids=UpperCAmelCase_		,     attention_mask=UpperCAmelCase_ )[0]
						A_		:    List[Any]         =				(embs * attention_mask.unsqueeze(2 )).sum(dim=1 ) / attention_mask.sum(dim=1 )[:, None]
						return self.LinearTransformation(UpperCAmelCase_ ), embs







from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


_UpperCAmelCase            =		{
    """configuration_instructblip""": [
        """INSTRUCTBLIP_PRETRAINED_CONFIG_ARCHIVE_MAP""",
        """InstructBlipConfig""",
        """InstructBlipQFormerConfig""",
        """InstructBlipVisionConfig""",
    ],
    """processing_instructblip""": ["""InstructBlipProcessor"""],
}

try:
	if not is_torch_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	_UpperCAmelCase            =		[
	    """INSTRUCTBLIP_PRETRAINED_MODEL_ARCHIVE_LIST""",
	    """InstructBlipQFormerModel""",
	    """InstructBlipPreTrainedModel""",
	    """InstructBlipForConditionalGeneration""",
	    """InstructBlipVisionModel""",
	]

if TYPE_CHECKING:
	from .configuration_instructblip import (
	    INSTRUCTBLIP_PRETRAINED_CONFIG_ARCHIVE_MAP,
	    InstructBlipConfig,
	    InstructBlipQFormerConfig,
	    InstructBlipVisionConfig,
	)
	from .processing_instructblip import InstructBlipProcessor

	try:
		if not is_torch_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_instructblip import (
		    INSTRUCTBLIP_PRETRAINED_MODEL_ARCHIVE_LIST,
		    InstructBlipForConditionalGeneration,
		    InstructBlipPreTrainedModel,
		    InstructBlipQFormerModel,
		    InstructBlipVisionModel,
		)

else:
	import sys

	_UpperCAmelCase            =		_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)






