


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





      '''simple docstring'''






      def       UpperCamelCase__		(self    :    List[str] ):

             '''simple docstring'''







             lowercase__      			= '''ZinengTang/tvlt-base'''
             lowercase__      			= tempfile.mkdtemp()



      def       UpperCamelCase__		(self    :    int   ,						**UpperCamelCase    :    List[str] ):

             '''simple docstring'''







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



      def       UpperCamelCase__		(self    :    int   ,						**UpperCamelCase    :    str ):

             '''simple docstring'''







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



      def       UpperCamelCase__		(self    :    Tuple ):

             '''simple docstring'''







             shutil.rmtree(self.tmpdirname )



      def       UpperCamelCase__		(self    :    Optional[Any] ):

             '''simple docstring'''







             lowercase__      			= self.get_image_processor()
             lowercase__      			= self.get_feature_extractor()

             lowercase__      			= TvltProcessor(image_processor=UpperCamelCase   ,						feature_extractor=UpperCamelCase )
             processor.save_pretrained(self.tmpdirname )
             lowercase__      			= TvltProcessor.from_pretrained(self.tmpdirname )

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



      def       UpperCamelCase__		(self    :    Optional[int] ):

             '''simple docstring'''







             lowercase__      			= self.get_image_processor()
             lowercase__      			= self.get_feature_extractor()

             lowercase__      			= TvltProcessor(image_processor=UpperCamelCase   ,						feature_extractor=UpperCamelCase )

             lowercase__      			= np.ones([12000] )

             lowercase__      			= feature_extractor(UpperCamelCase   ,						return_tensors='''np''' )
             lowercase__      			= processor(audio=UpperCamelCase   ,						return_tensors='''np''' )

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



      def       UpperCamelCase__		(self    :    Optional[int] ):

             '''simple docstring'''







             lowercase__      			= self.get_image_processor()
             lowercase__      			= self.get_feature_extractor()

             lowercase__      			= TvltProcessor(image_processor=UpperCamelCase   ,						feature_extractor=UpperCamelCase )

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

             lowercase__      			= image_processor(UpperCamelCase   ,						return_tensors='''np''' )
             lowercase__      			= processor(images=UpperCamelCase   ,						return_tensors='''np''' )

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



      def       UpperCamelCase__		(self    :    List[str] ):

             '''simple docstring'''







             lowercase__      			= self.get_image_processor()
             lowercase__      			= self.get_feature_extractor()

             lowercase__      			= TvltProcessor(image_processor=UpperCamelCase   ,						feature_extractor=UpperCamelCase )

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

             lowercase__      			= processor(audio=UpperCamelCase   ,						images=UpperCamelCase )

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






      def       UpperCamelCase__		(self    :    Any ):

             '''simple docstring'''







             lowercase__      			= self.get_image_processor()
             lowercase__      			= self.get_feature_extractor()

             lowercase__      			= TvltProcessor(image_processor=UpperCamelCase   ,						feature_extractor=UpperCamelCase )

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

import warnings

from ...configuration_utils import PretrainedConfig
from ...utils import logging


lowerCamelCase							:   str  						=	logging.get_logger(__name__)

lowerCamelCase							:   int  						=	{
    'RUCAIBox/mvp': 'https://huggingface.co/RUCAIBox/mvp/resolve/main/config.json',
}
class   __lowerCAmelCase						(lowercase_     ):





      '''simple docstring'''






      lowerCAmelCase__					:     Union[str, Any]  					=							"""mvp"""
      lowerCAmelCase__					:     Optional[Any]  					=							["""past_key_values"""]
      lowerCAmelCase__					:     List[str]  					=							{"""num_attention_heads""": """encoder_attention_heads""", """hidden_size""": """d_model"""}



      def __init__(self    :    Any   ,						UpperCamelCase    :    Optional[int]=50267   ,						UpperCamelCase    :    Tuple=1024   ,						UpperCamelCase    :    int=12   ,						UpperCamelCase    :    Tuple=4096   ,						UpperCamelCase    :    Dict=16   ,						UpperCamelCase    :    int=12   ,						UpperCamelCase    :    Optional[int]=4096   ,						UpperCamelCase    :    Optional[int]=16   ,						UpperCamelCase    :    Tuple=0.0   ,						UpperCamelCase    :    Tuple=0.0   ,						UpperCamelCase    :    List[Any]="gelu"   ,						UpperCamelCase    :    Union[str, Any]=1024   ,						UpperCamelCase    :    Optional[Any]=0.1   ,						UpperCamelCase    :    str=0.0   ,						UpperCamelCase    :    str=0.0   ,						UpperCamelCase    :    Optional[Any]=0.02   ,						UpperCamelCase    :    List[str]=0.0   ,						UpperCamelCase    :    List[str]=False   ,						UpperCamelCase    :    Optional[int]=True   ,						UpperCamelCase    :    Any=1   ,						UpperCamelCase    :    int=0   ,						UpperCamelCase    :    int=2   ,						UpperCamelCase    :    Any=True   ,						UpperCamelCase    :    Optional[Any]=2   ,						UpperCamelCase    :    Optional[Any]=2   ,						UpperCamelCase    :    Tuple=False   ,						UpperCamelCase    :    int=100   ,						UpperCamelCase    :    Optional[Any]=800   ,						**UpperCamelCase    :    str   ,						):

             '''simple docstring'''







             lowercase__      			= vocab_size
             lowercase__      			= max_position_embeddings
             lowercase__      			= d_model
             lowercase__      			= encoder_ffn_dim
             lowercase__      			= encoder_layers
             lowercase__      			= encoder_attention_heads
             lowercase__      			= decoder_ffn_dim
             lowercase__      			= decoder_layers
             lowercase__      			= decoder_attention_heads
             lowercase__      			= dropout
             lowercase__      			= attention_dropout
             lowercase__      			= activation_dropout
             lowercase__      			= activation_function
             lowercase__      			= init_std
             lowercase__      			= encoder_layerdrop
             lowercase__      			= decoder_layerdrop
             lowercase__      			= classifier_dropout
             lowercase__      			= use_cache
             lowercase__      			= encoder_layers
             lowercase__      			= scale_embedding  # scale factor will be sqrt(d_model) if True
             lowercase__      			= use_prompt
             lowercase__      			= prompt_length
             lowercase__      			= prompt_mid_dim

             super().__init__(
                 pad_token_id=UpperCamelCase   ,						bos_token_id=UpperCamelCase   ,						eos_token_id=UpperCamelCase   ,						is_encoder_decoder=UpperCamelCase   ,						decoder_start_token_id=UpperCamelCase   ,						forced_eos_token_id=UpperCamelCase   ,						**UpperCamelCase   ,						)

             if self.forced_bos_token_id is None and kwargs.get('''force_bos_token_to_be_generated'''   ,						UpperCamelCase ):
                    lowercase__      			= self.bos_token_id
                    warnings.warn(
                        f"Please make sure the config includes `forced_bos_token_id={self.bos_token_id}` in future versions. "
                        '''The config can simply be saved and uploaded again to be fixed.''' )




