

'''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       __magic_name__							(							self					:      Union[str, Any]  ):



								'''simple docstring'''



								snake_case__						:       int       						=  '''ZinengTang/tvlt-base'''
								snake_case__						:       Optional[Any]       						=  tempfile.mkdtemp()







						def       __magic_name__							(							self					:      Union[str, Any]			,			**snake_case_					:      List[str]  ):



								'''simple docstring'''



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







						def       __magic_name__							(							self					:      Union[str, Any]			,			**snake_case_					:      str  ):



								'''simple docstring'''



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







						def       __magic_name__							(							self					:      str  ):



								'''simple docstring'''



								shutil.rmtree(self.tmpdirname  )







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



								'''simple docstring'''



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

								snake_case__						:       Tuple       						=  TvltProcessor(image_processor=snake_case_			,			feature_extractor=snake_case_  )
								processor.save_pretrained(self.tmpdirname  )
								snake_case__						:       Tuple       						=  TvltProcessor.from_pretrained(self.tmpdirname  )

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







						def       __magic_name__							(							self					:      Any  ):



								'''simple docstring'''



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

								snake_case__						:       int       						=  TvltProcessor(image_processor=snake_case_			,			feature_extractor=snake_case_  )

								snake_case__						:       Dict       						=  np.ones([1_2_0_0_0]  )

								snake_case__						:       str       						=  feature_extractor(snake_case_			,			return_tensors='''np'''  )
								snake_case__						:       List[Any]       						=  processor(audio=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       __magic_name__							(							self					:      str  ):



								'''simple docstring'''



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

								snake_case__						:       List[Any]       						=  TvltProcessor(image_processor=snake_case_			,			feature_extractor=snake_case_  )

								snake_case__						:       Optional[Any]       						=  np.ones([3, 2_2_4, 2_2_4]  )

								snake_case__						:       Any       						=  image_processor(snake_case_			,			return_tensors='''np'''  )
								snake_case__						:       List[Any]       						=  processor(images=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       __magic_name__							(							self					:      Union[str, Any]  ):



								'''simple docstring'''



								snake_case__						:       Tuple       						=  self.get_image_processor()
								snake_case__						:       Dict       						=  self.get_feature_extractor()

								snake_case__						:       List[Any]       						=  TvltProcessor(image_processor=snake_case_			,			feature_extractor=snake_case_  )

								snake_case__						:       str       						=  np.ones([1_2_0_0_0]  )
								snake_case__						:       Optional[Any]       						=  np.ones([3, 2_2_4, 2_2_4]  )

								snake_case__						:       int       						=  processor(audio=snake_case_			,			images=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(snake_case_  ):
										processor()







						def       __magic_name__							(							self					:      Any  ):



								'''simple docstring'''



								snake_case__						:       Union[str, Any]       						=  self.get_image_processor()
								snake_case__						:       Any       						=  self.get_feature_extractor()

								snake_case__						:       Union[str, Any]       						=  TvltProcessor(image_processor=snake_case_			,			feature_extractor=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


lowerCAmelCase__						:       Dict										=						logging.get_logger(__name__)

lowerCAmelCase__						:       Tuple										=						{"""ctrl""": """https://huggingface.co/ctrl/resolve/main/config.json"""}




class     a			(				SCREAMING_SNAKE_CASE       ):






						"""simple docstring"""




						__UpperCAmelCase			     =    """ctrl"""
						__UpperCAmelCase			     =    ["""past_key_values"""]
						__UpperCAmelCase			     =    {
						    """max_position_embeddings""": """n_positions""",
						    """hidden_size""": """n_embd""",
						    """num_attention_heads""": """n_head""",
						    """num_hidden_layers""": """n_layer""",
						}







						def __init__(							self					:      Tuple			,			snake_case_					:      Dict=2_4_6_5_3_4			,			snake_case_					:      Optional[int]=2_5_6			,			snake_case_					:      Dict=1_2_8_0			,			snake_case_					:      Union[str, Any]=8_1_9_2			,			snake_case_					:      Any=4_8			,			snake_case_					:      List[Any]=1_6			,			snake_case_					:      Optional[Any]=0.1			,			snake_case_					:      Union[str, Any]=0.1			,			snake_case_					:      Optional[Any]=1e-6			,			snake_case_					:      List[Any]=0.0_2			,			snake_case_					:      Dict=True			,			**snake_case_					:      List[Any]			,			):



								'''simple docstring'''



								snake_case__						:       Any       						=  vocab_size
								snake_case__						:       int       						=  n_positions
								snake_case__						:       Optional[int]       						=  n_embd
								snake_case__						:       str       						=  n_layer
								snake_case__						:       Any       						=  n_head
								snake_case__						:       str       						=  dff
								snake_case__						:       Any       						=  resid_pdrop
								snake_case__						:       Tuple       						=  embd_pdrop
								snake_case__						:       List[str]       						=  layer_norm_epsilon
								snake_case__						:       int       						=  initializer_range

								snake_case__						:       Optional[int]       						=  use_cache

								super().__init__(**snake_case_  )



