



"""simple docstring"""





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  lowercase__  (       SCREAMING_SNAKE_CASE ):







       '''simple docstring'''


       def 	lowercase__							(				self     :    Optional[int]       )					->		str:


             '''simple docstring'''




             UpperCAmelCase_     					=				self.config_class(**self.inputs_dict       )
             self.parent.assertTrue(hasattr(_UpperCAmelCase						,							"hidden_sizes"       )       )
             self.parent.assertTrue(hasattr(_UpperCAmelCase						,							"num_attention_heads"       )       )
             self.parent.assertTrue(hasattr(_UpperCAmelCase						,							"num_encoder_blocks"       )       )



class  lowercase__  :







       '''simple docstring'''


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


             '''simple docstring'''




             UpperCAmelCase_     					=				parent
             UpperCAmelCase_     					=				batch_size
             UpperCAmelCase_     					=				image_size
             UpperCAmelCase_     					=				num_channels
             UpperCAmelCase_     					=				num_encoder_blocks
             UpperCAmelCase_     					=				sr_ratios
             UpperCAmelCase_     					=				depths
             UpperCAmelCase_     					=				hidden_sizes
             UpperCAmelCase_     					=				downsampling_rates
             UpperCAmelCase_     					=				num_attention_heads
             UpperCAmelCase_     					=				is_training
             UpperCAmelCase_     					=				use_labels
             UpperCAmelCase_     					=				hidden_act
             UpperCAmelCase_     					=				hidden_dropout_prob
             UpperCAmelCase_     					=				attention_probs_dropout_prob
             UpperCAmelCase_     					=				initializer_range
             UpperCAmelCase_     					=				num_labels
             UpperCAmelCase_     					=				scope



       def 	lowercase__							(				self     :    List[Any]       )					->		Tuple:


             '''simple docstring'''




             UpperCAmelCase_     					=				floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]       )

             UpperCAmelCase_     					=				None
             if self.use_labels:
                   UpperCAmelCase_     					=				ids_tensor([self.batch_size, self.image_size, self.image_size]						,							self.num_labels       )

             UpperCAmelCase_     					=				self.get_config()
             return config, pixel_values, labels



       def 	lowercase__							(				self     :    str       )					->		Optional[int]:


             '''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 	lowercase__							(				self     :    Optional[Any]						,							_UpperCAmelCase     :    Optional[Any]						,							_UpperCAmelCase     :    List[str]						,							_UpperCAmelCase     :    str       )					->		Any:


             '''simple docstring'''




             UpperCAmelCase_     					=				SegformerModel(config=_UpperCAmelCase       )
             model.to(_UpperCAmelCase       )
             model.eval()
             UpperCAmelCase_     					=				model(_UpperCAmelCase       )
             UpperCAmelCase_     					=				UpperCAmelCase_     					=				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 	lowercase__							(				self     :    List[Any]						,							_UpperCAmelCase     :    List[str]						,							_UpperCAmelCase     :    List[str]						,							_UpperCAmelCase     :    Any       )					->		List[Any]:


             '''simple docstring'''




             UpperCAmelCase_     					=				self.num_labels
             UpperCAmelCase_     					=				SegformerForSemanticSegmentation(_UpperCAmelCase       )
             model.to(_UpperCAmelCase       )
             model.eval()
             UpperCAmelCase_     					=				model(_UpperCAmelCase       )
             self.parent.assertEqual(
                 result.logits.shape						,							(self.batch_size, self.num_labels, self.image_size // 4, self.image_size // 4)       )
             UpperCAmelCase_     					=				model(_UpperCAmelCase						,							labels=_UpperCAmelCase       )
             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 	lowercase__							(				self     :    Dict						,							_UpperCAmelCase     :    Optional[Any]						,							_UpperCAmelCase     :    Union[str, Any]						,							_UpperCAmelCase     :    int       )					->		Any:


             '''simple docstring'''




             UpperCAmelCase_     					=				1
             UpperCAmelCase_     					=				SegformerForSemanticSegmentation(config=_UpperCAmelCase       )
             model.to(_UpperCAmelCase       )
             model.eval()
             UpperCAmelCase_     					=				torch.randint(0						,							1						,							(self.batch_size, self.image_size, self.image_size)       ).to(_UpperCAmelCase       )
             UpperCAmelCase_     					=				model(_UpperCAmelCase						,							labels=_UpperCAmelCase       )
             self.parent.assertGreater(result.loss						,							0.0       )







       def 	lowercase__							(				self     :    Union[str, Any]       )					->		str:


             '''simple docstring'''




             UpperCAmelCase_     					=				self.prepare_config_and_inputs()
             UpperCAmelCase_					,       UpperCAmelCase_					,       UpperCAmelCase_     					=				config_and_inputs
             UpperCAmelCase_     					=				{"pixel_values": pixel_values}
             return config, inputs_dict



@require_torch
class  lowercase__  (       SCREAMING_SNAKE_CASE							,   SCREAMING_SNAKE_CASE							,   unittest.TestCase ):







       '''simple docstring'''


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

       UpperCamelCase		=	True
       UpperCamelCase		=	False
       UpperCamelCase		=	False
       UpperCamelCase		=	False



       def 	lowercase__							(				self     :    Any       )					->		str:


             '''simple docstring'''




             UpperCAmelCase_     					=				SegformerModelTester(self       )
             UpperCAmelCase_     					=				SegformerConfigTester(self						,							config_class=_UpperCAmelCase       )



       def 	lowercase__							(				self     :    Union[str, Any]       )					->		Tuple:


             '''simple docstring'''




             self.config_tester.run_common_tests()



       def 	lowercase__							(				self     :    List[Any]       )					->		str:


             '''simple docstring'''




             UpperCAmelCase_     					=				self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_model(*_UpperCAmelCase       )



       def 	lowercase__							(				self     :    List[Any]       )					->		str:


             '''simple docstring'''




             UpperCAmelCase_     					=				self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_binary_image_segmentation(*_UpperCAmelCase       )



       def 	lowercase__							(				self     :    Union[str, Any]       )					->		int:


             '''simple docstring'''




             UpperCAmelCase_     					=				self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_image_segmentation(*_UpperCAmelCase       )



       @unittest.skip("SegFormer does not use inputs_embeds"       )
       def 	lowercase__							(				self     :    Optional[Any]       )					->		Union[str, Any]:


             '''simple docstring'''




             pass



       @unittest.skip("SegFormer does not have get_input_embeddings method and get_output_embeddings methods"       )
       def 	lowercase__							(				self     :    List[str]       )					->		Optional[Any]:


             '''simple docstring'''




             pass



       def 	lowercase__							(				self     :    Optional[int]       )					->		int:


             '''simple docstring'''




             UpperCAmelCase_					,       UpperCAmelCase_     					=				self.model_tester.prepare_config_and_inputs_for_common()

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

                   UpperCAmelCase_     					=				["pixel_values"]
                   self.assertListEqual(arg_names[:1]						,							_UpperCAmelCase       )



       def 	lowercase__							(				self     :    str       )					->		Optional[int]:


             '''simple docstring'''




             UpperCAmelCase_					,       UpperCAmelCase_     					=				self.model_tester.prepare_config_and_inputs_for_common()
             UpperCAmelCase_     					=				True

             for model_class in self.all_model_classes:
                   UpperCAmelCase_     					=				True
                   UpperCAmelCase_     					=				False
                   UpperCAmelCase_     					=				True
                   UpperCAmelCase_     					=				model_class(_UpperCAmelCase       )
                   model.to(_UpperCAmelCase       )
                   model.eval()
                   with torch.no_grad():
                         UpperCAmelCase_     					=				model(**self._prepare_for_class(_UpperCAmelCase						,							_UpperCAmelCase       )       )
                   UpperCAmelCase_     					=				outputs.attentions

                   UpperCAmelCase_     					=				sum(self.model_tester.depths       )
                   self.assertEqual(len(_UpperCAmelCase       )						,							_UpperCAmelCase       )

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

                   self.assertEqual(len(_UpperCAmelCase       )						,							_UpperCAmelCase       )

                   # verify the first attentions (first block, first layer)
                   UpperCAmelCase_     					=				(self.model_tester.image_size // 4) ** 2
                   UpperCAmelCase_     					=				(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)
                   UpperCAmelCase_     					=				(self.model_tester.image_size // 32) ** 2
                   UpperCAmelCase_     					=				(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]						,							)
                   UpperCAmelCase_     					=				len(_UpperCAmelCase       )

                   # Check attention is always last and order is fine
                   UpperCAmelCase_     					=				True
                   UpperCAmelCase_     					=				True
                   UpperCAmelCase_     					=				model_class(_UpperCAmelCase       )
                   model.to(_UpperCAmelCase       )
                   model.eval()
                   with torch.no_grad():
                         UpperCAmelCase_     					=				model(**self._prepare_for_class(_UpperCAmelCase						,							_UpperCAmelCase       )       )

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

                   UpperCAmelCase_     					=				outputs.attentions

                   self.assertEqual(len(_UpperCAmelCase       )						,							_UpperCAmelCase       )
                   # verify the first attentions (first block, first layer)
                   UpperCAmelCase_     					=				(self.model_tester.image_size // 4) ** 2
                   UpperCAmelCase_     					=				(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 	lowercase__							(				self     :    Dict       )					->		int:


             '''simple docstring'''




             def check_hidden_states_output(_UpperCAmelCase     :    List[str]						,							_UpperCAmelCase     :    Optional[Any]						,							_UpperCAmelCase     :    Optional[int]       ):
                   UpperCAmelCase_     					=				model_class(_UpperCAmelCase       )
                   model.to(_UpperCAmelCase       )
                   model.eval()

                   with torch.no_grad():
                         UpperCAmelCase_     					=				model(**self._prepare_for_class(_UpperCAmelCase						,							_UpperCAmelCase       )       )

                   UpperCAmelCase_     					=				outputs.hidden_states

                   UpperCAmelCase_     					=				self.model_tester.num_encoder_blocks
                   self.assertEqual(len(_UpperCAmelCase       )						,							_UpperCAmelCase       )

                   # 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,
                       ]						,							)

             UpperCAmelCase_					,       UpperCAmelCase_     					=				self.model_tester.prepare_config_and_inputs_for_common()

             for model_class in self.all_model_classes:
                   UpperCAmelCase_     					=				True
                   check_hidden_states_output(_UpperCAmelCase						,							_UpperCAmelCase						,							_UpperCAmelCase       )

                   # check that output_hidden_states also work using config
                   del inputs_dict["output_hidden_states"]
                   UpperCAmelCase_     					=				True

                   check_hidden_states_output(_UpperCAmelCase						,							_UpperCAmelCase						,							_UpperCAmelCase       )



       def 	lowercase__							(				self     :    Tuple       )					->		List[Any]:


             '''simple docstring'''




             if not self.model_tester.is_training:
                   return

             UpperCAmelCase_					,       UpperCAmelCase_     					=				self.model_tester.prepare_config_and_inputs_for_common()
             UpperCAmelCase_     					=				True

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

                   UpperCAmelCase_     					=				model_class(_UpperCAmelCase       )
                   model.to(_UpperCAmelCase       )
                   model.train()
                   UpperCAmelCase_     					=				self._prepare_for_class(_UpperCAmelCase						,							_UpperCAmelCase						,							return_labels=_UpperCAmelCase       )
                   UpperCAmelCase_     					=				model(**_UpperCAmelCase       ).loss
                   loss.backward()



       @unittest.skip("Will be fixed soon by reducing the size of the model used for common tests."       )
       def 	lowercase__							(				self     :    Optional[Any]       )					->		Dict:


             '''simple docstring'''




             pass







       @slow
       def 	lowercase__							(				self     :    List[Any]       )					->		Tuple:


             '''simple docstring'''




             for model_name in SEGFORMER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                   UpperCAmelCase_     					=				SegformerModel.from_pretrained(_UpperCAmelCase       )
                   self.assertIsNotNone(_UpperCAmelCase       )



def   a__      ( ):
      UpperCAmelCase_     					=				Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png" )
      return image


@require_torch
class  lowercase__  (       unittest.TestCase ):







       '''simple docstring'''


       @slow
       def 	lowercase__							(				self     :    Tuple       )					->		List[Any]:


             '''simple docstring'''




             UpperCAmelCase_     					=				SegformerImageProcessor(
                 image_scale=(512, 512)						,							keep_ratio=_UpperCAmelCase						,							align=_UpperCAmelCase						,							do_random_crop=_UpperCAmelCase       )
             UpperCAmelCase_     					=				SegformerForSemanticSegmentation.from_pretrained("nvidia/segformer-b0-finetuned-ade-512-512"       ).to(
                 _UpperCAmelCase       )

             UpperCAmelCase_     					=				prepare_img()
             UpperCAmelCase_     					=				image_processor(images=_UpperCAmelCase						,							return_tensors="pt"       )
             UpperCAmelCase_     					=				encoded_inputs.pixel_values.to(_UpperCAmelCase       )

             with torch.no_grad():
                   UpperCAmelCase_     					=				model(_UpperCAmelCase       )

             UpperCAmelCase_     					=				torch.Size((1, model.config.num_labels, 128, 128)       )
             self.assertEqual(outputs.logits.shape						,							_UpperCAmelCase       )

             UpperCAmelCase_     					=				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(_UpperCAmelCase       )
             self.assertTrue(torch.allclose(outputs.logits[0, :3, :3, :3]						,							_UpperCAmelCase						,							atol=1e-4       )       )



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


             '''simple docstring'''




             UpperCAmelCase_     					=				SegformerImageProcessor(
                 image_scale=(512, 512)						,							keep_ratio=_UpperCAmelCase						,							align=_UpperCAmelCase						,							do_random_crop=_UpperCAmelCase       )
             UpperCAmelCase_     					=				SegformerForSemanticSegmentation.from_pretrained(
                 "nvidia/segformer-b1-finetuned-cityscapes-1024-1024"       ).to(_UpperCAmelCase       )

             UpperCAmelCase_     					=				prepare_img()
             UpperCAmelCase_     					=				image_processor(images=_UpperCAmelCase						,							return_tensors="pt"       )
             UpperCAmelCase_     					=				encoded_inputs.pixel_values.to(_UpperCAmelCase       )

             with torch.no_grad():
                   UpperCAmelCase_     					=				model(_UpperCAmelCase       )

             UpperCAmelCase_     					=				torch.Size((1, model.config.num_labels, 128, 128)       )
             self.assertEqual(outputs.logits.shape						,							_UpperCAmelCase       )

             UpperCAmelCase_     					=				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(_UpperCAmelCase       )
             self.assertTrue(torch.allclose(outputs.logits[0, :3, :3, :3]						,							_UpperCAmelCase						,							atol=1e-1       )       )







       @slow
       def 	lowercase__							(				self     :    Dict       )					->		Optional[Any]:


             '''simple docstring'''




             UpperCAmelCase_     					=				SegformerImageProcessor(
                 image_scale=(512, 512)						,							keep_ratio=_UpperCAmelCase						,							align=_UpperCAmelCase						,							do_random_crop=_UpperCAmelCase       )
             UpperCAmelCase_     					=				SegformerForSemanticSegmentation.from_pretrained("nvidia/segformer-b0-finetuned-ade-512-512"       ).to(
                 _UpperCAmelCase       )

             UpperCAmelCase_     					=				prepare_img()
             UpperCAmelCase_     					=				image_processor(images=_UpperCAmelCase						,							return_tensors="pt"       )
             UpperCAmelCase_     					=				encoded_inputs.pixel_values.to(_UpperCAmelCase       )

             with torch.no_grad():
                   UpperCAmelCase_     					=				model(_UpperCAmelCase       )

             UpperCAmelCase_     					=				outputs.logits.detach().cpu()

             UpperCAmelCase_     					=				image_processor.post_process_semantic_segmentation(outputs=_UpperCAmelCase						,							target_sizes=[(500, 300)]       )
             UpperCAmelCase_     					=				torch.Size((500, 300)       )
             self.assertEqual(segmentation[0].shape						,							_UpperCAmelCase       )

             UpperCAmelCase_     					=				image_processor.post_process_semantic_segmentation(outputs=_UpperCAmelCase       )
             UpperCAmelCase_     					=				torch.Size((128, 128)       )
             self.assertEqual(segmentation[0].shape						,							_UpperCAmelCase       )











"""simple docstring"""



import functools
import operator

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


a_					=     logging.get_logger(__name__)

a_					=     {
    """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 						__snake_case   (						SCREAMING_SNAKE_CASE__	):





 """simple docstring"""


 _lowerCamelCase								=	"""unispeech"""

 def __init__(       self   ,		__lowerCamelCase=32   ,		__lowerCamelCase=768   ,		__lowerCamelCase=12   ,		__lowerCamelCase=12   ,		__lowerCamelCase=3072   ,		__lowerCamelCase="gelu"   ,		__lowerCamelCase=0.1   ,		__lowerCamelCase=0.1   ,		__lowerCamelCase=0.1   ,		__lowerCamelCase=0.0   ,		__lowerCamelCase=0.0   ,		__lowerCamelCase=0.1   ,		__lowerCamelCase=0.1   ,		__lowerCamelCase=0.0_2   ,		__lowerCamelCase=1e-5   ,		__lowerCamelCase="group"   ,		__lowerCamelCase="gelu"   ,		__lowerCamelCase=(512, 512, 512, 512, 512, 512, 512)   ,		__lowerCamelCase=(5, 2, 2, 2, 2, 2, 2)   ,		__lowerCamelCase=(10, 3, 3, 3, 3, 2, 2)   ,		__lowerCamelCase=False   ,		__lowerCamelCase=128   ,		__lowerCamelCase=16   ,		__lowerCamelCase=False   ,		__lowerCamelCase=True   ,		__lowerCamelCase=0.0_5   ,		__lowerCamelCase=10   ,		__lowerCamelCase=2   ,		__lowerCamelCase=0.0   ,		__lowerCamelCase=10   ,		__lowerCamelCase=0   ,		__lowerCamelCase=320   ,		__lowerCamelCase=2   ,		__lowerCamelCase=0.1   ,		__lowerCamelCase=100   ,		__lowerCamelCase=256   ,		__lowerCamelCase=256   ,		__lowerCamelCase=0.1   ,		__lowerCamelCase="mean"   ,		__lowerCamelCase=False   ,		__lowerCamelCase=False   ,		__lowerCamelCase=256   ,		__lowerCamelCase=80   ,		__lowerCamelCase=0   ,		__lowerCamelCase=1   ,		__lowerCamelCase=2   ,		__lowerCamelCase=0.5   ,		**__lowerCamelCase   ,		):



     '''simple docstring'''




     super().__init__(**__lowerCamelCase   ,		pad_token_id=__lowerCamelCase   ,		bos_token_id=__lowerCamelCase   ,		eos_token_id=__lowerCamelCase    )
     __A       :		Dict							=	hidden_size
     __A       :		Dict							=	feat_extract_norm
     __A       :		int							=	feat_extract_activation
     __A       :		Dict							=	list(__lowerCamelCase    )
     __A       :		str							=	list(__lowerCamelCase    )
     __A       :		Dict							=	list(__lowerCamelCase    )
     __A       :		str							=	conv_bias
     __A       :		Optional[int]							=	num_conv_pos_embeddings
     __A       :		int							=	num_conv_pos_embedding_groups
     __A       :		Union[str, Any]							=	len(self.conv_dim    )
     __A       :		List[str]							=	num_hidden_layers
     __A       :		Dict							=	intermediate_size
     __A       :		List[str]							=	hidden_act
     __A       :		int							=	num_attention_heads
     __A       :		str							=	hidden_dropout
     __A       :		str							=	attention_dropout
     __A       :		Optional[Any]							=	activation_dropout
     __A       :		Optional[int]							=	feat_proj_dropout
     __A       :		Optional[Any]							=	final_dropout
     __A       :		List[Any]							=	layerdrop
     __A       :		Any							=	layer_norm_eps
     __A       :		str							=	initializer_range
     __A       :		List[str]							=	num_ctc_classes
     __A       :		Dict							=	vocab_size
     __A       :		Dict							=	do_stable_layer_norm
     __A       :		Union[str, Any]							=	use_weighted_layer_sum
     __A       :		Tuple							=	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       :		List[Any]							=	apply_spec_augment
     __A       :		str							=	mask_time_prob
     __A       :		Dict							=	mask_time_length
     __A       :		List[str]							=	mask_time_min_masks
     __A       :		Union[str, Any]							=	mask_feature_prob
     __A       :		Tuple							=	mask_feature_length
     __A       :		Any							=	mask_feature_min_masks

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

     # ctc loss
     __A       :		Tuple							=	ctc_loss_reduction
     __A       :		Optional[int]							=	ctc_zero_infinity

     # pretraining loss
     __A       :		str							=	replace_prob







 @property
 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     return functools.reduce(operator.mul   ,		self.conv_stride   ,		1    )




