

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


SCREAMING_SNAKE_CASE_            = logging.get_logger(__name__)

SCREAMING_SNAKE_CASE_            = {
    'google/realm-cc-news-pretrained-embedder': (
        'https://huggingface.co/google/realm-cc-news-pretrained-embedder/resolve/main/config.json'
    ),
    'google/realm-cc-news-pretrained-encoder': (
        'https://huggingface.co/google/realm-cc-news-pretrained-encoder/resolve/main/config.json'
    ),
    'google/realm-cc-news-pretrained-scorer': (
        'https://huggingface.co/google/realm-cc-news-pretrained-scorer/resolve/main/config.json'
    ),
    'google/realm-cc-news-pretrained-openqa': (
        'https://huggingface.co/google/realm-cc-news-pretrained-openqa/aresolve/main/config.json'
    ),
    'google/realm-orqa-nq-openqa': 'https://huggingface.co/google/realm-orqa-nq-openqa/resolve/main/config.json',
    'google/realm-orqa-nq-reader': 'https://huggingface.co/google/realm-orqa-nq-reader/resolve/main/config.json',
    'google/realm-orqa-wq-openqa': 'https://huggingface.co/google/realm-orqa-wq-openqa/resolve/main/config.json',
    'google/realm-orqa-wq-reader': 'https://huggingface.co/google/realm-orqa-wq-reader/resolve/main/config.json',
    # See all REALM models at https://huggingface.co/models?filter=realm
}

class 			a					(		UpperCAmelCase			):
						_lowercase        =     "realm"


						def __init__(    self  ,   A_=30522  ,   A_=768  ,   A_=128  ,   A_=12  ,   A_=12  ,   A_=8  ,   A_=3072  ,   A_="gelu_new"  ,   A_=0.1  ,   A_=0.1  ,   A_=512  ,   A_=2  ,   A_=0.02  ,   A_=1e-12  ,   A_=256  ,   A_=10  ,   A_=1e-3  ,   A_=5  ,   A_=320  ,   A_=13353718  ,   A_=5000  ,   A_=1  ,   A_=0  ,   A_=2  ,   **A_  ,   ):







										'''simple docstring'''


										super().__init__(pad_token_id=A_  ,   bos_token_id=A_  ,   eos_token_id=A_  ,   **A_		)

										# Common config
										_UpperCAmelCase    :						str							=      vocab_size
										_UpperCAmelCase    :						Any							=      max_position_embeddings
										_UpperCAmelCase    :						Union[str, Any]							=      hidden_size
										_UpperCAmelCase    :						Tuple							=      retriever_proj_size
										_UpperCAmelCase    :						Tuple							=      num_hidden_layers
										_UpperCAmelCase    :						str							=      num_attention_heads
										_UpperCAmelCase    :						List[Any]							=      num_candidates
										_UpperCAmelCase    :						Dict							=      intermediate_size
										_UpperCAmelCase    :						Optional[Any]							=      hidden_act
										_UpperCAmelCase    :						Optional[int]							=      hidden_dropout_prob
										_UpperCAmelCase    :						Any							=      attention_probs_dropout_prob
										_UpperCAmelCase    :						List[Any]							=      initializer_range
										_UpperCAmelCase    :						int							=      type_vocab_size
										_UpperCAmelCase    :						List[Any]							=      layer_norm_eps

										# Reader config
										_UpperCAmelCase    :						Optional[Any]							=      span_hidden_size
										_UpperCAmelCase    :						Dict							=      max_span_width
										_UpperCAmelCase    :						Union[str, Any]							=      reader_layer_norm_eps
										_UpperCAmelCase    :						List[Any]							=      reader_beam_size
										_UpperCAmelCase    :						Any							=      reader_seq_len

										# Retrieval config
										_UpperCAmelCase    :						Tuple							=      num_block_records
										_UpperCAmelCase    :						List[str]							=      searcher_beam_size





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


						def     _UpperCAmelCase			(    self		):







										'''simple docstring'''


										_UpperCAmelCase    :						int							=      "ZinengTang/tvlt-base"
										_UpperCAmelCase    :						int							=      tempfile.mkdtemp()


						def     _UpperCAmelCase			(    self  ,   **A_		):







										'''simple docstring'''


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


						def     _UpperCAmelCase			(    self  ,   **A_		):







										'''simple docstring'''


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


						def     _UpperCAmelCase			(    self		):







										'''simple docstring'''


										shutil.rmtree(self.tmpdirname		)


						def     _UpperCAmelCase			(    self		):







										'''simple docstring'''


										_UpperCAmelCase    :						Dict							=      self.get_image_processor()
										_UpperCAmelCase    :						Optional[int]							=      self.get_feature_extractor()

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

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


						def     _UpperCAmelCase			(    self		):







										'''simple docstring'''


										_UpperCAmelCase    :						List[Any]							=      self.get_image_processor()
										_UpperCAmelCase    :						int							=      self.get_feature_extractor()

										_UpperCAmelCase    :						Tuple							=      TvltProcessor(image_processor=A_  ,   feature_extractor=A_		)

										_UpperCAmelCase    :						List[str]							=      np.ones([12000]		)

										_UpperCAmelCase    :						int							=      feature_extractor(A_  ,   return_tensors="np"		)
										_UpperCAmelCase    :						int							=      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     _UpperCAmelCase			(    self		):







										'''simple docstring'''


										_UpperCAmelCase    :						List[str]							=      self.get_image_processor()
										_UpperCAmelCase    :						int							=      self.get_feature_extractor()

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

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

										_UpperCAmelCase    :						Tuple							=      image_processor(A_  ,   return_tensors="np"		)
										_UpperCAmelCase    :						List[str]							=      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     _UpperCAmelCase			(    self		):







										'''simple docstring'''


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

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

										_UpperCAmelCase    :						str							=      np.ones([12000]		)
										_UpperCAmelCase    :						Optional[Any]							=      np.ones([3, 224, 224]		)

										_UpperCAmelCase    :						List[Any]							=      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     _UpperCAmelCase			(    self		):







										'''simple docstring'''


										_UpperCAmelCase    :						Optional[Any]							=      self.get_image_processor()
										_UpperCAmelCase    :						int							=      self.get_feature_extractor()

										_UpperCAmelCase    :						str							=      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"  ,   )


