



from collections import OrderedDict
from typing import TYPE_CHECKING, Any, Mapping, Optional, Union

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig, OnnxSeqaSeqConfigWithPast
from ...utils import logging


if TYPE_CHECKING:
						from ...feature_extraction_utils import FeatureExtractionMixin
						from ...tokenization_utils_base import PreTrainedTokenizerBase
						from ...utils import TensorType

lowerCamelCase		       =      logging.get_logger(__name__)

lowerCamelCase		       =      {
    """openai/whisper-base""": """https://huggingface.co/openai/whisper-base/resolve/main/config.json""",
}

# fmt: off
lowerCamelCase		       =      [
    1, 2, 7, 8, 9, 10, 14, 25,
    26, 27, 28, 29, 31, 58, 59, 60, 61, 62,
    63, 90, 91, 92, 93, 3_57, 3_66, 4_38, 5_32, 6_85,
    7_05, 7_96, 9_30, 10_58, 12_20, 12_67, 12_79, 13_03, 13_43, 13_77,
    13_91, 16_35, 17_82, 18_75, 21_62, 23_61, 24_88, 34_67, 40_08, 42_11,
    46_00, 48_08, 52_99, 58_55, 63_29, 72_03, 96_09, 99_59, 1_05_63, 1_07_86,
    1_14_20, 1_17_09, 1_19_07, 1_31_63, 1_36_97, 1_37_00, 1_48_08, 1_53_06, 1_64_10, 1_67_91,
    1_79_92, 1_92_03, 1_95_10, 2_07_24, 2_23_05, 2_29_35, 2_70_07, 3_01_09, 3_04_20, 3_34_09,
    3_49_49, 4_02_83, 4_04_93, 4_05_49, 4_72_82, 4_91_46, 5_02_57, 5_03_59, 5_03_60, 5_03_61
]
lowerCamelCase		       =      [
    1, 2, 7, 8, 9, 10, 14, 25,
    26, 27, 28, 29, 31, 58, 59, 60, 61, 62,
    63, 90, 91, 92, 93, 3_59, 5_03, 5_22, 5_42, 8_73,
    8_93, 9_02, 9_18, 9_22, 9_31, 13_50, 18_53, 19_82, 24_60, 26_27,
    32_46, 32_53, 32_68, 35_36, 38_46, 39_61, 41_83, 46_67, 65_85, 66_47,
    72_73, 90_61, 93_83, 1_04_28, 1_09_29, 1_19_38, 1_20_33, 1_23_31, 1_25_62, 1_37_93,
    1_41_57, 1_46_35, 1_52_65, 1_56_18, 1_65_53, 1_66_04, 1_83_62, 1_89_56, 2_00_75, 2_16_75,
    2_25_20, 2_61_30, 2_61_61, 2_64_35, 2_82_79, 2_94_64, 3_16_50, 3_23_02, 3_24_70, 3_68_65,
    4_28_63, 4_74_25, 4_98_70, 5_02_54, 5_02_58, 5_03_60, 5_03_61, 5_03_62
]


class 				_a						(       SCREAMING_SNAKE_CASE			):





							'''simple docstring'''

							A				:str =       "whisper"
							A				:Tuple =       ["past_key_values"]
							A				:int =       {"num_attention_heads": "encoder_attention_heads", "hidden_size": "d_model"}



							def __init__(							self ,					__UpperCAmelCase=5_1865 ,					__UpperCAmelCase=80 ,					__UpperCAmelCase=6 ,					__UpperCAmelCase=4 ,					__UpperCAmelCase=6 ,					__UpperCAmelCase=4 ,					__UpperCAmelCase=1536 ,					__UpperCAmelCase=1536 ,					__UpperCAmelCase=0.0 ,					__UpperCAmelCase=0.0 ,					__UpperCAmelCase=5_0257 ,					__UpperCAmelCase=True ,					__UpperCAmelCase=True ,					__UpperCAmelCase="gelu" ,					__UpperCAmelCase=256 ,					__UpperCAmelCase=0.0 ,					__UpperCAmelCase=0.0 ,					__UpperCAmelCase=0.0 ,					__UpperCAmelCase=0.0_2 ,					__UpperCAmelCase=False ,					__UpperCAmelCase=1500 ,					__UpperCAmelCase=448 ,					__UpperCAmelCase=5_0256 ,					__UpperCAmelCase=5_0256 ,					__UpperCAmelCase=5_0256 ,					__UpperCAmelCase=None ,					__UpperCAmelCase=[220, 5_0256] ,					__UpperCAmelCase=False ,					__UpperCAmelCase=256 ,					__UpperCAmelCase=False ,					__UpperCAmelCase=0.0_5 ,					__UpperCAmelCase=10 ,					__UpperCAmelCase=2 ,					__UpperCAmelCase=0.0 ,					__UpperCAmelCase=10 ,					__UpperCAmelCase=0 ,					__UpperCAmelCase=7 ,					**__UpperCAmelCase ,					):







											"""simple docstring"""



											a__	:							List[str]      						= vocab_size
											a__	:							List[str]      						= num_mel_bins
											a__	:							str      						= d_model
											a__	:							Union[str, Any]      						= encoder_layers
											a__	:							int      						= encoder_attention_heads
											a__	:							List[Any]      						= decoder_layers
											a__	:							Any      						= decoder_attention_heads
											a__	:							Dict      						= decoder_ffn_dim
											a__	:							Tuple      						= encoder_ffn_dim
											a__	:							Union[str, Any]      						= dropout
											a__	:							Optional[int]      						= attention_dropout
											a__	:							Union[str, Any]      						= activation_dropout
											a__	:							Optional[int]      						= activation_function
											a__	:							List[Any]      						= init_std
											a__	:							List[str]      						= encoder_layerdrop
											a__	:							str      						= decoder_layerdrop
											a__	:							List[Any]      						= use_cache
											a__	:							Dict      						= encoder_layers
											a__	:							Tuple      						= scale_embedding  # scale factor will be sqrt(d_model) if True
											a__	:							Optional[int]      						= max_source_positions
											a__	:							Tuple      						= max_target_positions

											# Audio Classification-specific parameters. Feel free to ignore for other classes.
											a__	:							int      						= classifier_proj_size
											a__	:							Union[str, Any]      						= use_weighted_layer_sum

											# fine-tuning config parameters for SpecAugment: https://arxiv.org/abs/1904.08779
											a__	:							str      						= apply_spec_augment
											a__	:							Dict      						= mask_time_prob
											a__	:							List[Any]      						= mask_time_length
											a__	:							Union[str, Any]      						= mask_time_min_masks
											a__	:							List[str]      						= mask_feature_prob
											a__	:							Dict      						= mask_feature_length
											a__	:							Any      						= mask_feature_min_masks

											a__	:							Union[str, Any]      						= median_filter_width

											super().__init__(
											    pad_token_id=__UpperCAmelCase ,					bos_token_id=__UpperCAmelCase ,					eos_token_id=__UpperCAmelCase ,					is_encoder_decoder=__UpperCAmelCase ,					decoder_start_token_id=__UpperCAmelCase ,					suppress_tokens=__UpperCAmelCase ,					begin_suppress_tokens=__UpperCAmelCase ,					**__UpperCAmelCase ,					)





class 				_a						(       SCREAMING_SNAKE_CASE			):





							'''simple docstring'''

							@property
							def 		_A	(							self				):







											"""simple docstring"""



											a__	:							Any      						= OrderedDict(
											    [
											        ("input_features", {0: "batch", 1: "feature_size", 2: "encoder_sequence"}),
											    ]				)
											if self.use_past:
															a__	:							Dict      						= {0: "batch"}
											else:
															a__	:							Union[str, Any]      						= {0: "batch", 1: "decoder_sequence"}

											if self.use_past:
															self.fill_with_past_key_values_(__UpperCAmelCase ,					direction="inputs"				)

											return common_inputs



							def 		_A	(							self ,					__UpperCAmelCase ,					__UpperCAmelCase = -1 ,					__UpperCAmelCase = -1 ,					__UpperCAmelCase = False ,					__UpperCAmelCase = None ,					__UpperCAmelCase = 2_2050 ,					__UpperCAmelCase = 5.0 ,					__UpperCAmelCase = 220 ,					):







											"""simple docstring"""



											a__	:							Optional[Any]      						= OrderedDict()
											a__	:							str      						= OnnxConfig.generate_dummy_inputs(
											    self ,					preprocessor=preprocessor.feature_extractor ,					batch_size=__UpperCAmelCase ,					framework=__UpperCAmelCase ,					sampling_rate=__UpperCAmelCase ,					time_duration=__UpperCAmelCase ,					frequency=__UpperCAmelCase ,					)
											a__	:							Optional[Any]      						= encoder_inputs["input_features"].shape[2]
											a__	:							Optional[Any]      						= encoder_sequence_length // 2 if self.use_past else seq_length

											a__	:							int      						= super().generate_dummy_inputs(
											    preprocessor.tokenizer ,					__UpperCAmelCase ,					__UpperCAmelCase ,					__UpperCAmelCase ,					__UpperCAmelCase				)

											a__	:							List[Any]      						= encoder_inputs.pop("input_features"				)
											a__	:							Dict      						= decoder_inputs.pop("decoder_input_ids"				)

											if "past_key_values" in decoder_inputs:
															a__	:							Tuple      						= decoder_inputs.pop("past_key_values"				)

											return dummy_inputs




							@property
							def 		_A	(							self				):







											"""simple docstring"""



											return 1E-3







import warnings
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 				_a						(       SCREAMING_SNAKE_CASE			):





							'''simple docstring'''

							A				:int =       ["image_processor", "tokenizer"]
							A				:Any =       "LayoutLMv3ImageProcessor"
							A				:str =       ("LayoutLMv3Tokenizer", "LayoutLMv3TokenizerFast")



							def __init__(							self ,					__UpperCAmelCase=None ,					__UpperCAmelCase=None ,					**__UpperCAmelCase				):







											"""simple docstring"""



											a__	:							str      						= None
											if "feature_extractor" in kwargs:
															warnings.warn(
															    "The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`"
															    " instead." ,					__UpperCAmelCase ,					)
															a__	:							List[str]      						= kwargs.pop("feature_extractor"				)

											a__	:							Optional[int]      						= image_processor if image_processor is not None else feature_extractor
											if image_processor is None:
															raise ValueError("You need to specify an `image_processor`."				)
											if tokenizer is None:
															raise ValueError("You need to specify a `tokenizer`."				)

											super().__init__(__UpperCAmelCase ,					__UpperCAmelCase				)



							def __call__(							self ,					__UpperCAmelCase ,					__UpperCAmelCase = None ,					__UpperCAmelCase = None ,					__UpperCAmelCase = None ,					__UpperCAmelCase = None ,					__UpperCAmelCase = True ,					__UpperCAmelCase = False ,					__UpperCAmelCase = None ,					__UpperCAmelCase = None ,					__UpperCAmelCase = 0 ,					__UpperCAmelCase = None ,					__UpperCAmelCase = None ,					__UpperCAmelCase = None ,					__UpperCAmelCase = False ,					__UpperCAmelCase = False ,					__UpperCAmelCase = False ,					__UpperCAmelCase = False ,					__UpperCAmelCase = True ,					__UpperCAmelCase = None ,					**__UpperCAmelCase ,					):







											"""simple docstring"""



											if self.image_processor.apply_ocr and (boxes is not None):
															raise ValueError(
															    "You cannot provide bounding boxes if you initialized the image processor with apply_ocr set to True."				)

											if self.image_processor.apply_ocr and (word_labels is not None):
															raise ValueError(
															    "You cannot provide word labels if you initialized the image processor with apply_ocr set to True."				)

											# first, apply the image processor
											a__	:							List[str]      						= self.image_processor(images=__UpperCAmelCase ,					return_tensors=__UpperCAmelCase				)

											# second, apply the tokenizer
											if text is not None and self.image_processor.apply_ocr and text_pair is None:
															if isinstance(__UpperCAmelCase ,					__UpperCAmelCase				):
																			a__	:							Union[str, Any]      						= [text]  # add batch dimension (as the image processor always adds a batch dimension)
															a__	:							Optional[Any]      						= features["words"]

											a__	:							Union[str, Any]      						= self.tokenizer(
											    text=text if text is not None else features["words"] ,					text_pair=text_pair if text_pair is not None else None ,					boxes=boxes if boxes is not None else features["boxes"] ,					word_labels=__UpperCAmelCase ,					add_special_tokens=__UpperCAmelCase ,					padding=__UpperCAmelCase ,					truncation=__UpperCAmelCase ,					max_length=__UpperCAmelCase ,					stride=__UpperCAmelCase ,					pad_to_multiple_of=__UpperCAmelCase ,					return_token_type_ids=__UpperCAmelCase ,					return_attention_mask=__UpperCAmelCase ,					return_overflowing_tokens=__UpperCAmelCase ,					return_special_tokens_mask=__UpperCAmelCase ,					return_offsets_mapping=__UpperCAmelCase ,					return_length=__UpperCAmelCase ,					verbose=__UpperCAmelCase ,					return_tensors=__UpperCAmelCase ,					**__UpperCAmelCase ,					)

											# add pixel values
											a__	:							Dict      						= features.pop("pixel_values"				)
											if return_overflowing_tokens is True:
															a__	:							str      						= self.get_overflowing_images(__UpperCAmelCase ,					encoded_inputs["overflow_to_sample_mapping"]				)
											a__	:							Tuple      						= images

											return encoded_inputs



							def 		_A	(							self ,					__UpperCAmelCase ,					__UpperCAmelCase				):







											"""simple docstring"""



											a__	:							Any      						= []
											for sample_idx in overflow_to_sample_mapping:
															images_with_overflow.append(images[sample_idx]				)

											if len(__UpperCAmelCase				) != len(__UpperCAmelCase				):
															raise ValueError(
															    "Expected length of images to be the same as the length of `overflow_to_sample_mapping`, but got"
															    f' {len(__UpperCAmelCase				)} and {len(__UpperCAmelCase				)}'				)

											return images_with_overflow



							def 		_A	(							self ,					*__UpperCAmelCase ,					**__UpperCAmelCase				):







											"""simple docstring"""



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



							def 		_A	(							self ,					*__UpperCAmelCase ,					**__UpperCAmelCase				):







											"""simple docstring"""



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



							@property
							def 		_A	(							self				):







											"""simple docstring"""



											return ["input_ids", "bbox", "attention_mask", "pixel_values"]



							@property
							def 		_A	(							self				):







											"""simple docstring"""



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




							@property
							def 		_A	(							self				):







											"""simple docstring"""



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


