






import tempfile

import torch

from diffusers import (
    DEISMultistepScheduler,
    DPMSolverMultistepScheduler,
    DPMSolverSinglestepScheduler,
    UniPCMultistepScheduler,
)

from .test_schedulers import SchedulerCommonTest



class 				__UpperCAmelCase		(_UpperCAmelCase   ):
			__snake_case    :				Optional[int]									=							(DEISMultistepScheduler,)
			__snake_case    :				List[Any]									=							(("num_inference_steps", 25),)







			def 							UpperCamelCase				(     self:  List[str]				,     **UpperCAmelCase_:  List[Any]					):







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE     				=  {
									    """num_train_timesteps""": 1_000,
									    """beta_start""": 0.00_01,
									    """beta_end""": 0.02,
									    """beta_schedule""": """linear""",
									    """solver_order""": 2,
									}

									config.update(**UpperCAmelCase_					)
									return config







			def 							UpperCamelCase				(     self:  str				,     UpperCAmelCase_:  List[Any]=0				,     **UpperCAmelCase_:  Tuple					):







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE     				=  dict(self.forward_default_kwargs					)
									_SCREAMING_SNAKE_CASE     				=  kwargs.pop("""num_inference_steps"""				,     UpperCAmelCase_					)
									_SCREAMING_SNAKE_CASE     				=  self.dummy_sample
									_SCREAMING_SNAKE_CASE     				=  0.1 * sample
									_SCREAMING_SNAKE_CASE     				=  [residual + 0.2, residual + 0.15, residual + 0.10]

									for scheduler_class in self.scheduler_classes:
															_SCREAMING_SNAKE_CASE     				=  self.get_scheduler_config(**UpperCAmelCase_					)
															_SCREAMING_SNAKE_CASE     				=  scheduler_class(**UpperCAmelCase_					)
															scheduler.set_timesteps(UpperCAmelCase_					)
															# copy over dummy past residuals
															_SCREAMING_SNAKE_CASE     				=  dummy_past_residuals[: scheduler.config.solver_order]

															with tempfile.TemporaryDirectory() as tmpdirname:
																					scheduler.save_config(UpperCAmelCase_					)
																					_SCREAMING_SNAKE_CASE     				=  scheduler_class.from_pretrained(UpperCAmelCase_					)
																					new_scheduler.set_timesteps(UpperCAmelCase_					)
																					# copy over dummy past residuals
																					_SCREAMING_SNAKE_CASE     				=  dummy_past_residuals[: new_scheduler.config.solver_order]

															_SCREAMING_SNAKE_CASE				,					_SCREAMING_SNAKE_CASE     				=  sample, sample
															for t in range(UpperCAmelCase_				,     time_step + scheduler.config.solver_order + 1					):
																					_SCREAMING_SNAKE_CASE     				=  scheduler.step(UpperCAmelCase_				,     UpperCAmelCase_				,     UpperCAmelCase_				,     **UpperCAmelCase_					).prev_sample
																					_SCREAMING_SNAKE_CASE     				=  new_scheduler.step(UpperCAmelCase_				,     UpperCAmelCase_				,     UpperCAmelCase_				,     **UpperCAmelCase_					).prev_sample

																					assert torch.sum(torch.abs(output - new_output					)					) < 1E-5, "Scheduler outputs are not identical"







			def 							UpperCamelCase				(     self:  Tuple					):







									'''simple docstring'''




									pass







			def 							UpperCamelCase				(     self:  Union[str, Any]				,     UpperCAmelCase_:  Optional[Any]=0				,     **UpperCAmelCase_:  Any					):







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE     				=  dict(self.forward_default_kwargs					)
									_SCREAMING_SNAKE_CASE     				=  kwargs.pop("""num_inference_steps"""				,     UpperCAmelCase_					)
									_SCREAMING_SNAKE_CASE     				=  self.dummy_sample
									_SCREAMING_SNAKE_CASE     				=  0.1 * sample
									_SCREAMING_SNAKE_CASE     				=  [residual + 0.2, residual + 0.15, residual + 0.10]

									for scheduler_class in self.scheduler_classes:
															_SCREAMING_SNAKE_CASE     				=  self.get_scheduler_config()
															_SCREAMING_SNAKE_CASE     				=  scheduler_class(**UpperCAmelCase_					)
															scheduler.set_timesteps(UpperCAmelCase_					)

															# copy over dummy past residuals (must be after setting timesteps)
															_SCREAMING_SNAKE_CASE     				=  dummy_past_residuals[: scheduler.config.solver_order]

															with tempfile.TemporaryDirectory() as tmpdirname:
																					scheduler.save_config(UpperCAmelCase_					)
																					_SCREAMING_SNAKE_CASE     				=  scheduler_class.from_pretrained(UpperCAmelCase_					)
																					# copy over dummy past residuals
																					new_scheduler.set_timesteps(UpperCAmelCase_					)

																					# copy over dummy past residual (must be after setting timesteps)
																					_SCREAMING_SNAKE_CASE     				=  dummy_past_residuals[: new_scheduler.config.solver_order]

															_SCREAMING_SNAKE_CASE     				=  scheduler.step(UpperCAmelCase_				,     UpperCAmelCase_				,     UpperCAmelCase_				,     **UpperCAmelCase_					).prev_sample
															_SCREAMING_SNAKE_CASE     				=  new_scheduler.step(UpperCAmelCase_				,     UpperCAmelCase_				,     UpperCAmelCase_				,     **UpperCAmelCase_					).prev_sample

															assert torch.sum(torch.abs(output - new_output					)					) < 1E-5, "Scheduler outputs are not identical"







			def 							UpperCamelCase				(     self:  Optional[int]				,     UpperCAmelCase_:  str=None				,     **UpperCAmelCase_:  List[str]					):







									'''simple docstring'''




									if scheduler is None:
															_SCREAMING_SNAKE_CASE     				=  self.scheduler_classes[0]
															_SCREAMING_SNAKE_CASE     				=  self.get_scheduler_config(**UpperCAmelCase_					)
															_SCREAMING_SNAKE_CASE     				=  scheduler_class(**UpperCAmelCase_					)

									_SCREAMING_SNAKE_CASE     				=  self.scheduler_classes[0]
									_SCREAMING_SNAKE_CASE     				=  self.get_scheduler_config(**UpperCAmelCase_					)
									_SCREAMING_SNAKE_CASE     				=  scheduler_class(**UpperCAmelCase_					)

									_SCREAMING_SNAKE_CASE     				=  10
									_SCREAMING_SNAKE_CASE     				=  self.dummy_model()
									_SCREAMING_SNAKE_CASE     				=  self.dummy_sample_deter
									scheduler.set_timesteps(UpperCAmelCase_					)

									for i, t in enumerate(scheduler.timesteps					):
															_SCREAMING_SNAKE_CASE     				=  model(UpperCAmelCase_				,     UpperCAmelCase_					)
															_SCREAMING_SNAKE_CASE     				=  scheduler.step(UpperCAmelCase_				,     UpperCAmelCase_				,     UpperCAmelCase_					).prev_sample

									return sample







			def 							UpperCamelCase				(     self:  Tuple					):







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE     				=  dict(self.forward_default_kwargs					)

									_SCREAMING_SNAKE_CASE     				=  kwargs.pop("""num_inference_steps"""				,     UpperCAmelCase_					)

									for scheduler_class in self.scheduler_classes:
															_SCREAMING_SNAKE_CASE     				=  self.get_scheduler_config()
															_SCREAMING_SNAKE_CASE     				=  scheduler_class(**UpperCAmelCase_					)

															_SCREAMING_SNAKE_CASE     				=  self.dummy_sample
															_SCREAMING_SNAKE_CASE     				=  0.1 * sample

															if num_inference_steps is not None and hasattr(UpperCAmelCase_				,     """set_timesteps"""					):
																					scheduler.set_timesteps(UpperCAmelCase_					)
															elif num_inference_steps is not None and not hasattr(UpperCAmelCase_				,     """set_timesteps"""					):
																					_SCREAMING_SNAKE_CASE     				=  num_inference_steps

															# copy over dummy past residuals (must be done after set_timesteps)
															_SCREAMING_SNAKE_CASE     				=  [residual + 0.2, residual + 0.15, residual + 0.10]
															_SCREAMING_SNAKE_CASE     				=  dummy_past_residuals[: scheduler.config.solver_order]

															_SCREAMING_SNAKE_CASE     				=  scheduler.timesteps[5]
															_SCREAMING_SNAKE_CASE     				=  scheduler.timesteps[6]

															_SCREAMING_SNAKE_CASE     				=  scheduler.step(UpperCAmelCase_				,     UpperCAmelCase_				,     UpperCAmelCase_				,     **UpperCAmelCase_					).prev_sample
															_SCREAMING_SNAKE_CASE     				=  scheduler.step(UpperCAmelCase_				,     UpperCAmelCase_				,     UpperCAmelCase_				,     **UpperCAmelCase_					).prev_sample

															self.assertEqual(output_a.shape				,     sample.shape					)
															self.assertEqual(output_a.shape				,     output_a.shape					)







			def 							UpperCamelCase				(     self:  Optional[int]					):







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE     				=  DEISMultistepScheduler(**self.get_scheduler_config()					)
									_SCREAMING_SNAKE_CASE     				=  self.full_loop(scheduler=UpperCAmelCase_					)
									_SCREAMING_SNAKE_CASE     				=  torch.mean(torch.abs(UpperCAmelCase_					)					)

									assert abs(result_mean.item() - 0.2_39_16					) < 1E-3

									_SCREAMING_SNAKE_CASE     				=  DPMSolverSinglestepScheduler.from_config(scheduler.config					)
									_SCREAMING_SNAKE_CASE     				=  DPMSolverMultistepScheduler.from_config(scheduler.config					)
									_SCREAMING_SNAKE_CASE     				=  UniPCMultistepScheduler.from_config(scheduler.config					)
									_SCREAMING_SNAKE_CASE     				=  DEISMultistepScheduler.from_config(scheduler.config					)

									_SCREAMING_SNAKE_CASE     				=  self.full_loop(scheduler=UpperCAmelCase_					)
									_SCREAMING_SNAKE_CASE     				=  torch.mean(torch.abs(UpperCAmelCase_					)					)

									assert abs(result_mean.item() - 0.2_39_16					) < 1E-3







			def 							UpperCamelCase				(     self:  Optional[Any]					):







									'''simple docstring'''




									for timesteps in [25, 50, 100, 999, 1_000]:
															self.check_over_configs(num_train_timesteps=UpperCAmelCase_					)







			def 							UpperCamelCase				(     self:  List[str]					):







									'''simple docstring'''




									self.check_over_configs(thresholding=UpperCAmelCase_					)
									for order in [1, 2, 3]:
															for solver_type in ["logrho"]:
																					for threshold in [0.5, 1.0, 2.0]:
																											for prediction_type in ["epsilon", "sample"]:
																																	self.check_over_configs(
																																	    thresholding=UpperCAmelCase_				,     prediction_type=UpperCAmelCase_				,     sample_max_value=UpperCAmelCase_				,     algorithm_type="""deis"""				,     solver_order=UpperCAmelCase_				,     solver_type=UpperCAmelCase_				,     )







			def 							UpperCamelCase				(     self:  Any					):







									'''simple docstring'''




									for prediction_type in ["epsilon", "v_prediction"]:
															self.check_over_configs(prediction_type=UpperCAmelCase_					)







			def 							UpperCamelCase				(     self:  int					):







									'''simple docstring'''




									for algorithm_type in ["deis"]:
															for solver_type in ["logrho"]:
																					for order in [1, 2, 3]:
																											for prediction_type in ["epsilon", "sample"]:
																																	self.check_over_configs(
																																	    solver_order=UpperCAmelCase_				,     solver_type=UpperCAmelCase_				,     prediction_type=UpperCAmelCase_				,     algorithm_type=UpperCAmelCase_				,     )
																																	_SCREAMING_SNAKE_CASE     				=  self.full_loop(
																																	    solver_order=UpperCAmelCase_				,     solver_type=UpperCAmelCase_				,     prediction_type=UpperCAmelCase_				,     algorithm_type=UpperCAmelCase_				,     )
																																	assert not torch.isnan(UpperCAmelCase_					).any(), "Samples have nan numbers"







			def 							UpperCamelCase				(     self:  Any					):







									'''simple docstring'''




									self.check_over_configs(lower_order_final=UpperCAmelCase_					)
									self.check_over_configs(lower_order_final=UpperCAmelCase_					)







			def 							UpperCamelCase				(     self:  List[Any]					):







									'''simple docstring'''




									for num_inference_steps in [1, 2, 3, 5, 10, 50, 100, 999, 1_000]:
															self.check_over_forward(num_inference_steps=UpperCAmelCase_				,     time_step=0					)







			def 							UpperCamelCase				(     self:  Dict					):







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE     				=  self.full_loop()
									_SCREAMING_SNAKE_CASE     				=  torch.mean(torch.abs(UpperCAmelCase_					)					)

									assert abs(result_mean.item() - 0.2_39_16					) < 1E-3







			def 							UpperCamelCase				(     self:  List[Any]					):







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE     				=  self.full_loop(prediction_type="""v_prediction"""					)
									_SCREAMING_SNAKE_CASE     				=  torch.mean(torch.abs(UpperCAmelCase_					)					)

									assert abs(result_mean.item() - 0.0_91					) < 1E-3







			def 							UpperCamelCase				(     self:  Tuple					):







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE     				=  self.scheduler_classes[0]
									_SCREAMING_SNAKE_CASE     				=  self.get_scheduler_config(thresholding=UpperCAmelCase_				,     dynamic_thresholding_ratio=0					)
									_SCREAMING_SNAKE_CASE     				=  scheduler_class(**UpperCAmelCase_					)

									_SCREAMING_SNAKE_CASE     				=  10
									_SCREAMING_SNAKE_CASE     				=  self.dummy_model()
									_SCREAMING_SNAKE_CASE     				=  self.dummy_sample_deter.half()
									scheduler.set_timesteps(UpperCAmelCase_					)

									for i, t in enumerate(scheduler.timesteps					):
															_SCREAMING_SNAKE_CASE     				=  model(UpperCAmelCase_				,     UpperCAmelCase_					)
															_SCREAMING_SNAKE_CASE     				=  scheduler.step(UpperCAmelCase_				,     UpperCAmelCase_				,     UpperCAmelCase_					).prev_sample

									assert sample.dtype == torch.floataa









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







			def __init__(     self:  Optional[int]				,     UpperCAmelCase_:  List[str]				,     UpperCAmelCase_:  int=13				,     UpperCAmelCase_:  List[str]=7				,     UpperCAmelCase_:  Union[str, Any]=True				,     UpperCAmelCase_:  List[str]=True				,     UpperCAmelCase_:  Dict=True				,     UpperCAmelCase_:  str=True				,     UpperCAmelCase_:  List[str]=99				,     UpperCAmelCase_:  int=32				,     UpperCAmelCase_:  List[Any]=2				,     UpperCAmelCase_:  Union[str, Any]=4				,     UpperCAmelCase_:  Dict=37				,     UpperCAmelCase_:  Tuple="gelu"				,     UpperCAmelCase_:  Any=0.1				,     UpperCAmelCase_:  List[str]=0.1				,     UpperCAmelCase_:  List[Any]=512				,     UpperCAmelCase_:  Optional[int]=16				,     UpperCAmelCase_:  Optional[Any]=2				,     UpperCAmelCase_:  Optional[int]=0.02				,     UpperCAmelCase_:  Union[str, Any]=3				,     UpperCAmelCase_:  Optional[int]=4				,     UpperCAmelCase_:  Tuple=None				,     UpperCAmelCase_:  Any=0				,     ):







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE     				=  parent
									_SCREAMING_SNAKE_CASE     				=  batch_size
									_SCREAMING_SNAKE_CASE     				=  seq_length
									_SCREAMING_SNAKE_CASE     				=  is_training
									_SCREAMING_SNAKE_CASE     				=  use_input_mask
									_SCREAMING_SNAKE_CASE     				=  use_token_type_ids
									_SCREAMING_SNAKE_CASE     				=  use_labels
									_SCREAMING_SNAKE_CASE     				=  vocab_size
									_SCREAMING_SNAKE_CASE     				=  hidden_size
									_SCREAMING_SNAKE_CASE     				=  num_hidden_layers
									_SCREAMING_SNAKE_CASE     				=  num_attention_heads
									_SCREAMING_SNAKE_CASE     				=  intermediate_size
									_SCREAMING_SNAKE_CASE     				=  hidden_act
									_SCREAMING_SNAKE_CASE     				=  hidden_dropout_prob
									_SCREAMING_SNAKE_CASE     				=  attention_probs_dropout_prob
									_SCREAMING_SNAKE_CASE     				=  max_position_embeddings
									_SCREAMING_SNAKE_CASE     				=  type_vocab_size
									_SCREAMING_SNAKE_CASE     				=  type_sequence_label_size
									_SCREAMING_SNAKE_CASE     				=  initializer_range
									_SCREAMING_SNAKE_CASE     				=  num_labels
									_SCREAMING_SNAKE_CASE     				=  num_choices
									_SCREAMING_SNAKE_CASE     				=  scope
									_SCREAMING_SNAKE_CASE     				=  projection_dim







			def 							UpperCamelCase				(     self:  Any					):







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE     				=  ids_tensor([self.batch_size, self.seq_length]				,     self.vocab_size					)

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

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

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

									_SCREAMING_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=UpperCAmelCase_				,     initializer_range=self.initializer_range				,     )
									_SCREAMING_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 							UpperCamelCase				(     self:  Optional[int]				,     UpperCAmelCase_:  Optional[Any]				,     UpperCAmelCase_:  Any				,     UpperCAmelCase_:  int				,     UpperCAmelCase_:  List[str]				,     UpperCAmelCase_:  Dict				,     UpperCAmelCase_:  Dict				,     UpperCAmelCase_:  Any					):







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE     				=  TFDPRContextEncoder(config=UpperCAmelCase_					)
									_SCREAMING_SNAKE_CASE     				=  model(UpperCAmelCase_				,     attention_mask=UpperCAmelCase_				,     token_type_ids=UpperCAmelCase_					)
									_SCREAMING_SNAKE_CASE     				=  model(UpperCAmelCase_				,     token_type_ids=UpperCAmelCase_					)
									_SCREAMING_SNAKE_CASE     				=  model(UpperCAmelCase_					)
									self.parent.assertEqual(result.pooler_output.shape				,     (self.batch_size, self.projection_dim or self.hidden_size)					)







			def 							UpperCamelCase				(     self:  List[Any]				,     UpperCAmelCase_:  Union[str, Any]				,     UpperCAmelCase_:  Any				,     UpperCAmelCase_:  Dict				,     UpperCAmelCase_:  Union[str, Any]				,     UpperCAmelCase_:  Union[str, Any]				,     UpperCAmelCase_:  List[Any]				,     UpperCAmelCase_:  Any					):







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE     				=  TFDPRQuestionEncoder(config=UpperCAmelCase_					)
									_SCREAMING_SNAKE_CASE     				=  model(UpperCAmelCase_				,     attention_mask=UpperCAmelCase_				,     token_type_ids=UpperCAmelCase_					)
									_SCREAMING_SNAKE_CASE     				=  model(UpperCAmelCase_				,     token_type_ids=UpperCAmelCase_					)
									_SCREAMING_SNAKE_CASE     				=  model(UpperCAmelCase_					)
									self.parent.assertEqual(result.pooler_output.shape				,     (self.batch_size, self.projection_dim or self.hidden_size)					)







			def 							UpperCamelCase				(     self:  Optional[Any]				,     UpperCAmelCase_:  Dict				,     UpperCAmelCase_:  Optional[int]				,     UpperCAmelCase_:  List[Any]				,     UpperCAmelCase_:  str				,     UpperCAmelCase_:  Optional[Any]				,     UpperCAmelCase_:  Union[str, Any]				,     UpperCAmelCase_:  str					):







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE     				=  TFDPRReader(config=UpperCAmelCase_					)
									_SCREAMING_SNAKE_CASE     				=  model(UpperCAmelCase_				,     attention_mask=UpperCAmelCase_					)

									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 							UpperCamelCase				(     self:  Optional[int]					):







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE     				=  self.prepare_config_and_inputs()
									(
									    (
									    _SCREAMING_SNAKE_CASE
									)				,					(
									    _SCREAMING_SNAKE_CASE
									)				,					(
									    _SCREAMING_SNAKE_CASE
									)				,					(
									    _SCREAMING_SNAKE_CASE
									)				,					(
									    _SCREAMING_SNAKE_CASE
									)				,					(
									    _SCREAMING_SNAKE_CASE
									)				,					(
									    _SCREAMING_SNAKE_CASE
									)				,					
									)     				=  config_and_inputs
									_SCREAMING_SNAKE_CASE     				=  {"""input_ids""": input_ids}
									return config, inputs_dict



@require_tf
class 				__UpperCAmelCase		(_UpperCAmelCase	,_UpperCAmelCase	,unittest.TestCase   ):
			__snake_case    :				Dict									=							(
			    (
			        TFDPRContextEncoder,
			        TFDPRQuestionEncoder,
			        TFDPRReader,
			    )
			    if is_tf_available()
			    else ()
			)
			__snake_case    :				Optional[Any]									=							{"feature-extraction": TFDPRQuestionEncoder} if is_tf_available() else {}

			__snake_case    :				str									=							False
			__snake_case    :				List[Any]									=							False
			__snake_case    :				Any									=							False
			__snake_case    :				List[Any]									=							False
			__snake_case    :				Tuple									=							False







			def 							UpperCamelCase				(     self:  int					):







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE     				=  TFDPRModelTester(self					)
									_SCREAMING_SNAKE_CASE     				=  ConfigTester(self				,     config_class=UpperCAmelCase_				,     hidden_size=37					)







			def 							UpperCamelCase				(     self:  Any					):







									'''simple docstring'''




									self.config_tester.run_common_tests()







			def 							UpperCamelCase				(     self:  List[Any]					):







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE     				=  self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_dpr_context_encoder(*UpperCAmelCase_					)







			def 							UpperCamelCase				(     self:  Optional[Any]					):







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE     				=  self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_dpr_question_encoder(*UpperCAmelCase_					)







			def 							UpperCamelCase				(     self:  int					):







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE     				=  self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_dpr_reader(*UpperCAmelCase_					)







			@slow
			def 							UpperCamelCase				(     self:  List[Any]					):







									'''simple docstring'''




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

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

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

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



@require_tf
class 				__UpperCAmelCase		(unittest.TestCase   ):







			@slow
			def 							UpperCamelCase				(     self:  Union[str, Any]					):







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE     				=  TFDPRQuestionEncoder.from_pretrained("""facebook/dpr-question_encoder-single-nq-base"""					)

									_SCREAMING_SNAKE_CASE     				=  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]
									_SCREAMING_SNAKE_CASE     				=  model(UpperCAmelCase_					)[0]  # embedding shape = (1, 768)
									# compare the actual values for a slice.
									_SCREAMING_SNAKE_CASE     				=  tf.constant(
									    [
									        [
									            0.03_23_62_53,
									            0.12_75_33_35,
									            0.16_81_85_09,
									            0.00_27_97_86,
									            0.3_89_69_33,
									            0.24_26_49_45,
									            0.2_17_89_71,
									            -0.02_33_52_27,
									            -0.08_48_19_59,
									            -0.14_32_41_17,
									        ]
									    ]					)
									self.assertTrue(numpy.allclose(output[:, :10].numpy()				,     expected_slice.numpy()				,     atol=1E-4					)					)

