





"""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 						__snake_case   :





 """simple docstring"""


 def __init__(       self   ,		__lowerCamelCase   ,		__lowerCamelCase=2   ,		__lowerCamelCase=True   ,		__lowerCamelCase=False   ,		__lowerCamelCase=10   ,		__lowerCamelCase=3   ,		__lowerCamelCase=32 * 4   ,		__lowerCamelCase=32 * 6   ,		__lowerCamelCase=4   ,		__lowerCamelCase=32   ,		):



     '''simple docstring'''




     __A       :		Dict							=	parent
     __A       :		Any							=	batch_size
     __A       :		List[Any]							=	is_training
     __A       :		Tuple							=	use_auxiliary_loss
     __A       :		int							=	num_queries
     __A       :		Union[str, Any]							=	num_channels
     __A       :		Dict							=	min_size
     __A       :		Any							=	max_size
     __A       :		Union[str, Any]							=	num_labels
     __A       :		Union[str, Any]							=	mask_feature_size

 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     __A       :		Tuple							=	floats_tensor([self.batch_size, self.num_channels, self.min_size, self.max_size]    ).to(
         __lowerCamelCase    )

     __A       :		Union[str, Any]							=	torch.ones([self.batch_size, self.min_size, self.max_size]   ,		device=__lowerCamelCase    )

     __A       :		List[str]							=	(
         torch.rand([self.batch_size, self.num_labels, self.min_size, self.max_size]   ,		device=__lowerCamelCase    ) > 0.5
     ).float()
     __A       :		Optional[Any]							=	(torch.rand((self.batch_size, self.num_labels)   ,		device=__lowerCamelCase    ) > 0.5).long()

     __A       :		List[str]							=	self.get_config()
     return config, pixel_values, pixel_mask, mask_labels, class_labels

 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     return MaskFormerConfig.from_backbone_and_decoder_configs(
         backbone_config=SwinConfig(
             depths=[1, 1, 1, 1]   ,		)   ,		decoder_config=DetrConfig(
             decoder_ffn_dim=128   ,		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    UpperCamelCase__(       self    ):



     '''simple docstring'''




     __A					,			__A					,			__A					,			__A					,			__A       :		Union[str, Any]							=	self.prepare_config_and_inputs()
     __A       :		Dict							=	{'''pixel_values''': pixel_values, '''pixel_mask''': pixel_mask}
     return config, inputs_dict

 def    UpperCamelCase__(       self   ,		__lowerCamelCase   ,		__lowerCamelCase    ):



     '''simple docstring'''




     __A       :		Union[str, Any]							=	output.encoder_hidden_states
     __A       :		int							=	output.pixel_decoder_hidden_states
     __A       :		Optional[int]							=	output.transformer_decoder_hidden_states

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

 def    UpperCamelCase__(       self   ,		__lowerCamelCase   ,		__lowerCamelCase   ,		__lowerCamelCase   ,		__lowerCamelCase=False    ):



     '''simple docstring'''




     with torch.no_grad():
         __A       :		Optional[Any]							=	MaskFormerModel(config=__lowerCamelCase    )
         model.to(__lowerCamelCase    )
         model.eval()

         __A       :		Dict							=	model(pixel_values=__lowerCamelCase   ,		pixel_mask=__lowerCamelCase    )
         __A       :		Optional[Any]							=	model(__lowerCamelCase   ,		output_hidden_states=__lowerCamelCase    )
     # 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(__lowerCamelCase   ,		__lowerCamelCase    )







 def    UpperCamelCase__(       self   ,		__lowerCamelCase   ,		__lowerCamelCase   ,		__lowerCamelCase   ,		__lowerCamelCase   ,		__lowerCamelCase    ):



     '''simple docstring'''




     __A       :		List[Any]							=	MaskFormerForInstanceSegmentation(config=__lowerCamelCase    )
     model.to(__lowerCamelCase    )
     model.eval()

     def comm_check_on_output(__lowerCamelCase    ):
         # 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():
         __A       :		List[Any]							=	model(pixel_values=__lowerCamelCase   ,		pixel_mask=__lowerCamelCase    )
         __A       :		List[str]							=	model(__lowerCamelCase    )

         comm_check_on_output(__lowerCamelCase    )

         __A       :		Optional[Any]							=	model(
             pixel_values=__lowerCamelCase   ,		pixel_mask=__lowerCamelCase   ,		mask_labels=__lowerCamelCase   ,		class_labels=__lowerCamelCase    )

     comm_check_on_output(__lowerCamelCase    )

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






@require_torch
class 						__snake_case   (						SCREAMING_SNAKE_CASE__				,				SCREAMING_SNAKE_CASE__				,				unittest.TestCase	):





 """simple docstring"""


 _lowerCamelCase								=	(MaskFormerModel, MaskFormerForInstanceSegmentation) if is_torch_available() else ()
 _lowerCamelCase								=	(
     {"""feature-extraction""": MaskFormerModel, """image-segmentation""": MaskFormerForInstanceSegmentation}
     if is_torch_available()
     else {}
 )

 _lowerCamelCase								=	False
 _lowerCamelCase								=	False
 _lowerCamelCase								=	False
 _lowerCamelCase								=	False

 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     __A       :		int							=	MaskFormerModelTester(self    )
     __A       :		List[str]							=	ConfigTester(self   ,		config_class=__lowerCamelCase   ,		has_text_modality=__lowerCamelCase    )

 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     self.config_tester.run_common_tests()

 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     __A					,			__A       :		Any							=	self.model_tester.prepare_config_and_inputs_for_common()
     self.model_tester.create_and_check_maskformer_model(__lowerCamelCase   ,		**__lowerCamelCase   ,		output_hidden_states=__lowerCamelCase    )

 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     __A       :		List[str]							=	self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_maskformer_instance_segmentation_head_model(*__lowerCamelCase    )

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



     '''simple docstring'''




     pass

 @unittest.skip(reason='''MaskFormer does not have a get_input_embeddings method'''    )
 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     pass

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



     '''simple docstring'''




     pass

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



     '''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    UpperCamelCase__(       self    ):



     '''simple docstring'''




     pass

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



     '''simple docstring'''




     pass

 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     __A					,			__A       :		Tuple							=	self.model_tester.prepare_config_and_inputs_for_common()

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

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

 @slow
 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




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

 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     __A       :		Dict							=	(self.model_tester.min_size,) * 2
     __A       :		List[Any]							=	{
         '''pixel_values''': torch.randn((2, 3, *size)   ,		device=__lowerCamelCase    ),
         '''mask_labels''': torch.randn((2, 10, *size)   ,		device=__lowerCamelCase    ),
         '''class_labels''': torch.zeros(2   ,		10   ,		device=__lowerCamelCase    ).long(),
     }

     __A       :		Any							=	MaskFormerForInstanceSegmentation(MaskFormerConfig()    ).to(__lowerCamelCase    )
     __A       :		Optional[Any]							=	model(**__lowerCamelCase    )
     self.assertTrue(outputs.loss is not None    )

 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     __A					,			__A       :		Union[str, Any]							=	self.model_tester.prepare_config_and_inputs_for_common()
     self.model_tester.create_and_check_maskformer_model(__lowerCamelCase   ,		**__lowerCamelCase   ,		output_hidden_states=__lowerCamelCase    )

 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     __A					,			__A       :		Dict							=	self.model_tester.prepare_config_and_inputs_for_common()

     for model_class in self.all_model_classes:
         __A       :		Optional[int]							=	model_class(__lowerCamelCase    ).to(__lowerCamelCase    )
         __A       :		Dict							=	model(**__lowerCamelCase   ,		output_attentions=__lowerCamelCase    )
         self.assertTrue(outputs.attentions is not None    )

 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




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

     __A       :		Optional[int]							=	model_class(__lowerCamelCase    )
     model.to(__lowerCamelCase    )
     model.train()

     __A       :		Tuple							=	model(__lowerCamelCase   ,		mask_labels=__lowerCamelCase   ,		class_labels=__lowerCamelCase    ).loss
     loss.backward()







 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     __A       :		List[str]							=	self.all_model_classes[1]
     __A					,			__A					,			__A					,			__A					,			__A       :		Dict							=	self.model_tester.prepare_config_and_inputs()
     __A       :		int							=	True
     __A       :		Dict							=	True

     __A       :		Optional[int]							=	model_class(__lowerCamelCase    )
     model.to(__lowerCamelCase    )
     model.train()

     __A       :		Any							=	model(__lowerCamelCase   ,		mask_labels=__lowerCamelCase   ,		class_labels=__lowerCamelCase    )

     __A       :		Union[str, Any]							=	outputs.encoder_hidden_states[0]
     encoder_hidden_states.retain_grad()

     __A       :		Dict							=	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
     __A       :		Union[str, Any]							=	outputs.transformer_decoder_hidden_states[0]
     transformer_decoder_hidden_states.retain_grad()

     __A       :		Optional[Any]							=	outputs.attentions[0]
     attentions.retain_grad()

     outputs.loss.backward(retain_graph=__lowerCamelCase    )

     self.assertIsNotNone(encoder_hidden_states.grad    )
     self.assertIsNotNone(pixel_decoder_hidden_states.grad    )
     self.assertIsNotNone(transformer_decoder_hidden_states.grad    )
     self.assertIsNotNone(attentions.grad    )






a_					=     1e-4







def 						__lowercase	(  )  ->Optional[int]:



    '''simple docstring'''







    __A       :		int							=	Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''		)
    return image






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





 """simple docstring"""


 @cached_property
 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




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

 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     __A       :		Union[str, Any]							=	MaskFormerModel.from_pretrained('''facebook/maskformer-swin-small-coco'''    ).to(__lowerCamelCase    )
     __A       :		List[str]							=	self.default_image_processor
     __A       :		int							=	prepare_img()
     __A       :		Any							=	image_processor(__lowerCamelCase   ,		return_tensors='''pt'''    ).to(__lowerCamelCase    )
     __A       :		Optional[int]							=	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(__lowerCamelCase   ,		(1, 3, 800, 1088)    )

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

     __A       :		List[Any]							=	torch.tensor(
         [[-0.0_4_8_2, 0.9_2_2_8, 0.4_9_5_1], [-0.2_5_4_7, 0.8_0_1_7, 0.8_5_2_7], [-0.0_0_6_9, 0.3_3_8_5, -0.0_0_8_9]]    ).to(__lowerCamelCase    )
     self.assertTrue(
         torch.allclose(
             outputs.encoder_last_hidden_state[0, 0, :3, :3]   ,		__lowerCamelCase   ,		atol=__lowerCamelCase    )    )

     __A       :		Optional[int]							=	torch.tensor(
         [[-0.8_4_2_2, -0.8_4_3_4, -0.9_7_1_8], [-1.0_1_4_4, -0.5_5_6_5, -0.4_1_9_5], [-1.0_0_3_8, -0.4_4_8_4, -0.1_9_6_1]]    ).to(__lowerCamelCase    )
     self.assertTrue(
         torch.allclose(
             outputs.pixel_decoder_last_hidden_state[0, 0, :3, :3]   ,		__lowerCamelCase   ,		atol=__lowerCamelCase    )    )

     __A       :		Tuple							=	torch.tensor(
         [[0.2_8_5_2, -0.0_1_5_9, 0.9_7_3_5], [0.6_2_5_4, 0.1_8_5_8, 0.8_5_2_9], [-0.0_6_8_0, -0.4_1_1_6, 1.8_4_1_3]]    ).to(__lowerCamelCase    )
     self.assertTrue(
         torch.allclose(
             outputs.transformer_decoder_last_hidden_state[0, :3, :3]   ,		__lowerCamelCase   ,		atol=__lowerCamelCase    )    )

 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     __A       :		List[Any]							=	(
         MaskFormerForInstanceSegmentation.from_pretrained('''facebook/maskformer-swin-small-coco'''    )
         .to(__lowerCamelCase    )
         .eval()
     )
     __A       :		int							=	self.default_image_processor
     __A       :		str							=	prepare_img()
     __A       :		Optional[int]							=	image_processor(__lowerCamelCase   ,		return_tensors='''pt'''    ).to(__lowerCamelCase    )
     __A       :		Union[str, Any]							=	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(__lowerCamelCase   ,		(1, 3, 800, 1088)    )

     with torch.no_grad():
         __A       :		Optional[Any]							=	model(**__lowerCamelCase    )
     # masks_queries_logits
     __A       :		str							=	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)   ,		)
     __A       :		Any							=	[
         [-1.3_7_3_7_1_2_4, -1.7_7_2_4_9_3_7, -1.9_3_6_4_2_3_3],
         [-1.5_9_7_7_2_8_1, -1.9_8_6_7_9_3_9, -2.1_5_2_3_6_9_5],
         [-1.5_7_9_5_3_9_8, -1.9_2_6_9_8_3_2, -2.0_9_3_9_4_2],
     ]
     __A       :		Optional[int]							=	torch.tensor(__lowerCamelCase    ).to(__lowerCamelCase    )
     self.assertTrue(torch.allclose(masks_queries_logits[0, 0, :3, :3]   ,		__lowerCamelCase   ,		atol=__lowerCamelCase    )    )
     # class_queries_logits
     __A       :		Tuple							=	outputs.class_queries_logits
     self.assertEqual(
         class_queries_logits.shape   ,		(1, model.config.decoder_config.num_queries, model.config.num_labels + 1)    )
     __A       :		List[Any]							=	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(__lowerCamelCase    )
     self.assertTrue(torch.allclose(outputs.class_queries_logits[0, :3, :3]   ,		__lowerCamelCase   ,		atol=__lowerCamelCase    )    )

 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     __A       :		Tuple							=	(
         MaskFormerForInstanceSegmentation.from_pretrained('''facebook/maskformer-resnet101-coco-stuff'''    )
         .to(__lowerCamelCase    )
         .eval()
     )
     __A       :		Any							=	self.default_image_processor
     __A       :		Dict							=	prepare_img()
     __A       :		List[Any]							=	image_processor(__lowerCamelCase   ,		return_tensors='''pt'''    ).to(__lowerCamelCase    )
     __A       :		List[str]							=	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(__lowerCamelCase   ,		(1, 3, 800, 1088)    )

     with torch.no_grad():
         __A       :		Tuple							=	model(**__lowerCamelCase    )
     # masks_queries_logits
     __A       :		Tuple							=	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)   ,		)
     __A       :		Optional[Any]							=	[[-0.9_0_4_6, -2.6_3_6_6, -4.6_0_6_2], [-3.4_1_7_9, -5.7_8_9_0, -8.8_0_5_7], [-4.9_1_7_9, -7.6_5_6_0, -1_0.7_7_1_1]]
     __A       :		Union[str, Any]							=	torch.tensor(__lowerCamelCase    ).to(__lowerCamelCase    )
     self.assertTrue(torch.allclose(masks_queries_logits[0, 0, :3, :3]   ,		__lowerCamelCase   ,		atol=__lowerCamelCase    )    )
     # class_queries_logits
     __A       :		Dict							=	outputs.class_queries_logits
     self.assertEqual(
         class_queries_logits.shape   ,		(1, model.config.decoder_config.num_queries, model.config.num_labels + 1)    )
     __A       :		str							=	torch.tensor(
         [[4.7_1_8_8, -3.2_5_8_5, -2.8_8_5_7], [6.6_8_7_1, -2.9_1_8_1, -1.2_4_8_7], [7.2_4_4_9, -2.2_7_6_4, -2.1_8_7_4]]    ).to(__lowerCamelCase    )
     self.assertTrue(torch.allclose(outputs.class_queries_logits[0, :3, :3]   ,		__lowerCamelCase   ,		atol=__lowerCamelCase    )    )







 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     __A       :		Optional[Any]							=	(
         MaskFormerForInstanceSegmentation.from_pretrained('''facebook/maskformer-swin-small-coco'''    )
         .to(__lowerCamelCase    )
         .eval()
     )
     __A       :		Tuple							=	self.default_image_processor

     __A       :		Tuple							=	image_processor(
         [np.zeros((3, 800, 1333)    ), np.zeros((3, 800, 1333)    )]   ,		segmentation_maps=[np.zeros((384, 384)    ).astype(np.floataa    ), np.zeros((384, 384)    ).astype(np.floataa    )]   ,		return_tensors='''pt'''   ,		)

     __A       :		str							=	inputs['''pixel_values'''].to(__lowerCamelCase    )
     __A       :		Dict							=	[el.to(__lowerCamelCase    ) for el in inputs['''mask_labels''']]
     __A       :		Dict							=	[el.to(__lowerCamelCase    ) for el in inputs['''class_labels''']]

     with torch.no_grad():
         __A       :		Optional[int]							=	model(**__lowerCamelCase    )

     self.assertTrue(outputs.loss is not None    )











"""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    )




