


'''simple docstring'''






from collections import OrderedDict
from typing import Mapping

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


lowercase							=logging.get_logger(__name__)

lowercase							={
    'xlm-mlm-en-2048': 'https://huggingface.co/xlm-mlm-en-2048/resolve/main/config.json',
    'xlm-mlm-ende-1024': 'https://huggingface.co/xlm-mlm-ende-1024/resolve/main/config.json',
    'xlm-mlm-enfr-1024': 'https://huggingface.co/xlm-mlm-enfr-1024/resolve/main/config.json',
    'xlm-mlm-enro-1024': 'https://huggingface.co/xlm-mlm-enro-1024/resolve/main/config.json',
    'xlm-mlm-tlm-xnli15-1024': 'https://huggingface.co/xlm-mlm-tlm-xnli15-1024/resolve/main/config.json',
    'xlm-mlm-xnli15-1024': 'https://huggingface.co/xlm-mlm-xnli15-1024/resolve/main/config.json',
    'xlm-clm-enfr-1024': 'https://huggingface.co/xlm-clm-enfr-1024/resolve/main/config.json',
    'xlm-clm-ende-1024': 'https://huggingface.co/xlm-clm-ende-1024/resolve/main/config.json',
    'xlm-mlm-17-1280': 'https://huggingface.co/xlm-mlm-17-1280/resolve/main/config.json',
    'xlm-mlm-100-1280': 'https://huggingface.co/xlm-mlm-100-1280/resolve/main/config.json',
}






class  __magic_name__							(		lowerCAmelCase    ):
       UpperCAmelCase										="xlm"
       UpperCAmelCase										={
           "hidden_size": "emb_dim",
           "num_attention_heads": "n_heads",
           "num_hidden_layers": "n_layers",
           "n_words": "vocab_size",  # For backward compatibility
       }






       def __init__(      self  ,							snake_case=3_0_1_4_5  ,							snake_case=2_0_4_8  ,							snake_case=1_2  ,							snake_case=1_6  ,							snake_case=0.1  ,							snake_case=0.1  ,							snake_case=True  ,							snake_case=False  ,							snake_case=False  ,							snake_case=False  ,							snake_case=1  ,							snake_case=True  ,							snake_case=5_1_2  ,							snake_case=2_0_4_8**-0.5  ,							snake_case=1E-1_2  ,							snake_case=0.02  ,							snake_case=0  ,							snake_case=1  ,							snake_case=2  ,							snake_case=3  ,							snake_case=5  ,							snake_case=True  ,							snake_case="first"  ,							snake_case=True  ,							snake_case=None  ,							snake_case=True  ,							snake_case=0.1  ,							snake_case=5  ,							snake_case=5  ,							snake_case=0  ,							snake_case=0  ,							snake_case=2  ,							snake_case=0  ,							**snake_case  ,							)						->  int:




          '''simple docstring'''
          _UpperCAmelCase       :       int							   =vocab_size
          _UpperCAmelCase       :       Optional[Any]							   =emb_dim
          _UpperCAmelCase       :       Union[str, Any]							   =n_layers
          _UpperCAmelCase       :       str							   =n_heads
          _UpperCAmelCase       :       List[str]							   =dropout
          _UpperCAmelCase       :       Optional[Any]							   =attention_dropout
          _UpperCAmelCase       :       Tuple							   =gelu_activation
          _UpperCAmelCase       :       Dict							   =sinusoidal_embeddings
          _UpperCAmelCase       :       Optional[int]							   =causal
          _UpperCAmelCase       :       Optional[Any]							   =asm
          _UpperCAmelCase       :       Any							   =n_langs
          _UpperCAmelCase       :       Dict							   =use_lang_emb
          _UpperCAmelCase       :       Union[str, Any]							   =layer_norm_eps
          _UpperCAmelCase       :       List[str]							   =bos_index
          _UpperCAmelCase       :       int							   =eos_index
          _UpperCAmelCase       :       Optional[int]							   =pad_index
          _UpperCAmelCase       :       List[Any]							   =unk_index
          _UpperCAmelCase       :       Optional[int]							   =mask_index
          _UpperCAmelCase       :       str							   =is_encoder
          _UpperCAmelCase       :       Dict							   =max_position_embeddings
          _UpperCAmelCase       :       Optional[Any]							   =embed_init_std
          _UpperCAmelCase       :       List[str]							   =init_std
          _UpperCAmelCase       :       Tuple							   =summary_type
          _UpperCAmelCase       :       Dict							   =summary_use_proj
          _UpperCAmelCase       :       Dict							   =summary_activation
          _UpperCAmelCase       :       Optional[Any]							   =summary_proj_to_labels
          _UpperCAmelCase       :       Dict							   =summary_first_dropout
          _UpperCAmelCase       :       Optional[int]							   =start_n_top
          _UpperCAmelCase       :       Dict							   =end_n_top
          _UpperCAmelCase       :       Tuple							   =mask_token_id
          _UpperCAmelCase       :       Optional[int]							   =lang_id

          if "n_words" in kwargs:
             _UpperCAmelCase       :       Tuple							   =kwargs['n_words']

          super().__init__(pad_token_id=snake_case  ,							bos_token_id=snake_case  ,							**snake_case)






class  __magic_name__							(		lowerCAmelCase    ):






       @property
       def       lowerCAmelCase		(      self)						->  Mapping[str, Mapping[int, str]]:




          '''simple docstring'''
          if self.task == "multiple-choice":
             _UpperCAmelCase       :       str							   ={0: 'batch', 1: 'choice', 2: 'sequence'}
          else:
             _UpperCAmelCase       :       List[str]							   ={0: 'batch', 1: 'sequence'}
          return OrderedDict(
              [
                  ('input_ids', dynamic_axis),
                  ('attention_mask', dynamic_axis),
                  ('token_type_ids', dynamic_axis),
              ])





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






       def       lowerCAmelCase		(      self)						->  str:




          '''simple docstring'''
          _UpperCAmelCase       :       Dict							   ='ZinengTang/tvlt-base'
          _UpperCAmelCase       :       Dict							   =tempfile.mkdtemp()






       def       lowerCAmelCase		(      self  ,							**snake_case)						->  Union[str, Any]:




          '''simple docstring'''
          return TvltImageProcessor.from_pretrained(self.checkpoint  ,							**snake_case)






       def       lowerCAmelCase		(      self  ,							**snake_case)						->  Dict:




          '''simple docstring'''
          return TvltFeatureExtractor.from_pretrained(self.checkpoint  ,							**snake_case)






       def       lowerCAmelCase		(      self)						->  Any:




          '''simple docstring'''
          shutil.rmtree(self.tmpdirname)






       def       lowerCAmelCase		(      self)						->  Optional[int]:




          '''simple docstring'''
          _UpperCAmelCase       :       Any							   =self.get_image_processor()
          _UpperCAmelCase       :       Optional[Any]							   =self.get_feature_extractor()

          _UpperCAmelCase       :       str							   =TvltProcessor(image_processor=snake_case  ,							feature_extractor=snake_case)
          processor.save_pretrained(self.tmpdirname)
          _UpperCAmelCase       :       str							   =TvltProcessor.from_pretrained(self.tmpdirname)

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






       def       lowerCAmelCase		(      self)						->  Union[str, Any]:




          '''simple docstring'''
          _UpperCAmelCase       :       str							   =self.get_image_processor()
          _UpperCAmelCase       :       List[Any]							   =self.get_feature_extractor()

          _UpperCAmelCase       :       str							   =TvltProcessor(image_processor=snake_case  ,							feature_extractor=snake_case)

          _UpperCAmelCase       :       Optional[int]							   =np.ones([1_2_0_0_0])

          _UpperCAmelCase       :       str							   =feature_extractor(snake_case  ,							return_tensors='np')
          _UpperCAmelCase       :       Dict							   =processor(audio=snake_case  ,							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:




          '''simple docstring'''
          _UpperCAmelCase       :       Dict							   =self.get_image_processor()
          _UpperCAmelCase       :       int							   =self.get_feature_extractor()

          _UpperCAmelCase       :       int							   =TvltProcessor(image_processor=snake_case  ,							feature_extractor=snake_case)

          _UpperCAmelCase       :       Union[str, Any]							   =np.ones([3, 2_2_4, 2_2_4])

          _UpperCAmelCase       :       Optional[Any]							   =image_processor(snake_case  ,							return_tensors='np')
          _UpperCAmelCase       :       List[Any]							   =processor(images=snake_case  ,							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[str]:




          '''simple docstring'''
          _UpperCAmelCase       :       List[str]							   =self.get_image_processor()
          _UpperCAmelCase       :       Dict							   =self.get_feature_extractor()

          _UpperCAmelCase       :       Optional[int]							   =TvltProcessor(image_processor=snake_case  ,							feature_extractor=snake_case)

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

          _UpperCAmelCase       :       Optional[int]							   =processor(audio=snake_case  ,							images=snake_case)

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






       def       lowerCAmelCase		(      self)						->  Optional[int]:




          '''simple docstring'''
          _UpperCAmelCase       :       Optional[int]							   =self.get_image_processor()
          _UpperCAmelCase       :       Tuple							   =self.get_feature_extractor()

          _UpperCAmelCase       :       Dict							   =TvltProcessor(image_processor=snake_case  ,							feature_extractor=snake_case)

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

