





"""simple docstring"""






import functools
import operator

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


A	     =					logging.get_logger(__name__)

A	     =					{
    '''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 			__lowercase     (     a_							):







     '''simple docstring'''




     __lowerCAmelCase					=					'''unispeech-sat'''







     def __init__(  self		,     _UpperCAmelCase=32		,     _UpperCAmelCase=768		,     _UpperCAmelCase=12		,     _UpperCAmelCase=12		,     _UpperCAmelCase=3072		,     _UpperCAmelCase="gelu"		,     _UpperCAmelCase=0.1		,     _UpperCAmelCase=0.1		,     _UpperCAmelCase=0.1		,     _UpperCAmelCase=0.0		,     _UpperCAmelCase=0.0		,     _UpperCAmelCase=0.1		,     _UpperCAmelCase=0.1		,     _UpperCAmelCase=0.0_2		,     _UpperCAmelCase=1e-5		,     _UpperCAmelCase="group"		,     _UpperCAmelCase="gelu"		,     _UpperCAmelCase=(512, 512, 512, 512, 512, 512, 512)		,     _UpperCAmelCase=(5, 2, 2, 2, 2, 2, 2)		,     _UpperCAmelCase=(10, 3, 3, 3, 3, 2, 2)		,     _UpperCAmelCase=False		,     _UpperCAmelCase=128		,     _UpperCAmelCase=16		,     _UpperCAmelCase=False		,     _UpperCAmelCase=True		,     _UpperCAmelCase=0.0_5		,     _UpperCAmelCase=10		,     _UpperCAmelCase=2		,     _UpperCAmelCase=0.0		,     _UpperCAmelCase=10		,     _UpperCAmelCase=0		,     _UpperCAmelCase=320		,     _UpperCAmelCase=2		,     _UpperCAmelCase=0.1		,     _UpperCAmelCase=100		,     _UpperCAmelCase=256		,     _UpperCAmelCase=256		,     _UpperCAmelCase=0.1		,     _UpperCAmelCase="mean"		,     _UpperCAmelCase=False		,     _UpperCAmelCase=False		,     _UpperCAmelCase=256		,     _UpperCAmelCase=(512, 512, 512, 512, 1500)		,     _UpperCAmelCase=(5, 3, 3, 1, 1)		,     _UpperCAmelCase=(1, 2, 3, 1, 1)		,     _UpperCAmelCase=512		,     _UpperCAmelCase=0		,     _UpperCAmelCase=1		,     _UpperCAmelCase=2		,     _UpperCAmelCase=504		,     **_UpperCAmelCase		,     ):
         super().__init__(**lowercase_		,     pad_token_id=lowercase_		,     bos_token_id=lowercase_		,     eos_token_id=lowercase_       )
         __a	:  Any         =					hidden_size
         __a	:  Union[str, Any]         =					feat_extract_norm
         __a	:  Dict         =					feat_extract_activation
         __a	:  Optional[Any]         =					list(lowercase_       )
         __a	:  str         =					list(lowercase_       )
         __a	:  Optional[int]         =					list(lowercase_       )
         __a	:  Dict         =					conv_bias
         __a	:  Dict         =					num_conv_pos_embeddings
         __a	:  List[Any]         =					num_conv_pos_embedding_groups
         __a	:  Dict         =					len(self.conv_dim       )
         __a	:  str         =					num_hidden_layers
         __a	:  Optional[Any]         =					intermediate_size
         __a	:  Any         =					hidden_act
         __a	:  Any         =					num_attention_heads
         __a	:  str         =					hidden_dropout
         __a	:  List[str]         =					attention_dropout
         __a	:  Any         =					activation_dropout
         __a	:  Optional[Any]         =					feat_proj_dropout
         __a	:  Any         =					final_dropout
         __a	:  Tuple         =					layerdrop
         __a	:  Optional[int]         =					layer_norm_eps
         __a	:  Any         =					initializer_range
         __a	:  Optional[Any]         =					vocab_size
         __a	:  Any         =					num_clusters
         __a	:  str         =					do_stable_layer_norm
         __a	:  Dict         =					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
         __a	:  List[str]         =					apply_spec_augment
         __a	:  Optional[int]         =					mask_time_prob
         __a	:  Tuple         =					mask_time_length
         __a	:  Union[str, Any]         =					mask_time_min_masks
         __a	:  List[Any]         =					mask_feature_prob
         __a	:  Optional[Any]         =					mask_feature_length
         __a	:  List[Any]         =					mask_feature_min_masks

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

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

         # SequenceClassification-specific parameter. Feel free to ignore for other classes.
         __a	:  List[Any]         =					classifier_proj_size

         # XVector-specific parameters. Feel free to ignore for other classes.
         __a	:  Dict         =					list(lowercase_       )
         __a	:  int         =					list(lowercase_       )
         __a	:  Dict         =					list(lowercase_       )
         __a	:  Tuple         =					xvector_output_dim







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






"""simple docstring"""






import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
		import torch

if is_vision_available():
		from PIL import Image

		from transformers import ViTImageProcessor




class 			__lowercase     (     unittest.TestCase							):







					'''simple docstring'''




					def __init__(  self		,     _UpperCAmelCase		,     _UpperCAmelCase=13		,     _UpperCAmelCase=3		,     _UpperCAmelCase=224		,     _UpperCAmelCase=30		,     _UpperCAmelCase=400		,     _UpperCAmelCase=True		,     _UpperCAmelCase=None		,     _UpperCAmelCase=True		,     _UpperCAmelCase=[0.5, 0.5, 0.5]		,     _UpperCAmelCase=[0.5, 0.5, 0.5]		,     ):
									__a	:  int         =					size if size is not None else {'''height''': 18, '''width''': 18}
									__a	:  List[Any]         =					parent
									__a	:  Dict         =					batch_size
									__a	:  Dict         =					num_channels
									__a	:  int         =					image_size
									__a	:  Optional[Any]         =					min_resolution
									__a	:  Optional[int]         =					max_resolution
									__a	:  Dict         =					do_resize
									__a	:  List[Any]         =					size
									__a	:  int         =					do_normalize
									__a	:  Optional[Any]         =					image_mean
									__a	:  int         =					image_std







					def 	_lowerCamelCase						(  self       ):
									return {
									    "image_mean": self.image_mean,
									    "image_std": self.image_std,
									    "do_normalize": self.do_normalize,
									    "do_resize": self.do_resize,
									    "size": self.size,
									}






@require_torch
@require_vision
class 			__lowercase     (     _UpperCamelCase				, unittest.TestCase							):







					'''simple docstring'''




					__lowerCAmelCase					=					ViTImageProcessor if is_vision_available() else None







					def 	_lowerCamelCase						(  self       ):
									__a	:  int         =					EfficientFormerImageProcessorTester(self       )







					@property
					def 	_lowerCamelCase						(  self       ):
									return self.image_proc_tester.prepare_image_processor_dict()







					def 	_lowerCamelCase						(  self       ):
									__a	:  List[str]         =					self.image_processing_class(**self.image_processor_dict       )
									self.assertTrue(hasattr(_UpperCAmelCase		,     '''image_mean'''       )       )
									self.assertTrue(hasattr(_UpperCAmelCase		,     '''image_std'''       )       )
									self.assertTrue(hasattr(_UpperCAmelCase		,     '''do_normalize'''       )       )
									self.assertTrue(hasattr(_UpperCAmelCase		,     '''do_resize'''       )       )
									self.assertTrue(hasattr(_UpperCAmelCase		,     '''size'''       )       )







					def 	_lowerCamelCase						(  self       ):
									pass







					def 	_lowerCamelCase						(  self       ):
									# Initialize image_processor
									__a	:  Any         =					self.image_processing_class(**self.image_processor_dict       )
									# create random PIL images
									__a	:  int         =					prepare_image_inputs(self.image_proc_tester		,     equal_resolution=_UpperCAmelCase       )
									for image in image_inputs:
													self.assertIsInstance(_UpperCAmelCase		,     Image.Image       )

									# Test not batched input
									__a	:  Dict         =					image_processor(image_inputs[0]		,     return_tensors='''pt'''       ).pixel_values
									self.assertEqual(
									    encoded_images.shape		,     (
									        1,
									        self.image_proc_tester.num_channels,
									        self.image_proc_tester.size['''height'''],
									        self.image_proc_tester.size['''width'''],
									    )		,     )

									# Test batched
									__a	:  Any         =					image_processor(_UpperCAmelCase		,     return_tensors='''pt'''       ).pixel_values
									self.assertEqual(
									    encoded_images.shape		,     (
									        self.image_proc_tester.batch_size,
									        self.image_proc_tester.num_channels,
									        self.image_proc_tester.size['''height'''],
									        self.image_proc_tester.size['''width'''],
									    )		,     )







					def 	_lowerCamelCase						(  self       ):
									# Initialize image_processor
									__a	:  Tuple         =					self.image_processing_class(**self.image_processor_dict       )
									# create random numpy tensors
									__a	:  int         =					prepare_image_inputs(self.image_proc_tester		,     equal_resolution=_UpperCAmelCase		,     numpify=_UpperCAmelCase       )
									for image in image_inputs:
													self.assertIsInstance(_UpperCAmelCase		,     np.ndarray       )

									# Test not batched input
									__a	:  Optional[int]         =					image_processor(image_inputs[0]		,     return_tensors='''pt'''       ).pixel_values
									self.assertEqual(
									    encoded_images.shape		,     (
									        1,
									        self.image_proc_tester.num_channels,
									        self.image_proc_tester.size['''height'''],
									        self.image_proc_tester.size['''width'''],
									    )		,     )

									# Test batched
									__a	:  str         =					image_processor(_UpperCAmelCase		,     return_tensors='''pt'''       ).pixel_values
									self.assertEqual(
									    encoded_images.shape		,     (
									        self.image_proc_tester.batch_size,
									        self.image_proc_tester.num_channels,
									        self.image_proc_tester.size['''height'''],
									        self.image_proc_tester.size['''width'''],
									    )		,     )







					def 	_lowerCamelCase						(  self       ):
									# Initialize image_processor
									__a	:  int         =					self.image_processing_class(**self.image_processor_dict       )
									# create random PyTorch tensors
									__a	:  List[Any]         =					prepare_image_inputs(self.image_proc_tester		,     equal_resolution=_UpperCAmelCase		,     torchify=_UpperCAmelCase       )
									for image in image_inputs:
													self.assertIsInstance(_UpperCAmelCase		,     torch.Tensor       )

									# Test not batched input
									__a	:  str         =					image_processor(image_inputs[0]		,     return_tensors='''pt'''       ).pixel_values
									self.assertEqual(
									    encoded_images.shape		,     (
									        1,
									        self.image_proc_tester.num_channels,
									        self.image_proc_tester.size['''height'''],
									        self.image_proc_tester.size['''width'''],
									    )		,     )

									# Test batched
									__a	:  Tuple         =					image_processor(_UpperCAmelCase		,     return_tensors='''pt'''       ).pixel_values
									self.assertEqual(
									    encoded_images.shape		,     (
									        self.image_proc_tester.batch_size,
									        self.image_proc_tester.num_channels,
									        self.image_proc_tester.size['''height'''],
									        self.image_proc_tester.size['''width'''],
									    )		,     )