





import copy

from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ..auto.configuration_auto import AutoConfig
from ..clip.configuration_clip import CLIPVisionConfig


_UpperCAmelCase										=					logging.get_logger(__name__)



class 				_UpperCamelCase       (						lowerCAmelCase_  ):
       _UpperCamelCase					:       Optional[int]       = """vision-text-dual-encoder"""
       _UpperCamelCase					:       Optional[Any]       = True

       def __init__(		self:			Optional[int]       , _SCREAMING_SNAKE_CASE:			Optional[int]=512       , _SCREAMING_SNAKE_CASE:			Optional[int]=2.65_92       , **_SCREAMING_SNAKE_CASE:			Tuple		)							->			Any:




              """simple docstring"""


              super().__init__(**UpperCAmelCase__		)

              if "vision_config" not in kwargs:
                     raise ValueError("`vision_config` can not be `None`."		)

              if "text_config" not in kwargs:
                     raise ValueError("`text_config` can not be `None`."		)

              UpperCamelCase_ 							=	kwargs.pop("vision_config"		)
              UpperCamelCase_ 							=	kwargs.pop("text_config"		)

              UpperCamelCase_ 							=	vision_config.pop("model_type"		)
              UpperCamelCase_ 							=	text_config.pop("model_type"		)

              if vision_model_type == "clip":
                     UpperCamelCase_ 							=	AutoConfig.for_model(UpperCAmelCase__       , **UpperCAmelCase__		).vision_config
              elif vision_model_type == "clip_vision_model":
                     UpperCamelCase_ 							=	CLIPVisionConfig(**UpperCAmelCase__		)
              else:
                     UpperCamelCase_ 							=	AutoConfig.for_model(UpperCAmelCase__       , **UpperCAmelCase__		)

              UpperCamelCase_ 							=	AutoConfig.for_model(UpperCAmelCase__       , **UpperCAmelCase__		)

              UpperCamelCase_ 							=	projection_dim
              UpperCamelCase_ 							=	logit_scale_init_value

       @classmethod
       def lowercase			(		cls:			Optional[Any]       , _SCREAMING_SNAKE_CASE:			PretrainedConfig       , _SCREAMING_SNAKE_CASE:			PretrainedConfig       , **_SCREAMING_SNAKE_CASE:			str		)							->			str:




              """simple docstring"""


              return cls(vision_config=vision_config.to_dict()       , text_config=text_config.to_dict()       , **UpperCAmelCase__		)



       def lowercase			(		self:			List[Any]		)							->			List[str]:




              """simple docstring"""


              UpperCamelCase_ 							=	copy.deepcopy(self.__dict__		)
              UpperCamelCase_ 							=	self.vision_config.to_dict()
              UpperCamelCase_ 							=	self.text_config.to_dict()
              UpperCamelCase_ 							=	self.__class__.model_type
              return output




from typing import List, Optional, Tuple, Union

from . import logging
from .import_utils import is_torch_available, is_torch_version


if is_torch_available():
  import torch

UpperCAmelCase__			:  int					     =     logging.get_logger(__name__)  # pylint: disable=invalid-name

try:
  from torch._dynamo import allow_in_graph as maybe_allow_in_graph
except (ImportError, ModuleNotFoundError):






  def        __lowercase   (  cls      )  ->    Any:
        return cls






def        __lowercase   (  _A    ,     _A = None    ,     _A = None    ,     _A = None    ,     _A = None    ,     )  ->    Tuple:
      SCREAMING_SNAKE_CASE			:   Optional[Any]	  = device
      SCREAMING_SNAKE_CASE			:   Tuple	  = shape[0]

      SCREAMING_SNAKE_CASE			:   Optional[int]	  = layout or torch.strided
      SCREAMING_SNAKE_CASE			:   Dict	  = device or torch.device("""cpu"""      )

      if generator is not None:
            SCREAMING_SNAKE_CASE			:   Optional[Any]	  = generator.device.type if not isinstance(_A    ,     _A      ) else generator[0].device.type
            if gen_device_type != device.type and gen_device_type == "cpu":
                  SCREAMING_SNAKE_CASE			:   Tuple	  = """cpu"""
                  if device != "mps":
                        logger.info(
                            F"The passed generator was created on 'cpu' even though a tensor on {device} was expected."
                            F" Tensors will be created on 'cpu' and then moved to {device}. Note that one can probably"
                            F" slighly speed up this function by passing a generator that was created on the {device} device."      )
            elif gen_device_type != device.type and gen_device_type == "cuda":
                  raise ValueError(F"Cannot generate a {device} tensor from a generator of type {gen_device_type}."      )

      if isinstance(_A    ,     _A      ):
            SCREAMING_SNAKE_CASE			:   int	  = (1,) + shape[1:]
            SCREAMING_SNAKE_CASE			:   Any	  = [
                torch.randn(_A    ,     generator=generator[i]    ,     device=_A    ,     dtype=_A    ,     layout=_A      )
                for i in range(_A      )
            ]
            SCREAMING_SNAKE_CASE			:   Any	  = torch.cat(_A    ,     dim=0      ).to(_A      )
      else:
            SCREAMING_SNAKE_CASE			:   int	  = torch.randn(_A    ,     generator=_A    ,     device=_A    ,     dtype=_A    ,     layout=_A      ).to(_A      )

      return latents







def        __lowercase   (  _A      )  ->    Dict:
      if is_torch_version("""<"""    ,     """2.0.0"""      ) or not hasattr(_A    ,     """_dynamo"""      ):
            return False
      return isinstance(_A    ,     torch._dynamo.eval_frame.OptimizedModule      )




