

from collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


a__												=						logging.get_logger(__name__)

a__												=						{
    '''microsoft/beit-base-patch16-224-pt22k''': (
        '''https://huggingface.co/microsoft/beit-base-patch16-224-pt22k/resolve/main/config.json'''
    ),
    # See all BEiT models at https://huggingface.co/models?filter=beit
}

class 							UpperCAmelCase_						(     __lowercase  ):
							"""simple docstring"""







							UpperCAmelCase__			:		str             =       "beit"


							def __init__(     self			,				_a=8_1_9_2			,				_a=7_6_8			,				_a=1_2			,				_a=1_2			,				_a=3_0_7_2			,				_a="gelu"			,				_a=0.0			,				_a=0.0			,				_a=0.02			,				_a=1e-1_2			,				_a=2_2_4			,				_a=1_6			,				_a=3			,				_a=False			,				_a=False			,				_a=False			,				_a=False			,				_a=0.1			,				_a=0.1			,				_a=True			,				_a=[3, 5, 7, 1_1]			,				_a=[1, 2, 3, 6]			,				_a=True			,				_a=0.4			,				_a=2_5_6			,				_a=1			,				_a=False			,				_a=2_5_5			,				**_a			,				)       ->       Tuple:
												super().__init__(**_a			)

												_a      :       Dict   =						vocab_size
												_a      :       Tuple   =						hidden_size
												_a      :       List[Any]   =						num_hidden_layers
												_a      :       int   =						num_attention_heads
												_a      :       List[Any]   =						intermediate_size
												_a      :       Any   =						hidden_act
												_a      :       Optional[int]   =						hidden_dropout_prob
												_a      :       Union[str, Any]   =						attention_probs_dropout_prob
												_a      :       Any   =						initializer_range
												_a      :       List[str]   =						layer_norm_eps

												_a      :       Dict   =						image_size
												_a      :       int   =						patch_size
												_a      :       Tuple   =						num_channels
												_a      :       Any   =						use_mask_token
												_a      :       int   =						use_absolute_position_embeddings
												_a      :       Optional[int]   =						use_relative_position_bias
												_a      :       List[Any]   =						use_shared_relative_position_bias
												_a      :       str   =						layer_scale_init_value
												_a      :       List[str]   =						drop_path_rate
												_a      :       List[Any]   =						use_mean_pooling
												# decode head attributes (semantic segmentation)
												_a      :       str   =						out_indices
												_a      :       Tuple   =						pool_scales
												# auxiliary head attributes (semantic segmentation)
												_a      :       Any   =						use_auxiliary_head
												_a      :       List[Any]   =						auxiliary_loss_weight
												_a      :       Optional[int]   =						auxiliary_channels
												_a      :       Tuple   =						auxiliary_num_convs
												_a      :       List[Any]   =						auxiliary_concat_input
												_a      :       Tuple   =						semantic_loss_ignore_index



class 							UpperCAmelCase_						(     __lowercase  ):
							"""simple docstring"""







							UpperCAmelCase__			:		str             =       version.parse("1.11"  )


							@property
							def 							__lowercase							(     self			)       ->       Mapping[str, Mapping[int, str]]:
												return OrderedDict(
												    [
												        ('''pixel_values''', {0: '''batch''', 1: '''num_channels''', 2: '''height''', 3: '''width'''}),
												    ]			)




							@property
							def 							__lowercase							(     self			)       ->       float:
												return 1e-4






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  ):
							"""simple docstring"""







							def 							__lowercase							(     self			)       ->       int:
												_a      :       Dict   =						'''ZinengTang/tvlt-base'''
												_a      :       List[str]   =						tempfile.mkdtemp()


							def 							__lowercase							(     self			,				**_a			)       ->       int:
												return TvltImageProcessor.from_pretrained(self.checkpoint			,				**_a			)


							def 							__lowercase							(     self			,				**_a			)       ->       List[Any]:
												return TvltFeatureExtractor.from_pretrained(self.checkpoint			,				**_a			)


							def 							__lowercase							(     self			)       ->       Optional[int]:
												shutil.rmtree(self.tmpdirname			)


							def 							__lowercase							(     self			)       ->       Dict:
												_a      :       Union[str, Any]   =						self.get_image_processor()
												_a      :       Dict   =						self.get_feature_extractor()

												_a      :       Optional[int]   =						TvltProcessor(image_processor=_a			,				feature_extractor=_a			)
												processor.save_pretrained(self.tmpdirname			)
												_a      :       Any   =						TvltProcessor.from_pretrained(self.tmpdirname			)

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


							def 							__lowercase							(     self			)       ->       Any:
												_a      :       Optional[Any]   =						self.get_image_processor()
												_a      :       Dict   =						self.get_feature_extractor()

												_a      :       Dict   =						TvltProcessor(image_processor=_a			,				feature_extractor=_a			)

												_a      :       Union[str, Any]   =						np.ones([1_2_0_0_0]			)

												_a      :       Dict   =						feature_extractor(_a			,				return_tensors='''np'''			)
												_a      :       Tuple   =						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 							__lowercase							(     self			)       ->       int:
												_a      :       Optional[Any]   =						self.get_image_processor()
												_a      :       Union[str, Any]   =						self.get_feature_extractor()

												_a      :       Optional[Any]   =						TvltProcessor(image_processor=_a			,				feature_extractor=_a			)

												_a      :       List[Any]   =						np.ones([3, 2_2_4, 2_2_4]			)

												_a      :       int   =						image_processor(_a			,				return_tensors='''np'''			)
												_a      :       Optional[int]   =						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 							__lowercase							(     self			)       ->       Union[str, Any]:
												_a      :       int   =						self.get_image_processor()
												_a      :       Union[str, Any]   =						self.get_feature_extractor()

												_a      :       Any   =						TvltProcessor(image_processor=_a			,				feature_extractor=_a			)

												_a      :       List[str]   =						np.ones([1_2_0_0_0]			)
												_a      :       Optional[int]   =						np.ones([3, 2_2_4, 2_2_4]			)

												_a      :       int   =						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 							__lowercase							(     self			)       ->       Union[str, Any]:
												_a      :       str   =						self.get_image_processor()
												_a      :       Union[str, Any]   =						self.get_feature_extractor()

												_a      :       Dict   =						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'''			,				)



