





"""simple docstring"""




from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tf_available, is_torch_available


UpperCamelCase__     =	{
    'configuration_xlm': ['XLM_PRETRAINED_CONFIG_ARCHIVE_MAP', 'XLMConfig', 'XLMOnnxConfig'],
    'tokenization_xlm': ['XLMTokenizer'],
}

try:
					if not is_torch_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					UpperCamelCase__     =	[
					    'XLM_PRETRAINED_MODEL_ARCHIVE_LIST',
					    'XLMForMultipleChoice',
					    'XLMForQuestionAnswering',
					    'XLMForQuestionAnsweringSimple',
					    'XLMForSequenceClassification',
					    'XLMForTokenClassification',
					    'XLMModel',
					    'XLMPreTrainedModel',
					    'XLMWithLMHeadModel',
					]

try:
					if not is_tf_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					UpperCamelCase__     =	[
					    'TF_XLM_PRETRAINED_MODEL_ARCHIVE_LIST',
					    'TFXLMForMultipleChoice',
					    'TFXLMForQuestionAnsweringSimple',
					    'TFXLMForSequenceClassification',
					    'TFXLMForTokenClassification',
					    'TFXLMMainLayer',
					    'TFXLMModel',
					    'TFXLMPreTrainedModel',
					    'TFXLMWithLMHeadModel',
					]


if TYPE_CHECKING:
					from .configuration_xlm import XLM_PRETRAINED_CONFIG_ARCHIVE_MAP, XLMConfig, XLMOnnxConfig
					from .tokenization_xlm import XLMTokenizer

					try:
										if not is_torch_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_xlm import (
										    XLM_PRETRAINED_MODEL_ARCHIVE_LIST,
										    XLMForMultipleChoice,
										    XLMForQuestionAnswering,
										    XLMForQuestionAnsweringSimple,
										    XLMForSequenceClassification,
										    XLMForTokenClassification,
										    XLMModel,
										    XLMPreTrainedModel,
										    XLMWithLMHeadModel,
										)

					try:
										if not is_tf_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_tf_xlm import (
										    TF_XLM_PRETRAINED_MODEL_ARCHIVE_LIST,
										    TFXLMForMultipleChoice,
										    TFXLMForQuestionAnsweringSimple,
										    TFXLMForSequenceClassification,
										    TFXLMForTokenClassification,
										    TFXLMMainLayer,
										    TFXLMModel,
										    TFXLMPreTrainedModel,
										    TFXLMWithLMHeadModel,
										)

else:
					import sys

					UpperCamelCase__     =	_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)











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






							def 			_lowerCamelCase						(  self					):
														UpperCamelCase__			       =     """ZinengTang/tvlt-base"""
														UpperCamelCase__			       =     tempfile.mkdtemp()






							def 			_lowerCamelCase						(  self					,	**__lowerCAmelCase					):
														return TvltImageProcessor.from_pretrained(self.checkpoint					,	**__lowerCAmelCase					)






							def 			_lowerCamelCase						(  self					,	**__lowerCAmelCase					):
														return TvltFeatureExtractor.from_pretrained(self.checkpoint					,	**__lowerCAmelCase					)






							def 			_lowerCamelCase						(  self					):
														shutil.rmtree(self.tmpdirname					)






							def 			_lowerCamelCase						(  self					):
														UpperCamelCase__			       =     self.get_image_processor()
														UpperCamelCase__			       =     self.get_feature_extractor()

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

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






							def 			_lowerCamelCase						(  self					):
														UpperCamelCase__			       =     self.get_image_processor()
														UpperCamelCase__			       =     self.get_feature_extractor()

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

														UpperCamelCase__			       =     np.ones([12000]					)

														UpperCamelCase__			       =     feature_extractor(__lowerCAmelCase					,	return_tensors="""np"""					)
														UpperCamelCase__			       =     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					):
														UpperCamelCase__			       =     self.get_image_processor()
														UpperCamelCase__			       =     self.get_feature_extractor()

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

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

														UpperCamelCase__			       =     image_processor(__lowerCAmelCase					,	return_tensors="""np"""					)
														UpperCamelCase__			       =     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					):
														UpperCamelCase__			       =     self.get_image_processor()
														UpperCamelCase__			       =     self.get_feature_extractor()

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

														UpperCamelCase__			       =     np.ones([12000]					)
														UpperCamelCase__			       =     np.ones([3, 224, 224]					)

														UpperCamelCase__			       =     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					):
														UpperCamelCase__			       =     self.get_image_processor()
														UpperCamelCase__			       =     self.get_feature_extractor()

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




