



'''simple docstring'''





from __future__ import annotations

import unittest

from transformers import DistilBertConfig, 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 tensorflow as tf

  from transformers.models.distilbert.modeling_tf_distilbert import (
      TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
      TFDistilBertForMaskedLM,
      TFDistilBertForMultipleChoice,
      TFDistilBertForQuestionAnswering,
      TFDistilBertForSequenceClassification,
      TFDistilBertForTokenClassification,
      TFDistilBertModel,
  )






class __A			:



 '''simple docstring'''







 def __init__(self ,   A ,   )    ->     Optional[Any]:


      """simple docstring"""



      _a      =  parent
      _a      =  13
      _a      =  7
      _a      =  True
      _a      =  True
      _a      =  False
      _a      =  True
      _a      =  99
      _a      =  32
      _a      =  2
      _a      =  4
      _a      =  37
      _a      =  '''gelu'''
      _a      =  0.1
      _a      =  0.1
      _a      =  512
      _a      =  16
      _a      =  2
      _a      =  0.02
      _a      =  3
      _a      =  4
      _a      =  None



 def 					a__  (self       )    ->     str:


      """simple docstring"""



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

      _a      =  None
      if self.use_input_mask:
           _a      =  random_attention_mask([self.batch_size, self.seq_length]       )

      _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      =  DistilBertConfig(
          vocab_size=self.vocab_size ,   dim=self.hidden_size ,   n_layers=self.num_hidden_layers ,   n_heads=self.num_attention_heads ,   hidden_dim=self.intermediate_size ,   hidden_act=self.hidden_act ,   dropout=self.hidden_dropout_prob ,   attention_dropout=self.attention_probs_dropout_prob ,   max_position_embeddings=self.max_position_embeddings ,   initializer_range=self.initializer_range ,   )

      return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels



 def 					a__  (self ,   A ,   A ,   A ,   A ,   A ,   A       )    ->     int:


      """simple docstring"""



      _a      =  TFDistilBertModel(config=A       )
      _a      =  {'''input_ids''': input_ids, '''attention_mask''': input_mask}

      _a      =  model(A       )

      _a      =  [input_ids, input_mask]

      _a      =  model(A       )

      self.parent.assertEqual(result.last_hidden_state.shape ,   (self.batch_size, self.seq_length, self.hidden_size)       )



 def 					a__  (self ,   A ,   A ,   A ,   A ,   A ,   A       )    ->     Dict:


      """simple docstring"""



      _a      =  TFDistilBertForMaskedLM(config=A       )
      _a      =  {'''input_ids''': input_ids, '''attention_mask''': input_mask}
      _a      =  model(A       )
      self.parent.assertEqual(result.logits.shape ,   (self.batch_size, self.seq_length, self.vocab_size)       )



 def 					a__  (self ,   A ,   A ,   A ,   A ,   A ,   A       )    ->     str:


      """simple docstring"""



      _a      =  TFDistilBertForQuestionAnswering(config=A       )
      _a      =  {
          '''input_ids''': input_ids,
          '''attention_mask''': input_mask,
      }
      _a      =  model(A       )
      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)       )



 def 					a__  (self ,   A ,   A ,   A ,   A ,   A ,   A       )    ->     List[str]:


      """simple docstring"""



      _a      =  self.num_labels
      _a      =  TFDistilBertForSequenceClassification(A       )
      _a      =  {'''input_ids''': input_ids, '''attention_mask''': input_mask}
      _a      =  model(A       )
      self.parent.assertEqual(result.logits.shape ,   (self.batch_size, self.num_labels)       )



 def 					a__  (self ,   A ,   A ,   A ,   A ,   A ,   A       )    ->     Optional[Any]:


      """simple docstring"""



      _a      =  self.num_choices
      _a      =  TFDistilBertForMultipleChoice(A       )
      _a      =  tf.tile(tf.expand_dims(A ,   1       ) ,   (1, self.num_choices, 1)       )
      _a      =  tf.tile(tf.expand_dims(A ,   1       ) ,   (1, self.num_choices, 1)       )
      _a      =  {
          '''input_ids''': multiple_choice_inputs_ids,
          '''attention_mask''': multiple_choice_input_mask,
      }
      _a      =  model(A       )
      self.parent.assertEqual(result.logits.shape ,   (self.batch_size, self.num_choices)       )



 def 					a__  (self ,   A ,   A ,   A ,   A ,   A ,   A       )    ->     int:


      """simple docstring"""



      _a      =  self.num_labels
      _a      =  TFDistilBertForTokenClassification(A       )
      _a      =  {'''input_ids''': input_ids, '''attention_mask''': input_mask}
      _a      =  model(A       )
      self.parent.assertEqual(result.logits.shape ,   (self.batch_size, self.seq_length, self.num_labels)       )



 def 					a__  (self       )    ->     Optional[Any]:


      """simple docstring"""



      _a      =  self.prepare_config_and_inputs()
      ((_a)  ,    (_a)  ,    (_a)  ,    (_a)  ,    (_a)  ,    (_a))      =  config_and_inputs
      _a      =  {'''input_ids''': input_ids, '''attention_mask''': input_mask}
      return config, inputs_dict






@require_tf
class __A			(  A   ,   A   ,   unittest.TestCase						):



 '''simple docstring'''







 __lowerCamelCase    :       List[Any]          =       (
     (
         TFDistilBertModel,
         TFDistilBertForMaskedLM,
         TFDistilBertForQuestionAnswering,
         TFDistilBertForSequenceClassification,
         TFDistilBertForTokenClassification,
         TFDistilBertForMultipleChoice,
     )
     if is_tf_available()
     else None
 )
 __lowerCamelCase    :       List[Any]          =       (
     {
         'feature-extraction': TFDistilBertModel,
         'fill-mask': TFDistilBertForMaskedLM,
         'question-answering': TFDistilBertForQuestionAnswering,
         'text-classification': TFDistilBertForSequenceClassification,
         'token-classification': TFDistilBertForTokenClassification,
         'zero-shot': TFDistilBertForSequenceClassification,
     }
     if is_tf_available()
     else {}
 )
 __lowerCamelCase    :       List[Any]          =       False
 __lowerCamelCase    :       Dict          =       False



 def 					a__  (self       )    ->     Tuple:


      """simple docstring"""



      _a      =  TFDistilBertModelTester(self       )
      _a      =  ConfigTester(self ,   config_class=A ,   dim=37       )



 def 					a__  (self       )    ->     Tuple:


      """simple docstring"""



      self.config_tester.run_common_tests()



 def 					a__  (self       )    ->     Tuple:


      """simple docstring"""



      _a      =  self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_distilbert_model(*A       )



 def 					a__  (self       )    ->     List[str]:


      """simple docstring"""



      _a      =  self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_distilbert_for_masked_lm(*A       )



 def 					a__  (self       )    ->     Optional[Any]:


      """simple docstring"""



      _a      =  self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_distilbert_for_question_answering(*A       )



 def 					a__  (self       )    ->     Optional[Any]:


      """simple docstring"""



      _a      =  self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_distilbert_for_sequence_classification(*A       )



 def 					a__  (self       )    ->     List[Any]:


      """simple docstring"""



      _a      =  self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_distilbert_for_multiple_choice(*A       )



 def 					a__  (self       )    ->     Optional[int]:


      """simple docstring"""



      _a      =  self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_distilbert_for_token_classification(*A       )



 @slow
 def 					a__  (self       )    ->     int:


      """simple docstring"""



      for model_name in list(TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]       ):
           _a      =  TFDistilBertModel.from_pretrained(A       )
           self.assertIsNotNone(A       )






@require_tf
class __A			(  unittest.TestCase						):



 '''simple docstring'''







 @slow
 def 					a__  (self       )    ->     str:


      """simple docstring"""



      _a      =  TFDistilBertModel.from_pretrained('''distilbert-base-uncased'''       )
      _a      =  tf.constant([[0, 1, 2, 3, 4, 5]]       )
      _a      =  model(A       )[0]

      _a      =  [1, 6, 768]
      self.assertEqual(output.shape ,   A       )

      _a      =  tf.constant(
          [
              [
                  [0.19261885, -0.13732955, 0.4119799],
                  [0.22150156, -0.07422661, 0.39037204],
                  [0.22756018, -0.0896414, 0.3701467],
              ]
          ]       )
      tf.debugging.assert_near(output[:, :3, :3] ,   A ,   atol=1E-4       )








'''simple docstring'''





from ...configuration_utils import PretrainedConfig
from ...utils import logging


lowercase_		       =  logging.get_logger(__name__)

lowercase_		       =  {
    "vinvino02/glpn-kitti": "https://huggingface.co/vinvino02/glpn-kitti/resolve/main/config.json",
    # See all GLPN models at https://huggingface.co/models?filter=glpn
}






class __A			(  A						):



 '''simple docstring'''







 __lowerCamelCase    :       str          =       'glpn'



 def __init__(self ,   A=3 ,   A=4 ,   A=[2, 2, 2, 2] ,   A=[8, 4, 2, 1] ,   A=[32, 64, 160, 256] ,   A=[7, 3, 3, 3] ,   A=[4, 2, 2, 2] ,   A=[1, 2, 5, 8] ,   A=[4, 4, 4, 4] ,   A="gelu" ,   A=0.0 ,   A=0.0 ,   A=0.02 ,   A=0.1 ,   A=1E-6 ,   A=64 ,   A=10 ,   A=-1 ,   **A ,   )    ->     Any:


      """simple docstring"""



      super().__init__(**A       )

      _a      =  num_channels
      _a      =  num_encoder_blocks
      _a      =  depths
      _a      =  sr_ratios
      _a      =  hidden_sizes
      _a      =  patch_sizes
      _a      =  strides
      _a      =  mlp_ratios
      _a      =  num_attention_heads
      _a      =  hidden_act
      _a      =  hidden_dropout_prob
      _a      =  attention_probs_dropout_prob
      _a      =  initializer_range
      _a      =  drop_path_rate
      _a      =  layer_norm_eps
      _a      =  decoder_hidden_size
      _a      =  max_depth
      _a      =  head_in_index



