"""simple docstring"""




import unittest

from transformers import (
    MODEL_FOR_CAUSAL_LM_MAPPING,
    TF_MODEL_FOR_CAUSAL_LM_MAPPING,
    TextGenerationPipeline,
    logging,
    pipeline,
)
from transformers.testing_utils import (
    CaptureLogger,
    is_pipeline_test,
    require_accelerate,
    require_tf,
    require_torch,
    require_torch_gpu,
    require_torch_or_tf,
)

from .test_pipelines_common import ANY

@is_pipeline_test
@require_torch_or_tf
class    a_   (  unittest.TestCase      ):
					UpperCamelCase_			:						List[Any]      =     MODEL_FOR_CAUSAL_LM_MAPPING
					UpperCamelCase_			:						Optional[Any]      =     TF_MODEL_FOR_CAUSAL_LM_MAPPING




					@require_torch
					def     _SCREAMING_SNAKE_CASE    (						self    :  Union[str, Any]  ):
							lowerCAmelCase__   = pipeline(task="""text-generation"""	,    model="""sshleifer/tiny-ctrl"""	,    framework="""pt"""  )
							# Using `do_sample=False` to force deterministic output
							lowerCAmelCase__   = text_generator("""This is a test"""	,    do_sample=snake_case__  )
							self.assertEqual(
							    snake_case__	,    [
							        {
							            """generated_text""": (
							                """This is a test ☃ ☃ segmental segmental segmental 议议eski eski flutter flutter Lacy oscope."""
							                """ oscope. FiliFili@@"""
							            )
							        }
							    ]	,    )

							lowerCAmelCase__   = text_generator(["""This is a test""", """This is a second test"""]  )
							self.assertEqual(
							    snake_case__	,    [
							        [
							            {
							                """generated_text""": (
							                    """This is a test ☃ ☃ segmental segmental segmental 议议eski eski flutter flutter Lacy oscope."""
							                    """ oscope. FiliFili@@"""
							                )
							            }
							        ],
							        [
							            {
							                """generated_text""": (
							                    """This is a second test ☃ segmental segmental segmental 议议eski eski flutter flutter Lacy"""
							                    """ oscope. oscope. FiliFili@@"""
							                )
							            }
							        ],
							    ]	,    )

							lowerCAmelCase__   = text_generator("""This is a test"""	,    do_sample=snake_case__	,    num_return_sequences=2	,    return_tensors=snake_case__  )
							self.assertEqual(
							    snake_case__	,    [
							        {"""generated_token_ids""": ANY(snake_case__  )},
							        {"""generated_token_ids""": ANY(snake_case__  )},
							    ]	,    )
							lowerCAmelCase__   = text_generator.model.config.eos_token_id
							lowerCAmelCase__   = """<pad>"""
							lowerCAmelCase__   = text_generator(
							    ["""This is a test""", """This is a second test"""]	,    do_sample=snake_case__	,    num_return_sequences=2	,    batch_size=2	,    return_tensors=snake_case__	,    )
							self.assertEqual(
							    snake_case__	,    [
							        [
							            {"""generated_token_ids""": ANY(snake_case__  )},
							            {"""generated_token_ids""": ANY(snake_case__  )},
							        ],
							        [
							            {"""generated_token_ids""": ANY(snake_case__  )},
							            {"""generated_token_ids""": ANY(snake_case__  )},
							        ],
							    ]	,    )




					@require_tf
					def     _SCREAMING_SNAKE_CASE    (						self    :  Any  ):
							lowerCAmelCase__   = pipeline(task="""text-generation"""	,    model="""sshleifer/tiny-ctrl"""	,    framework="""tf"""  )

							# Using `do_sample=False` to force deterministic output
							lowerCAmelCase__   = text_generator("""This is a test"""	,    do_sample=snake_case__  )
							self.assertEqual(
							    snake_case__	,    [
							        {
							            """generated_text""": (
							                """This is a test FeyFeyFey(Croatis.), s.), Cannes Cannes Cannes 閲閲Cannes Cannes Cannes 攵"""
							                """ please,"""
							            )
							        }
							    ]	,    )

							lowerCAmelCase__   = text_generator(["""This is a test""", """This is a second test"""]	,    do_sample=snake_case__  )
							self.assertEqual(
							    snake_case__	,    [
							        [
							            {
							                """generated_text""": (
							                    """This is a test FeyFeyFey(Croatis.), s.), Cannes Cannes Cannes 閲閲Cannes Cannes Cannes 攵"""
							                    """ please,"""
							                )
							            }
							        ],
							        [
							            {
							                """generated_text""": (
							                    """This is a second test Chieftain Chieftain prefecture prefecture prefecture Cannes Cannes"""
							                    """ Cannes 閲閲Cannes Cannes Cannes 攵 please,"""
							                )
							            }
							        ],
							    ]	,    )




					def     _SCREAMING_SNAKE_CASE    (						self    :  Any	,    snake_case__    :  Optional[Any]	,    snake_case__    :  Tuple	,    snake_case__    :  List[Any]  ):
							lowerCAmelCase__   = TextGenerationPipeline(model=snake_case__	,    tokenizer=snake_case__  )
							return text_generator, ["This is a test", "Another test"]




					def     _SCREAMING_SNAKE_CASE    (						self    :  Any  ):
							lowerCAmelCase__   = """Hello I believe in"""
							lowerCAmelCase__   = pipeline("""text-generation"""	,    model="""hf-internal-testing/tiny-random-gpt2"""  )
							lowerCAmelCase__   = text_generator(snake_case__  )
							self.assertEqual(
							    snake_case__	,    [{"""generated_text""": """Hello I believe in fe fe fe fe fe fe fe fe fe fe fe fe"""}]	,    )

							lowerCAmelCase__   = text_generator(snake_case__	,    stop_sequence=""" fe"""  )
							self.assertEqual(snake_case__	,    [{"""generated_text""": """Hello I believe in fe"""}]  )




					def     _SCREAMING_SNAKE_CASE    (						self    :  Tuple	,    snake_case__    :  int	,    snake_case__    :  Union[str, Any]  ):
							lowerCAmelCase__   = text_generator.model
							lowerCAmelCase__   = text_generator.tokenizer

							lowerCAmelCase__   = text_generator("""This is a test"""  )
							self.assertEqual(snake_case__	,    [{"""generated_text""": ANY(snake_case__  )}]  )
							self.assertTrue(outputs[0]["""generated_text"""].startswith("""This is a test"""  )  )

							lowerCAmelCase__   = text_generator("""This is a test"""	,    return_full_text=snake_case__  )
							self.assertEqual(snake_case__	,    [{"""generated_text""": ANY(snake_case__  )}]  )
							self.assertNotIn("""This is a test"""	,    outputs[0]["""generated_text"""]  )

							lowerCAmelCase__   = pipeline(task="""text-generation"""	,    model=snake_case__	,    tokenizer=snake_case__	,    return_full_text=snake_case__  )
							lowerCAmelCase__   = text_generator("""This is a test"""  )
							self.assertEqual(snake_case__	,    [{"""generated_text""": ANY(snake_case__  )}]  )
							self.assertNotIn("""This is a test"""	,    outputs[0]["""generated_text"""]  )

							lowerCAmelCase__   = text_generator("""This is a test"""	,    return_full_text=snake_case__  )
							self.assertEqual(snake_case__	,    [{"""generated_text""": ANY(snake_case__  )}]  )
							self.assertTrue(outputs[0]["""generated_text"""].startswith("""This is a test"""  )  )

							lowerCAmelCase__   = text_generator(["""This is great !""", """Something else"""]	,    num_return_sequences=2	,    do_sample=snake_case__  )
							self.assertEqual(
							    snake_case__	,    [
							        [{"""generated_text""": ANY(snake_case__  )}, {"""generated_text""": ANY(snake_case__  )}],
							        [{"""generated_text""": ANY(snake_case__  )}, {"""generated_text""": ANY(snake_case__  )}],
							    ]	,    )

							if text_generator.tokenizer.pad_token is not None:
									lowerCAmelCase__   = text_generator(
									    ["""This is great !""", """Something else"""]	,    num_return_sequences=2	,    batch_size=2	,    do_sample=snake_case__  )
									self.assertEqual(
									    snake_case__	,    [
									        [{"""generated_text""": ANY(snake_case__  )}, {"""generated_text""": ANY(snake_case__  )}],
									        [{"""generated_text""": ANY(snake_case__  )}, {"""generated_text""": ANY(snake_case__  )}],
									    ]	,    )

							with self.assertRaises(snake_case__  ):
									lowerCAmelCase__   = text_generator("""test"""	,    return_full_text=snake_case__	,    return_text=snake_case__  )
							with self.assertRaises(snake_case__  ):
									lowerCAmelCase__   = text_generator("""test"""	,    return_full_text=snake_case__	,    return_tensors=snake_case__  )
							with self.assertRaises(snake_case__  ):
									lowerCAmelCase__   = text_generator("""test"""	,    return_text=snake_case__	,    return_tensors=snake_case__  )

							# Empty prompt is slighly special
							# it requires BOS token to exist.
							# Special case for Pegasus which will always append EOS so will
							# work even without BOS.
							if (
							    text_generator.tokenizer.bos_token_id is not None
							    or "Pegasus" in tokenizer.__class__.__name__
							    or "Git" in model.__class__.__name__
							):
									lowerCAmelCase__   = text_generator(""""""  )
									self.assertEqual(snake_case__	,    [{"""generated_text""": ANY(snake_case__  )}]  )
							else:
									with self.assertRaises((ValueError, AssertionError)  ):
											lowerCAmelCase__   = text_generator(""""""  )

							if text_generator.framework == "tf":
									# TF generation does not support max_new_tokens, and it's impossible
									# to control long generation with only max_length without
									# fancy calculation, dismissing tests for now.
									return
							# We don't care about infinite range models.
							# They already work.
							# Skip this test for XGLM, since it uses sinusoidal positional embeddings which are resized on-the-fly.
							lowerCAmelCase__   = ["""RwkvForCausalLM""", """XGLMForCausalLM""", """GPTNeoXForCausalLM"""]
							if (
							    tokenizer.model_max_length < 10000
							    and text_generator.model.__class__.__name__ not in EXTRA_MODELS_CAN_HANDLE_LONG_INPUTS
							):
									# Handling of large generations
									with self.assertRaises((RuntimeError, IndexError, ValueError, AssertionError)  ):
											text_generator("""This is a test""" * 500	,    max_new_tokens=20  )

									lowerCAmelCase__   = text_generator("""This is a test""" * 500	,    handle_long_generation="""hole"""	,    max_new_tokens=20  )
									# Hole strategy cannot work
									with self.assertRaises(snake_case__  ):
											text_generator(
											    """This is a test""" * 500	,    handle_long_generation="""hole"""	,    max_new_tokens=tokenizer.model_max_length + 10	,    )




					@require_torch
					@require_accelerate
					@require_torch_gpu
					def     _SCREAMING_SNAKE_CASE    (						self    :  str  ):
							import torch

							# Classic `model_kwargs`
							lowerCAmelCase__   = pipeline(
							    model="""hf-internal-testing/tiny-random-bloom"""	,    model_kwargs={"""device_map""": """auto""", """torch_dtype""": torch.bfloataa}	,    )
							self.assertEqual(pipe.model.device	,    torch.device(0  )  )
							self.assertEqual(pipe.model.lm_head.weight.dtype	,    torch.bfloataa  )
							lowerCAmelCase__   = pipe("""This is a test"""  )
							self.assertEqual(
							    snake_case__	,    [
							        {
							            """generated_text""": (
							                """This is a test test test test test test test test test test test test test test test test"""
							                """ test"""
							            )
							        }
							    ]	,    )

							# Upgraded those two to real pipeline arguments (they just get sent for the model as they're unlikely to mean anything else.)
							lowerCAmelCase__   = pipeline(model="""hf-internal-testing/tiny-random-bloom"""	,    device_map="""auto"""	,    torch_dtype=torch.bfloataa  )
							self.assertEqual(pipe.model.device	,    torch.device(0  )  )
							self.assertEqual(pipe.model.lm_head.weight.dtype	,    torch.bfloataa  )
							lowerCAmelCase__   = pipe("""This is a test"""  )
							self.assertEqual(
							    snake_case__	,    [
							        {
							            """generated_text""": (
							                """This is a test test test test test test test test test test test test test test test test"""
							                """ test"""
							            )
							        }
							    ]	,    )

							# torch_dtype will be automatically set to float32 if not provided - check: https://github.com/huggingface/transformers/pull/20602
							lowerCAmelCase__   = pipeline(model="""hf-internal-testing/tiny-random-bloom"""	,    device_map="""auto"""  )
							self.assertEqual(pipe.model.device	,    torch.device(0  )  )
							self.assertEqual(pipe.model.lm_head.weight.dtype	,    torch.floataa  )
							lowerCAmelCase__   = pipe("""This is a test"""  )
							self.assertEqual(
							    snake_case__	,    [
							        {
							            """generated_text""": (
							                """This is a test test test test test test test test test test test test test test test test"""
							                """ test"""
							            )
							        }
							    ]	,    )




					@require_torch
					@require_torch_gpu
					def     _SCREAMING_SNAKE_CASE    (						self    :  Optional[int]  ):
							import torch

							lowerCAmelCase__   = pipeline(model="""hf-internal-testing/tiny-random-bloom"""	,    device=0	,    torch_dtype=torch.floataa  )
							pipe("""This is a test"""  )




					@require_torch
					@require_accelerate
					@require_torch_gpu
					def     _SCREAMING_SNAKE_CASE    (						self    :  Union[str, Any]  ):
							import torch

							lowerCAmelCase__   = pipeline(model="""hf-internal-testing/tiny-random-bloom"""	,    device_map="""auto"""	,    torch_dtype=torch.floataa  )
							pipe("""This is a test"""	,    do_sample=snake_case__	,    top_p=0.5  )




					def     _SCREAMING_SNAKE_CASE    (						self    :  Union[str, Any]  ):
							lowerCAmelCase__   = """Hello world"""
							lowerCAmelCase__   = pipeline("""text-generation"""	,    model="""hf-internal-testing/tiny-random-gpt2"""  )
							if text_generator.model.framework == "tf":
									lowerCAmelCase__   = logging.get_logger("""transformers.generation.tf_utils"""  )
							else:
									lowerCAmelCase__   = logging.get_logger("""transformers.generation.utils"""  )
							lowerCAmelCase__   = """Both `max_new_tokens`"""  # The beggining of the message to be checked in this test

							# Both are set by the user -> log warning
							with CaptureLogger(snake_case__  ) as cl:
									lowerCAmelCase__   = text_generator(snake_case__	,    max_length=10	,    max_new_tokens=1  )
							self.assertIn(snake_case__	,    cl.out  )

							# The user only sets one -> no warning
							with CaptureLogger(snake_case__  ) as cl:
									lowerCAmelCase__   = text_generator(snake_case__	,    max_new_tokens=1  )
							self.assertNotIn(snake_case__	,    cl.out  )

							with CaptureLogger(snake_case__  ) as cl:
									lowerCAmelCase__   = text_generator(snake_case__	,    max_length=10  )
							self.assertNotIn(snake_case__	,    cl.out  )





"""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  )  )




