




import inspect
import unittest

from transformers import ViTHybridConfig
from transformers.testing_utils import require_accelerate, require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
     import torch
     from torch import nn

     from transformers import ViTHybridForImageClassification, ViTHybridImageProcessor, ViTHybridModel
     from transformers.models.vit_hybrid.modeling_vit_hybrid import VIT_HYBRID_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
     from PIL import Image





class 			__lowerCamelCase	:




    """simple docstring"""

    def __init__(	self					:					Optional[Any]       ,     SCREAMING_SNAKE_CASE__					:					Optional[Any]       ,     SCREAMING_SNAKE_CASE__					:					Optional[Any]=13       ,     SCREAMING_SNAKE_CASE__					:					List[Any]=64       ,     SCREAMING_SNAKE_CASE__					:					List[str]=2       ,     SCREAMING_SNAKE_CASE__					:					int=3       ,     SCREAMING_SNAKE_CASE__					:					List[Any]=True       ,     SCREAMING_SNAKE_CASE__					:					List[str]=True       ,     SCREAMING_SNAKE_CASE__					:					Dict=32       ,     SCREAMING_SNAKE_CASE__					:					str=5       ,     SCREAMING_SNAKE_CASE__					:					Optional[int]=4       ,     SCREAMING_SNAKE_CASE__					:					Optional[Any]=37       ,     SCREAMING_SNAKE_CASE__					:					List[str]="gelu"       ,     SCREAMING_SNAKE_CASE__					:					List[str]=0.1       ,     SCREAMING_SNAKE_CASE__					:					Optional[int]=0.1       ,     SCREAMING_SNAKE_CASE__					:					Optional[Any]=10       ,     SCREAMING_SNAKE_CASE__					:					Optional[Any]=0.02       ,     SCREAMING_SNAKE_CASE__					:					int=[1, 16, 4, 4]       ,     SCREAMING_SNAKE_CASE__					:					List[str]=None       ,     )				->	Tuple:
         lowerCAmelCase__          =			parent
         lowerCAmelCase__          =			batch_size
         lowerCAmelCase__          =			image_size
         lowerCAmelCase__          =			patch_size
         lowerCAmelCase__          =			num_channels
         lowerCAmelCase__          =			is_training
         lowerCAmelCase__          =			use_labels
         lowerCAmelCase__          =			hidden_size
         lowerCAmelCase__          =			num_hidden_layers
         lowerCAmelCase__          =			num_attention_heads
         lowerCAmelCase__          =			intermediate_size
         lowerCAmelCase__          =			hidden_act
         lowerCAmelCase__          =			hidden_dropout_prob
         lowerCAmelCase__          =			attention_probs_dropout_prob
         lowerCAmelCase__          =			type_sequence_label_size
         lowerCAmelCase__          =			initializer_range
         lowerCAmelCase__          =			scope
         lowerCAmelCase__          =			backbone_featmap_shape

         # in ViT hybrid, the seq length equals the number of patches + 1 (we add 1 for the [CLS] token)
         # the number of patches is based on the feature map of the backbone, which by default uses an output stride
         # of 32, which means that the feature map has a spatial resolution of 1/32 of the input image size
         lowerCAmelCase__          =			(self.image_size // 32) ** 2
         lowerCAmelCase__          =			num_patches + 1


    def        a				(	self					:					Union[str, Any]       )				->	Dict:
         lowerCAmelCase__          =			floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]       )

         lowerCAmelCase__          =			None
         if self.use_labels:
              lowerCAmelCase__          =			ids_tensor([self.batch_size]       ,     self.type_sequence_label_size       )

         lowerCAmelCase__          =			self.get_config()

         return config, pixel_values, labels


    def        a				(	self					:					List[Any]       )				->	List[str]:
         lowerCAmelCase__          =			{
             "global_padding": "same",
             "layer_type": "bottleneck",
             "depths": [3, 4, 9],
             "out_features": ["stage1", "stage2", "stage3"],
             "embedding_dynamic_padding": True,
             "hidden_sizes": [4, 8, 16, 32],
             "num_groups": 2,
         }

         return ViTHybridConfig(
             image_size=self.image_size       ,     patch_size=self.patch_size       ,     num_channels=self.num_channels       ,     hidden_size=self.hidden_size       ,     num_hidden_layers=self.num_hidden_layers       ,     num_attention_heads=self.num_attention_heads       ,     intermediate_size=self.intermediate_size       ,     hidden_act=self.hidden_act       ,     hidden_dropout_prob=self.hidden_dropout_prob       ,     attention_probs_dropout_prob=self.attention_probs_dropout_prob       ,     is_decoder=SCREAMING_SNAKE_CASE__       ,     initializer_range=self.initializer_range       ,     backbone_featmap_shape=self.backbone_featmap_shape       ,     backbone_config=SCREAMING_SNAKE_CASE__       ,     )


    def        a				(	self					:					int       ,     SCREAMING_SNAKE_CASE__					:					Dict       ,     SCREAMING_SNAKE_CASE__					:					Any       ,     SCREAMING_SNAKE_CASE__					:					Union[str, Any]       )				->	Optional[Any]:
         lowerCAmelCase__          =			ViTHybridModel(config=SCREAMING_SNAKE_CASE__       )
         model.to(SCREAMING_SNAKE_CASE__       )
         model.eval()
         lowerCAmelCase__          =			model(SCREAMING_SNAKE_CASE__       )
         self.parent.assertEqual(result.last_hidden_state.shape       ,     (self.batch_size, self.seq_length, self.hidden_size)       )


    def        a				(	self					:					Union[str, Any]       ,     SCREAMING_SNAKE_CASE__					:					List[Any]       ,     SCREAMING_SNAKE_CASE__					:					Union[str, Any]       ,     SCREAMING_SNAKE_CASE__					:					str       )				->	Union[str, Any]:
         lowerCAmelCase__          =			self.type_sequence_label_size
         lowerCAmelCase__          =			ViTHybridForImageClassification(SCREAMING_SNAKE_CASE__       )
         model.to(SCREAMING_SNAKE_CASE__       )
         model.eval()
         lowerCAmelCase__          =			model(SCREAMING_SNAKE_CASE__       ,     labels=SCREAMING_SNAKE_CASE__       )
         self.parent.assertEqual(result.logits.shape       ,     (self.batch_size, self.type_sequence_label_size)       )


    def        a				(	self					:					Tuple       )				->	List[str]:
         lowerCAmelCase__          =			self.prepare_config_and_inputs()
         lowerCAmelCase__     ,		lowerCAmelCase__     ,		lowerCAmelCase__          =			config_and_inputs
         lowerCAmelCase__          =			{"pixel_values": pixel_values}
         return config, inputs_dict






@require_torch
class 			__lowerCamelCase	(   UpperCamelCase__     ,    UpperCamelCase__     ,    unittest.TestCase   ):




    """simple docstring"""

    snake_case__ =				(ViTHybridModel, ViTHybridForImageClassification) if is_torch_available() else ()
    snake_case__ =				(
        {"feature-extraction": ViTHybridModel, "image-classification": ViTHybridForImageClassification}
        if is_torch_available()
        else {}
    )
    snake_case__ =				False
    snake_case__ =				False
    snake_case__ =				False


    def        a				(	self					:					Optional[Any]       )				->	Optional[int]:
         lowerCAmelCase__          =			ViTHybridModelTester(self       )
         lowerCAmelCase__          =			ConfigTester(self       ,     config_class=SCREAMING_SNAKE_CASE__       ,     has_text_modality=SCREAMING_SNAKE_CASE__       ,     hidden_size=37       )


    def        a				(	self					:					Optional[Any]       )				->	Any:
         self.config_tester.run_common_tests()


    @unittest.skip(reason="ViT does not use inputs_embeds"       )
    def        a				(	self					:					List[str]       )				->	Tuple:
         pass


    def        a				(	self					:					Dict       )				->	Tuple:
         lowerCAmelCase__     ,		lowerCAmelCase__          =			self.model_tester.prepare_config_and_inputs_for_common()

         for model_class in self.all_model_classes:
              lowerCAmelCase__          =			model_class(SCREAMING_SNAKE_CASE__       )
              self.assertIsInstance(model.get_input_embeddings()       ,     (nn.Module)       )
              lowerCAmelCase__          =			model.get_output_embeddings()
              self.assertTrue(x is None or isinstance(SCREAMING_SNAKE_CASE__       ,     nn.Linear       )       )


    def        a				(	self					:					Optional[int]       )				->	Any:
         lowerCAmelCase__     ,		lowerCAmelCase__          =			self.model_tester.prepare_config_and_inputs_for_common()

         for model_class in self.all_model_classes:
              lowerCAmelCase__          =			model_class(SCREAMING_SNAKE_CASE__       )
              lowerCAmelCase__          =			inspect.signature(model.forward       )
              # signature.parameters is an OrderedDict => so arg_names order is deterministic
              lowerCAmelCase__          =			[*signature.parameters.keys()]

              lowerCAmelCase__          =			["pixel_values"]
              self.assertListEqual(arg_names[:1]       ,     SCREAMING_SNAKE_CASE__       )


    def        a				(	self					:					Union[str, Any]       )				->	Union[str, Any]:
         lowerCAmelCase__          =			self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_model(*SCREAMING_SNAKE_CASE__       )


    def        a				(	self					:					Tuple       )				->	str:
         lowerCAmelCase__          =			self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_image_classification(*SCREAMING_SNAKE_CASE__       )


    def        a				(	self					:					Dict       )				->	List[str]:
         lowerCAmelCase__     ,		lowerCAmelCase__          =			self.model_tester.prepare_config_and_inputs_for_common()

         lowerCAmelCase__          =			_config_zero_init(SCREAMING_SNAKE_CASE__       )
         for model_class in self.all_model_classes:
              lowerCAmelCase__          =			model_class(config=SCREAMING_SNAKE_CASE__       )
              # Skip the check for the backbone
              for name, module in model.named_modules():
                   if module.__class__.__name__ == "ViTHybridPatchEmbeddings":
                        lowerCAmelCase__          =			[f'{name}.{key}' for key in module.state_dict().keys()]
                        break

              for name, param in model.named_parameters():
                   if param.requires_grad:
                        if name in backbone_params:
                             continue
                        self.assertIn(
                            ((param.data.mean() * 1e9).round() / 1e9).item()       ,     [0.0, 1.0]       ,     msg=f'Parameter {name} of model {model_class} seems not properly initialized'       ,     )


    @slow
    def        a				(	self					:					Dict       )				->	List[str]:
         for model_name in VIT_HYBRID_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
              lowerCAmelCase__          =			ViTHybridModel.from_pretrained(SCREAMING_SNAKE_CASE__       )
              self.assertIsNotNone(SCREAMING_SNAKE_CASE__       )






def 							_A       (						):
     """simple docstring"""

     lowerCAmelCase__          =			Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"      )
     return image






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




    """simple docstring"""

    @cached_property
    def        a				(	self					:					int       )				->	Tuple:
         return (
             ViTHybridImageProcessor.from_pretrained(VIT_HYBRID_PRETRAINED_MODEL_ARCHIVE_LIST[0]       )
             if is_vision_available()
             else None
         )


    @slow
    def        a				(	self					:					List[str]       )				->	List[Any]:
         lowerCAmelCase__          =			ViTHybridForImageClassification.from_pretrained(VIT_HYBRID_PRETRAINED_MODEL_ARCHIVE_LIST[0]       ).to(
             SCREAMING_SNAKE_CASE__       )

         lowerCAmelCase__          =			self.default_image_processor
         lowerCAmelCase__          =			prepare_img()
         lowerCAmelCase__          =			image_processor(images=SCREAMING_SNAKE_CASE__       ,     return_tensors="pt"       ).to(SCREAMING_SNAKE_CASE__       )

         # forward pass
         with torch.no_grad():
              lowerCAmelCase__          =			model(**SCREAMING_SNAKE_CASE__       )

         # verify the logits
         lowerCAmelCase__          =			torch.Size((1, 1_000)       )
         self.assertEqual(outputs.logits.shape       ,     SCREAMING_SNAKE_CASE__       )

         lowerCAmelCase__          =			torch.tensor([-1.9_090, -0.4_993, -0.2_389]       ).to(SCREAMING_SNAKE_CASE__       )

         self.assertTrue(torch.allclose(outputs.logits[0, :3]       ,     SCREAMING_SNAKE_CASE__       ,     atol=1e-4       )       )


    @slow
    @require_accelerate
    def        a				(	self					:					Dict       )				->	int:
         lowerCAmelCase__          =			ViTHybridImageProcessor.from_pretrained("google/vit-hybrid-base-bit-384"       )
         lowerCAmelCase__          =			ViTHybridForImageClassification.from_pretrained("google/vit-hybrid-base-bit-384"       ,     device_map="auto"       )

         lowerCAmelCase__          =			prepare_img()

         lowerCAmelCase__          =			image_processor(images=SCREAMING_SNAKE_CASE__       ,     return_tensors="pt"       )
         lowerCAmelCase__          =			model(**SCREAMING_SNAKE_CASE__       )
         lowerCAmelCase__          =			outputs.logits
         # model predicts one of the 1000 ImageNet classes
         lowerCAmelCase__          =			logits.argmax(-1       ).item()

         self.assertTrue(model.config.idalabel[predicted_class_idx]       ,     "tabby, tabby cat"       )






from __future__ import annotations

import unittest

from transformers import is_tf_available
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
     import numpy
     import tensorflow as tf

     from transformers import (
         TF_DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST,
         TF_DPR_QUESTION_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST,
         TF_DPR_READER_PRETRAINED_MODEL_ARCHIVE_LIST,
         BertConfig,
         DPRConfig,
         TFDPRContextEncoder,
         TFDPRQuestionEncoder,
         TFDPRReader,
     )





class 			__lowerCamelCase	:




    """simple docstring"""

    def __init__(	self					:					str       ,     SCREAMING_SNAKE_CASE__					:					List[str]       ,     SCREAMING_SNAKE_CASE__					:					List[Any]=13       ,     SCREAMING_SNAKE_CASE__					:					Optional[Any]=7       ,     SCREAMING_SNAKE_CASE__					:					str=True       ,     SCREAMING_SNAKE_CASE__					:					Optional[Any]=True       ,     SCREAMING_SNAKE_CASE__					:					Dict=True       ,     SCREAMING_SNAKE_CASE__					:					Optional[Any]=True       ,     SCREAMING_SNAKE_CASE__					:					int=99       ,     SCREAMING_SNAKE_CASE__					:					List[str]=32       ,     SCREAMING_SNAKE_CASE__					:					Tuple=2       ,     SCREAMING_SNAKE_CASE__					:					List[str]=4       ,     SCREAMING_SNAKE_CASE__					:					Union[str, Any]=37       ,     SCREAMING_SNAKE_CASE__					:					List[Any]="gelu"       ,     SCREAMING_SNAKE_CASE__					:					int=0.1       ,     SCREAMING_SNAKE_CASE__					:					Dict=0.1       ,     SCREAMING_SNAKE_CASE__					:					List[Any]=512       ,     SCREAMING_SNAKE_CASE__					:					List[Any]=16       ,     SCREAMING_SNAKE_CASE__					:					List[str]=2       ,     SCREAMING_SNAKE_CASE__					:					Optional[int]=0.02       ,     SCREAMING_SNAKE_CASE__					:					Tuple=3       ,     SCREAMING_SNAKE_CASE__					:					int=4       ,     SCREAMING_SNAKE_CASE__					:					Optional[Any]=None       ,     SCREAMING_SNAKE_CASE__					:					str=0       ,     )				->	List[Any]:
         lowerCAmelCase__          =			parent
         lowerCAmelCase__          =			batch_size
         lowerCAmelCase__          =			seq_length
         lowerCAmelCase__          =			is_training
         lowerCAmelCase__          =			use_input_mask
         lowerCAmelCase__          =			use_token_type_ids
         lowerCAmelCase__          =			use_labels
         lowerCAmelCase__          =			vocab_size
         lowerCAmelCase__          =			hidden_size
         lowerCAmelCase__          =			num_hidden_layers
         lowerCAmelCase__          =			num_attention_heads
         lowerCAmelCase__          =			intermediate_size
         lowerCAmelCase__          =			hidden_act
         lowerCAmelCase__          =			hidden_dropout_prob
         lowerCAmelCase__          =			attention_probs_dropout_prob
         lowerCAmelCase__          =			max_position_embeddings
         lowerCAmelCase__          =			type_vocab_size
         lowerCAmelCase__          =			type_sequence_label_size
         lowerCAmelCase__          =			initializer_range
         lowerCAmelCase__          =			num_labels
         lowerCAmelCase__          =			num_choices
         lowerCAmelCase__          =			scope
         lowerCAmelCase__          =			projection_dim


    def        a				(	self					:					Any       )				->	Any:
         lowerCAmelCase__          =			ids_tensor([self.batch_size, self.seq_length]       ,     self.vocab_size       )

         lowerCAmelCase__          =			None
         if self.use_input_mask:
              # follow test_modeling_tf_ctrl.py
              lowerCAmelCase__          =			random_attention_mask([self.batch_size, self.seq_length]       )

         lowerCAmelCase__          =			None
         if self.use_token_type_ids:
              lowerCAmelCase__          =			ids_tensor([self.batch_size, self.seq_length]       ,     self.type_vocab_size       )

         lowerCAmelCase__          =			None
         lowerCAmelCase__          =			None
         lowerCAmelCase__          =			None
         if self.use_labels:
              lowerCAmelCase__          =			ids_tensor([self.batch_size]       ,     self.type_sequence_label_size       )
              lowerCAmelCase__          =			ids_tensor([self.batch_size, self.seq_length]       ,     self.num_labels       )
              lowerCAmelCase__          =			ids_tensor([self.batch_size]       ,     self.num_choices       )

         lowerCAmelCase__          =			BertConfig(
             vocab_size=self.vocab_size       ,     hidden_size=self.hidden_size       ,     num_hidden_layers=self.num_hidden_layers       ,     num_attention_heads=self.num_attention_heads       ,     intermediate_size=self.intermediate_size       ,     hidden_act=self.hidden_act       ,     hidden_dropout_prob=self.hidden_dropout_prob       ,     attention_probs_dropout_prob=self.attention_probs_dropout_prob       ,     max_position_embeddings=self.max_position_embeddings       ,     type_vocab_size=self.type_vocab_size       ,     is_decoder=SCREAMING_SNAKE_CASE__       ,     initializer_range=self.initializer_range       ,     )
         lowerCAmelCase__          =			DPRConfig(projection_dim=self.projection_dim       ,     **config.to_dict()       )

         return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels


    def        a				(	self					:					Dict       ,     SCREAMING_SNAKE_CASE__					:					Dict       ,     SCREAMING_SNAKE_CASE__					:					Tuple       ,     SCREAMING_SNAKE_CASE__					:					Tuple       ,     SCREAMING_SNAKE_CASE__					:					Any       ,     SCREAMING_SNAKE_CASE__					:					Any       ,     SCREAMING_SNAKE_CASE__					:					Union[str, Any]       ,     SCREAMING_SNAKE_CASE__					:					List[Any]       )				->	List[str]:
         lowerCAmelCase__          =			TFDPRContextEncoder(config=SCREAMING_SNAKE_CASE__       )
         lowerCAmelCase__          =			model(SCREAMING_SNAKE_CASE__       ,     attention_mask=SCREAMING_SNAKE_CASE__       ,     token_type_ids=SCREAMING_SNAKE_CASE__       )
         lowerCAmelCase__          =			model(SCREAMING_SNAKE_CASE__       ,     token_type_ids=SCREAMING_SNAKE_CASE__       )
         lowerCAmelCase__          =			model(SCREAMING_SNAKE_CASE__       )
         self.parent.assertEqual(result.pooler_output.shape       ,     (self.batch_size, self.projection_dim or self.hidden_size)       )


    def        a				(	self					:					Dict       ,     SCREAMING_SNAKE_CASE__					:					Tuple       ,     SCREAMING_SNAKE_CASE__					:					int       ,     SCREAMING_SNAKE_CASE__					:					Tuple       ,     SCREAMING_SNAKE_CASE__					:					Optional[Any]       ,     SCREAMING_SNAKE_CASE__					:					Any       ,     SCREAMING_SNAKE_CASE__					:					Optional[Any]       ,     SCREAMING_SNAKE_CASE__					:					str       )				->	List[str]:
         lowerCAmelCase__          =			TFDPRQuestionEncoder(config=SCREAMING_SNAKE_CASE__       )
         lowerCAmelCase__          =			model(SCREAMING_SNAKE_CASE__       ,     attention_mask=SCREAMING_SNAKE_CASE__       ,     token_type_ids=SCREAMING_SNAKE_CASE__       )
         lowerCAmelCase__          =			model(SCREAMING_SNAKE_CASE__       ,     token_type_ids=SCREAMING_SNAKE_CASE__       )
         lowerCAmelCase__          =			model(SCREAMING_SNAKE_CASE__       )
         self.parent.assertEqual(result.pooler_output.shape       ,     (self.batch_size, self.projection_dim or self.hidden_size)       )


    def        a				(	self					:					Dict       ,     SCREAMING_SNAKE_CASE__					:					List[Any]       ,     SCREAMING_SNAKE_CASE__					:					Tuple       ,     SCREAMING_SNAKE_CASE__					:					Tuple       ,     SCREAMING_SNAKE_CASE__					:					str       ,     SCREAMING_SNAKE_CASE__					:					Optional[Any]       ,     SCREAMING_SNAKE_CASE__					:					List[Any]       ,     SCREAMING_SNAKE_CASE__					:					Tuple       )				->	List[Any]:
         lowerCAmelCase__          =			TFDPRReader(config=SCREAMING_SNAKE_CASE__       )
         lowerCAmelCase__          =			model(SCREAMING_SNAKE_CASE__       ,     attention_mask=SCREAMING_SNAKE_CASE__       )

         self.parent.assertEqual(result.start_logits.shape       ,     (self.batch_size, self.seq_length)       )
         self.parent.assertEqual(result.end_logits.shape       ,     (self.batch_size, self.seq_length)       )
         self.parent.assertEqual(result.relevance_logits.shape       ,     (self.batch_size,)       )


    def        a				(	self					:					Optional[int]       )				->	Union[str, Any]:
         lowerCAmelCase__          =			self.prepare_config_and_inputs()
         (
             (
             lowerCAmelCase__
         )     ,		(
             lowerCAmelCase__
         )     ,		(
             lowerCAmelCase__
         )     ,		(
             lowerCAmelCase__
         )     ,		(
             lowerCAmelCase__
         )     ,		(
             lowerCAmelCase__
         )     ,		(
             lowerCAmelCase__
         )     ,		
         )          =			config_and_inputs
         lowerCAmelCase__          =			{"input_ids": input_ids}
         return config, inputs_dict






@require_tf
class 			__lowerCamelCase	(   UpperCamelCase__     ,    UpperCamelCase__     ,    unittest.TestCase   ):




    """simple docstring"""

    snake_case__ =				(
        (
            TFDPRContextEncoder,
            TFDPRQuestionEncoder,
            TFDPRReader,
        )
        if is_tf_available()
        else ()
    )
    snake_case__ =				{"feature-extraction": TFDPRQuestionEncoder} if is_tf_available() else {}

    snake_case__ =				False
    snake_case__ =				False
    snake_case__ =				False
    snake_case__ =				False
    snake_case__ =				False


    def        a				(	self					:					Dict       )				->	int:
         lowerCAmelCase__          =			TFDPRModelTester(self       )
         lowerCAmelCase__          =			ConfigTester(self       ,     config_class=SCREAMING_SNAKE_CASE__       ,     hidden_size=37       )


    def        a				(	self					:					List[Any]       )				->	List[Any]:
         self.config_tester.run_common_tests()


    def        a				(	self					:					Tuple       )				->	Dict:
         lowerCAmelCase__          =			self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_dpr_context_encoder(*SCREAMING_SNAKE_CASE__       )


    def        a				(	self					:					Union[str, Any]       )				->	Optional[int]:
         lowerCAmelCase__          =			self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_dpr_question_encoder(*SCREAMING_SNAKE_CASE__       )


    def        a				(	self					:					List[Any]       )				->	Dict:
         lowerCAmelCase__          =			self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_dpr_reader(*SCREAMING_SNAKE_CASE__       )


    @slow
    def        a				(	self					:					List[str]       )				->	Union[str, Any]:
         for model_name in TF_DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
              lowerCAmelCase__          =			TFDPRContextEncoder.from_pretrained(SCREAMING_SNAKE_CASE__       )
              self.assertIsNotNone(SCREAMING_SNAKE_CASE__       )

         for model_name in TF_DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
              lowerCAmelCase__          =			TFDPRContextEncoder.from_pretrained(SCREAMING_SNAKE_CASE__       )
              self.assertIsNotNone(SCREAMING_SNAKE_CASE__       )

         for model_name in TF_DPR_QUESTION_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
              lowerCAmelCase__          =			TFDPRQuestionEncoder.from_pretrained(SCREAMING_SNAKE_CASE__       )
              self.assertIsNotNone(SCREAMING_SNAKE_CASE__       )

         for model_name in TF_DPR_READER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
              lowerCAmelCase__          =			TFDPRReader.from_pretrained(SCREAMING_SNAKE_CASE__       )
              self.assertIsNotNone(SCREAMING_SNAKE_CASE__       )






@require_tf
class 			__lowerCamelCase	(   unittest.TestCase   ):




    """simple docstring"""

    @slow
    def        a				(	self					:					Optional[Any]       )				->	List[str]:
         lowerCAmelCase__          =			TFDPRQuestionEncoder.from_pretrained("facebook/dpr-question_encoder-single-nq-base"       )

         lowerCAmelCase__          =			tf.constant(
             [[101, 7_592, 1_010, 2_003, 2_026, 3_899, 10_140, 1_029, 102]]       )  # [CLS] hello, is my dog cute? [SEP]
         lowerCAmelCase__          =			model(SCREAMING_SNAKE_CASE__       )[0]  # embedding shape = (1, 768)
         # compare the actual values for a slice.
         lowerCAmelCase__          =			tf.constant(
             [
                 [
                     0.03_236_253,
                     0.12_753_335,
                     0.16_818_509,
                     0.00_279_786,
                     0.3_896_933,
                     0.24_264_945,
                     0.2_178_971,
                     -0.02_335_227,
                     -0.08_481_959,
                     -0.14_324_117,
                 ]
             ]       )
         self.assertTrue(numpy.allclose(output[:, :10].numpy()       ,     expected_slice.numpy()       ,     atol=1e-4       )       )
