
'''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       _lowerCAmelCase   :







							'''simple docstring'''

							def __init__(self  ,  UpperCAmelCase  ,  UpperCAmelCase=13  ,  UpperCAmelCase=7  ,  UpperCAmelCase=True  ,  UpperCAmelCase=True  ,  UpperCAmelCase=True  ,  UpperCAmelCase=True  ,  UpperCAmelCase=99  ,  UpperCAmelCase=32  ,  UpperCAmelCase=2  ,  UpperCAmelCase=4  ,  UpperCAmelCase=37  ,  UpperCAmelCase="gelu"  ,  UpperCAmelCase=0.1  ,  UpperCAmelCase=0.1  ,  UpperCAmelCase=512  ,  UpperCAmelCase=16  ,  UpperCAmelCase=2  ,  UpperCAmelCase=0.02  ,  UpperCAmelCase=3  ,  UpperCAmelCase=4  ,  UpperCAmelCase=None  ,  UpperCAmelCase=0  ,  )					->       str:
														_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 	lowercase							(self  )					->       List[str]:
														_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=UpperCAmelCase  ,  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 	lowercase							(self  ,  UpperCAmelCase  ,  UpperCAmelCase  ,  UpperCAmelCase  ,  UpperCAmelCase  ,  UpperCAmelCase  ,  UpperCAmelCase  ,  UpperCAmelCase  )					->       List[Any]:
														_snake_case       =  TFDPRContextEncoder(config=UpperCAmelCase  )
														_snake_case       =  model(UpperCAmelCase  ,  attention_mask=UpperCAmelCase  ,  token_type_ids=UpperCAmelCase  )
														_snake_case       =  model(UpperCAmelCase  ,  token_type_ids=UpperCAmelCase  )
														_snake_case       =  model(UpperCAmelCase  )
														self.parent.assertEqual(result.pooler_output.shape  ,  (self.batch_size, self.projection_dim or self.hidden_size)  )

							def 	lowercase							(self  ,  UpperCAmelCase  ,  UpperCAmelCase  ,  UpperCAmelCase  ,  UpperCAmelCase  ,  UpperCAmelCase  ,  UpperCAmelCase  ,  UpperCAmelCase  )					->       Any:
														_snake_case       =  TFDPRQuestionEncoder(config=UpperCAmelCase  )
														_snake_case       =  model(UpperCAmelCase  ,  attention_mask=UpperCAmelCase  ,  token_type_ids=UpperCAmelCase  )
														_snake_case       =  model(UpperCAmelCase  ,  token_type_ids=UpperCAmelCase  )
														_snake_case       =  model(UpperCAmelCase  )
														self.parent.assertEqual(result.pooler_output.shape  ,  (self.batch_size, self.projection_dim or self.hidden_size)  )

							def 	lowercase							(self  ,  UpperCAmelCase  ,  UpperCAmelCase  ,  UpperCAmelCase  ,  UpperCAmelCase  ,  UpperCAmelCase  ,  UpperCAmelCase  ,  UpperCAmelCase  )					->       Union[str, Any]:
														_snake_case       =  TFDPRReader(config=UpperCAmelCase  )
														_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 	lowercase							(self  )					->       Tuple:
														_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       _lowerCAmelCase   (   __snake_case					,							__snake_case					,							unittest.TestCase				):







							'''simple docstring'''

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

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

							def 	lowercase							(self  )					->       Dict:
														_snake_case       =  TFDPRModelTester(self  )
														_snake_case       =  ConfigTester(self  ,  config_class=UpperCAmelCase  ,  hidden_size=37  )

							def 	lowercase							(self  )					->       str:
														self.config_tester.run_common_tests()

							def 	lowercase							(self  )					->       List[str]:
														_snake_case       =  self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_dpr_context_encoder(*UpperCAmelCase  )

							def 	lowercase							(self  )					->       List[str]:
														_snake_case       =  self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_dpr_question_encoder(*UpperCAmelCase  )

							def 	lowercase							(self  )					->       Optional[Any]:
														_snake_case       =  self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_dpr_reader(*UpperCAmelCase  )





							@slow
							def 	lowercase							(self  )					->       List[Any]:
														for model_name in TF_DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																					_snake_case       =  TFDPRContextEncoder.from_pretrained(UpperCAmelCase  )
																					self.assertIsNotNone(UpperCAmelCase  )

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

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

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


@require_tf
class       _lowerCAmelCase   (   unittest.TestCase				):







							'''simple docstring'''

							@slow
							def 	lowercase							(self  )					->       str:
														_snake_case       =  TFDPRQuestionEncoder.from_pretrained("""facebook/dpr-question_encoder-single-nq-base"""  )

														_snake_case       =  tf.constant(
														    [[101, 7592, 1010, 2003, 2026, 3899, 10140, 1029, 102]]  )  # [CLS] hello, is my dog cute? [SEP]
														_snake_case       =  model(UpperCAmelCase  )[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  )  )

'''simple docstring'''
from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_torch_available,
)


__lowerCAmelCase												=	{
    'configuration_encodec': [
        'ENCODEC_PRETRAINED_CONFIG_ARCHIVE_MAP',
        'EncodecConfig',
    ],
    'feature_extraction_encodec': ['EncodecFeatureExtractor'],
}

try:
				if not is_torch_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				__lowerCAmelCase												=	[
				    'ENCODEC_PRETRAINED_MODEL_ARCHIVE_LIST',
				    'EncodecModel',
				    'EncodecPreTrainedModel',
				]

if TYPE_CHECKING:
				from .configuration_encodec import (
				    ENCODEC_PRETRAINED_CONFIG_ARCHIVE_MAP,
				    EncodecConfig,
				)
				from .feature_extraction_encodec import EncodecFeatureExtractor

				try:
								if not is_torch_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .modeling_encodec import (
								    ENCODEC_PRETRAINED_MODEL_ARCHIVE_LIST,
								    EncodecModel,
								    EncodecPreTrainedModel,
								)

else:
				import sys

				__lowerCAmelCase												=	_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)