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







   """simple docstring"""

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

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

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

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

        _A    		=  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, )
        _A    		=  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      :			Tuple, UpperCamelCase__      :			Any, UpperCamelCase__      :			Any, UpperCamelCase__      :			Tuple, UpperCamelCase__      :			List[Any], UpperCamelCase__      :			Any, UpperCamelCase__      :			List[Any], UpperCamelCase__      :			Union[str, Any]     )  ->			int:
        _A    		=  TFDPRContextEncoder(config=UpperCamelCase__     )
        _A    		=  model(UpperCamelCase__, attention_mask=UpperCamelCase__, token_type_ids=UpperCamelCase__     )
        _A    		=  model(UpperCamelCase__, token_type_ids=UpperCamelCase__     )
        _A    		=  model(UpperCamelCase__     )
        self.parent.assertEqual(result.pooler_output.shape, (self.batch_size, self.projection_dim or self.hidden_size)     )
   def 	__UpperCAmelCase   (      self      :			Dict, UpperCamelCase__      :			int, UpperCamelCase__      :			List[Any], UpperCamelCase__      :			List[str], UpperCamelCase__      :			List[Any], UpperCamelCase__      :			Tuple, UpperCamelCase__      :			str, UpperCamelCase__      :			str     )  ->			int:
        _A    		=  TFDPRQuestionEncoder(config=UpperCamelCase__     )
        _A    		=  model(UpperCamelCase__, attention_mask=UpperCamelCase__, token_type_ids=UpperCamelCase__     )
        _A    		=  model(UpperCamelCase__, token_type_ids=UpperCamelCase__     )
        _A    		=  model(UpperCamelCase__     )
        self.parent.assertEqual(result.pooler_output.shape, (self.batch_size, self.projection_dim or self.hidden_size)     )
   def 	__UpperCAmelCase   (      self      :			int, UpperCamelCase__      :			Union[str, Any], UpperCamelCase__      :			List[str], UpperCamelCase__      :			Tuple, UpperCamelCase__      :			List[str], UpperCamelCase__      :			Tuple, UpperCamelCase__      :			Optional[int], UpperCamelCase__      :			Optional[int]     )  ->			Any:
        _A    		=  TFDPRReader(config=UpperCamelCase__     )
        _A    		=  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      :			Dict     )  ->			Dict:
        _A    		=  self.prepare_config_and_inputs()
        (
            (
            _A
        )		,       (
            _A
        )		,       (
            _A
        )		,       (
            _A
        )		,       (
            _A
        )		,       (
            _A
        )		,       (
            _A
        )		,       
        )    		=  config_and_inputs
        _A    		=  {'input_ids': input_ids}
        return config, inputs_dict







@require_tf
class lowercase_       (		_UpperCamelCase    ,    _UpperCamelCase    ,    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 	__UpperCAmelCase   (      self      :			Optional[int]     )  ->			Union[str, Any]:
        _A    		=  TFDPRModelTester(self     )
        _A    		=  ConfigTester(self, config_class=UpperCamelCase__, hidden_size=37     )
   def 	__UpperCAmelCase   (      self      :			List[str]     )  ->			Union[str, Any]:
        self.config_tester.run_common_tests()
   def 	__UpperCAmelCase   (      self      :			List[str]     )  ->			List[str]:
        _A    		=  self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_dpr_context_encoder(*UpperCamelCase__     )
   def 	__UpperCAmelCase   (      self      :			int     )  ->			List[str]:
        _A    		=  self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_dpr_question_encoder(*UpperCamelCase__     )
   def 	__UpperCAmelCase   (      self      :			int     )  ->			Tuple:
        _A    		=  self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_dpr_reader(*UpperCamelCase__     )

   @slow
   def 	__UpperCAmelCase   (      self      :			List[Any]     )  ->			Union[str, Any]:
        for model_name in TF_DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
             _A    		=  TFDPRContextEncoder.from_pretrained(UpperCamelCase__     )
             self.assertIsNotNone(UpperCamelCase__     )

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

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

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







@require_tf
class lowercase_       (		unittest.TestCase			):







   """simple docstring"""

   @slow
   def 	__UpperCAmelCase   (      self      :			Union[str, Any]     )  ->			Optional[Any]:
        _A    		=  TFDPRQuestionEncoder.from_pretrained('facebook/dpr-question_encoder-single-nq-base'     )

        _A    		=  tf.constant(
            [[1_01, 75_92, 10_10, 20_03, 20_26, 38_99, 1_01_40, 10_29, 1_02]]     )  # [CLS] hello, is my dog cute? [SEP]
        _A    		=  model(UpperCamelCase__     )[0]  # embedding shape = (1, 768)
        # compare the actual values for a slice.
        _A    		=  tf.constant(
            [
                [
                    0.03_236_253,
                    0.12_753_335,
                    0.16_818_509,
                    0.00_279_786,
                    0.3_896_933,
                    0.24_264_945,
                    0.2_178_971,
                    -0.02_335_227,
                    -0.08_481_959,
                    -0.14_324_117,
                ]
            ]     )
        self.assertTrue(numpy.allclose(output[:, :10].numpy(), expected_slice.numpy(), atol=1e-4     )     )










'''simple docstring'''


import warnings

from ...utils import logging
from .image_processing_yolos import YolosImageProcessor


_SCREAMING_SNAKE_CASE									=				logging.get_logger(__name__)

class  lowerCAmelCase_		(		__magic_name__		):




 def __init__(						self      ,  *_lowerCAmelCase      ,  **_lowerCAmelCase		)     ->				None:
     warnings.warn(
         "The class YolosFeatureExtractor is deprecated and will be removed in version 5 of Transformers. Please"
         " use YolosImageProcessor instead."      ,  _lowerCAmelCase      ,  )
     super().__init__(*_lowerCAmelCase      ,  **_lowerCAmelCase		)


