

import inspect
import unittest

from transformers import SegformerConfig, is_torch_available, is_vision_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
			import torch

			from transformers import (
			    MODEL_MAPPING,
			    SegformerForImageClassification,
			    SegformerForSemanticSegmentation,
			    SegformerModel,
			)
			from transformers.models.segformer.modeling_segformer import SEGFORMER_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
			from PIL import Image

			from transformers import SegformerImageProcessor






class _UpperCamelCase				(				_lowercase ):
			'''simple docstring'''







			def 				__UpperCamelCase			(      self				:			Dict						)				->							Tuple:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE :   Union[str, Any]					  =							self.config_class(**self.inputs_dict						)
				self.parent.assertTrue(hasattr(__A   ,   "hidden_sizes"						)						)
				self.parent.assertTrue(hasattr(__A   ,   "num_attention_heads"						)						)
				self.parent.assertTrue(hasattr(__A   ,   "num_encoder_blocks"						)						)






class _UpperCamelCase				:
			'''simple docstring'''







			def __init__(      self				:			List[str]   ,   a				:			str   ,   a				:			str=13   ,   a				:			str=64   ,   a				:			Any=3   ,   a				:			List[str]=4   ,   a				:			Union[str, Any]=[2, 2, 2, 2]   ,   a				:			Any=[8, 4, 2, 1]   ,   a				:			int=[16, 32, 64, 128]   ,   a				:			List[str]=[1, 4, 8, 16]   ,   a				:			Optional[int]=[1, 2, 4, 8]   ,   a				:			Optional[int]=True   ,   a				:			List[Any]=True   ,   a				:			List[Any]="gelu"   ,   a				:			Union[str, Any]=0.1   ,   a				:			Tuple=0.1   ,   a				:			Optional[int]=0.02   ,   a				:			Dict=3   ,   a				:			Any=None   ,   )				->							Tuple:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE :   Optional[Any]					  =							parent
				SCREAMING_SNAKE_CASE :   int					  =							batch_size
				SCREAMING_SNAKE_CASE :   Optional[int]					  =							image_size
				SCREAMING_SNAKE_CASE :   Tuple					  =							num_channels
				SCREAMING_SNAKE_CASE :   List[Any]					  =							num_encoder_blocks
				SCREAMING_SNAKE_CASE :   List[Any]					  =							sr_ratios
				SCREAMING_SNAKE_CASE :   Optional[int]					  =							depths
				SCREAMING_SNAKE_CASE :   str					  =							hidden_sizes
				SCREAMING_SNAKE_CASE :   str					  =							downsampling_rates
				SCREAMING_SNAKE_CASE :   Any					  =							num_attention_heads
				SCREAMING_SNAKE_CASE :   Optional[int]					  =							is_training
				SCREAMING_SNAKE_CASE :   Union[str, Any]					  =							use_labels
				SCREAMING_SNAKE_CASE :   Any					  =							hidden_act
				SCREAMING_SNAKE_CASE :   Union[str, Any]					  =							hidden_dropout_prob
				SCREAMING_SNAKE_CASE :   Tuple					  =							attention_probs_dropout_prob
				SCREAMING_SNAKE_CASE :   Any					  =							initializer_range
				SCREAMING_SNAKE_CASE :   Dict					  =							num_labels
				SCREAMING_SNAKE_CASE :   List[Any]					  =							scope
			def 				__UpperCamelCase			(      self				:			int						)				->							Optional[Any]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE :   List[str]					  =							floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]						)

				SCREAMING_SNAKE_CASE :   Optional[Any]					  =							None
				if self.use_labels:
					SCREAMING_SNAKE_CASE :   List[Any]					  =							ids_tensor([self.batch_size, self.image_size, self.image_size]   ,   self.num_labels						)

				SCREAMING_SNAKE_CASE :   Any					  =							self.get_config()
				return config, pixel_values, labels
			def 				__UpperCamelCase			(      self				:			Union[str, Any]						)				->							Tuple:

				"""simple docstring"""

				return SegformerConfig(
				    image_size=self.image_size   ,   num_channels=self.num_channels   ,   num_encoder_blocks=self.num_encoder_blocks   ,   depths=self.depths   ,   hidden_sizes=self.hidden_sizes   ,   num_attention_heads=self.num_attention_heads   ,   hidden_act=self.hidden_act   ,   hidden_dropout_prob=self.hidden_dropout_prob   ,   attention_probs_dropout_prob=self.attention_probs_dropout_prob   ,   initializer_range=self.initializer_range   ,   )
			def 				__UpperCamelCase			(      self				:			Dict   ,   a				:			Dict   ,   a				:			List[Any]   ,   a				:			str						)				->							Optional[Any]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE :   List[Any]					  =							SegformerModel(config=__A						)
				model.to(__A						)
				model.eval()
				SCREAMING_SNAKE_CASE :   Dict					  =							model(__A						)
				SCREAMING_SNAKE_CASE :   Union[str, Any]					  =							self.image_size // (self.downsampling_rates[-1] * 2)
				self.parent.assertEqual(
				    result.last_hidden_state.shape   ,   (self.batch_size, self.hidden_sizes[-1], expected_height, expected_width)						)
			def 				__UpperCamelCase			(      self				:			List[str]   ,   a				:			int   ,   a				:			Tuple   ,   a				:			List[str]						)				->							Any:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE :   int					  =							self.num_labels
				SCREAMING_SNAKE_CASE :   int					  =							SegformerForSemanticSegmentation(__A						)
				model.to(__A						)
				model.eval()
				SCREAMING_SNAKE_CASE :   int					  =							model(__A						)
				self.parent.assertEqual(
				    result.logits.shape   ,   (self.batch_size, self.num_labels, self.image_size // 4, self.image_size // 4)						)
				SCREAMING_SNAKE_CASE :   Union[str, Any]					  =							model(__A   ,   labels=__A						)
				self.parent.assertEqual(
				    result.logits.shape   ,   (self.batch_size, self.num_labels, self.image_size // 4, self.image_size // 4)						)
				self.parent.assertGreater(result.loss   ,   0.0						)
			def 				__UpperCamelCase			(      self				:			Union[str, Any]   ,   a				:			List[Any]   ,   a				:			List[str]   ,   a				:			Optional[Any]						)				->							Dict:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE :   List[str]					  =							1
				SCREAMING_SNAKE_CASE :   Union[str, Any]					  =							SegformerForSemanticSegmentation(config=__A						)
				model.to(__A						)
				model.eval()
				SCREAMING_SNAKE_CASE :   Any					  =							torch.randint(0   ,   1   ,   (self.batch_size, self.image_size, self.image_size)						).to(__A						)
				SCREAMING_SNAKE_CASE :   int					  =							model(__A   ,   labels=__A						)
				self.parent.assertGreater(result.loss   ,   0.0						)






			def 				__UpperCamelCase			(      self				:			List[Any]						)				->							List[Any]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE :   Optional[int]					  =							self.prepare_config_and_inputs()
				SCREAMING_SNAKE_CASE :   Tuple					  =							config_and_inputs
				SCREAMING_SNAKE_CASE :   str					  =							{"""pixel_values""": pixel_values}
				return config, inputs_dict






@require_torch
class _UpperCamelCase				(				_lowercase				,						_lowercase				,						unittest.TestCase ):
			'''simple docstring'''







			lowerCamelCase__							     =(
			    (
			        SegformerModel,
			        SegformerForSemanticSegmentation,
			        SegformerForImageClassification,
			    )
			    if is_torch_available()
			    else ()
			)
			lowerCamelCase__							     =(
			    {
			        '''feature-extraction''': SegformerModel,
			        '''image-classification''': SegformerForImageClassification,
			        '''image-segmentation''': SegformerForSemanticSegmentation,
			    }
			    if is_torch_available()
			    else {}
			)

			lowerCamelCase__							     =True
			lowerCamelCase__							     =False
			lowerCamelCase__							     =False
			lowerCamelCase__							     =False
			def 				__UpperCamelCase			(      self				:			Tuple						)				->							Union[str, Any]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE :   str					  =							SegformerModelTester(self						)
				SCREAMING_SNAKE_CASE :   Optional[int]					  =							SegformerConfigTester(self   ,   config_class=__A						)
			def 				__UpperCamelCase			(      self				:			List[str]						)				->							Tuple:

				"""simple docstring"""

				self.config_tester.run_common_tests()
			def 				__UpperCamelCase			(      self				:			int						)				->							List[str]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE :   List[Any]					  =							self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_model(*__A						)
			def 				__UpperCamelCase			(      self				:			Optional[int]						)				->							Optional[int]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE :   Optional[Any]					  =							self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_binary_image_segmentation(*__A						)
			def 				__UpperCamelCase			(      self				:			Optional[int]						)				->							List[Any]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE :   Optional[int]					  =							self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_image_segmentation(*__A						)
			@unittest.skip("SegFormer does not use inputs_embeds"						)
			def 				__UpperCamelCase			(      self				:			Union[str, Any]						)				->							Tuple:

				"""simple docstring"""

				pass
			@unittest.skip("SegFormer does not have get_input_embeddings method and get_output_embeddings methods"						)
			def 				__UpperCamelCase			(      self				:			Tuple						)				->							str:

				"""simple docstring"""

				pass
			def 				__UpperCamelCase			(      self				:			Optional[int]						)				->							Optional[int]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE :   Optional[int]					  =							self.model_tester.prepare_config_and_inputs_for_common()

				for model_class in self.all_model_classes:
					SCREAMING_SNAKE_CASE :   int					  =							model_class(__A						)
					SCREAMING_SNAKE_CASE :   Dict					  =							inspect.signature(model.forward						)
					# signature.parameters is an OrderedDict => so arg_names order is deterministic
					SCREAMING_SNAKE_CASE :   Tuple					  =							[*signature.parameters.keys()]

					SCREAMING_SNAKE_CASE :   str					  =							["""pixel_values"""]
					self.assertListEqual(arg_names[:1]   ,   __A						)
			def 				__UpperCamelCase			(      self				:			int						)				->							Tuple:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE :   Tuple					  =							self.model_tester.prepare_config_and_inputs_for_common()
				SCREAMING_SNAKE_CASE :   Union[str, Any]					  =							True

				for model_class in self.all_model_classes:
					SCREAMING_SNAKE_CASE :   Optional[Any]					  =							True
					SCREAMING_SNAKE_CASE :   Tuple					  =							False
					SCREAMING_SNAKE_CASE :   Union[str, Any]					  =							True
					SCREAMING_SNAKE_CASE :   List[str]					  =							model_class(__A						)
					model.to(__A						)
					model.eval()
					with torch.no_grad():
						SCREAMING_SNAKE_CASE :   Any					  =							model(**self._prepare_for_class(__A   ,   __A						)						)
					SCREAMING_SNAKE_CASE :   Optional[int]					  =							outputs.attentions

					SCREAMING_SNAKE_CASE :   List[str]					  =							sum(self.model_tester.depths						)
					self.assertEqual(len(__A						)   ,   __A						)

					# check that output_attentions also work using config
					del inputs_dict["output_attentions"]
					SCREAMING_SNAKE_CASE :   Optional[Any]					  =							True
					SCREAMING_SNAKE_CASE :   Union[str, Any]					  =							model_class(__A						)
					model.to(__A						)
					model.eval()
					with torch.no_grad():
						SCREAMING_SNAKE_CASE :   Optional[Any]					  =							model(**self._prepare_for_class(__A   ,   __A						)						)
					SCREAMING_SNAKE_CASE :   str					  =							outputs.attentions

					self.assertEqual(len(__A						)   ,   __A						)

					# verify the first attentions (first block, first layer)
					SCREAMING_SNAKE_CASE :   Union[str, Any]					  =							(self.model_tester.image_size // 4) ** 2
					SCREAMING_SNAKE_CASE :   Any					  =							(self.model_tester.image_size // (4 * self.model_tester.sr_ratios[0])) ** 2
					self.assertListEqual(
					    list(attentions[0].shape[-3:]						)   ,   [self.model_tester.num_attention_heads[0], expected_seq_len, expected_reduced_seq_len]   ,   )

					# verify the last attentions (last block, last layer)
					SCREAMING_SNAKE_CASE :   Tuple					  =							(self.model_tester.image_size // 32) ** 2
					SCREAMING_SNAKE_CASE :   Optional[int]					  =							(self.model_tester.image_size // (32 * self.model_tester.sr_ratios[-1])) ** 2
					self.assertListEqual(
					    list(attentions[-1].shape[-3:]						)   ,   [self.model_tester.num_attention_heads[-1], expected_seq_len, expected_reduced_seq_len]   ,   )
					SCREAMING_SNAKE_CASE :   Union[str, Any]					  =							len(__A						)

					# Check attention is always last and order is fine
					SCREAMING_SNAKE_CASE :   Union[str, Any]					  =							True
					SCREAMING_SNAKE_CASE :   List[Any]					  =							True
					SCREAMING_SNAKE_CASE :   Any					  =							model_class(__A						)
					model.to(__A						)
					model.eval()
					with torch.no_grad():
						SCREAMING_SNAKE_CASE :   str					  =							model(**self._prepare_for_class(__A   ,   __A						)						)

					self.assertEqual(out_len + 1   ,   len(__A						)						)

					SCREAMING_SNAKE_CASE :   List[Any]					  =							outputs.attentions

					self.assertEqual(len(__A						)   ,   __A						)
					# verify the first attentions (first block, first layer)
					SCREAMING_SNAKE_CASE :   Tuple					  =							(self.model_tester.image_size // 4) ** 2
					SCREAMING_SNAKE_CASE :   Any					  =							(self.model_tester.image_size // (4 * self.model_tester.sr_ratios[0])) ** 2
					self.assertListEqual(
					    list(self_attentions[0].shape[-3:]						)   ,   [self.model_tester.num_attention_heads[0], expected_seq_len, expected_reduced_seq_len]   ,   )
			def 				__UpperCamelCase			(      self				:			Tuple						)				->							Tuple:

				"""simple docstring"""

				def check_hidden_states_output(a				:			Optional[int]   ,   a				:			int   ,   a				:			Dict						):
					SCREAMING_SNAKE_CASE :   List[str]					  =							model_class(__A						)
					model.to(__A						)
					model.eval()

					with torch.no_grad():
						SCREAMING_SNAKE_CASE :   Any					  =							model(**self._prepare_for_class(__A   ,   __A						)						)

					SCREAMING_SNAKE_CASE :   Optional[Any]					  =							outputs.hidden_states

					SCREAMING_SNAKE_CASE :   Dict					  =							self.model_tester.num_encoder_blocks
					self.assertEqual(len(__A						)   ,   __A						)

					# verify the first hidden states (first block)
					self.assertListEqual(
					    list(hidden_states[0].shape[-3:]						)   ,   [
					        self.model_tester.hidden_sizes[0],
					        self.model_tester.image_size // 4,
					        self.model_tester.image_size // 4,
					    ]   ,   )

				SCREAMING_SNAKE_CASE :   Dict					  =							self.model_tester.prepare_config_and_inputs_for_common()

				for model_class in self.all_model_classes:
					SCREAMING_SNAKE_CASE :   Optional[int]					  =							True
					check_hidden_states_output(__A   ,   __A   ,   __A						)

					# check that output_hidden_states also work using config
					del inputs_dict["output_hidden_states"]
					SCREAMING_SNAKE_CASE :   Any					  =							True

					check_hidden_states_output(__A   ,   __A   ,   __A						)
			def 				__UpperCamelCase			(      self				:			str						)				->							List[Any]:

				"""simple docstring"""

				if not self.model_tester.is_training:
					return

				SCREAMING_SNAKE_CASE :   Optional[Any]					  =							self.model_tester.prepare_config_and_inputs_for_common()
				SCREAMING_SNAKE_CASE :   List[str]					  =							True

				for model_class in self.all_model_classes:
					if model_class in get_values(__A						):
						continue

					SCREAMING_SNAKE_CASE :   List[str]					  =							model_class(__A						)
					model.to(__A						)
					model.train()
					SCREAMING_SNAKE_CASE :   Any					  =							self._prepare_for_class(__A   ,   __A   ,   return_labels=__A						)
					SCREAMING_SNAKE_CASE :   Optional[int]					  =							model(**__A						).loss
					loss.backward()
			@unittest.skip("Will be fixed soon by reducing the size of the model used for common tests."						)
			def 				__UpperCamelCase			(      self				:			List[Any]						)				->							Optional[int]:

				"""simple docstring"""

				pass






			@slow
			def 				__UpperCamelCase			(      self				:			Optional[int]						)				->							int:

				"""simple docstring"""

				for model_name in SEGFORMER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
					SCREAMING_SNAKE_CASE :   Dict					  =							SegformerModel.from_pretrained(__A						)
					self.assertIsNotNone(__A						)

def 			lowerCamelCase__			(       ):
	SCREAMING_SNAKE_CASE :   Optional[Any]					  =							Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png")
	return image






@require_torch
class _UpperCamelCase				(				unittest.TestCase ):
			'''simple docstring'''







			@slow
			def 				__UpperCamelCase			(      self				:			str						)				->							int:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE :   Optional[int]					  =							SegformerImageProcessor(
				    image_scale=(512, 512)   ,   keep_ratio=__A   ,   align=__A   ,   do_random_crop=__A						)
				SCREAMING_SNAKE_CASE :   Optional[int]					  =							SegformerForSemanticSegmentation.from_pretrained("nvidia/segformer-b0-finetuned-ade-512-512"						).to(
				    __A						)

				SCREAMING_SNAKE_CASE :   int					  =							prepare_img()
				SCREAMING_SNAKE_CASE :   List[Any]					  =							image_processor(images=__A   ,   return_tensors="pt"						)
				SCREAMING_SNAKE_CASE :   Any					  =							encoded_inputs.pixel_values.to(__A						)

				with torch.no_grad():
					SCREAMING_SNAKE_CASE :   List[str]					  =							model(__A						)

				SCREAMING_SNAKE_CASE :   Tuple					  =							torch.Size((1, model.config.num_labels, 128, 128)						)
				self.assertEqual(outputs.logits.shape   ,   __A						)

				SCREAMING_SNAKE_CASE :   Any					  =							torch.tensor(
				    [
				        [[-4.6310, -5.5232, -6.2356], [-5.1921, -6.1444, -6.5996], [-5.4424, -6.2790, -6.7574]],
				        [[-12.1391, -13.3122, -13.9554], [-12.8732, -13.9352, -14.3563], [-12.9438, -13.8226, -14.2513]],
				        [[-12.5134, -13.4686, -14.4915], [-12.8669, -14.4343, -14.7758], [-13.2523, -14.5819, -15.0694]],
				    ]						).to(__A						)
				self.assertTrue(torch.allclose(outputs.logits[0, :3, :3, :3]   ,   __A   ,   atol=1e-4						)						)
			@slow
			def 				__UpperCamelCase			(      self				:			Optional[Any]						)				->							List[Any]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE :   str					  =							SegformerImageProcessor(
				    image_scale=(512, 512)   ,   keep_ratio=__A   ,   align=__A   ,   do_random_crop=__A						)
				SCREAMING_SNAKE_CASE :   Tuple					  =							SegformerForSemanticSegmentation.from_pretrained(
				    "nvidia/segformer-b1-finetuned-cityscapes-1024-1024"						).to(__A						)

				SCREAMING_SNAKE_CASE :   Optional[int]					  =							prepare_img()
				SCREAMING_SNAKE_CASE :   int					  =							image_processor(images=__A   ,   return_tensors="pt"						)
				SCREAMING_SNAKE_CASE :   List[Any]					  =							encoded_inputs.pixel_values.to(__A						)

				with torch.no_grad():
					SCREAMING_SNAKE_CASE :   Dict					  =							model(__A						)

				SCREAMING_SNAKE_CASE :   int					  =							torch.Size((1, model.config.num_labels, 128, 128)						)
				self.assertEqual(outputs.logits.shape   ,   __A						)

				SCREAMING_SNAKE_CASE :   Optional[int]					  =							torch.tensor(
				    [
				        [[-13.5748, -13.9111, -12.6500], [-14.3500, -15.3683, -14.2328], [-14.7532, -16.0424, -15.6087]],
				        [[-17.1651, -15.8725, -12.9653], [-17.2580, -17.3718, -14.8223], [-16.6058, -16.8783, -16.7452]],
				        [[-3.6456, -3.0209, -1.4203], [-3.0797, -3.1959, -2.0000], [-1.8757, -1.9217, -1.6997]],
				    ]						).to(__A						)
				self.assertTrue(torch.allclose(outputs.logits[0, :3, :3, :3]   ,   __A   ,   atol=1e-1						)						)






			@slow
			def 				__UpperCamelCase			(      self				:			Optional[int]						)				->							Any:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE :   Tuple					  =							SegformerImageProcessor(
				    image_scale=(512, 512)   ,   keep_ratio=__A   ,   align=__A   ,   do_random_crop=__A						)
				SCREAMING_SNAKE_CASE :   List[Any]					  =							SegformerForSemanticSegmentation.from_pretrained("nvidia/segformer-b0-finetuned-ade-512-512"						).to(
				    __A						)

				SCREAMING_SNAKE_CASE :   Any					  =							prepare_img()
				SCREAMING_SNAKE_CASE :   str					  =							image_processor(images=__A   ,   return_tensors="pt"						)
				SCREAMING_SNAKE_CASE :   int					  =							encoded_inputs.pixel_values.to(__A						)

				with torch.no_grad():
					SCREAMING_SNAKE_CASE :   int					  =							model(__A						)

				SCREAMING_SNAKE_CASE :   Optional[int]					  =							outputs.logits.detach().cpu()

				SCREAMING_SNAKE_CASE :   Union[str, Any]					  =							image_processor.post_process_semantic_segmentation(outputs=__A   ,   target_sizes=[(500, 300)]						)
				SCREAMING_SNAKE_CASE :   Tuple					  =							torch.Size((500, 300)						)
				self.assertEqual(segmentation[0].shape   ,   __A						)

				SCREAMING_SNAKE_CASE :   Optional[Any]					  =							image_processor.post_process_semantic_segmentation(outputs=__A						)
				SCREAMING_SNAKE_CASE :   Dict					  =							torch.Size((128, 128)						)
				self.assertEqual(segmentation[0].shape   ,   __A						)


import functools
import operator

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


UpperCAmelCase_							:					List[str]		 =   logging.get_logger(__name__)

UpperCAmelCase_							:					str		 =   {
    '''microsoft/unispeech-large-1500h-cv''': (
        '''https://huggingface.co/microsoft/unispeech-large-1500h-cv/resolve/main/config.json'''
    ),
    # See all UniSpeech models at https://huggingface.co/models?filter=unispeech
}






class      lowerCamelCase_      (	_lowercase	):
	_lowercase		:   Dict     					=				'''unispeech'''




	def __init__(     self						:     str					,      __A						:     Tuple=32					,      __A						:     List[str]=768					,      __A						:     Dict=12					,      __A						:     Union[str, Any]=12					,      __A						:     Tuple=3072					,      __A						:     Any="gelu"					,      __A						:     int=0.1					,      __A						:     Optional[int]=0.1					,      __A						:     List[Any]=0.1					,      __A						:     Any=0.0					,      __A						:     List[str]=0.0					,      __A						:     int=0.1					,      __A						:     List[Any]=0.1					,      __A						:     List[str]=0.0_2					,      __A						:     List[str]=1e-5					,      __A						:     List[Any]="group"					,      __A						:     int="gelu"					,      __A						:     Any=(512, 512, 512, 512, 512, 512, 512)					,      __A						:     Union[str, Any]=(5, 2, 2, 2, 2, 2, 2)					,      __A						:     Tuple=(10, 3, 3, 3, 3, 2, 2)					,      __A						:     Optional[int]=False					,      __A						:     Any=128					,      __A						:     Union[str, Any]=16					,      __A						:     Optional[Any]=False					,      __A						:     str=True					,      __A						:     Dict=0.0_5					,      __A						:     Optional[Any]=10					,      __A						:     Dict=2					,      __A						:     int=0.0					,      __A						:     List[str]=10					,      __A						:     str=0					,      __A						:     List[str]=320					,      __A						:     List[Any]=2					,      __A						:     Tuple=0.1					,      __A						:     Optional[int]=100					,      __A						:     Any=256					,      __A						:     Dict=256					,      __A						:     Tuple=0.1					,      __A						:     List[str]="mean"					,      __A						:     int=False					,      __A						:     List[str]=False					,      __A						:     List[Any]=256					,      __A						:     str=80					,      __A						:     Tuple=0					,      __A						:     Tuple=1					,      __A						:     int=2					,      __A						:     Dict=0.5					,      **__A						:     List[Any]					,      ):
		super().__init__(**__A					,      pad_token_id=__A					,      bos_token_id=__A					,      eos_token_id=__A							)
		__A :			Dict		    =			hidden_size
		__A :			Optional[Any]		    =			feat_extract_norm
		__A :			List[Any]		    =			feat_extract_activation
		__A :			str		    =			list(__A							)
		__A :			Optional[Any]		    =			list(__A							)
		__A :			Optional[int]		    =			list(__A							)
		__A :			List[Any]		    =			conv_bias
		__A :			Optional[int]		    =			num_conv_pos_embeddings
		__A :			List[Any]		    =			num_conv_pos_embedding_groups
		__A :			int		    =			len(self.conv_dim							)
		__A :			Optional[Any]		    =			num_hidden_layers
		__A :			List[str]		    =			intermediate_size
		__A :			Union[str, Any]		    =			hidden_act
		__A :			Optional[int]		    =			num_attention_heads
		__A :			Tuple		    =			hidden_dropout
		__A :			Optional[Any]		    =			attention_dropout
		__A :			Union[str, Any]		    =			activation_dropout
		__A :			Dict		    =			feat_proj_dropout
		__A :			Optional[int]		    =			final_dropout
		__A :			Dict		    =			layerdrop
		__A :			Optional[int]		    =			layer_norm_eps
		__A :			Optional[Any]		    =			initializer_range
		__A :			Optional[int]		    =			num_ctc_classes
		__A :			Dict		    =			vocab_size
		__A :			List[str]		    =			do_stable_layer_norm
		__A :			Tuple		    =			use_weighted_layer_sum
		__A :			Any		    =			classifier_proj_size

		if (
		    (len(self.conv_stride							) != self.num_feat_extract_layers)
		    or (len(self.conv_kernel							) != self.num_feat_extract_layers)
		    or (len(self.conv_dim							) != self.num_feat_extract_layers)
		):
			raise ValueError(
			    """Configuration for convolutional layers is incorrect. It is required that `len(config.conv_dim)` =="""
			    """ `len(config.conv_stride)` == `len(config.conv_kernel)`, but is `len(config.conv_dim) ="""
			    F""" {len(self.conv_dim							)}`, `len(config.conv_stride) = {len(self.conv_stride							)}`,"""
			    F""" `len(config.conv_kernel) = {len(self.conv_kernel							)}`."""							)

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

		# parameters for pretraining with codevector quantized representations
		__A :			Any		    =			num_codevectors_per_group
		__A :			Tuple		    =			num_codevector_groups
		__A :			List[str]		    =			contrastive_logits_temperature
		__A :			Optional[int]		    =			feat_quantizer_dropout
		__A :			int		    =			num_negatives
		__A :			List[str]		    =			codevector_dim
		__A :			int		    =			proj_codevector_dim
		__A :			Union[str, Any]		    =			diversity_loss_weight

		# ctc loss
		__A :			List[str]		    =			ctc_loss_reduction
		__A :			Any		    =			ctc_zero_infinity

		# pretraining loss
		__A :			Union[str, Any]		    =			replace_prob




	@property
	def        lowerCAmelCase_       (     self						:     int							):
		return functools.reduce(operator.mul					,      self.conv_stride					,      1							)





