
'''simple docstring'''
import inspect
import unittest
from typing import List

import numpy as np

from transformers import EfficientFormerConfig
from transformers.testing_utils import require_tf, require_vision, slow
from transformers.utils import cached_property, is_tf_available, is_vision_available

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


if is_tf_available():
						import tensorflow as tf

						from transformers import (
						    TFEfficientFormerForImageClassification,
						    TFEfficientFormerForImageClassificationWithTeacher,
						    TFEfficientFormerModel,
						)
						from transformers.models.efficientformer.modeling_tf_efficientformer import (
						    TF_EFFICIENTFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
						)


if is_vision_available():
						from PIL import Image

						from transformers import EfficientFormerImageProcessor


class 			SCREAMING_SNAKE_CASE__      :







				def __init__(       self						,				A_						,				A_ = 13						,				A_ = 64						,				A_ = 2						,				A_ = 3						,				A_ = 3						,				A_ = True						,				A_ = True						,				A_ = 128						,				A_=[16, 32, 64, 128]						,				A_ = 7						,				A_ = 4						,				A_ = 37						,				A_ = "gelu"						,				A_ = 0.1						,				A_ = 0.1						,				A_ = 10						,				A_ = 0.02						,				A_ = 2						,				A_ = 1						,				A_ = 128						,				A_ = [2, 2, 2, 2]						,				A_ = 2						,				A_ = 2						,				)->		int:







											'''simple docstring'''






											UpperCamelCase   			=     parent
											UpperCamelCase   			=     batch_size
											UpperCamelCase   			=     image_size
											UpperCamelCase   			=     patch_size
											UpperCamelCase   			=     num_channels
											UpperCamelCase   			=     is_training
											UpperCamelCase   			=     use_labels
											UpperCamelCase   			=     hidden_size
											UpperCamelCase   			=     num_hidden_layers
											UpperCamelCase   			=     num_attention_heads
											UpperCamelCase   			=     intermediate_size
											UpperCamelCase   			=     hidden_act
											UpperCamelCase   			=     hidden_dropout_prob
											UpperCamelCase   			=     attention_probs_dropout_prob
											UpperCamelCase   			=     type_sequence_label_size
											UpperCamelCase   			=     initializer_range
											UpperCamelCase   			=     encoder_stride
											UpperCamelCase   			=     num_attention_outputs
											UpperCamelCase   			=     embed_dim
											UpperCamelCase   			=     embed_dim + 1
											UpperCamelCase   			=     resolution
											UpperCamelCase   			=     depths
											UpperCamelCase   			=     hidden_sizes
											UpperCamelCase   			=     dim
											UpperCamelCase   			=     mlp_expansion_ratio







				def 						UpperCAmelCase_    (       self     )->		int:







											'''simple docstring'''






											UpperCamelCase   			=     floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]     )

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

											UpperCamelCase   			=     self.get_config()

											return config, pixel_values, labels







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







											'''simple docstring'''






											return EfficientFormerConfig(
											    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=A_						,				initializer_range=self.initializer_range						,				encoder_stride=self.encoder_stride						,				resolution=self.resolution						,				depths=self.depths						,				hidden_sizes=self.hidden_sizes						,				dim=self.dim						,				mlp_expansion_ratio=self.mlp_expansion_ratio						,				)







				def 						UpperCAmelCase_    (       self						,				A_						,				A_						,				A_     )->		int:







											'''simple docstring'''






											UpperCamelCase   			=     TFEfficientFormerModel(config=A_     )
											UpperCamelCase   			=     model(A_						,				training=A_     )
											self.parent.assertEqual(result.last_hidden_state.shape						,				(self.batch_size, self.seq_length, self.hidden_size)     )







				def 						UpperCAmelCase_    (       self						,				A_						,				A_						,				A_     )->		Optional[Any]:







											'''simple docstring'''






											UpperCamelCase   			=     self.type_sequence_label_size
											UpperCamelCase   			=     TFEfficientFormerForImageClassification(A_     )
											UpperCamelCase   			=     model(A_						,				labels=A_						,				training=A_     )
											self.parent.assertEqual(result.logits.shape						,				(self.batch_size, self.type_sequence_label_size)     )

											# test greyscale images
											UpperCamelCase   			=     1
											UpperCamelCase   			=     TFEfficientFormerForImageClassification(A_     )

											UpperCamelCase   			=     floats_tensor([self.batch_size, 1, self.image_size, self.image_size]     )
											UpperCamelCase   			=     model(A_						,				labels=A_     )
											self.parent.assertEqual(result.logits.shape						,				(self.batch_size, self.type_sequence_label_size)     )







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







											'''simple docstring'''






											UpperCamelCase   			=     self.prepare_config_and_inputs()
											UpperCamelCase			,	UpperCamelCase			,	UpperCamelCase   			=     config_and_inputs
											UpperCamelCase   			=     {'pixel_values': pixel_values}
											return config, inputs_dict


@require_tf
class 			SCREAMING_SNAKE_CASE__      (     snake_case_							,       snake_case_							,       unittest.TestCase):
				lowerCAmelCase_     			=							(
				    (
				        TFEfficientFormerModel,
				        TFEfficientFormerForImageClassificationWithTeacher,
				        TFEfficientFormerForImageClassification,
				    )
				    if is_tf_available()
				    else ()
				)
				lowerCAmelCase_     			=							(
				    {
				        """feature-extraction""": TFEfficientFormerModel,
				        """image-classification""": (
				            TFEfficientFormerForImageClassification,
				            TFEfficientFormerForImageClassificationWithTeacher,
				        ),
				    }
				    if is_tf_available()
				    else {}
				)

				lowerCAmelCase_     			=							False

				lowerCAmelCase_     			=							False
				lowerCAmelCase_     			=							False
				lowerCAmelCase_     			=							False
				lowerCAmelCase_     			=							False







				def 						UpperCAmelCase_    (       self     )->		Any:







											'''simple docstring'''






											UpperCamelCase   			=     TFEfficientFormerModelTester(self     )
											UpperCamelCase   			=     ConfigTester(
											    self						,				config_class=A_						,				has_text_modality=A_						,				hidden_size=37     )







				def 						UpperCAmelCase_    (       self     )->		Optional[Any]:







											'''simple docstring'''






											self.config_tester.run_common_tests()







				@unittest.skip(reason='EfficientFormer does not use inputs_embeds'     )
				def 						UpperCAmelCase_    (       self     )->		List[Any]:







											'''simple docstring'''






											pass







				@unittest.skip(reason='EfficientFormer does not support input and output embeddings'     )
				def 						UpperCAmelCase_    (       self     )->		int:







											'''simple docstring'''






											pass







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







											'''simple docstring'''






											UpperCamelCase			,	UpperCamelCase   			=     self.model_tester.prepare_config_and_inputs_for_common()

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

																		UpperCamelCase   			=     ['pixel_values']
																		self.assertListEqual(arg_names[:1]						,				A_     )







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







											'''simple docstring'''






											def check_hidden_states_output(A_						,				A_						,				A_     ):
																		UpperCamelCase   			=     model_class(A_     )

																		UpperCamelCase   			=     model(**self._prepare_for_class(A_						,				A_     )						,				training=A_     )
																		UpperCamelCase   			=     outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

																		UpperCamelCase   			=     getattr(
																		    self.model_tester						,				'expected_num_hidden_layers'						,				self.model_tester.num_hidden_layers + 1     )
																		self.assertEqual(len(A_     )						,				A_     )

																		if hasattr(self.model_tester						,				'encoder_seq_length'     ):
																									UpperCamelCase   			=     self.model_tester.encoder_seq_length
																									if hasattr(self.model_tester						,				'chunk_length'     ) and self.model_tester.chunk_length > 1:
																																UpperCamelCase   			=     seq_length * self.model_tester.chunk_length
																		else:
																									UpperCamelCase   			=     self.model_tester.seq_length

																		self.assertListEqual(
																		    list(hidden_states[-1].shape[-2:]     )						,				[seq_length, self.model_tester.hidden_size]						,				)

																		if config.is_encoder_decoder:
																									UpperCamelCase   			=     outputs.decoder_hidden_states

																									self.asseretIsInstance(A_						,				(list, tuple)     )
																									self.assertEqual(len(A_     )						,				A_     )
																									UpperCamelCase   			=     getattr(self.model_tester						,				'seq_length'						,				A_     )
																									UpperCamelCase   			=     getattr(self.model_tester						,				'decoder_seq_length'						,				A_     )

																									self.assertListEqual(
																									    list(hidden_states[-1].shape[-2:]     )						,				[decoder_seq_length, self.model_tester.hidden_size]						,				)

											UpperCamelCase			,	UpperCamelCase   			=     self.model_tester.prepare_config_and_inputs_for_common()

											for model_class in self.all_model_classes:
																		UpperCamelCase   			=     True
																		check_hidden_states_output(A_						,				A_						,				A_     )

																		# check that output_hidden_states also work using config
																		del inputs_dict["output_hidden_states"]
																		UpperCamelCase   			=     True

																		check_hidden_states_output(A_						,				A_						,				A_     )







				def 						UpperCAmelCase_    (       self						,				A_						,				A_						,				A_=False     )->		int:







											'''simple docstring'''






											UpperCamelCase   			=     super()._prepare_for_class(A_						,				A_						,				return_labels=A_     )

											if return_labels:
																		if model_class.__name__ == "TFEfficientFormerForImageClassificationWithTeacher":
																									del inputs_dict["labels"]

											return inputs_dict







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







											'''simple docstring'''






											UpperCamelCase   			=     self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_model(*A_     )







				@unittest.skip(reason='EfficientFormer does not implement masked image modeling yet'     )
				def 						UpperCAmelCase_    (       self     )->		List[Any]:







											'''simple docstring'''






											UpperCamelCase   			=     self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_masked_image_modeling(*A_     )







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







											'''simple docstring'''






											UpperCamelCase   			=     self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_image_classification(*A_     )







				@slow
				def 						UpperCAmelCase_    (       self     )->		Any:







											'''simple docstring'''






											for model_name in TF_EFFICIENTFORMER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																		UpperCamelCase   			=     TFEfficientFormerModel.from_pretrained(A_     )
																		self.assertIsNotNone(A_     )







				def 						UpperCAmelCase_    (       self     )->		List[Any]:







											'''simple docstring'''






											UpperCamelCase			,	UpperCamelCase   			=     self.model_tester.prepare_config_and_inputs_for_common()
											UpperCamelCase   			=     True

											UpperCamelCase   			=     getattr(self.model_tester						,				'seq_length'						,				A_     )
											UpperCamelCase   			=     getattr(self.model_tester						,				'encoder_seq_length'						,				A_     )
											UpperCamelCase   			=     getattr(self.model_tester						,				'key_length'						,				A_     )
											UpperCamelCase   			=     getattr(self.model_tester						,				'chunk_length'						,				A_     )

											if chunk_length is not None and hasattr(self.model_tester						,				'num_hashes'     ):
																		UpperCamelCase   			=     encoder_seq_length * self.model_tester.num_hashes

											for model_class in self.all_model_classes:
																		UpperCamelCase   			=     True
																		UpperCamelCase   			=     False
																		UpperCamelCase   			=     True
																		UpperCamelCase   			=     model_class(A_     )

																		UpperCamelCase   			=     model(**self._prepare_for_class(A_						,				A_     )						,				training=A_     )
																		UpperCamelCase   			=     outputs.encoder_attentions if config.is_encoder_decoder else outputs.attentions
																		self.assertEqual(len(A_     )						,				self.model_tester.num_attention_outputs     )

																		# check that output_attentions also work using config
																		del inputs_dict["output_attentions"]
																		UpperCamelCase   			=     True
																		UpperCamelCase   			=     model_class(A_     )
																		UpperCamelCase   			=     model(**self._prepare_for_class(A_						,				A_     )						,				training=A_     )

																		UpperCamelCase   			=     outputs.encoder_attentions if config.is_encoder_decoder else outputs.attentions
																		self.assertEqual(len(A_     )						,				self.model_tester.num_attention_outputs     )

																		if chunk_length is not None:
																									self.assertListEqual(
																									    list(attentions[0].shape[-4:]     )						,				[self.model_tester.num_attention_heads, encoder_seq_length, chunk_length, encoder_key_length]						,				)
																		else:
																									self.assertListEqual(
																									    list(attentions[0].shape[-3:]     )						,				[self.model_tester.num_attention_heads, encoder_seq_length, encoder_key_length]						,				)







				def 						UpperCAmelCase_    (       self     )->		List[str]:







											'''simple docstring'''






											UpperCamelCase			,	UpperCamelCase   			=     self.model_tester.prepare_config_and_inputs_for_common()

											for model_class in self.all_model_classes:
																		# Prepare our model
																		UpperCamelCase   			=     model_class(A_     )
																		# These are maximally general inputs for the model, with multiple None dimensions
																		# Hopefully this will catch any conditionals that fail for flexible shapes
																		UpperCamelCase   			=     {
																		    key: tf.keras.Input(shape=val.shape[1:]						,				dtype=val.dtype						,				name=A_     )
																		    for key, val in model.input_signature.items()
																		    if key in model.dummy_inputs
																		}
																		UpperCamelCase   			=     model(A_     )
																		self.assertTrue(outputs_dict is not None     )







def 		A_(     ):
							UpperCamelCase   			=     Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png')
							return image





@require_tf
@require_vision
class 			SCREAMING_SNAKE_CASE__      (     unittest.TestCase):







				@cached_property
				def 						UpperCAmelCase_    (       self     )->		Optional[int]:







											'''simple docstring'''






											return (
											    EfficientFormerImageProcessor.from_pretrained('snap-research/efficientformer-l1-300'     )
											    if is_vision_available()
											    else None
											)







				@slow
				def 						UpperCAmelCase_    (       self     )->		Dict:







											'''simple docstring'''






											UpperCamelCase   			=     TFEfficientFormerForImageClassification.from_pretrained('snap-research/efficientformer-l1-300'     )
											UpperCamelCase   			=     self.default_image_processor
											UpperCamelCase   			=     prepare_img()
											UpperCamelCase   			=     image_processor(images=A_						,				return_tensors='tf'     )
											# forward pass
											UpperCamelCase   			=     model(**A_						,				training=A_     )
											# verify the logits
											UpperCamelCase   			=     tf.TensorShape((1, 1000)     )
											self.assertEqual(outputs.logits.shape						,				A_     )
											UpperCamelCase   			=     tf.constant([-0.0_555, 0.4_825, -0.0_852]     )
											self.assertTrue(np.allclose(outputs.logits[0, :3]						,				A_						,				atol=1e-4     )     )







				@slow
				def 						UpperCAmelCase_    (       self     )->		Optional[int]:







											'''simple docstring'''






											UpperCamelCase   			=     TFEfficientFormerForImageClassificationWithTeacher.from_pretrained(
											    'snap-research/efficientformer-l1-300'     )
											UpperCamelCase   			=     self.default_image_processor
											UpperCamelCase   			=     prepare_img()
											UpperCamelCase   			=     image_processor(images=A_						,				return_tensors='tf'     )
											# forward pass
											UpperCamelCase   			=     model(**A_						,				training=A_     )
											# verify the logits
											UpperCamelCase   			=     tf.TensorShape((1, 1000)     )
											self.assertEqual(outputs.logits.shape						,				A_     )
											UpperCamelCase   			=     tf.constant([-0.1_312, 0.4_353, -1.0_499]     )
											self.assertTrue(np.allclose(outputs.logits[0, :3]						,				A_						,				atol=1e-4     )     )










'''simple docstring'''

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 		a							:


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


				def     A_					(						self       :   int   ):
									snake_case_		     =							ids_tensor([self.batch_size, self.seq_length]			,							self.vocab_size   )

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

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

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

									snake_case_		     =							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=lowercase_			,							initializer_range=self.initializer_range			,							)
									snake_case_		     =							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			,							lowercase_       :   Optional[Any]			,							lowercase_       :   int			,							lowercase_       :   Optional[int]			,							lowercase_       :   int			,							lowercase_       :   int			,							lowercase_       :   Union[str, Any]			,							lowercase_       :   str   ):
									snake_case_		     =							TFDPRContextEncoder(config=lowercase_   )
									snake_case_		     =							model(lowercase_			,							attention_mask=lowercase_			,							token_type_ids=lowercase_   )
									snake_case_		     =							model(lowercase_			,							token_type_ids=lowercase_   )
									snake_case_		     =							model(lowercase_   )
									self.parent.assertEqual(result.pooler_output.shape			,							(self.batch_size, self.projection_dim or self.hidden_size)   )


				def     A_					(						self       :   Any			,							lowercase_       :   Optional[Any]			,							lowercase_       :   List[str]			,							lowercase_       :   Union[str, Any]			,							lowercase_       :   Dict			,							lowercase_       :   Dict			,							lowercase_       :   Dict			,							lowercase_       :   Any   ):
									snake_case_		     =							TFDPRQuestionEncoder(config=lowercase_   )
									snake_case_		     =							model(lowercase_			,							attention_mask=lowercase_			,							token_type_ids=lowercase_   )
									snake_case_		     =							model(lowercase_			,							token_type_ids=lowercase_   )
									snake_case_		     =							model(lowercase_   )
									self.parent.assertEqual(result.pooler_output.shape			,							(self.batch_size, self.projection_dim or self.hidden_size)   )


				def     A_					(						self       :   str			,							lowercase_       :   Tuple			,							lowercase_       :   Tuple			,							lowercase_       :   Tuple			,							lowercase_       :   Tuple			,							lowercase_       :   Tuple			,							lowercase_       :   Dict			,							lowercase_       :   Dict   ):
									snake_case_		     =							TFDPRReader(config=lowercase_   )
									snake_case_		     =							model(lowercase_			,							attention_mask=lowercase_   )

									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       :   Union[str, Any]   ):
									snake_case_		     =							self.prepare_config_and_inputs()
									(
									    (
									    snake_case_
									)     ,(
									    snake_case_
									)     ,(
									    snake_case_
									)     ,(
									    snake_case_
									)     ,(
									    snake_case_
									)     ,(
									    snake_case_
									)     ,(
									    snake_case_
									)     ,
									)		     =							config_and_inputs
									snake_case_		     =							{'''input_ids''': input_ids}
									return config, inputs_dict







@require_tf
class 		a							(  _lowerCamelCase  ,	_lowerCamelCase  ,	unittest.TestCase	):
				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       :   List[Any]   ):
									snake_case_		     =							TFDPRModelTester(self   )
									snake_case_		     =							ConfigTester(self			,							config_class=lowercase_			,							hidden_size=37   )


				def     A_					(						self       :   Any   ):
									self.config_tester.run_common_tests()


				def     A_					(						self       :   int   ):
									snake_case_		     =							self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_dpr_context_encoder(*lowercase_   )


				def     A_					(						self       :   List[Any]   ):
									snake_case_		     =							self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_dpr_question_encoder(*lowercase_   )


				def     A_					(						self       :   Any   ):
									snake_case_		     =							self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_dpr_reader(*lowercase_   )


				@slow
				def     A_					(						self       :   int   ):
									for model_name in TF_DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
														snake_case_		     =							TFDPRContextEncoder.from_pretrained(lowercase_   )
														self.assertIsNotNone(lowercase_   )

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

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

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







@require_tf
class 		a							(  unittest.TestCase	):


				@slow
				def     A_					(						self       :   Dict   ):
									snake_case_		     =							TFDPRQuestionEncoder.from_pretrained('''facebook/dpr-question_encoder-single-nq-base'''   )

									snake_case_		     =							tf.constant(
									    [[101, 7592, 1010, 2003, 2026, 3899, 1_0140, 1029, 102]]   )  # [CLS] hello, is my dog cute? [SEP]
									snake_case_		     =							model(lowercase_   )[0]  # embedding shape = (1, 768)
									# compare the actual values for a slice.
									snake_case_		     =							tf.constant(
									    [
									        [
									            0.0323_6253,
									            0.1275_3335,
									            0.1681_8509,
									            0.0027_9786,
									            0.389_6933,
									            0.2426_4945,
									            0.217_8971,
									            -0.0233_5227,
									            -0.0848_1959,
									            -0.1432_4117,
									        ]
									    ]   )
									self.assertTrue(numpy.allclose(output[:, :10].numpy()			,							expected_slice.numpy()			,							atol=1e-4   )   )

