


import functools
import operator

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


lowerCamelCase__							:						str							     =   logging.get_logger(__name__)

lowerCamelCase__							:						List[Any]							     =   {
    """asapp/sew-tiny-100k""": """https://huggingface.co/asapp/sew-tiny-100k/resolve/main/config.json""",
    # See all SEW models at https://huggingface.co/models?filter=sew
}
class 		__magic_name__						(snake_case_				):





     '''simple docstring'''



     __lowercase				:							Union[str, Any]	   =       'sew'

     def __init__(					self:Any     ,		_a:Union[str, Any]=32     ,		_a:Optional[int]=7_68     ,		_a:Optional[int]=12     ,		_a:Any=12     ,		_a:List[Any]=30_72     ,		_a:List[str]=2     ,		_a:int="gelu"     ,		_a:Any=0.1     ,		_a:Tuple=0.1     ,		_a:int=0.1     ,		_a:int=0.0     ,		_a:Any=0.1     ,		_a:Tuple=0.1     ,		_a:List[Any]=0.02     ,		_a:List[str]=1e-5     ,		_a:Union[str, Any]="group"     ,		_a:Optional[int]="gelu"     ,		_a:Optional[Any]=(64, 1_28, 1_28, 1_28, 1_28, 2_56, 2_56, 2_56, 2_56, 5_12, 5_12, 5_12, 5_12)     ,		_a:Optional[Any]=(5, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1)     ,		_a:Optional[int]=(10, 3, 1, 3, 1, 3, 1, 3, 1, 2, 1, 2, 1)     ,		_a:Tuple=False     ,		_a:Any=1_28     ,		_a:Optional[Any]=16     ,		_a:str=True     ,		_a:Dict=0.05     ,		_a:Tuple=10     ,		_a:Optional[Any]=2     ,		_a:str=0.0     ,		_a:Union[str, Any]=10     ,		_a:Optional[Any]=0     ,		_a:Union[str, Any]="mean"     ,		_a:Tuple=False     ,		_a:List[str]=False     ,		_a:Optional[Any]=2_56     ,		_a:Any=0     ,		_a:Any=1     ,		_a:List[str]=2     ,		**_a:Any     ,		):
       super().__init__(**_a     ,		pad_token_id=_a     ,		bos_token_id=_a     ,		eos_token_id=_a   )
       snake_case__						= hidden_size
       snake_case__						= feat_extract_norm
       snake_case__						= feat_extract_activation
       snake_case__						= list(_a   )
       snake_case__						= list(_a   )
       snake_case__						= list(_a   )
       snake_case__						= conv_bias
       snake_case__						= num_conv_pos_embeddings
       snake_case__						= num_conv_pos_embedding_groups
       snake_case__						= len(self.conv_dim   )
       snake_case__						= num_hidden_layers
       snake_case__						= intermediate_size
       snake_case__						= squeeze_factor
       snake_case__						= hidden_act
       snake_case__						= num_attention_heads
       snake_case__						= hidden_dropout
       snake_case__						= attention_dropout
       snake_case__						= activation_dropout
       snake_case__						= feat_proj_dropout
       snake_case__						= final_dropout
       snake_case__						= layerdrop
       snake_case__						= layer_norm_eps
       snake_case__						= initializer_range
       snake_case__						= vocab_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)`,'''
             F"""but is `len(config.conv_dim) = {len(self.conv_dim   )}`, `len(config.conv_stride)"""
             F"""= {len(self.conv_stride   )}`, `len(config.conv_kernel) = {len(self.conv_kernel   )}`."""   )

       # fine-tuning config parameters for SpecAugment: https://arxiv.org/abs/1904.08779
       snake_case__						= apply_spec_augment
       snake_case__						= mask_time_prob
       snake_case__						= mask_time_length
       snake_case__						= mask_time_min_masks
       snake_case__						= mask_feature_prob
       snake_case__						= mask_feature_length
       snake_case__						= mask_feature_min_masks

       # ctc loss
       snake_case__						= ctc_loss_reduction
       snake_case__						= ctc_zero_infinity

       # sequence classification
       snake_case__						= use_weighted_layer_sum
       snake_case__						= classifier_proj_size







     @property
     def 	SCREAMING_SNAKE_CASE__						(					self:Optional[int]   ):
       return functools.reduce(operator.mul     ,		self.conv_stride     ,		1   )





import shutil
import tempfile
import unittest

import numpy as np
import pytest

from transformers import is_speech_available, is_vision_available
from transformers.testing_utils import require_torch


if is_vision_available():
   from transformers import TvltImageProcessor

if is_speech_available():
   from transformers import TvltFeatureExtractor

from transformers import TvltProcessor
@require_torch
class 		__magic_name__						(unittest.TestCase				):





     '''simple docstring'''



     def 	SCREAMING_SNAKE_CASE__						(					self:str   ):
       snake_case__						= '''ZinengTang/tvlt-base'''
       snake_case__						= tempfile.mkdtemp()

     def 	SCREAMING_SNAKE_CASE__						(					self:Dict     ,		**_a:List[Any]   ):
       return TvltImageProcessor.from_pretrained(self.checkpoint     ,		**_a   )

     def 	SCREAMING_SNAKE_CASE__						(					self:Optional[Any]     ,		**_a:Tuple   ):
       return TvltFeatureExtractor.from_pretrained(self.checkpoint     ,		**_a   )

     def 	SCREAMING_SNAKE_CASE__						(					self:Dict   ):
       shutil.rmtree(self.tmpdirname   )

     def 	SCREAMING_SNAKE_CASE__						(					self:List[str]   ):
       snake_case__						= self.get_image_processor()
       snake_case__						= self.get_feature_extractor()

       snake_case__						= TvltProcessor(image_processor=_a     ,		feature_extractor=_a   )
       processor.save_pretrained(self.tmpdirname   )
       snake_case__						= TvltProcessor.from_pretrained(self.tmpdirname   )

       self.assertIsInstance(processor.feature_extractor     ,		_a   )
       self.assertIsInstance(processor.image_processor     ,		_a   )

     def 	SCREAMING_SNAKE_CASE__						(					self:Dict   ):
       snake_case__						= self.get_image_processor()
       snake_case__						= self.get_feature_extractor()

       snake_case__						= TvltProcessor(image_processor=_a     ,		feature_extractor=_a   )

       snake_case__						= np.ones([1_20_00]   )

       snake_case__						= feature_extractor(_a     ,		return_tensors='''np'''   )
       snake_case__						= processor(audio=_a     ,		return_tensors='''np'''   )

       for key in audio_dict.keys():
         self.assertAlmostEqual(audio_dict[key].sum()     ,		input_processor[key].sum()     ,		delta=1e-2   )

     def 	SCREAMING_SNAKE_CASE__						(					self:List[Any]   ):
       snake_case__						= self.get_image_processor()
       snake_case__						= self.get_feature_extractor()

       snake_case__						= TvltProcessor(image_processor=_a     ,		feature_extractor=_a   )

       snake_case__						= np.ones([3, 2_24, 2_24]   )

       snake_case__						= image_processor(_a     ,		return_tensors='''np'''   )
       snake_case__						= processor(images=_a     ,		return_tensors='''np'''   )

       for key in image_dict.keys():
         self.assertAlmostEqual(image_dict[key].sum()     ,		input_processor[key].sum()     ,		delta=1e-2   )

     def 	SCREAMING_SNAKE_CASE__						(					self:Any   ):
       snake_case__						= self.get_image_processor()
       snake_case__						= self.get_feature_extractor()

       snake_case__						= TvltProcessor(image_processor=_a     ,		feature_extractor=_a   )

       snake_case__						= np.ones([1_20_00]   )
       snake_case__						= np.ones([3, 2_24, 2_24]   )

       snake_case__						= processor(audio=_a     ,		images=_a   )

       self.assertListEqual(list(inputs.keys()   )     ,		['''audio_values''', '''audio_mask''', '''pixel_values''', '''pixel_mask''']   )

       # test if it raises when no input is passed
       with pytest.raises(_a   ):
         processor()







     def 	SCREAMING_SNAKE_CASE__						(					self:List[Any]   ):
       snake_case__						= self.get_image_processor()
       snake_case__						= self.get_feature_extractor()

       snake_case__						= TvltProcessor(image_processor=_a     ,		feature_extractor=_a   )

       self.assertListEqual(
           processor.model_input_names     ,		image_processor.model_input_names + feature_extractor.model_input_names     ,		msg='''`processor` and `image_processor`+`feature_extractor` model input names do not match'''     ,		)

