


from dataclasses import dataclass
from typing import Dict, Optional, Union

import torch
import torch.nn.functional as F
from torch import nn

from ..configuration_utils import ConfigMixin, register_to_config
from ..utils import BaseOutput
from .attention import BasicTransformerBlock
from .attention_processor import AttentionProcessor, AttnProcessor
from .embeddings import TimestepEmbedding, Timesteps
from .modeling_utils import ModelMixin

@dataclass
class 							lowercase  (						_UpperCAmelCase			):
     lowerCamelCase			:			torch.FloatTensor




class 							lowercase  (						_UpperCAmelCase    ,       _UpperCAmelCase			):







     @register_to_config
     def __init__(						self :						Optional[Any]   ,   _lowercase :						int = 32   ,   _lowercase :						int = 64   ,   _lowercase :						int = 20   ,   _lowercase :						int = 7_68   ,   _lowercase :						Dict=77   ,   _lowercase :						List[str]=4   ,   _lowercase :						float = 0.0   ,   _lowercase :						str = "silu"   ,   _lowercase :						Optional[str] = None   ,   _lowercase :						Optional[str] = None   ,   _lowercase :						Optional[str] = "linear"   ,   _lowercase :						Optional[str] = "prd"   ,   _lowercase :						Optional[int] = None   ,   _lowercase :						Optional[int] = None   ,   _lowercase :						Optional[int] = None   ,   ):
           super().__init__()
           SCREAMING_SNAKE_CASE__       :  List[Any]						     =		num_attention_heads
           SCREAMING_SNAKE_CASE__       :  Tuple						     =		attention_head_dim
           SCREAMING_SNAKE_CASE__       :  Any						     =		num_attention_heads * attention_head_dim
           SCREAMING_SNAKE_CASE__       :  Dict						     =		additional_embeddings

           SCREAMING_SNAKE_CASE__       :  int						     =		time_embed_dim or inner_dim
           SCREAMING_SNAKE_CASE__       :  List[Any]						     =		embedding_proj_dim or embedding_dim
           SCREAMING_SNAKE_CASE__       :  Optional[int]						     =		clip_embed_dim or embedding_dim

           SCREAMING_SNAKE_CASE__       :  Dict						     =		Timesteps(_lowercase   ,   _lowercase   ,   0      )
           SCREAMING_SNAKE_CASE__       :  Dict						     =		TimestepEmbedding(_lowercase   ,   _lowercase   ,   out_dim=_lowercase   ,   act_fn=_lowercase      )

           SCREAMING_SNAKE_CASE__       :  List[str]						     =		nn.Linear(_lowercase   ,   _lowercase      )

           if embedding_proj_norm_type is None:
                 SCREAMING_SNAKE_CASE__       :  Optional[Any]						     =		None
           elif embedding_proj_norm_type == "layer":
                 SCREAMING_SNAKE_CASE__       :  List[str]						     =		nn.LayerNorm(_lowercase      )
           else:
                 raise ValueError(f"""unsupported embedding_proj_norm_type: {embedding_proj_norm_type}"""      )

           SCREAMING_SNAKE_CASE__       :  Dict						     =		nn.Linear(_lowercase   ,   _lowercase      )

           if encoder_hid_proj_type is None:
                 SCREAMING_SNAKE_CASE__       :  Any						     =		None
           elif encoder_hid_proj_type == "linear":
                 SCREAMING_SNAKE_CASE__       :  List[str]						     =		nn.Linear(_lowercase   ,   _lowercase      )
           else:
                 raise ValueError(f"""unsupported encoder_hid_proj_type: {encoder_hid_proj_type}"""      )

           SCREAMING_SNAKE_CASE__       :  Tuple						     =		nn.Parameter(torch.zeros(1   ,   num_embeddings + additional_embeddings   ,   _lowercase      )      )

           if added_emb_type == "prd":
                 SCREAMING_SNAKE_CASE__       :  Any						     =		nn.Parameter(torch.zeros(1   ,   1   ,   _lowercase      )      )
           elif added_emb_type is None:
                 SCREAMING_SNAKE_CASE__       :  Union[str, Any]						     =		None
           else:
                 raise ValueError(
                     f"""`added_emb_type`: {added_emb_type} is not supported. Make sure to choose one of `'prd'` or `None`."""      )

           SCREAMING_SNAKE_CASE__       :  List[str]						     =		nn.ModuleList(
               [
                   BasicTransformerBlock(
                       _lowercase   ,   _lowercase   ,   _lowercase   ,   dropout=_lowercase   ,   activation_fn='''gelu'''   ,   attention_bias=_lowercase   ,   )
                   for d in range(_lowercase      )
               ]      )

           if norm_in_type == "layer":
                 SCREAMING_SNAKE_CASE__       :  Optional[int]						     =		nn.LayerNorm(_lowercase      )
           elif norm_in_type is None:
                 SCREAMING_SNAKE_CASE__       :  Tuple						     =		None
           else:
                 raise ValueError(f"""Unsupported norm_in_type: {norm_in_type}."""      )

           SCREAMING_SNAKE_CASE__       :  List[Any]						     =		nn.LayerNorm(_lowercase      )

           SCREAMING_SNAKE_CASE__       :  int						     =		nn.Linear(_lowercase   ,   _lowercase      )

           SCREAMING_SNAKE_CASE__       :  Optional[Any]						     =		torch.full(
               [num_embeddings + additional_embeddings, num_embeddings + additional_embeddings]   ,   -10000.0      )
           causal_attention_mask.triu_(1      )
           SCREAMING_SNAKE_CASE__       :  str						     =		causal_attention_mask[None, ...]
           self.register_buffer('''causal_attention_mask'''   ,   _lowercase   ,   persistent=_lowercase      )

           SCREAMING_SNAKE_CASE__       :  Dict						     =		nn.Parameter(torch.zeros(1   ,   _lowercase      )      )
           SCREAMING_SNAKE_CASE__       :  Dict						     =		nn.Parameter(torch.zeros(1   ,   _lowercase      )      )







     @property
     # Copied from diffusers.models.unet_2d_condition.UNet2DConditionModel.attn_processors
     def 							lowercase__       (						self :						Optional[Any]      ):
           SCREAMING_SNAKE_CASE__       :  Dict						     =		{}

           def fn_recursive_add_processors(_lowercase :						str   ,   _lowercase :						torch.nn.Module   ,   _lowercase :						Dict[str, AttentionProcessor]      ):
                 if hasattr(_lowercase   ,   '''set_processor'''      ):
                       SCREAMING_SNAKE_CASE__       :  Optional[int]						     =		module.processor

                 for sub_name, child in module.named_children():
                       fn_recursive_add_processors(f"""{name}.{sub_name}"""   ,   _lowercase   ,   _lowercase      )

                 return processors

           for name, module in self.named_children():
                 fn_recursive_add_processors(_lowercase   ,   _lowercase   ,   _lowercase      )

           return processors







     def 							lowercase__       (						self :						Tuple   ,   _lowercase :						Union[AttentionProcessor, Dict[str, AttentionProcessor]]      ):
           SCREAMING_SNAKE_CASE__       :  List[Any]						     =		len(self.attn_processors.keys()      )

           if isinstance(_lowercase   ,   _lowercase      ) and len(_lowercase      ) != count:
                 raise ValueError(
                     f"""A dict of processors was passed, but the number of processors {len(_lowercase      )} does not match the"""
                     f""" number of attention layers: {count}. Please make sure to pass {count} processor classes."""      )

           def fn_recursive_attn_processor(_lowercase :						str   ,   _lowercase :						torch.nn.Module   ,   _lowercase :						Tuple      ):
                 if hasattr(_lowercase   ,   '''set_processor'''      ):
                       if not isinstance(_lowercase   ,   _lowercase      ):
                             module.set_processor(_lowercase      )
                       else:
                             module.set_processor(processor.pop(f"""{name}.processor"""      )      )

                 for sub_name, child in module.named_children():
                       fn_recursive_attn_processor(f"""{name}.{sub_name}"""   ,   _lowercase   ,   _lowercase      )

           for name, module in self.named_children():
                 fn_recursive_attn_processor(_lowercase   ,   _lowercase   ,   _lowercase      )







     def 							lowercase__       (						self :						Union[str, Any]      ):
           self.set_attn_processor(AttnProcessor()      )







     def 							lowercase__       (						self :						Tuple   ,   _lowercase :						Optional[int]   ,   _lowercase :						Union[torch.Tensor, float, int]   ,   _lowercase :						torch.FloatTensor   ,   _lowercase :						Optional[torch.FloatTensor] = None   ,   _lowercase :						Optional[torch.BoolTensor] = None   ,   _lowercase :						bool = True   ,   ):
           SCREAMING_SNAKE_CASE__       :  List[str]						     =		hidden_states.shape[0]

           SCREAMING_SNAKE_CASE__       :  int						     =		timestep
           if not torch.is_tensor(_lowercase      ):
                 SCREAMING_SNAKE_CASE__       :  List[str]						     =		torch.tensor([timesteps]   ,   dtype=torch.long   ,   device=hidden_states.device      )
           elif torch.is_tensor(_lowercase      ) and len(timesteps.shape      ) == 0:
                 SCREAMING_SNAKE_CASE__       :  Dict						     =		timesteps[None].to(hidden_states.device      )

           # broadcast to batch dimension in a way that's compatible with ONNX/Core ML
           SCREAMING_SNAKE_CASE__       :  Optional[int]						     =		timesteps * torch.ones(_lowercase   ,   dtype=timesteps.dtype   ,   device=timesteps.device      )

           SCREAMING_SNAKE_CASE__       :  Optional[Any]						     =		self.time_proj(_lowercase      )

           # timesteps does not contain any weights and will always return f32 tensors
           # but time_embedding might be fp16, so we need to cast here.
           SCREAMING_SNAKE_CASE__       :  Tuple						     =		timesteps_projected.to(dtype=self.dtype      )
           SCREAMING_SNAKE_CASE__       :  Tuple						     =		self.time_embedding(_lowercase      )

           if self.embedding_proj_norm is not None:
                 SCREAMING_SNAKE_CASE__       :  str						     =		self.embedding_proj_norm(_lowercase      )

           SCREAMING_SNAKE_CASE__       :  Tuple						     =		self.embedding_proj(_lowercase      )
           if self.encoder_hidden_states_proj is not None and encoder_hidden_states is not None:
                 SCREAMING_SNAKE_CASE__       :  Dict						     =		self.encoder_hidden_states_proj(_lowercase      )
           elif self.encoder_hidden_states_proj is not None and encoder_hidden_states is None:
                 raise ValueError('''`encoder_hidden_states_proj` requires `encoder_hidden_states` to be set'''      )

           SCREAMING_SNAKE_CASE__       :  str						     =		self.proj_in(_lowercase      )

           SCREAMING_SNAKE_CASE__       :  Tuple						     =		self.positional_embedding.to(hidden_states.dtype      )

           SCREAMING_SNAKE_CASE__       :  Tuple						     =		[]
           SCREAMING_SNAKE_CASE__       :  Union[str, Any]						     =		0

           if encoder_hidden_states is not None:
                 additional_embeds.append(_lowercase      )
                 additional_embeddings_len += encoder_hidden_states.shape[1]

           if len(proj_embeddings.shape      ) == 2:
                 SCREAMING_SNAKE_CASE__       :  int						     =		proj_embeddings[:, None, :]

           if len(hidden_states.shape      ) == 2:
                 SCREAMING_SNAKE_CASE__       :  Optional[int]						     =		hidden_states[:, None, :]

           SCREAMING_SNAKE_CASE__       :  Optional[int]						     =		additional_embeds + [
               proj_embeddings,
               time_embeddings[:, None, :],
               hidden_states,
           ]

           if self.prd_embedding is not None:
                 SCREAMING_SNAKE_CASE__       :  int						     =		self.prd_embedding.to(hidden_states.dtype      ).expand(_lowercase   ,   -1   ,   -1      )
                 additional_embeds.append(_lowercase      )

           SCREAMING_SNAKE_CASE__       :  Optional[Any]						     =		torch.cat(
               _lowercase   ,   dim=1   ,   )

           # Allow positional_embedding to not include the `addtional_embeddings` and instead pad it with zeros for these additional tokens
           SCREAMING_SNAKE_CASE__       :  Any						     =		additional_embeddings_len + proj_embeddings.shape[1] + 1
           if positional_embeddings.shape[1] < hidden_states.shape[1]:
                 SCREAMING_SNAKE_CASE__       :  Union[str, Any]						     =		F.pad(
                     _lowercase   ,   (
                         0,
                         0,
                         additional_embeddings_len,
                         self.prd_embedding.shape[1] if self.prd_embedding is not None else 0,
                     )   ,   value=0.0   ,   )

           SCREAMING_SNAKE_CASE__       :  List[str]						     =		hidden_states + positional_embeddings

           if attention_mask is not None:
                 SCREAMING_SNAKE_CASE__       :  Optional[Any]						     =		(1 - attention_mask.to(hidden_states.dtype      )) * -10000.0
                 SCREAMING_SNAKE_CASE__       :  int						     =		F.pad(_lowercase   ,   (0, self.additional_embeddings)   ,   value=0.0      )
                 SCREAMING_SNAKE_CASE__       :  Tuple						     =		(attention_mask[:, None, :] + self.causal_attention_mask).to(hidden_states.dtype      )
                 SCREAMING_SNAKE_CASE__       :  Dict						     =		attention_mask.repeat_interleave(self.config.num_attention_heads   ,   dim=0      )

           if self.norm_in is not None:
                 SCREAMING_SNAKE_CASE__       :  Dict						     =		self.norm_in(_lowercase      )

           for block in self.transformer_blocks:
                 SCREAMING_SNAKE_CASE__       :  str						     =		block(_lowercase   ,   attention_mask=_lowercase      )

           SCREAMING_SNAKE_CASE__       :  Dict						     =		self.norm_out(_lowercase      )

           if self.prd_embedding is not None:
                 SCREAMING_SNAKE_CASE__       :  Any						     =		hidden_states[:, -1]
           else:
                 SCREAMING_SNAKE_CASE__       :  Dict						     =		hidden_states[:, additional_embeddings_len:]

           SCREAMING_SNAKE_CASE__       :  List[str]						     =		self.proj_to_clip_embeddings(_lowercase      )

           if not return_dict:
                 return (predicted_image_embedding,)

           return PriorTransformerOutput(predicted_image_embedding=_lowercase      )







     def 							lowercase__       (						self :						Optional[int]   ,   _lowercase :						Any      ):
           SCREAMING_SNAKE_CASE__       :  Optional[int]						     =		(prior_latents * self.clip_std) + self.clip_mean
           return prior_latents







"""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    :  Union[str, Any]	,    snake_case__    :  Dict	,    snake_case__    :  int=13	,    snake_case__    :  List[str]=7	,    snake_case__    :  Any=True	,    snake_case__    :  Any=True	,    snake_case__    :  Dict=True	,    snake_case__    :  List[Any]=True	,    snake_case__    :  List[str]=99	,    snake_case__    :  Any=32	,    snake_case__    :  List[str]=2	,    snake_case__    :  Any=4	,    snake_case__    :  Dict=37	,    snake_case__    :  Optional[int]="gelu"	,    snake_case__    :  Optional[int]=0.1	,    snake_case__    :  Dict=0.1	,    snake_case__    :  Optional[int]=512	,    snake_case__    :  Union[str, Any]=16	,    snake_case__    :  str=2	,    snake_case__    :  Dict=0.02	,    snake_case__    :  Tuple=3	,    snake_case__    :  List[Any]=4	,    snake_case__    :  List[Any]=None	,    snake_case__    :  str=0	,    ):
							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     _SCREAMING_SNAKE_CASE    (						self    :  Optional[int]  ):
							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=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     _SCREAMING_SNAKE_CASE    (						self    :  Optional[Any]	,    snake_case__    :  int	,    snake_case__    :  Optional[int]	,    snake_case__    :  Optional[Any]	,    snake_case__    :  str	,    snake_case__    :  Tuple	,    snake_case__    :  Dict	,    snake_case__    :  List[Any]  ):
							lowerCAmelCase__   = TFDPRContextEncoder(config=snake_case__  )
							lowerCAmelCase__   = model(snake_case__	,    attention_mask=snake_case__	,    token_type_ids=snake_case__  )
							lowerCAmelCase__   = model(snake_case__	,    token_type_ids=snake_case__  )
							lowerCAmelCase__   = model(snake_case__  )
							self.parent.assertEqual(result.pooler_output.shape	,    (self.batch_size, self.projection_dim or self.hidden_size)  )




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




					def     _SCREAMING_SNAKE_CASE    (						self    :  Tuple	,    snake_case__    :  Tuple	,    snake_case__    :  Any	,    snake_case__    :  str	,    snake_case__    :  Tuple	,    snake_case__    :  List[str]	,    snake_case__    :  List[str]	,    snake_case__    :  Tuple  ):
							lowerCAmelCase__   = TFDPRReader(config=snake_case__  )
							lowerCAmelCase__   = model(snake_case__	,    attention_mask=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     _SCREAMING_SNAKE_CASE    (						self    :  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    a_   (  __UpperCamelCase			,		__UpperCamelCase			,		unittest.TestCase      ):
					UpperCamelCase_			:						Optional[Any]      =     (
					    (
					        TFDPRContextEncoder,
					        TFDPRQuestionEncoder,
					        TFDPRReader,
					    )
					    if is_tf_available()
					    else ()
					)
					UpperCamelCase_			:						Any      =     {"feature-extraction": TFDPRQuestionEncoder} if is_tf_available() else {}

					UpperCamelCase_			:						Optional[Any]      =     False
					UpperCamelCase_			:						Tuple      =     False
					UpperCamelCase_			:						Tuple      =     False
					UpperCamelCase_			:						Optional[int]      =     False
					UpperCamelCase_			:						Optional[Any]      =     False




					def     _SCREAMING_SNAKE_CASE    (						self    :  Any  ):
							lowerCAmelCase__   = TFDPRModelTester(self  )
							lowerCAmelCase__   = ConfigTester(self	,    config_class=snake_case__	,    hidden_size=37  )




					def     _SCREAMING_SNAKE_CASE    (						self    :  Optional[int]  ):
							self.config_tester.run_common_tests()




					def     _SCREAMING_SNAKE_CASE    (						self    :  Dict  ):
							lowerCAmelCase__   = self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_dpr_context_encoder(*snake_case__  )




					def     _SCREAMING_SNAKE_CASE    (						self    :  Tuple  ):
							lowerCAmelCase__   = self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_dpr_question_encoder(*snake_case__  )




					def     _SCREAMING_SNAKE_CASE    (						self    :  int  ):
							lowerCAmelCase__   = self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_dpr_reader(*snake_case__  )




					@slow
					def     _SCREAMING_SNAKE_CASE    (						self    :  List[Any]  ):
							for model_name in TF_DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
									lowerCAmelCase__   = TFDPRContextEncoder.from_pretrained(snake_case__  )
									self.assertIsNotNone(snake_case__  )

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

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

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

@require_tf
class    a_   (  unittest.TestCase      ):




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

							lowerCAmelCase__   = tf.constant(
							    [[101, 7592, 1010, 2003, 2026, 3899, 10140, 1029, 102]]  )  # [CLS] hello, is my dog cute? [SEP]
							lowerCAmelCase__   = model(snake_case__  )[0]  # embedding shape = (1, 768)
							# compare the actual values for a slice.
							lowerCAmelCase__   = 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  )  )




