





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




					def 	lowerCAmelCase			(		self  )		->							str:
										_snake_case									=				'ZinengTang/tvlt-base'
										_snake_case									=				tempfile.mkdtemp()




					def 	lowerCAmelCase			(		self				,						**lowerCAmelCase_  )		->							int:
										return TvltImageProcessor.from_pretrained(self.checkpoint				,						**__lowerCAmelCase  )




					def 	lowerCAmelCase			(		self				,						**lowerCAmelCase_  )		->							List[Any]:
										return TvltFeatureExtractor.from_pretrained(self.checkpoint				,						**__lowerCAmelCase  )




					def 	lowerCAmelCase			(		self  )		->							List[Any]:
										shutil.rmtree(self.tmpdirname  )




					def 	lowerCAmelCase			(		self  )		->							Optional[int]:
										_snake_case									=				self.get_image_processor()
										_snake_case									=				self.get_feature_extractor()

										_snake_case									=				TvltProcessor(image_processor=__lowerCAmelCase				,						feature_extractor=__lowerCAmelCase  )
										processor.save_pretrained(self.tmpdirname  )
										_snake_case									=				TvltProcessor.from_pretrained(self.tmpdirname  )

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




					def 	lowerCAmelCase			(		self  )		->							Optional[int]:
										_snake_case									=				self.get_image_processor()
										_snake_case									=				self.get_feature_extractor()

										_snake_case									=				TvltProcessor(image_processor=__lowerCAmelCase				,						feature_extractor=__lowerCAmelCase  )

										_snake_case									=				np.ones([1_2000]  )

										_snake_case									=				feature_extractor(__lowerCAmelCase				,						return_tensors='np'  )
										_snake_case									=				processor(audio=__lowerCAmelCase				,						return_tensors='np'  )

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




					def 	lowerCAmelCase			(		self  )		->							int:
										_snake_case									=				self.get_image_processor()
										_snake_case									=				self.get_feature_extractor()

										_snake_case									=				TvltProcessor(image_processor=__lowerCAmelCase				,						feature_extractor=__lowerCAmelCase  )

										_snake_case									=				np.ones([3, 224, 224]  )

										_snake_case									=				image_processor(__lowerCAmelCase				,						return_tensors='np'  )
										_snake_case									=				processor(images=__lowerCAmelCase				,						return_tensors='np'  )

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




					def 	lowerCAmelCase			(		self  )		->							List[Any]:
										_snake_case									=				self.get_image_processor()
										_snake_case									=				self.get_feature_extractor()

										_snake_case									=				TvltProcessor(image_processor=__lowerCAmelCase				,						feature_extractor=__lowerCAmelCase  )

										_snake_case									=				np.ones([1_2000]  )
										_snake_case									=				np.ones([3, 224, 224]  )

										_snake_case									=				processor(audio=__lowerCAmelCase				,						images=__lowerCAmelCase  )

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






					def 	lowerCAmelCase			(		self  )		->							Any:
										_snake_case									=				self.get_image_processor()
										_snake_case									=				self.get_feature_extractor()

										_snake_case									=				TvltProcessor(image_processor=__lowerCAmelCase				,						feature_extractor=__lowerCAmelCase  )

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










import unittest

from accelerate import debug_launcher
from accelerate.test_utils import require_cpu, test_ops, test_script
@require_cpu
class 			UpperCamelCase_		(  unittest.TestCase					):




					def 	lowerCAmelCase			(		self  )		->							List[Any]:
										debug_launcher(test_script.main  )






					def 	lowerCAmelCase			(		self  )		->							Optional[Any]:
										debug_launcher(test_ops.main  )



