

'''simple docstring'''



import copy
from typing import TYPE_CHECKING, Any, Mapping, Optional, OrderedDict

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging
from ..auto.configuration_auto import AutoConfig


if TYPE_CHECKING:
   from ... import PreTrainedTokenizerBase, TensorType

SCREAMING_SNAKE_CASE_     = logging.get_logger(__name__)

class       SCREAMING_SNAKE_CASE       (				_SCREAMING_SNAKE_CASE       ):






      '''simple docstring'''






      SCREAMING_SNAKE_CASE__			:					Optional[int]     =					'''vision-encoder-decoder'''
      SCREAMING_SNAKE_CASE__			:					Optional[Any]     =					True




      def __init__(       self			:		int  ,       **snake_case			:		Union[str, Any] ):



          """simple docstring"""





          super().__init__(**_lowercase )
          if "encoder" not in kwargs or "decoder" not in kwargs:
              raise ValueError(
                  F"""A configuraton of type {self.model_type} cannot be instantiated because """
                  F"""not both `encoder` and `decoder` sub-configurations are passed, but only {kwargs}""" )

          _snake_case			:			str				       =		kwargs.pop('encoder' )
          _snake_case			:			str				       =		encoder_config.pop('model_type' )
          _snake_case			:			int				       =		kwargs.pop('decoder' )
          _snake_case			:			int				       =		decoder_config.pop('model_type' )

          _snake_case			:			Union[str, Any]				       =		AutoConfig.for_model(_lowercase  ,       **_lowercase )
          _snake_case			:			List[str]				       =		AutoConfig.for_model(_lowercase  ,       **_lowercase )
          _snake_case			:			List[str]				       =		True




      @classmethod
      def 						__UpperCAmelCase      (       cls			:		Any  ,       snake_case			:		Tuple  ,       snake_case			:		Tuple  ,       **snake_case			:		List[str] ):



          """simple docstring"""





          logger.info('Setting `config.is_decoder=True` and `config.add_cross_attention=True` for decoder_config' )
          _snake_case			:			int				       =		True
          _snake_case			:			Optional[Any]				       =		True

          return cls(encoder=encoder_config.to_dict()  ,       decoder=decoder_config.to_dict()  ,       **_lowercase )




      def 						__UpperCAmelCase      (       self			:		Dict ):



          """simple docstring"""





          _snake_case			:			Tuple				       =		copy.deepcopy(self.__dict__ )
          _snake_case			:			str				       =		self.encoder.to_dict()
          _snake_case			:			Optional[Any]				       =		self.decoder.to_dict()
          _snake_case			:			Dict				       =		self.__class__.model_type
          return output



class       SCREAMING_SNAKE_CASE       (				_SCREAMING_SNAKE_CASE       ):






      '''simple docstring'''






      SCREAMING_SNAKE_CASE__			:					Optional[Any]     =					version.parse('''1.11'''       )




      @property
      def 						__UpperCAmelCase      (       self			:		Optional[Any] ):



          """simple docstring"""





          return OrderedDict(
              [
                  ('pixel_values', {0: 'batch', 1: 'num_channels', 2: 'height', 3: 'width'}),
              ] )




      @property
      def 						__UpperCAmelCase      (       self			:		List[str] ):



          """simple docstring"""





          return 1e-4




      @property
      def 						__UpperCAmelCase      (       self			:		Tuple ):



          """simple docstring"""





          return OrderedDict({'last_hidden_state': {0: 'batch', 1: 'encoder_sequence'}} )



class       SCREAMING_SNAKE_CASE       (				_SCREAMING_SNAKE_CASE       ):






      '''simple docstring'''






      @property
      def 						__UpperCAmelCase      (       self			:		List[str] ):



          """simple docstring"""





          _snake_case			:			List[str]				       =		OrderedDict()
          _snake_case			:			Dict				       =		{0: 'batch', 1: 'past_decoder_sequence + sequence'}
          _snake_case			:			int				       =		{0: 'batch', 1: 'past_decoder_sequence + sequence'}
          _snake_case			:			str				       =		{0: 'batch', 1: 'encoder_sequence'}

          return common_inputs




      def 						__UpperCAmelCase      (       self			:		Dict  ,       snake_case			:		List[Any]  ,       snake_case			:		Optional[Any] = -1  ,       snake_case			:		Dict = -1  ,       snake_case			:		Dict = False  ,       snake_case			:		List[str] = None  ,       ):



          """simple docstring"""





          import torch

          _snake_case			:			Dict				       =		OrderedDict()

          _snake_case			:			List[str]				       =		super().generate_dummy_inputs(
              _lowercase  ,       batch_size=_lowercase  ,       seq_length=_lowercase  ,       is_pair=_lowercase  ,       framework=_lowercase )

          _snake_case       ,				_snake_case			:			List[Any]				       =		dummy_input['input_ids'].shape
          _snake_case			:			int				       =		(batch, encoder_sequence, self._config.encoder_hidden_size)
          _snake_case			:			str				       =		dummy_input.pop('input_ids' )
          _snake_case			:			Dict				       =		dummy_input.pop('attention_mask' )
          _snake_case			:			Optional[int]				       =		torch.zeros(_lowercase )

          return common_inputs



class       SCREAMING_SNAKE_CASE       (				_SCREAMING_SNAKE_CASE       ):






      '''simple docstring'''






      @property
      def 						__UpperCAmelCase      (       self			:		Union[str, Any] ):



          """simple docstring"""





          pass




      def 						__UpperCAmelCase      (       self			:		str  ,       snake_case			:		str ):



          """simple docstring"""





          return VisionEncoderDecoderEncoderOnnxConfig(_lowercase )




      def 						__UpperCAmelCase      (       self			:		int  ,       snake_case			:		Tuple  ,       snake_case			:		int  ,       snake_case			:		Tuple = "default" ):



          """simple docstring"""





          _snake_case			:			Tuple				       =		encoder_config.hidden_size
          return VisionEncoderDecoderDecoderOnnxConfig(_lowercase  ,       _lowercase )





'''simple docstring'''



from ...utils import (
    OptionalDependencyNotAvailable,
    is_torch_available,
    is_transformers_available,
    is_transformers_version,
)


try:
						if not (is_transformers_available() and is_torch_available()):
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						from ...utils.dummy_torch_and_transformers_objects import (
						    ImageTextPipelineOutput,
						    UniDiffuserPipeline,
						)
else:
						from .modeling_text_decoder import UniDiffuserTextDecoder
						from .modeling_uvit import UniDiffuserModel, UTransformeraDModel
						from .pipeline_unidiffuser import ImageTextPipelineOutput, UniDiffuserPipeline
