


import re
import time
from typing import Optional

import IPython.display as disp

from ..trainer_callback import TrainerCallback
from ..trainer_utils import IntervalStrategy, has_length


def   _SCREAMING_SNAKE_CASE	( SCREAMING_SNAKE_CASE       ):
  A_      :				Union[str, Any]		     =					int(SCREAMING_SNAKE_CASE       )
  A_     ,       A_     ,       A_      :				Union[str, Any]		     =					t // 3_600, (t // 60) % 60, t % 60
  return f'''{h}:{m:02d}:{s:02d}''' if h != 0 else f'''{m:02d}:{s:02d}'''


def   _SCREAMING_SNAKE_CASE	( SCREAMING_SNAKE_CASE ,			SCREAMING_SNAKE_CASE ,			SCREAMING_SNAKE_CASE ,			SCREAMING_SNAKE_CASE ,			SCREAMING_SNAKE_CASE=300       ):
  return f'''\n    <div>\n      {prefix}\n      <progress value=\'{value}\' max=\'{total}\' style=\'width:{width}px; height:20px; vertical-align: middle;\'></progress>\n      {label}\n    </div>\n    '''


def   _SCREAMING_SNAKE_CASE	( SCREAMING_SNAKE_CASE       ):
  A_      :				List[str]		     =					'''<table border=\"1\" class=\"dataframe\">\n'''
  html_code += """  <thead>\n <tr style="text-align: left;">\n"""
  for i in items[0]:
    html_code += f'''      <th>{i}</th>\n'''
  html_code += "    </tr>\n  </thead>\n  <tbody>\n"
  for line in items[1:]:
    html_code += "    <tr>\n"
    for elt in line:
      A_      :				List[Any]		     =					f'''{elt:.6f}''' if isinstance(SCREAMING_SNAKE_CASE ,			SCREAMING_SNAKE_CASE       ) else str(SCREAMING_SNAKE_CASE       )
      html_code += f'''      <td>{elt}</td>\n'''
    html_code += "    </tr>\n"
  html_code += "  </tbody>\n</table><p>"
  return html_code






class   _lowerCamelCase :




       """simple docstring"""
       snake_case      =    5
       snake_case      =    0.2



       def __init__(      self				,       _SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE = None				,       _SCREAMING_SNAKE_CASE = True				,       _SCREAMING_SNAKE_CASE = None				,       _SCREAMING_SNAKE_CASE = 300				,       )->List[Any]:




         '''simple docstring'''





         A_      :				Tuple		     =					total
         A_      :				List[Any]		     =					'''''' if prefix is None else prefix
         A_      :				List[Any]		     =					leave
         A_      :				str		     =					parent
         A_      :				List[Any]		     =					width
         A_      :				Any		     =					None
         A_      :				Any		     =					None
         A_      :				Union[str, Any]		     =					None



       def        _snake_case       (      self				,       _SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE = False				,       _SCREAMING_SNAKE_CASE = None		)->Optional[int]:




         '''simple docstring'''





         A_      :				Any		     =					value
         if comment is not None:
           A_      :				Optional[Any]		     =					comment
         if self.last_value is None:
           A_      :				List[str]		     =					time.time()
           A_      :				Union[str, Any]		     =					value
           A_      :				Optional[int]		     =					None
           A_      :				Union[str, Any]		     =					self.warmup
           A_      :				Any		     =					1
           self.update_bar(_SCREAMING_SNAKE_CASE		)
         elif value <= self.last_value and not force_update:
           return
         elif force_update or self.first_calls > 0 or value >= min(self.last_value + self.wait_for				,       self.total		):
           if self.first_calls > 0:
             self.first_calls -= 1
           A_      :				Optional[int]		     =					time.time()
           A_      :				Optional[int]		     =					current_time - self.start_time
           # We could have value = self.start_value if the update is called twixe with the same start value.
           if value > self.start_value:
             A_      :				str		     =					self.elapsed_time / (value - self.start_value)
           else:
             A_      :				str		     =					None
           if value >= self.total:
             A_      :				List[Any]		     =					self.total
             A_      :				List[str]		     =					None
             if not self.leave:
               self.close()
           elif self.average_time_per_item is not None:
             A_      :				int		     =					self.average_time_per_item * (self.total - value)
           self.update_bar(_SCREAMING_SNAKE_CASE		)
           A_      :				List[Any]		     =					value
           A_      :				Dict		     =					current_time
           if self.average_time_per_item is None:
             A_      :				List[str]		     =					1
           else:
             A_      :				Any		     =					max(int(self.update_every / self.average_time_per_item		)				,       1		)



       def        _snake_case       (      self				,       _SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE=None		)->Dict:




         '''simple docstring'''





         A_      :				str		     =					''' ''' * (len(str(self.total		)		) - len(str(_SCREAMING_SNAKE_CASE		)		)) + str(_SCREAMING_SNAKE_CASE		)
         if self.elapsed_time is None:
           A_      :				List[Any]		     =					F'''[{spaced_value}/{self.total} : < :'''
         elif self.predicted_remaining is None:
           A_      :				Dict		     =					F'''[{spaced_value}/{self.total} {format_time(self.elapsed_time		)}'''
         else:
           A_      :				List[str]		     =					(
               F'''[{spaced_value}/{self.total} {format_time(self.elapsed_time		)} <'''
               F''' {format_time(self.predicted_remaining		)}'''
           )
           self.label += F''', {1/self.average_time_per_item:.2f} it/s'''
         self.label += "]" if self.comment is None or len(self.comment		) == 0 else F''', {self.comment}]'''
         self.display()



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




         '''simple docstring'''





         A_      :				int		     =					html_progress_bar(self.value				,       self.total				,       self.prefix				,       self.label				,       self.width		)
         if self.parent is not None:
           # If this is a child bar, the parent will take care of the display.
           self.parent.display()
           return
         if self.output is None:
           A_      :				Any		     =					disp.display(disp.HTML(self.html_code		)				,       display_id=_SCREAMING_SNAKE_CASE		)
         else:
           self.output.update(disp.HTML(self.html_code		)		)







       def        _snake_case       (      self		)->Dict:




         '''simple docstring'''





         if self.parent is None and self.output is not None:
           self.output.update(disp.HTML(''''''		)		)






class   _lowerCamelCase (					_UpperCAmelCase			):




       """simple docstring"""



       def __init__(      self				,       _SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE=None		)->List[str]:




         '''simple docstring'''





         super().__init__(_SCREAMING_SNAKE_CASE		)
         A_      :				str		     =					None if column_names is None else [column_names]
         A_      :				str		     =					None



       def        _snake_case       (      self		)->Any:




         '''simple docstring'''





         A_      :				Union[str, Any]		     =					html_progress_bar(self.value				,       self.total				,       self.prefix				,       self.label				,       self.width		)
         if self.inner_table is not None:
           self.html_code += text_to_html_table(self.inner_table		)
         if self.child_bar is not None:
           self.html_code += self.child_bar.html_code
         if self.output is None:
           A_      :				Union[str, Any]		     =					disp.display(disp.HTML(self.html_code		)				,       display_id=_SCREAMING_SNAKE_CASE		)
         else:
           self.output.update(disp.HTML(self.html_code		)		)



       def        _snake_case       (      self				,       _SCREAMING_SNAKE_CASE		)->int:




         '''simple docstring'''





         if self.inner_table is None:
           A_      :				Optional[int]		     =					[list(values.keys()		), list(values.values()		)]
         else:
           A_      :				Optional[int]		     =					self.inner_table[0]
           if len(self.inner_table		) == 1:
             # We give a chance to update the column names at the first iteration
             for key in values.keys():
               if key not in columns:
                 columns.append(_SCREAMING_SNAKE_CASE		)
             A_      :				Dict		     =					columns
           self.inner_table.append([values[c] for c in columns]		)



       def        _snake_case       (      self				,       _SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE=None				,       _SCREAMING_SNAKE_CASE=300		)->List[Any]:




         '''simple docstring'''





         A_      :				int		     =					NotebookProgressBar(_SCREAMING_SNAKE_CASE				,       prefix=_SCREAMING_SNAKE_CASE				,       parent=self				,       width=_SCREAMING_SNAKE_CASE		)
         return self.child_bar







       def        _snake_case       (      self		)->int:




         '''simple docstring'''





         A_      :				Union[str, Any]		     =					None
         self.display()






class   _lowerCamelCase (					_UpperCAmelCase			):




       """simple docstring"""



       def __init__(      self		)->Union[str, Any]:




         '''simple docstring'''





         A_      :				str		     =					None
         A_      :				List[Any]		     =					None
         A_      :				Optional[Any]		     =					False



       def        _snake_case       (      self				,       _SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       **_SCREAMING_SNAKE_CASE		)->Optional[Any]:




         '''simple docstring'''





         A_      :				Optional[Any]		     =					'''Epoch''' if args.evaluation_strategy == IntervalStrategy.EPOCH else '''Step'''
         A_      :				Dict		     =					0
         A_      :				Dict		     =					0
         A_      :				Tuple		     =					[self.first_column] + ['''Training Loss''']
         if args.evaluation_strategy != IntervalStrategy.NO:
           column_names.append('''Validation Loss'''		)
         A_      :				Dict		     =					NotebookTrainingTracker(state.max_steps				,       _SCREAMING_SNAKE_CASE		)



       def        _snake_case       (      self				,       _SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       **_SCREAMING_SNAKE_CASE		)->Dict:




         '''simple docstring'''





         A_      :				Optional[int]		     =					int(state.epoch		) if int(state.epoch		) == state.epoch else F'''{state.epoch:.2f}'''
         self.training_tracker.update(
             state.global_step + 1				,       comment=F'''Epoch {epoch}/{state.num_train_epochs}'''				,       force_update=self._force_next_update				,       )
         A_      :				Dict		     =					False



       def        _snake_case       (      self				,       _SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE=None				,       **_SCREAMING_SNAKE_CASE		)->Dict:




         '''simple docstring'''





         if not has_length(_SCREAMING_SNAKE_CASE		):
           return
         if self.prediction_bar is None:
           if self.training_tracker is not None:
             A_      :				Union[str, Any]		     =					self.training_tracker.add_child(len(_SCREAMING_SNAKE_CASE		)		)
           else:
             A_      :				List[str]		     =					NotebookProgressBar(len(_SCREAMING_SNAKE_CASE		)		)
           self.prediction_bar.update(1		)
         else:
           self.prediction_bar.update(self.prediction_bar.value + 1		)



       def        _snake_case       (      self				,       _SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       **_SCREAMING_SNAKE_CASE		)->Dict:




         '''simple docstring'''





         if self.prediction_bar is not None:
           self.prediction_bar.close()
         A_      :				Union[str, Any]		     =					None



       def        _snake_case       (      self				,       _SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE=None				,       **_SCREAMING_SNAKE_CASE		)->List[Any]:




         '''simple docstring'''





         if args.evaluation_strategy == IntervalStrategy.NO and "loss" in logs:
           A_      :				Union[str, Any]		     =					{'''Training Loss''': logs['''loss''']}
           # First column is necessarily Step sine we're not in epoch eval strategy
           A_      :				Dict		     =					state.global_step
           self.training_tracker.write_line(_SCREAMING_SNAKE_CASE		)



       def        _snake_case       (      self				,       _SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE=None				,       **_SCREAMING_SNAKE_CASE		)->List[str]:




         '''simple docstring'''





         if self.training_tracker is not None:
           A_      :				Any		     =					{'''Training Loss''': '''No log''', '''Validation Loss''': '''No log'''}
           for log in reversed(state.log_history		):
             if "loss" in log:
               A_      :				str		     =					log['''loss''']
               break

           if self.first_column == "Epoch":
             A_      :				List[Any]		     =					int(state.epoch		)
           else:
             A_      :				Optional[int]		     =					state.global_step
           A_      :				Optional[Any]		     =					'''eval'''
           for k in metrics:
             if k.endswith('''_loss'''		):
               A_      :				Tuple		     =					re.sub(R'''\_loss$'''				,       ''''''				,       _SCREAMING_SNAKE_CASE		)
           A_      :				Optional[Any]		     =					metrics.pop('''total_flos'''				,       _SCREAMING_SNAKE_CASE		)
           A_      :				Tuple		     =					metrics.pop('''epoch'''				,       _SCREAMING_SNAKE_CASE		)
           A_      :				Tuple		     =					metrics.pop(F'''{metric_key_prefix}_runtime'''				,       _SCREAMING_SNAKE_CASE		)
           A_      :				Tuple		     =					metrics.pop(F'''{metric_key_prefix}_samples_per_second'''				,       _SCREAMING_SNAKE_CASE		)
           A_      :				Any		     =					metrics.pop(F'''{metric_key_prefix}_steps_per_second'''				,       _SCREAMING_SNAKE_CASE		)
           A_      :				List[Any]		     =					metrics.pop(F'''{metric_key_prefix}_jit_compilation_time'''				,       _SCREAMING_SNAKE_CASE		)
           for k, v in metrics.items():
             if k == F'''{metric_key_prefix}_loss''':
               A_      :				Tuple		     =					v
             else:
               A_      :				Any		     =					k.split('''_'''		)
               A_      :				Any		     =					''' '''.join([part.capitalize() for part in splits[1:]]		)
               A_      :				Union[str, Any]		     =					v
           self.training_tracker.write_line(_SCREAMING_SNAKE_CASE		)
           self.training_tracker.remove_child()
           A_      :				Optional[int]		     =					None
           # Evaluation takes a long time so we should force the next update.
           A_      :				str		     =					True







       def        _snake_case       (      self				,       _SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       **_SCREAMING_SNAKE_CASE		)->List[Any]:




         '''simple docstring'''





         self.training_tracker.update(
             state.global_step				,       comment=F'''Epoch {int(state.epoch		)}/{state.num_train_epochs}'''				,       force_update=_SCREAMING_SNAKE_CASE		)
         A_      :				Optional[int]		     =					None











"""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 		lowercase					:





      def __init__(       self      ,						lowercase      ,						)		->     Optional[int]:
            lowerCAmelCase  						=       parent
            lowerCAmelCase  						=       13
            lowerCAmelCase  						=       7
            lowerCAmelCase  						=       True
            lowerCAmelCase  						=       True
            lowerCAmelCase  						=       False
            lowerCAmelCase  						=       True
            lowerCAmelCase  						=       99
            lowerCAmelCase  						=       32
            lowerCAmelCase  						=       2
            lowerCAmelCase  						=       4
            lowerCAmelCase  						=       37
            lowerCAmelCase  						=       """gelu"""
            lowerCAmelCase  						=       0.1
            lowerCAmelCase  						=       0.1
            lowerCAmelCase  						=       512
            lowerCAmelCase  						=       16
            lowerCAmelCase  						=       2
            lowerCAmelCase  						=       0.02
            lowerCAmelCase  						=       3
            lowerCAmelCase  						=       4
            lowerCAmelCase  						=       None





      def     _snake_case			(       self )		->     str:
            lowerCAmelCase  						=       ids_tensor([self.batch_size, self.seq_length]      ,						self.vocab_size )

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

            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  						=       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     _snake_case			(       self      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase )		->     List[Any]:
            lowerCAmelCase  						=       TFDistilBertModel(config=lowercase )
            lowerCAmelCase  						=       {"""input_ids""": input_ids, """attention_mask""": input_mask}

            lowerCAmelCase  						=       model(lowercase )

            lowerCAmelCase  						=       [input_ids, input_mask]

            lowerCAmelCase  						=       model(lowercase )

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





      def     _snake_case			(       self      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase )		->     Optional[int]:
            lowerCAmelCase  						=       TFDistilBertForMaskedLM(config=lowercase )
            lowerCAmelCase  						=       {"""input_ids""": input_ids, """attention_mask""": input_mask}
            lowerCAmelCase  						=       model(lowercase )
            self.parent.assertEqual(result.logits.shape      ,						(self.batch_size, self.seq_length, self.vocab_size) )





      def     _snake_case			(       self      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase )		->     List[Any]:
            lowerCAmelCase  						=       TFDistilBertForQuestionAnswering(config=lowercase )
            lowerCAmelCase  						=       {
                """input_ids""": input_ids,
                """attention_mask""": input_mask,
            }
            lowerCAmelCase  						=       model(lowercase )
            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     _snake_case			(       self      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase )		->     List[Any]:
            lowerCAmelCase  						=       self.num_labels
            lowerCAmelCase  						=       TFDistilBertForSequenceClassification(lowercase )
            lowerCAmelCase  						=       {"""input_ids""": input_ids, """attention_mask""": input_mask}
            lowerCAmelCase  						=       model(lowercase )
            self.parent.assertEqual(result.logits.shape      ,						(self.batch_size, self.num_labels) )





      def     _snake_case			(       self      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase )		->     Any:
            lowerCAmelCase  						=       self.num_choices
            lowerCAmelCase  						=       TFDistilBertForMultipleChoice(lowercase )
            lowerCAmelCase  						=       tf.tile(tf.expand_dims(lowercase      ,						1 )      ,						(1, self.num_choices, 1) )
            lowerCAmelCase  						=       tf.tile(tf.expand_dims(lowercase      ,						1 )      ,						(1, self.num_choices, 1) )
            lowerCAmelCase  						=       {
                """input_ids""": multiple_choice_inputs_ids,
                """attention_mask""": multiple_choice_input_mask,
            }
            lowerCAmelCase  						=       model(lowercase )
            self.parent.assertEqual(result.logits.shape      ,						(self.batch_size, self.num_choices) )





      def     _snake_case			(       self      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase      ,						lowercase )		->     int:
            lowerCAmelCase  						=       self.num_labels
            lowerCAmelCase  						=       TFDistilBertForTokenClassification(lowercase )
            lowerCAmelCase  						=       {"""input_ids""": input_ids, """attention_mask""": input_mask}
            lowerCAmelCase  						=       model(lowercase )
            self.parent.assertEqual(result.logits.shape      ,						(self.batch_size, self.seq_length, self.num_labels) )





      def     _snake_case			(       self )		->     Optional[Any]:
            lowerCAmelCase  						=       self.prepare_config_and_inputs()
            ((lowerCAmelCase)						,		(lowerCAmelCase)						,		(lowerCAmelCase)						,		(lowerCAmelCase)						,		(lowerCAmelCase)						,		(lowerCAmelCase))  						=       config_and_inputs
            lowerCAmelCase  						=       {"""input_ids""": input_ids, """attention_mask""": input_mask}
            return config, inputs_dict







@require_tf
class 		lowercase					(					_UpperCAmelCase     ,  _UpperCAmelCase     ,  unittest.TestCase					):
      _SCREAMING_SNAKE_CASE					=      (
          (
              TFDistilBertModel,
              TFDistilBertForMaskedLM,
              TFDistilBertForQuestionAnswering,
              TFDistilBertForSequenceClassification,
              TFDistilBertForTokenClassification,
              TFDistilBertForMultipleChoice,
          )
          if is_tf_available()
          else None
      )
      _SCREAMING_SNAKE_CASE					=      (
          {
              'feature-extraction': TFDistilBertModel,
              'fill-mask': TFDistilBertForMaskedLM,
              'question-answering': TFDistilBertForQuestionAnswering,
              'text-classification': TFDistilBertForSequenceClassification,
              'token-classification': TFDistilBertForTokenClassification,
              'zero-shot': TFDistilBertForSequenceClassification,
          }
          if is_tf_available()
          else {}
      )
      _SCREAMING_SNAKE_CASE					=      False
      _SCREAMING_SNAKE_CASE					=      False





      def     _snake_case			(       self )		->     Dict:
            lowerCAmelCase  						=       TFDistilBertModelTester(self )
            lowerCAmelCase  						=       ConfigTester(self      ,						config_class=lowercase      ,						dim=37 )





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





      def     _snake_case			(       self )		->     int:
            lowerCAmelCase  						=       self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_distilbert_model(*lowercase )





      def     _snake_case			(       self )		->     Any:
            lowerCAmelCase  						=       self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_distilbert_for_masked_lm(*lowercase )





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





      def     _snake_case			(       self )		->     Union[str, Any]:
            lowerCAmelCase  						=       self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_distilbert_for_sequence_classification(*lowercase )





      def     _snake_case			(       self )		->     List[Any]:
            lowerCAmelCase  						=       self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_distilbert_for_multiple_choice(*lowercase )





      def     _snake_case			(       self )		->     str:
            lowerCAmelCase  						=       self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_distilbert_for_token_classification(*lowercase )





      @slow
      def     _snake_case			(       self )		->     List[str]:
            for model_name in list(TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1] ):
                  lowerCAmelCase  						=       TFDistilBertModel.from_pretrained(lowercase )
                  self.assertIsNotNone(lowercase )







@require_tf
class 		lowercase					(					unittest.TestCase					):





      @slow
      def     _snake_case			(       self )		->     Any:
            lowerCAmelCase  						=       TFDistilBertModel.from_pretrained("""distilbert-base-uncased""" )
            lowerCAmelCase  						=       tf.constant([[0, 1, 2, 3, 4, 5]] )
            lowerCAmelCase  						=       model(lowercase )[0]

            lowerCAmelCase  						=       [1, 6, 768]
            self.assertEqual(output.shape      ,						lowercase )

            lowerCAmelCase  						=       tf.constant(
                [
                    [
                        [0.19_261_885, -0.13_732_955, 0.4_119_799],
                        [0.22_150_156, -0.07_422_661, 0.39_037_204],
                        [0.22_756_018, -0.0_896_414, 0.3_701_467],
                    ]
                ] )
            tf.debugging.assert_near(output[:, :3, :3]      ,						lowercase      ,						atol=1e-4 )






