


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


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

lowerCamelCase__							:						Optional[int]							     =   {
    """facebook/data2vec-vision-base-ft""": (
        """https://huggingface.co/facebook/data2vec-vision-base-ft/resolve/main/config.json"""
    ),
}
class 		__magic_name__						(snake_case_				):





     '''simple docstring'''



     __lowercase				:							Optional[int]	   =       'data2vec-vision'

     def __init__(					self:int     ,		_a:Tuple=7_68     ,		_a:int=12     ,		_a:Any=12     ,		_a:Optional[int]=30_72     ,		_a:Optional[int]="gelu"     ,		_a:Any=0.0     ,		_a:Any=0.0     ,		_a:List[str]=0.02     ,		_a:Dict=1e-12     ,		_a:Tuple=2_24     ,		_a:Any=16     ,		_a:str=3     ,		_a:str=False     ,		_a:Union[str, Any]=False     ,		_a:Optional[int]=False     ,		_a:Any=False     ,		_a:Dict=0.1     ,		_a:Dict=0.1     ,		_a:str=True     ,		_a:str=[3, 5, 7, 11]     ,		_a:List[str]=[1, 2, 3, 6]     ,		_a:List[str]=True     ,		_a:Any=0.4     ,		_a:str=2_56     ,		_a:Union[str, Any]=1     ,		_a:int=False     ,		_a:Optional[int]=2_55     ,		**_a:Dict     ,		):
       super().__init__(**_a   )

       snake_case__						= hidden_size
       snake_case__						= num_hidden_layers
       snake_case__						= num_attention_heads
       snake_case__						= intermediate_size
       snake_case__						= hidden_act
       snake_case__						= hidden_dropout_prob
       snake_case__						= attention_probs_dropout_prob
       snake_case__						= initializer_range
       snake_case__						= layer_norm_eps

       snake_case__						= image_size
       snake_case__						= patch_size
       snake_case__						= num_channels
       snake_case__						= use_mask_token
       snake_case__						= use_absolute_position_embeddings
       snake_case__						= use_relative_position_bias
       snake_case__						= use_shared_relative_position_bias
       snake_case__						= layer_scale_init_value
       snake_case__						= drop_path_rate
       snake_case__						= use_mean_pooling
       # decode head attributes (semantic segmentation)
       snake_case__						= out_indices
       snake_case__						= pool_scales
       # auxiliary head attributes (semantic segmentation)
       snake_case__						= use_auxiliary_head
       snake_case__						= auxiliary_loss_weight
       snake_case__						= auxiliary_channels
       snake_case__						= auxiliary_num_convs
       snake_case__						= auxiliary_concat_input
       snake_case__						= semantic_loss_ignore_index




class 		__magic_name__						(snake_case_				):





     '''simple docstring'''



     __lowercase				:							Any	   =       version.parse('1.11'				)

     @property
     def 	SCREAMING_SNAKE_CASE__						(					self:List[str]   ):
       return OrderedDict(
           [
               ('''pixel_values''', {0: '''batch''', 1: '''num_channels''', 2: '''height''', 3: '''width'''}),
           ]   )







     @property
     def 	SCREAMING_SNAKE_CASE__						(					self:Tuple   ):
       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 		__magic_name__						(unittest.TestCase				):





     '''simple docstring'''



     def 	SCREAMING_SNAKE_CASE__						(					self:str   ):
       snake_case__						= '''ZinengTang/tvlt-base'''
       snake_case__						= tempfile.mkdtemp()

     def 	SCREAMING_SNAKE_CASE__						(					self:Dict     ,		**_a:List[Any]   ):
       return TvltImageProcessor.from_pretrained(self.checkpoint     ,		**_a   )

     def 	SCREAMING_SNAKE_CASE__						(					self:Optional[Any]     ,		**_a:Tuple   ):
       return TvltFeatureExtractor.from_pretrained(self.checkpoint     ,		**_a   )

     def 	SCREAMING_SNAKE_CASE__						(					self:Dict   ):
       shutil.rmtree(self.tmpdirname   )

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

       snake_case__						= TvltProcessor(image_processor=_a     ,		feature_extractor=_a   )
       processor.save_pretrained(self.tmpdirname   )
       snake_case__						= TvltProcessor.from_pretrained(self.tmpdirname   )

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

     def 	SCREAMING_SNAKE_CASE__						(					self:Dict   ):
       snake_case__						= self.get_image_processor()
       snake_case__						= self.get_feature_extractor()

       snake_case__						= TvltProcessor(image_processor=_a     ,		feature_extractor=_a   )

       snake_case__						= np.ones([1_20_00]   )

       snake_case__						= feature_extractor(_a     ,		return_tensors='''np'''   )
       snake_case__						= 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 	SCREAMING_SNAKE_CASE__						(					self:List[Any]   ):
       snake_case__						= self.get_image_processor()
       snake_case__						= self.get_feature_extractor()

       snake_case__						= TvltProcessor(image_processor=_a     ,		feature_extractor=_a   )

       snake_case__						= np.ones([3, 2_24, 2_24]   )

       snake_case__						= image_processor(_a     ,		return_tensors='''np'''   )
       snake_case__						= 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 	SCREAMING_SNAKE_CASE__						(					self:Any   ):
       snake_case__						= self.get_image_processor()
       snake_case__						= self.get_feature_extractor()

       snake_case__						= TvltProcessor(image_processor=_a     ,		feature_extractor=_a   )

       snake_case__						= np.ones([1_20_00]   )
       snake_case__						= np.ones([3, 2_24, 2_24]   )

       snake_case__						= 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 	SCREAMING_SNAKE_CASE__						(					self:List[Any]   ):
       snake_case__						= self.get_image_processor()
       snake_case__						= self.get_feature_extractor()

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

