






from typing import List, Optional, Union

from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding, PaddingStrategy, PreTokenizedInput, TextInput, TruncationStrategy
from ...utils import TensorType




class 			snake_case__   (							lowercase_):

       '''simple docstring'''
       lowerCamelCase							:				Any 				= ["image_processor", "tokenizer"]
       lowerCamelCase							:				List[str] 				= "Pix2StructImageProcessor"
       lowerCamelCase							:				int 				= ("T5Tokenizer", "T5TokenizerFast")



       def __init__(							self			,						a__			,						a__    ) ->      str:






            '''simple docstring'''





            __snake_case			:Dict          =						False
            super().__init__(a__			,						a__    )



       def __call__(							self			,						a__=None			,						a__ = None			,						a__ = True			,						a__ = False			,						a__ = None			,						a__ = None			,						a__ = 20_48			,						a__ = 0			,						a__ = None			,						a__ = None			,						a__ = False			,						a__ = False			,						a__ = False			,						a__ = False			,						a__ = False			,						a__ = True			,						a__ = None			,						**a__			,						) ->      BatchEncoding:






            '''simple docstring'''





            if images is None and text is None:
                 raise ValueError("""You have to specify either images or text."""    )

            # Get only text
            if images is None and not self.image_processor.is_vqa:
                 __snake_case			:List[Any]          =						self.tokenizer
                 __snake_case			:Optional[Any]          =						self.tokenizer(
                     text=a__			,						add_special_tokens=a__			,						padding=a__			,						truncation=a__			,						max_length=a__			,						stride=a__			,						pad_to_multiple_of=a__			,						return_attention_mask=a__			,						return_overflowing_tokens=a__			,						return_special_tokens_mask=a__			,						return_offsets_mapping=a__			,						return_token_type_ids=a__			,						return_length=a__			,						verbose=a__			,						return_tensors=a__			,						**a__			,						)
                 return text_encoding

            if not self.image_processor.is_vqa:
                 # add pixel_values
                 __snake_case			:Tuple          =						self.image_processor(
                     a__			,						return_tensors=a__			,						max_patches=a__			,						**a__    )
            else:
                 # add pixel_values and bbox
                 __snake_case			:Optional[Any]          =						self.image_processor(
                     a__			,						return_tensors=a__			,						max_patches=a__			,						header_text=a__			,						**a__    )

            if text is not None and not self.image_processor.is_vqa:
                 __snake_case			:Dict          =						self.tokenizer(
                     text=a__			,						add_special_tokens=a__			,						padding=a__			,						truncation=a__			,						max_length=a__			,						stride=a__			,						pad_to_multiple_of=a__			,						return_attention_mask=a__			,						return_overflowing_tokens=a__			,						return_special_tokens_mask=a__			,						return_offsets_mapping=a__			,						return_token_type_ids=a__			,						return_length=a__			,						verbose=a__			,						return_tensors=a__			,						**a__			,						)

                 if "attention_mask" in text_encoding:
                      __snake_case			:List[str]          =						text_encoding.pop("""attention_mask"""    )
                 if "input_ids" in text_encoding:
                      __snake_case			:List[str]          =						text_encoding.pop("""input_ids"""    )
            else:
                 __snake_case			:int          =						None

            if text_encoding is not None:
                 encoding_image_processor.update(a__    )

            return encoding_image_processor



       def 					__lowercase						(							self			,						*a__			,						**a__    ) ->      Optional[Any]:






            '''simple docstring'''





            return self.tokenizer.batch_decode(*a__			,						**a__    )



       def 					__lowercase						(							self			,						*a__			,						**a__    ) ->      Dict:






            '''simple docstring'''





            return self.tokenizer.decode(*a__			,						**a__    )



       @property
       def 					__lowercase						(							self    ) ->      List[str]:






            '''simple docstring'''





            __snake_case			:Optional[Any]          =						self.tokenizer.model_input_names
            __snake_case			:Optional[int]          =						self.image_processor.model_input_names
            return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names    )    )









import copy
import os
from typing import TYPE_CHECKING, List, Union


if TYPE_CHECKING:
     pass

from ...configuration_utils import PretrainedConfig
from ...utils import logging


lowerCamelCase__							=     logging.get_logger(__name__)

lowerCamelCase__							=     {
    """kakaobrain/align-base""": """https://huggingface.co/kakaobrain/align-base/resolve/main/config.json""",
}




class 			snake_case__   (							lowercase_):

       '''simple docstring'''
       lowerCamelCase							:				Union[str, Any] 				= "align_text_model"



       def __init__(							self			,						a__=3_05_22			,						a__=7_68			,						a__=12			,						a__=12			,						a__=30_72			,						a__="gelu"			,						a__=0.1			,						a__=0.1			,						a__=5_12			,						a__=2			,						a__=0.02			,						a__=1e-12			,						a__=0			,						a__="absolute"			,						a__=True			,						**a__			,						) ->      List[str]:






            '''simple docstring'''





            super().__init__(**a__    )

            __snake_case			:Optional[int]          =						vocab_size
            __snake_case			:List[str]          =						hidden_size
            __snake_case			:Optional[Any]          =						num_hidden_layers
            __snake_case			:int          =						num_attention_heads
            __snake_case			:Optional[Any]          =						hidden_act
            __snake_case			:Union[str, Any]          =						intermediate_size
            __snake_case			:int          =						hidden_dropout_prob
            __snake_case			:Optional[Any]          =						attention_probs_dropout_prob
            __snake_case			:List[str]          =						max_position_embeddings
            __snake_case			:List[str]          =						type_vocab_size
            __snake_case			:Union[str, Any]          =						initializer_range
            __snake_case			:str          =						layer_norm_eps
            __snake_case			:Any          =						position_embedding_type
            __snake_case			:List[str]          =						use_cache
            __snake_case			:Optional[int]          =						pad_token_id



       @classmethod
       def 					__lowercase						(							cls			,						a__			,						**a__    ) ->      "PretrainedConfig":






            '''simple docstring'''





            cls._set_token_in_kwargs(a__    )

            __snake_case       , __snake_case			:Tuple          =						cls.get_config_dict(a__			,						**a__    )

            # get the text config dict if we are loading from AlignConfig
            if config_dict.get("""model_type"""    ) == "align":
                 __snake_case			:Any          =						config_dict["""text_config"""]

            if "model_type" in config_dict and hasattr(cls			,						"""model_type"""    ) and config_dict["model_type"] != cls.model_type:
                 logger.warning(
                     F'''You are using a model of type {config_dict['model_type']} to instantiate a model of type '''
                     F'''{cls.model_type}. This is not supported for all configurations of models and can yield errors.'''    )

            return cls.from_dict(a__			,						**a__    )




class 			snake_case__   (							lowercase_):

       '''simple docstring'''
       lowerCamelCase							:				Optional[int] 				= "align_vision_model"



       def __init__(							self			,						a__ = 3			,						a__ = 6_00			,						a__ = 2.0			,						a__ = 3.1			,						a__ = 8			,						a__ = [3, 3, 5, 3, 5, 5, 3]			,						a__ = [32, 16, 24, 40, 80, 1_12, 1_92]			,						a__ = [16, 24, 40, 80, 1_12, 1_92, 3_20]			,						a__ = []			,						a__ = [1, 2, 2, 2, 1, 2, 1]			,						a__ = [1, 2, 2, 3, 3, 4, 1]			,						a__ = [1, 6, 6, 6, 6, 6, 6]			,						a__ = 0.25			,						a__ = "swish"			,						a__ = 25_60			,						a__ = "mean"			,						a__ = 0.02			,						a__ = 0.0_01			,						a__ = 0.99			,						a__ = 0.2			,						**a__			,						) ->      List[Any]:






            '''simple docstring'''





            super().__init__(**a__    )

            __snake_case			:Union[str, Any]          =						num_channels
            __snake_case			:List[str]          =						image_size
            __snake_case			:int          =						width_coefficient
            __snake_case			:int          =						depth_coefficient
            __snake_case			:List[Any]          =						depth_divisor
            __snake_case			:Any          =						kernel_sizes
            __snake_case			:Optional[int]          =						in_channels
            __snake_case			:Optional[int]          =						out_channels
            __snake_case			:int          =						depthwise_padding
            __snake_case			:List[str]          =						strides
            __snake_case			:Union[str, Any]          =						num_block_repeats
            __snake_case			:Dict          =						expand_ratios
            __snake_case			:Union[str, Any]          =						squeeze_expansion_ratio
            __snake_case			:Any          =						hidden_act
            __snake_case			:Optional[Any]          =						hidden_dim
            __snake_case			:Union[str, Any]          =						pooling_type
            __snake_case			:Union[str, Any]          =						initializer_range
            __snake_case			:Optional[Any]          =						batch_norm_eps
            __snake_case			:List[Any]          =						batch_norm_momentum
            __snake_case			:Optional[int]          =						drop_connect_rate
            __snake_case			:Union[str, Any]          =						sum(a__    ) * 4



       @classmethod
       def 					__lowercase						(							cls			,						a__			,						**a__    ) ->      "PretrainedConfig":






            '''simple docstring'''





            cls._set_token_in_kwargs(a__    )

            __snake_case       , __snake_case			:int          =						cls.get_config_dict(a__			,						**a__    )

            # get the vision config dict if we are loading from AlignConfig
            if config_dict.get("""model_type"""    ) == "align":
                 __snake_case			:str          =						config_dict["""vision_config"""]

            if "model_type" in config_dict and hasattr(cls			,						"""model_type"""    ) and config_dict["model_type"] != cls.model_type:
                 logger.warning(
                     F'''You are using a model of type {config_dict['model_type']} to instantiate a model of type '''
                     F'''{cls.model_type}. This is not supported for all configurations of models and can yield errors.'''    )

            return cls.from_dict(a__			,						**a__    )




class 			snake_case__   (							lowercase_):

       '''simple docstring'''
       lowerCamelCase							:				str 				= "align"
       lowerCamelCase							:				Union[str, Any] 				= True



       def __init__(							self			,						a__=None			,						a__=None			,						a__=6_40			,						a__=1.0			,						a__=0.02			,						**a__			,						) ->      Dict:






            '''simple docstring'''





            super().__init__(**a__    )

            if text_config is None:
                 __snake_case			:Union[str, Any]          =						{}
                 logger.info("""text_config is None. Initializing the AlignTextConfig with default values."""    )

            if vision_config is None:
                 __snake_case			:str          =						{}
                 logger.info("""vision_config is None. Initializing the AlignVisionConfig with default values."""    )

            __snake_case			:List[Any]          =						AlignTextConfig(**a__    )
            __snake_case			:Tuple          =						AlignVisionConfig(**a__    )

            __snake_case			:Tuple          =						projection_dim
            __snake_case			:int          =						temperature_init_value
            __snake_case			:Any          =						initializer_range



       @classmethod
       def 					__lowercase						(							cls			,						a__			,						a__			,						**a__    ) ->      str:






            '''simple docstring'''





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



       def 					__lowercase						(							self    ) ->      Dict:






            '''simple docstring'''





            __snake_case			:Optional[Any]          =						copy.deepcopy(self.__dict__    )
            __snake_case			:Dict          =						self.text_config.to_dict()
            __snake_case			:Union[str, Any]          =						self.vision_config.to_dict()
            __snake_case			:List[Any]          =						self.__class__.model_type
            return output


