


from typing import Callable, Optional, Union

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


lowerCAmelCase__						:Union[str, Any]         =							logging.get_logger(__name__)

lowerCAmelCase__						:int         =							{
    '''microsoft/prophetnet-large-uncased''': (
        '''https://huggingface.co/microsoft/prophetnet-large-uncased/resolve/main/config.json'''
    ),
}

class 	__a   (       UpperCAmelCase    ):
		_a			:						Dict    			=			'prophetnet'
		_a			:						int    			=			['past_key_values']
		_a			:						Optional[int]    			=			{
		    'num_attention_heads': 'num_encoder_attention_heads',
		}
		def __init__(    self    ,					_SCREAMING_SNAKE_CASE = 0.1    ,					_SCREAMING_SNAKE_CASE = "gelu"    ,					_SCREAMING_SNAKE_CASE = 30522    ,					_SCREAMING_SNAKE_CASE = 1024    ,					_SCREAMING_SNAKE_CASE = 4096    ,					_SCREAMING_SNAKE_CASE = 12    ,					_SCREAMING_SNAKE_CASE = 16    ,					_SCREAMING_SNAKE_CASE = 4096    ,					_SCREAMING_SNAKE_CASE = 12    ,					_SCREAMING_SNAKE_CASE = 16    ,					_SCREAMING_SNAKE_CASE = 0.1    ,					_SCREAMING_SNAKE_CASE = 0.1    ,					_SCREAMING_SNAKE_CASE = 512    ,					_SCREAMING_SNAKE_CASE = 0.02    ,					_SCREAMING_SNAKE_CASE = True    ,					_SCREAMING_SNAKE_CASE = True    ,					_SCREAMING_SNAKE_CASE = 0    ,					_SCREAMING_SNAKE_CASE = 2    ,					_SCREAMING_SNAKE_CASE = 32    ,					_SCREAMING_SNAKE_CASE = 128    ,					_SCREAMING_SNAKE_CASE = False    ,					_SCREAMING_SNAKE_CASE = 0.0    ,					_SCREAMING_SNAKE_CASE = True    ,					_SCREAMING_SNAKE_CASE = 0    ,					_SCREAMING_SNAKE_CASE = 1    ,					_SCREAMING_SNAKE_CASE = 2    ,					**_SCREAMING_SNAKE_CASE    ,					)				-> Any:




									"""simple docstring"""





									_UpperCAmelCase					=    vocab_size
									_UpperCAmelCase					=    hidden_size
									_UpperCAmelCase					=    encoder_ffn_dim
									_UpperCAmelCase					=    num_encoder_layers
									_UpperCAmelCase					=    num_encoder_attention_heads
									_UpperCAmelCase					=    decoder_ffn_dim
									_UpperCAmelCase					=    num_decoder_layers
									_UpperCAmelCase					=    num_decoder_attention_heads
									_UpperCAmelCase					=    max_position_embeddings
									_UpperCAmelCase					=    init_std  # Normal(0, this parameter)
									_UpperCAmelCase					=    activation_function

									# parameters for prophetnet
									_UpperCAmelCase					=    ngram
									_UpperCAmelCase					=    num_buckets
									_UpperCAmelCase					=    relative_max_distance
									_UpperCAmelCase					=    disable_ngram_loss
									_UpperCAmelCase					=    eps

									# 3 Types of Dropout
									_UpperCAmelCase					=    attention_dropout
									_UpperCAmelCase					=    activation_dropout
									_UpperCAmelCase					=    dropout

									_UpperCAmelCase					=    use_cache

									super().__init__(
									    pad_token_id=_SCREAMING_SNAKE_CASE    ,					bos_token_id=_SCREAMING_SNAKE_CASE    ,					eos_token_id=_SCREAMING_SNAKE_CASE    ,					is_encoder_decoder=_SCREAMING_SNAKE_CASE    ,					add_cross_attention=_SCREAMING_SNAKE_CASE    ,					decoder_start_token_id=_SCREAMING_SNAKE_CASE    ,					**_SCREAMING_SNAKE_CASE    ,					)
		@property
		def 			UpperCAmelCase__       (    self		)				-> int:




									"""simple docstring"""





									return self.num_encoder_layers + self.num_decoder_layers






		@num_hidden_layers.setter
		def 			UpperCAmelCase__       (    self    ,					_SCREAMING_SNAKE_CASE		)				-> Tuple:




									"""simple docstring"""





									raise NotImplementedError(
									    'This model does not support the setting of `num_hidden_layers`. Please set `num_encoder_layers` and'
									    ' `num_decoder_layers`.'		)




import warnings

from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding

class 	__a   (       UpperCAmelCase    ):
		_a			:						int    			=			['image_processor', 'tokenizer']
		_a			:						Union[str, Any]    			=			'AutoImageProcessor'
		_a			:						Optional[int]    			=			'AutoTokenizer'
		def __init__(    self    ,					_SCREAMING_SNAKE_CASE=None    ,					_SCREAMING_SNAKE_CASE=None    ,					**_SCREAMING_SNAKE_CASE		)				-> Tuple:




									"""simple docstring"""





									_UpperCAmelCase					=    None
									if "feature_extractor" in kwargs:
																warnings.warn(
																    'The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`'
																    ' instead.'    ,					_SCREAMING_SNAKE_CASE    ,					)
																_UpperCAmelCase					=    kwargs.pop('feature_extractor'		)

									_UpperCAmelCase					=    image_processor if image_processor is not None else feature_extractor
									if image_processor is None:
																raise ValueError('You have to specify an image_processor.'		)
									if tokenizer is None:
																raise ValueError('You have to specify a tokenizer.'		)

									super().__init__(_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE		)
									_UpperCAmelCase					=    self.image_processor
		def __call__(    self    ,					_SCREAMING_SNAKE_CASE=None    ,					_SCREAMING_SNAKE_CASE=None    ,					_SCREAMING_SNAKE_CASE=None    ,					**_SCREAMING_SNAKE_CASE		)				-> Dict:




									"""simple docstring"""





									if text is None and images is None:
																raise ValueError('You have to specify either text or images. Both cannot be none.'		)

									if text is not None:
																_UpperCAmelCase					=    self.tokenizer(_SCREAMING_SNAKE_CASE    ,					return_tensors=_SCREAMING_SNAKE_CASE    ,					**_SCREAMING_SNAKE_CASE		)

									if images is not None:
																_UpperCAmelCase					=    self.image_processor(_SCREAMING_SNAKE_CASE    ,					return_tensors=_SCREAMING_SNAKE_CASE    ,					**_SCREAMING_SNAKE_CASE		)

									if text is not None and images is not None:
																_UpperCAmelCase					=    image_features.pixel_values
																return encoding
									elif text is not None:
																return encoding
									else:
																return BatchEncoding(data=dict(**_SCREAMING_SNAKE_CASE		)    ,					tensor_type=_SCREAMING_SNAKE_CASE		)
		def 			UpperCAmelCase__       (    self    ,					*_SCREAMING_SNAKE_CASE    ,					**_SCREAMING_SNAKE_CASE		)				-> int:




									"""simple docstring"""





									return self.tokenizer.batch_decode(*_SCREAMING_SNAKE_CASE    ,					**_SCREAMING_SNAKE_CASE		)
		def 			UpperCAmelCase__       (    self    ,					*_SCREAMING_SNAKE_CASE    ,					**_SCREAMING_SNAKE_CASE		)				-> Tuple:




									"""simple docstring"""





									return self.tokenizer.decode(*_SCREAMING_SNAKE_CASE    ,					**_SCREAMING_SNAKE_CASE		)
		@property
		def 			UpperCAmelCase__       (    self		)				-> Optional[int]:




									"""simple docstring"""





									_UpperCAmelCase					=    self.tokenizer.model_input_names
									_UpperCAmelCase					=    self.image_processor.model_input_names
									return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names		)		)
		@property
		def 			UpperCAmelCase__       (    self		)				-> Any:




									"""simple docstring"""





									warnings.warn(
									    '`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead.'    ,					_SCREAMING_SNAKE_CASE    ,					)
									return self.image_processor_class






		@property
		def 			UpperCAmelCase__       (    self		)				-> Any:




									"""simple docstring"""





									warnings.warn(
									    '`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead.'    ,					_SCREAMING_SNAKE_CASE    ,					)
									return self.image_processor
