'''simple docstring'''




import inspect
import unittest

import numpy as np

from tests.test_modeling_common import floats_tensor
from transformers import DetrConfig, MaskFormerConfig, SwinConfig, is_torch_available, is_vision_available
from transformers.testing_utils import require_torch, require_torch_multi_gpu, require_vision, slow, torch_device
from transformers.utils import cached_property

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
  import torch

  from transformers import MaskFormerForInstanceSegmentation, MaskFormerModel

  if is_vision_available():
    from transformers import MaskFormerImageProcessor

if is_vision_available():
  from PIL import Image




class    a__				:






     def __init__(			self		:		List[str]  ,    a		:		Tuple  ,    a		:		Any=2  ,    a		:		int=True  ,    a		:		Dict=False  ,    a		:		List[str]=10  ,    a		:		Dict=3  ,    a		:		Dict=32 * 4  ,    a		:		int=32 * 6  ,    a		:		str=4  ,    a		:		Dict=32  ,    ):





         """simple docstring"""



         __lowerCamelCase          =  parent
         __lowerCamelCase          =  batch_size
         __lowerCamelCase          =  is_training
         __lowerCamelCase          =  use_auxiliary_loss
         __lowerCamelCase          =  num_queries
         __lowerCamelCase          =  num_channels
         __lowerCamelCase          =  min_size
         __lowerCamelCase          =  max_size
         __lowerCamelCase          =  num_labels
         __lowerCamelCase          =  mask_feature_size






     def        SCREAMING_SNAKE_CASE__       (			self		:		Dict   ):





         """simple docstring"""



         __lowerCamelCase          =  floats_tensor([self.batch_size, self.num_channels, self.min_size, self.max_size]   ).to(
             a   )

         __lowerCamelCase          =  torch.ones([self.batch_size, self.min_size, self.max_size]  ,    device=a   )

         __lowerCamelCase          =  (
             torch.rand([self.batch_size, self.num_labels, self.min_size, self.max_size]  ,    device=a   ) > 0.5
         ).float()
         __lowerCamelCase          =  (torch.rand((self.batch_size, self.num_labels)  ,    device=a   ) > 0.5).long()

         __lowerCamelCase          =  self.get_config()
         return config, pixel_values, pixel_mask, mask_labels, class_labels






     def        SCREAMING_SNAKE_CASE__       (			self		:		int   ):





         """simple docstring"""



         return MaskFormerConfig.from_backbone_and_decoder_configs(
             backbone_config=SwinConfig(
                 depths=[1, 1, 1, 1]  ,    )  ,    decoder_config=DetrConfig(
                 decoder_ffn_dim=1_28  ,    num_queries=self.num_queries  ,    decoder_attention_heads=2  ,    d_model=self.mask_feature_size  ,    )  ,    mask_feature_size=self.mask_feature_size  ,    fpn_feature_size=self.mask_feature_size  ,    num_channels=self.num_channels  ,    num_labels=self.num_labels  ,    )






     def        SCREAMING_SNAKE_CASE__       (			self		:		Optional[int]   ):





         """simple docstring"""



         __lowerCamelCase     ,  __lowerCamelCase     ,  __lowerCamelCase     ,  __lowerCamelCase     ,  __lowerCamelCase          =  self.prepare_config_and_inputs()
         __lowerCamelCase          =  {'''pixel_values''': pixel_values, '''pixel_mask''': pixel_mask}
         return config, inputs_dict






     def        SCREAMING_SNAKE_CASE__       (			self		:		List[Any]  ,    a		:		Tuple  ,    a		:		str   ):





         """simple docstring"""



         __lowerCamelCase          =  output.encoder_hidden_states
         __lowerCamelCase          =  output.pixel_decoder_hidden_states
         __lowerCamelCase          =  output.transformer_decoder_hidden_states

         self.parent.assertTrue(len(a   )  ,    len(config.backbone_config.depths   )   )
         self.parent.assertTrue(len(a   )  ,    len(config.backbone_config.depths   )   )
         self.parent.assertTrue(len(a   )  ,    config.decoder_config.decoder_layers   )






     def        SCREAMING_SNAKE_CASE__       (			self		:		int  ,    a		:		str  ,    a		:		Optional[int]  ,    a		:		List[str]  ,    a		:		Optional[int]=False   ):





         """simple docstring"""



         with torch.no_grad():
             __lowerCamelCase          =  MaskFormerModel(config=a   )
             model.to(a   )
             model.eval()

             __lowerCamelCase          =  model(pixel_values=a  ,    pixel_mask=a   )
             __lowerCamelCase          =  model(a  ,    output_hidden_states=a   )
         # the correct shape of output.transformer_decoder_hidden_states ensure the correcteness of the
         # encoder and pixel decoder
         self.parent.assertEqual(
             output.transformer_decoder_last_hidden_state.shape  ,    (self.batch_size, self.num_queries, self.mask_feature_size)  ,    )
         # let's ensure the other two hidden state exists
         self.parent.assertTrue(output.pixel_decoder_last_hidden_state is not None   )
         self.parent.assertTrue(output.encoder_last_hidden_state is not None   )

         if output_hidden_states:
             self.check_output_hidden_state(a  ,    a   )






     def        SCREAMING_SNAKE_CASE__       (			self		:		List[str]  ,    a		:		Optional[int]  ,    a		:		List[str]  ,    a		:		Union[str, Any]  ,    a		:		List[Any]  ,    a		:		Union[str, Any]   ):





         """simple docstring"""



         __lowerCamelCase          =  MaskFormerForInstanceSegmentation(config=a   )
         model.to(a   )
         model.eval()

         def comm_check_on_output(a		:		Any   ):
             # let's still check that all the required stuff is there
             self.parent.assertTrue(result.transformer_decoder_last_hidden_state is not None   )
             self.parent.assertTrue(result.pixel_decoder_last_hidden_state is not None   )
             self.parent.assertTrue(result.encoder_last_hidden_state is not None   )
             # okay, now we need to check the logits shape
             # due to the encoder compression, masks have a //4 spatial size
             self.parent.assertEqual(
                 result.masks_queries_logits.shape  ,    (self.batch_size, self.num_queries, self.min_size // 4, self.max_size // 4)  ,    )
             # + 1 for null class
             self.parent.assertEqual(
                 result.class_queries_logits.shape  ,    (self.batch_size, self.num_queries, self.num_labels + 1)   )

         with torch.no_grad():
             __lowerCamelCase          =  model(pixel_values=a  ,    pixel_mask=a   )
             __lowerCamelCase          =  model(a   )

             comm_check_on_output(a   )

             __lowerCamelCase          =  model(
                 pixel_values=a  ,    pixel_mask=a  ,    mask_labels=a  ,    class_labels=a   )

         comm_check_on_output(a   )

         self.parent.assertTrue(result.loss is not None   )
         self.parent.assertEqual(result.loss.shape  ,    torch.Size([1]   )   )




@require_torch
class    a__				(       UpperCAmelCase__							,       UpperCAmelCase__							,       unittest.TestCase			):
     lowerCamelCase  :					Union[str, Any]							=(MaskFormerModel, MaskFormerForInstanceSegmentation) if is_torch_available() else ()
     lowerCamelCase  :					Any							=(
         {"feature-extraction": MaskFormerModel, "image-segmentation": MaskFormerForInstanceSegmentation}
         if is_torch_available()
         else {}
     )

     lowerCamelCase  :					List[str]							=False
     lowerCamelCase  :					Optional[int]							=False
     lowerCamelCase  :					Union[str, Any]							=False
     lowerCamelCase  :					Dict							=False






     def        SCREAMING_SNAKE_CASE__       (			self		:		str   ):





         """simple docstring"""



         __lowerCamelCase          =  MaskFormerModelTester(self   )
         __lowerCamelCase          =  ConfigTester(self  ,    config_class=a  ,    has_text_modality=a   )






     def        SCREAMING_SNAKE_CASE__       (			self		:		List[str]   ):





         """simple docstring"""



         self.config_tester.run_common_tests()






     def        SCREAMING_SNAKE_CASE__       (			self		:		int   ):





         """simple docstring"""



         __lowerCamelCase     ,  __lowerCamelCase          =  self.model_tester.prepare_config_and_inputs_for_common()
         self.model_tester.create_and_check_maskformer_model(a  ,    **a  ,    output_hidden_states=a   )






     def        SCREAMING_SNAKE_CASE__       (			self		:		Dict   ):





         """simple docstring"""



         __lowerCamelCase          =  self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_maskformer_instance_segmentation_head_model(*a   )






     @unittest.skip(reason='''MaskFormer does not use inputs_embeds'''   )
     def        SCREAMING_SNAKE_CASE__       (			self		:		str   ):





         """simple docstring"""



         pass






     @unittest.skip(reason='''MaskFormer does not have a get_input_embeddings method'''   )
     def        SCREAMING_SNAKE_CASE__       (			self		:		List[Any]   ):





         """simple docstring"""



         pass






     @unittest.skip(reason='''MaskFormer is not a generative model'''   )
     def        SCREAMING_SNAKE_CASE__       (			self		:		Any   ):





         """simple docstring"""



         pass






     @unittest.skip(reason='''MaskFormer does not use token embeddings'''   )
     def        SCREAMING_SNAKE_CASE__       (			self		:		str   ):





         """simple docstring"""



         pass






     @require_torch_multi_gpu
     @unittest.skip(
         reason='''MaskFormer has some layers using `add_module` which doesn\'t work well with `nn.DataParallel`'''   )
     def        SCREAMING_SNAKE_CASE__       (			self		:		List[Any]   ):





         """simple docstring"""



         pass






     @unittest.skip('''Will be fixed soon by reducing the size of the model used for common tests.'''   )
     def        SCREAMING_SNAKE_CASE__       (			self		:		List[str]   ):





         """simple docstring"""



         pass






     def        SCREAMING_SNAKE_CASE__       (			self		:		Any   ):





         """simple docstring"""



         __lowerCamelCase     ,  __lowerCamelCase          =  self.model_tester.prepare_config_and_inputs_for_common()

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

             __lowerCamelCase          =  ['''pixel_values''']
             self.assertListEqual(arg_names[:1]  ,    a   )






     @slow
     def        SCREAMING_SNAKE_CASE__       (			self		:		Optional[Any]   ):





         """simple docstring"""



         for model_name in ["facebook/maskformer-swin-small-coco"]:
             __lowerCamelCase          =  MaskFormerModel.from_pretrained(a   )
             self.assertIsNotNone(a   )






     def        SCREAMING_SNAKE_CASE__       (			self		:		List[Any]   ):





         """simple docstring"""



         __lowerCamelCase          =  (self.model_tester.min_size,) * 2
         __lowerCamelCase          =  {
             '''pixel_values''': torch.randn((2, 3, *size)  ,    device=a   ),
             '''mask_labels''': torch.randn((2, 10, *size)  ,    device=a   ),
             '''class_labels''': torch.zeros(2  ,    10  ,    device=a   ).long(),
         }

         __lowerCamelCase          =  MaskFormerForInstanceSegmentation(MaskFormerConfig()   ).to(a   )
         __lowerCamelCase          =  model(**a   )
         self.assertTrue(outputs.loss is not None   )






     def        SCREAMING_SNAKE_CASE__       (			self		:		Tuple   ):





         """simple docstring"""



         __lowerCamelCase     ,  __lowerCamelCase          =  self.model_tester.prepare_config_and_inputs_for_common()
         self.model_tester.create_and_check_maskformer_model(a  ,    **a  ,    output_hidden_states=a   )






     def        SCREAMING_SNAKE_CASE__       (			self		:		Any   ):





         """simple docstring"""



         __lowerCamelCase     ,  __lowerCamelCase          =  self.model_tester.prepare_config_and_inputs_for_common()

         for model_class in self.all_model_classes:
             __lowerCamelCase          =  model_class(a   ).to(a   )
             __lowerCamelCase          =  model(**a  ,    output_attentions=a   )
             self.assertTrue(outputs.attentions is not None   )






     def        SCREAMING_SNAKE_CASE__       (			self		:		Tuple   ):





         """simple docstring"""



         if not self.model_tester.is_training:
             return
         # only MaskFormerForInstanceSegmentation has the loss
         __lowerCamelCase          =  self.all_model_classes[1]
         __lowerCamelCase     ,  __lowerCamelCase     ,  __lowerCamelCase     ,  __lowerCamelCase     ,  __lowerCamelCase          =  self.model_tester.prepare_config_and_inputs()

         __lowerCamelCase          =  model_class(a   )
         model.to(a   )
         model.train()

         __lowerCamelCase          =  model(a  ,    mask_labels=a  ,    class_labels=a   ).loss
         loss.backward()






     def        SCREAMING_SNAKE_CASE__       (			self		:		Optional[int]   ):





         """simple docstring"""



         __lowerCamelCase          =  self.all_model_classes[1]
         __lowerCamelCase     ,  __lowerCamelCase     ,  __lowerCamelCase     ,  __lowerCamelCase     ,  __lowerCamelCase          =  self.model_tester.prepare_config_and_inputs()
         __lowerCamelCase          =  True
         __lowerCamelCase          =  True

         __lowerCamelCase          =  model_class(a   )
         model.to(a   )
         model.train()

         __lowerCamelCase          =  model(a  ,    mask_labels=a  ,    class_labels=a   )

         __lowerCamelCase          =  outputs.encoder_hidden_states[0]
         encoder_hidden_states.retain_grad()

         __lowerCamelCase          =  outputs.pixel_decoder_hidden_states[0]
         pixel_decoder_hidden_states.retain_grad()
         # we requires_grad=True in inputs_embeds (line 2152), the original implementation don't
         __lowerCamelCase          =  outputs.transformer_decoder_hidden_states[0]
         transformer_decoder_hidden_states.retain_grad()

         __lowerCamelCase          =  outputs.attentions[0]
         attentions.retain_grad()

         outputs.loss.backward(retain_graph=a   )

         self.assertIsNotNone(encoder_hidden_states.grad   )
         self.assertIsNotNone(pixel_decoder_hidden_states.grad   )
         self.assertIsNotNone(transformer_decoder_hidden_states.grad   )
         self.assertIsNotNone(attentions.grad   )
__UpperCAmelCase												=1e-4






def __lowerCAmelCase			(							)     ->   Union[str, Any]:
    __lowerCamelCase          =  Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''    )
    return image




@require_vision
@slow
class    a__				(       unittest.TestCase			):






     @cached_property
     def        SCREAMING_SNAKE_CASE__       (			self		:		Tuple   ):





         """simple docstring"""



         return (
             MaskFormerImageProcessor.from_pretrained('''facebook/maskformer-swin-small-coco'''   )
             if is_vision_available()
             else None
         )






     def        SCREAMING_SNAKE_CASE__       (			self		:		List[Any]   ):





         """simple docstring"""



         __lowerCamelCase          =  MaskFormerModel.from_pretrained('''facebook/maskformer-swin-small-coco'''   ).to(a   )
         __lowerCamelCase          =  self.default_image_processor
         __lowerCamelCase          =  prepare_img()
         __lowerCamelCase          =  image_processor(a  ,    return_tensors='''pt'''   ).to(a   )
         __lowerCamelCase          =  inputs['''pixel_values'''].shape
         # check size is divisible by 32
         self.assertTrue((inputs_shape[-1] % 32) == 0 and (inputs_shape[-2] % 32) == 0   )
         # check size
         self.assertEqual(a  ,    (1, 3, 8_00, 10_88)   )

         with torch.no_grad():
             __lowerCamelCase          =  model(**a   )

         __lowerCamelCase          =  torch.tensor(
             [[-0.04_82, 0.92_28, 0.49_51], [-0.25_47, 0.80_17, 0.85_27], [-0.00_69, 0.33_85, -0.00_89]]   ).to(a   )
         self.assertTrue(
             torch.allclose(
                 outputs.encoder_last_hidden_state[0, 0, :3, :3]  ,    a  ,    atol=a   )   )

         __lowerCamelCase          =  torch.tensor(
             [[-0.84_22, -0.84_34, -0.97_18], [-1.01_44, -0.55_65, -0.41_95], [-1.00_38, -0.44_84, -0.19_61]]   ).to(a   )
         self.assertTrue(
             torch.allclose(
                 outputs.pixel_decoder_last_hidden_state[0, 0, :3, :3]  ,    a  ,    atol=a   )   )

         __lowerCamelCase          =  torch.tensor(
             [[0.28_52, -0.01_59, 0.97_35], [0.62_54, 0.18_58, 0.85_29], [-0.06_80, -0.41_16, 1.84_13]]   ).to(a   )
         self.assertTrue(
             torch.allclose(
                 outputs.transformer_decoder_last_hidden_state[0, :3, :3]  ,    a  ,    atol=a   )   )






     def        SCREAMING_SNAKE_CASE__       (			self		:		Union[str, Any]   ):





         """simple docstring"""



         __lowerCamelCase          =  (
             MaskFormerForInstanceSegmentation.from_pretrained('''facebook/maskformer-swin-small-coco'''   )
             .to(a   )
             .eval()
         )
         __lowerCamelCase          =  self.default_image_processor
         __lowerCamelCase          =  prepare_img()
         __lowerCamelCase          =  image_processor(a  ,    return_tensors='''pt'''   ).to(a   )
         __lowerCamelCase          =  inputs['''pixel_values'''].shape
         # check size is divisible by 32
         self.assertTrue((inputs_shape[-1] % 32) == 0 and (inputs_shape[-2] % 32) == 0   )
         # check size
         self.assertEqual(a  ,    (1, 3, 8_00, 10_88)   )

         with torch.no_grad():
             __lowerCamelCase          =  model(**a   )
         # masks_queries_logits
         __lowerCamelCase          =  outputs.masks_queries_logits
         self.assertEqual(
             masks_queries_logits.shape  ,    (1, model.config.decoder_config.num_queries, inputs_shape[-2] // 4, inputs_shape[-1] // 4)  ,    )
         __lowerCamelCase          =  [
             [-1.3_73_71_24, -1.7_72_49_37, -1.9_36_42_33],
             [-1.5_97_72_81, -1.9_86_79_39, -2.1_52_36_95],
             [-1.5_79_53_98, -1.9_26_98_32, -2.09_39_42],
         ]
         __lowerCamelCase          =  torch.tensor(a   ).to(a   )
         self.assertTrue(torch.allclose(masks_queries_logits[0, 0, :3, :3]  ,    a  ,    atol=a   )   )
         # class_queries_logits
         __lowerCamelCase          =  outputs.class_queries_logits
         self.assertEqual(
             class_queries_logits.shape  ,    (1, model.config.decoder_config.num_queries, model.config.num_labels + 1)   )
         __lowerCamelCase          =  torch.tensor(
             [
                 [1.6_5_1_2e0_0, -5.2_5_7_2e0_0, -3.3_5_1_9e0_0],
                 [3.6_1_6_9e-0_2, -5.9_0_2_5e0_0, -2.9_3_1_3e0_0],
                 [1.0_7_6_6e-0_4, -7.7_6_3_0e0_0, -5.1_2_6_3e0_0],
             ]   ).to(a   )
         self.assertTrue(torch.allclose(outputs.class_queries_logits[0, :3, :3]  ,    a  ,    atol=a   )   )






     def        SCREAMING_SNAKE_CASE__       (			self		:		List[Any]   ):





         """simple docstring"""



         __lowerCamelCase          =  (
             MaskFormerForInstanceSegmentation.from_pretrained('''facebook/maskformer-resnet101-coco-stuff'''   )
             .to(a   )
             .eval()
         )
         __lowerCamelCase          =  self.default_image_processor
         __lowerCamelCase          =  prepare_img()
         __lowerCamelCase          =  image_processor(a  ,    return_tensors='''pt'''   ).to(a   )
         __lowerCamelCase          =  inputs['''pixel_values'''].shape
         # check size is divisible by 32
         self.assertTrue((inputs_shape[-1] % 32) == 0 and (inputs_shape[-2] % 32) == 0   )
         # check size
         self.assertEqual(a  ,    (1, 3, 8_00, 10_88)   )

         with torch.no_grad():
             __lowerCamelCase          =  model(**a   )
         # masks_queries_logits
         __lowerCamelCase          =  outputs.masks_queries_logits
         self.assertEqual(
             masks_queries_logits.shape  ,    (1, model.config.decoder_config.num_queries, inputs_shape[-2] // 4, inputs_shape[-1] // 4)  ,    )
         __lowerCamelCase          =  [[-0.90_46, -2.63_66, -4.60_62], [-3.41_79, -5.78_90, -8.80_57], [-4.91_79, -7.65_60, -10.77_11]]
         __lowerCamelCase          =  torch.tensor(a   ).to(a   )
         self.assertTrue(torch.allclose(masks_queries_logits[0, 0, :3, :3]  ,    a  ,    atol=a   )   )
         # class_queries_logits
         __lowerCamelCase          =  outputs.class_queries_logits
         self.assertEqual(
             class_queries_logits.shape  ,    (1, model.config.decoder_config.num_queries, model.config.num_labels + 1)   )
         __lowerCamelCase          =  torch.tensor(
             [[4.71_88, -3.25_85, -2.88_57], [6.68_71, -2.91_81, -1.24_87], [7.24_49, -2.27_64, -2.18_74]]   ).to(a   )
         self.assertTrue(torch.allclose(outputs.class_queries_logits[0, :3, :3]  ,    a  ,    atol=a   )   )






     def        SCREAMING_SNAKE_CASE__       (			self		:		int   ):





         """simple docstring"""



         __lowerCamelCase          =  (
             MaskFormerForInstanceSegmentation.from_pretrained('''facebook/maskformer-swin-small-coco'''   )
             .to(a   )
             .eval()
         )
         __lowerCamelCase          =  self.default_image_processor

         __lowerCamelCase          =  image_processor(
             [np.zeros((3, 8_00, 13_33)   ), np.zeros((3, 8_00, 13_33)   )]  ,    segmentation_maps=[np.zeros((3_84, 3_84)   ).astype(np.floataa   ), np.zeros((3_84, 3_84)   ).astype(np.floataa   )]  ,    return_tensors='''pt'''  ,    )

         __lowerCamelCase          =  inputs['''pixel_values'''].to(a   )
         __lowerCamelCase          =  [el.to(a   ) for el in inputs['''mask_labels''']]
         __lowerCamelCase          =  [el.to(a   ) for el in inputs['''class_labels''']]

         with torch.no_grad():
             __lowerCamelCase          =  model(**a   )

         self.assertTrue(outputs.loss is not None   )

'''simple docstring'''




import functools
import operator

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


__UpperCAmelCase												=logging.get_logger(__name__)

__UpperCAmelCase												={
    "microsoft/unispeech-sat-base-100h-libri-ft": (
        "https://huggingface.co/microsoft/unispeech-sat-base-100h-libri-ft/resolve/main/config.json"
    ),
    # See all UniSpeechSat models at https://huggingface.co/models?filter=unispeech_sat
}




class    a__				(       UpperCAmelCase__			):
     lowerCamelCase  :					List[Any]							="unispeech-sat"






     def __init__(			self		:		Dict  ,    a		:		str=32  ,    a		:		Any=7_68  ,    a		:		Optional[Any]=12  ,    a		:		Optional[int]=12  ,    a		:		int=30_72  ,    a		:		int="gelu"  ,    a		:		Dict=0.1  ,    a		:		Dict=0.1  ,    a		:		List[Any]=0.1  ,    a		:		Tuple=0.0  ,    a		:		Optional[Any]=0.0  ,    a		:		Tuple=0.1  ,    a		:		List[Any]=0.1  ,    a		:		str=0.02  ,    a		:		List[Any]=1e-5  ,    a		:		int="group"  ,    a		:		Union[str, Any]="gelu"  ,    a		:		Optional[int]=(5_12, 5_12, 5_12, 5_12, 5_12, 5_12, 5_12)  ,    a		:		List[Any]=(5, 2, 2, 2, 2, 2, 2)  ,    a		:		int=(10, 3, 3, 3, 3, 2, 2)  ,    a		:		Optional[Any]=False  ,    a		:		Any=1_28  ,    a		:		Tuple=16  ,    a		:		str=False  ,    a		:		Optional[Any]=True  ,    a		:		Dict=0.05  ,    a		:		List[Any]=10  ,    a		:		Any=2  ,    a		:		Optional[Any]=0.0  ,    a		:		Optional[Any]=10  ,    a		:		Any=0  ,    a		:		Any=3_20  ,    a		:		str=2  ,    a		:		List[str]=0.1  ,    a		:		List[str]=1_00  ,    a		:		List[str]=2_56  ,    a		:		str=2_56  ,    a		:		Dict=0.1  ,    a		:		Optional[Any]="mean"  ,    a		:		str=False  ,    a		:		Tuple=False  ,    a		:		Optional[Any]=2_56  ,    a		:		int=(5_12, 5_12, 5_12, 5_12, 15_00)  ,    a		:		int=(5, 3, 3, 1, 1)  ,    a		:		Any=(1, 2, 3, 1, 1)  ,    a		:		Union[str, Any]=5_12  ,    a		:		Optional[int]=0  ,    a		:		Optional[int]=1  ,    a		:		Optional[int]=2  ,    a		:		int=5_04  ,    **a		:		Dict  ,    ):





         """simple docstring"""



         super().__init__(**a  ,    pad_token_id=a  ,    bos_token_id=a  ,    eos_token_id=a   )
         __lowerCamelCase          =  hidden_size
         __lowerCamelCase          =  feat_extract_norm
         __lowerCamelCase          =  feat_extract_activation
         __lowerCamelCase          =  list(a   )
         __lowerCamelCase          =  list(a   )
         __lowerCamelCase          =  list(a   )
         __lowerCamelCase          =  conv_bias
         __lowerCamelCase          =  num_conv_pos_embeddings
         __lowerCamelCase          =  num_conv_pos_embedding_groups
         __lowerCamelCase          =  len(self.conv_dim   )
         __lowerCamelCase          =  num_hidden_layers
         __lowerCamelCase          =  intermediate_size
         __lowerCamelCase          =  hidden_act
         __lowerCamelCase          =  num_attention_heads
         __lowerCamelCase          =  hidden_dropout
         __lowerCamelCase          =  attention_dropout
         __lowerCamelCase          =  activation_dropout
         __lowerCamelCase          =  feat_proj_dropout
         __lowerCamelCase          =  final_dropout
         __lowerCamelCase          =  layerdrop
         __lowerCamelCase          =  layer_norm_eps
         __lowerCamelCase          =  initializer_range
         __lowerCamelCase          =  vocab_size
         __lowerCamelCase          =  num_clusters
         __lowerCamelCase          =  do_stable_layer_norm
         __lowerCamelCase          =  use_weighted_layer_sum

         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
         __lowerCamelCase          =  apply_spec_augment
         __lowerCamelCase          =  mask_time_prob
         __lowerCamelCase          =  mask_time_length
         __lowerCamelCase          =  mask_time_min_masks
         __lowerCamelCase          =  mask_feature_prob
         __lowerCamelCase          =  mask_feature_length
         __lowerCamelCase          =  mask_feature_min_masks

         # parameters for pretraining with codevector quantized representations
         __lowerCamelCase          =  num_codevectors_per_group
         __lowerCamelCase          =  num_codevector_groups
         __lowerCamelCase          =  contrastive_logits_temperature
         __lowerCamelCase          =  feat_quantizer_dropout
         __lowerCamelCase          =  num_negatives
         __lowerCamelCase          =  codevector_dim
         __lowerCamelCase          =  proj_codevector_dim
         __lowerCamelCase          =  diversity_loss_weight

         # ctc loss
         __lowerCamelCase          =  ctc_loss_reduction
         __lowerCamelCase          =  ctc_zero_infinity

         # SequenceClassification-specific parameter. Feel free to ignore for other classes.
         __lowerCamelCase          =  classifier_proj_size

         # XVector-specific parameters. Feel free to ignore for other classes.
         __lowerCamelCase          =  list(a   )
         __lowerCamelCase          =  list(a   )
         __lowerCamelCase          =  list(a   )
         __lowerCamelCase          =  xvector_output_dim






     @property
     def        SCREAMING_SNAKE_CASE__       (			self		:		Any   ):





         """simple docstring"""



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