



"""simple docstring"""






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 			A__   (  unittest.TestCase							):




	'''simple docstring'''





	def 							_SCREAMING_SNAKE_CASE   (     self:		Optional[int])				->       Tuple:

				"""simple docstring"""

				__lowerCAmelCase      :  Union[str, Any]												=       "ZinengTang/tvlt-base"
				__lowerCAmelCase      :  Dict												=       tempfile.mkdtemp()

	def 							_SCREAMING_SNAKE_CASE   (     self:		List[str]       ,			**_SCREAMING_SNAKE_CASE:		Optional[Any])				->       Any:

				"""simple docstring"""

				return TvltImageProcessor.from_pretrained(self.checkpoint       ,			**_SCREAMING_SNAKE_CASE)

	def 							_SCREAMING_SNAKE_CASE   (     self:		str       ,			**_SCREAMING_SNAKE_CASE:		str)				->       Any:

				"""simple docstring"""

				return TvltFeatureExtractor.from_pretrained(self.checkpoint       ,			**_SCREAMING_SNAKE_CASE)

	def 							_SCREAMING_SNAKE_CASE   (     self:		Dict)				->       str:

				"""simple docstring"""

				shutil.rmtree(self.tmpdirname)

	def 							_SCREAMING_SNAKE_CASE   (     self:		Tuple)				->       int:

				"""simple docstring"""

				__lowerCAmelCase      :  Tuple												=       self.get_image_processor()
				__lowerCAmelCase      :  List[Any]												=       self.get_feature_extractor()

				__lowerCAmelCase      :  Any												=       TvltProcessor(image_processor=_SCREAMING_SNAKE_CASE       ,			feature_extractor=_SCREAMING_SNAKE_CASE)
				processor.save_pretrained(self.tmpdirname)
				__lowerCAmelCase      :  int												=       TvltProcessor.from_pretrained(self.tmpdirname)

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

	def 							_SCREAMING_SNAKE_CASE   (     self:		List[Any])				->       Optional[int]:

				"""simple docstring"""

				__lowerCAmelCase      :  str												=       self.get_image_processor()
				__lowerCAmelCase      :  Tuple												=       self.get_feature_extractor()

				__lowerCAmelCase      :  str												=       TvltProcessor(image_processor=_SCREAMING_SNAKE_CASE       ,			feature_extractor=_SCREAMING_SNAKE_CASE)

				__lowerCAmelCase      :  Tuple												=       np.ones([1_2000])

				__lowerCAmelCase      :  List[Any]												=       feature_extractor(_SCREAMING_SNAKE_CASE       ,			return_tensors="np")
				__lowerCAmelCase      :  List[str]												=       processor(audio=_SCREAMING_SNAKE_CASE       ,			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])				->       int:

				"""simple docstring"""

				__lowerCAmelCase      :  Optional[Any]												=       self.get_image_processor()
				__lowerCAmelCase      :  Any												=       self.get_feature_extractor()

				__lowerCAmelCase      :  Dict												=       TvltProcessor(image_processor=_SCREAMING_SNAKE_CASE       ,			feature_extractor=_SCREAMING_SNAKE_CASE)

				__lowerCAmelCase      :  List[str]												=       np.ones([3, 224, 224])

				__lowerCAmelCase      :  Union[str, Any]												=       image_processor(_SCREAMING_SNAKE_CASE       ,			return_tensors="np")
				__lowerCAmelCase      :  Optional[int]												=       processor(images=_SCREAMING_SNAKE_CASE       ,			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:		Optional[Any])				->       int:

				"""simple docstring"""

				__lowerCAmelCase      :  Dict												=       self.get_image_processor()
				__lowerCAmelCase      :  List[str]												=       self.get_feature_extractor()

				__lowerCAmelCase      :  int												=       TvltProcessor(image_processor=_SCREAMING_SNAKE_CASE       ,			feature_extractor=_SCREAMING_SNAKE_CASE)

				__lowerCAmelCase      :  Tuple												=       np.ones([1_2000])
				__lowerCAmelCase      :  Any												=       np.ones([3, 224, 224])

				__lowerCAmelCase      :  int												=       processor(audio=_SCREAMING_SNAKE_CASE       ,			images=_SCREAMING_SNAKE_CASE)

				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(_SCREAMING_SNAKE_CASE):
							processor()







	def 							_SCREAMING_SNAKE_CASE   (     self:		int)				->       Optional[Any]:

				"""simple docstring"""

				__lowerCAmelCase      :  Optional[Any]												=       self.get_image_processor()
				__lowerCAmelCase      :  Dict												=       self.get_feature_extractor()

				__lowerCAmelCase      :  int												=       TvltProcessor(image_processor=_SCREAMING_SNAKE_CASE       ,			feature_extractor=_SCREAMING_SNAKE_CASE)

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




"""simple docstring"""






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


__snake_case							:   List[Any]      =    logging.get_logger(__name__)

__snake_case							:   Any      =    {
    'speechbrain/m-ctc-t-large': 'https://huggingface.co/speechbrain/m-ctc-t-large/resolve/main/config.json',
    # See all M-CTC-T models at https://huggingface.co/models?filter=mctct
}



class 			A__   (  __SCREAMING_SNAKE_CASE							):




	'''simple docstring'''





	SCREAMING_SNAKE_CASE          =	'mctct'

	def __init__(     self:		Union[str, Any]       ,			_SCREAMING_SNAKE_CASE:		str=8065       ,			_SCREAMING_SNAKE_CASE:		str=1536       ,			_SCREAMING_SNAKE_CASE:		str=36       ,			_SCREAMING_SNAKE_CASE:		Optional[Any]=6144       ,			_SCREAMING_SNAKE_CASE:		Optional[Any]=4       ,			_SCREAMING_SNAKE_CASE:		Union[str, Any]=384       ,			_SCREAMING_SNAKE_CASE:		Optional[Any]=920       ,			_SCREAMING_SNAKE_CASE:		Union[str, Any]=1e-5       ,			_SCREAMING_SNAKE_CASE:		List[Any]=0.3       ,			_SCREAMING_SNAKE_CASE:		Optional[Any]="relu"       ,			_SCREAMING_SNAKE_CASE:		Optional[int]=0.02       ,			_SCREAMING_SNAKE_CASE:		Optional[Any]=0.3       ,			_SCREAMING_SNAKE_CASE:		Dict=0.3       ,			_SCREAMING_SNAKE_CASE:		List[Any]=1       ,			_SCREAMING_SNAKE_CASE:		Optional[Any]=0       ,			_SCREAMING_SNAKE_CASE:		List[str]=2       ,			_SCREAMING_SNAKE_CASE:		Union[str, Any]=1       ,			_SCREAMING_SNAKE_CASE:		Tuple=0.3       ,			_SCREAMING_SNAKE_CASE:		Dict=1       ,			_SCREAMING_SNAKE_CASE:		int=(7,)       ,			_SCREAMING_SNAKE_CASE:		str=(3,)       ,			_SCREAMING_SNAKE_CASE:		Union[str, Any]=80       ,			_SCREAMING_SNAKE_CASE:		Tuple=1       ,			_SCREAMING_SNAKE_CASE:		Dict=None       ,			_SCREAMING_SNAKE_CASE:		Tuple="sum"       ,			_SCREAMING_SNAKE_CASE:		List[str]=False       ,			**_SCREAMING_SNAKE_CASE:		Tuple       ,			)				->       Tuple:

				"""simple docstring"""

				super().__init__(**_SCREAMING_SNAKE_CASE       ,			pad_token_id=_SCREAMING_SNAKE_CASE       ,			bos_token_id=_SCREAMING_SNAKE_CASE       ,			eos_token_id=_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  str												=       vocab_size
				__lowerCAmelCase      :  str												=       hidden_size
				__lowerCAmelCase      :  str												=       num_hidden_layers
				__lowerCAmelCase      :  str												=       intermediate_size
				__lowerCAmelCase      :  List[Any]												=       num_attention_heads
				__lowerCAmelCase      :  Dict												=       attention_head_dim
				__lowerCAmelCase      :  Optional[int]												=       max_position_embeddings
				__lowerCAmelCase      :  str												=       layer_norm_eps
				__lowerCAmelCase      :  Tuple												=       layerdrop
				__lowerCAmelCase      :  str												=       hidden_act
				__lowerCAmelCase      :  List[Any]												=       initializer_range
				__lowerCAmelCase      :  int												=       hidden_dropout_prob
				__lowerCAmelCase      :  Optional[Any]												=       attention_probs_dropout_prob
				__lowerCAmelCase      :  str												=       pad_token_id
				__lowerCAmelCase      :  Optional[int]												=       bos_token_id
				__lowerCAmelCase      :  Union[str, Any]												=       eos_token_id
				__lowerCAmelCase      :  Any												=       conv_glu_dim
				__lowerCAmelCase      :  Optional[int]												=       conv_dropout
				__lowerCAmelCase      :  Union[str, Any]												=       num_conv_layers
				__lowerCAmelCase      :  Optional[int]												=       input_feat_per_channel
				__lowerCAmelCase      :  Union[str, Any]												=       input_channels
				__lowerCAmelCase      :  Optional[Any]												=       conv_channels
				__lowerCAmelCase      :  Dict												=       ctc_loss_reduction
				__lowerCAmelCase      :  int												=       ctc_zero_infinity

				# prevents config testing fail with exporting to json
				__lowerCAmelCase      :  List[str]												=       list(_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  Dict												=       list(_SCREAMING_SNAKE_CASE)

				if len(self.conv_kernel) != self.num_conv_layers:
							raise ValueError(
							    "Configuration for convolutional module is incorrect. "
							    "It is required that `len(config.conv_kernel)` == `config.num_conv_layers` "
							    F"""but is `len(config.conv_kernel) = {len(self.conv_kernel)}`, """
							    F"""`config.num_conv_layers = {self.num_conv_layers}`.""")