


'''simple docstring'''



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


A__		:					Optional[Any]												=  logging.get_logger(__name__)

A__		:					Union[str, Any]												=  {
    """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    UpperCAmelCase_  (_UpperCAmelCase  ):





    """simple docstring"""






    lowerCamelCase  :					Optional[int]							     =			'realm'







    def __init__(							self			,     SCREAMING_SNAKE_CASE_=3_05_22			,     SCREAMING_SNAKE_CASE_=7_68			,     SCREAMING_SNAKE_CASE_=1_28			,     SCREAMING_SNAKE_CASE_=12			,     SCREAMING_SNAKE_CASE_=12			,     SCREAMING_SNAKE_CASE_=8			,     SCREAMING_SNAKE_CASE_=30_72			,     SCREAMING_SNAKE_CASE_="gelu_new"			,     SCREAMING_SNAKE_CASE_=0.1			,     SCREAMING_SNAKE_CASE_=0.1			,     SCREAMING_SNAKE_CASE_=5_12			,     SCREAMING_SNAKE_CASE_=2			,     SCREAMING_SNAKE_CASE_=0.0_2			,     SCREAMING_SNAKE_CASE_=1E-12			,     SCREAMING_SNAKE_CASE_=2_56			,     SCREAMING_SNAKE_CASE_=10			,     SCREAMING_SNAKE_CASE_=1E-3			,     SCREAMING_SNAKE_CASE_=5			,     SCREAMING_SNAKE_CASE_=3_20			,     SCREAMING_SNAKE_CASE_=13_35_37_18			,     SCREAMING_SNAKE_CASE_=50_00			,     SCREAMING_SNAKE_CASE_=1			,     SCREAMING_SNAKE_CASE_=0			,     SCREAMING_SNAKE_CASE_=2			,     **SCREAMING_SNAKE_CASE_			,     )				->     str:
         super().__init__(pad_token_id=SCREAMING_SNAKE_CASE_			,     bos_token_id=SCREAMING_SNAKE_CASE_			,     eos_token_id=SCREAMING_SNAKE_CASE_			,     **SCREAMING_SNAKE_CASE_	)

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

         # Reader config
         __lowerCamelCase   :	int								=		span_hidden_size
         __lowerCamelCase   :	str								=		max_span_width
         __lowerCamelCase   :	List[str]								=		reader_layer_norm_eps
         __lowerCamelCase   :	str								=		reader_beam_size
         __lowerCamelCase   :	Tuple								=		reader_seq_len

         # Retrieval config
         __lowerCamelCase   :	Tuple								=		num_block_records
         __lowerCamelCase   :	Any								=		searcher_beam_size










'''simple docstring'''



import unittest

from transformers import is_torch_available, is_vision_available
from transformers.testing_utils import require_torch, require_vision, slow, torch_device


if is_torch_available():
      import torch

      from transformers import AutoModelForImageClassification

if is_vision_available():
      from transformers import AutoImageProcessor





@require_torch
@require_vision
class    UpperCAmelCase_  (unittest.TestCase  ):





    """simple docstring"""






    @slow
    def       lowercase_				(							self	)				->     List[str]:
         __lowerCamelCase   :	Any								=		AutoImageProcessor.from_pretrained('microsoft/dit-base-finetuned-rvlcdip'	)
         __lowerCamelCase   :	Tuple								=		AutoModelForImageClassification.from_pretrained('microsoft/dit-base-finetuned-rvlcdip'	)
         model.to(SCREAMING_SNAKE_CASE_	)

         from datasets import load_dataset

         __lowerCamelCase   :	str								=		load_dataset('nielsr/rvlcdip-demo'	)

         __lowerCamelCase   :	List[Any]								=		dataset['train'][0]['image'].convert('RGB'	)

         __lowerCamelCase   :	str								=		image_processor(SCREAMING_SNAKE_CASE_			,     return_tensors='pt'	).to(SCREAMING_SNAKE_CASE_	)

         # forward pass
         with torch.no_grad():
              __lowerCamelCase   :	str								=		model(**SCREAMING_SNAKE_CASE_	)
              __lowerCamelCase   :	int								=		outputs.logits

         __lowerCamelCase   :	List[Any]								=		torch.Size((1, 16)	)
         self.assertEqual(logits.shape			,     SCREAMING_SNAKE_CASE_	)

         __lowerCamelCase   :	Optional[Any]								=		torch.tensor(
             [-0.4_1_5_8, -0.4_0_9_2, -0.4_3_4_7]			,     device=SCREAMING_SNAKE_CASE_			,     dtype=torch.float			,     )
         self.assertTrue(torch.allclose(logits[0, :3]			,     SCREAMING_SNAKE_CASE_			,     atol=1E-4	)	)






