import json
import os
from functools import lru_cache
from typing import List, Optional, Tuple

import regex as re

from ...tokenization_utils import AddedToken, PreTrainedTokenizer
from ...utils import logging


UpperCamelCase__    							= logging.get_logger(__name__)


UpperCamelCase__    							= {'vocab_file': 'vocab.json', 'merges_file': 'merges.txt'}

# See all BART models at https://huggingface.co/models?filter=bart
UpperCamelCase__    							= {
    'vocab_file': {
        'facebook/bart-base': 'https://huggingface.co/facebook/bart-base/resolve/main/vocab.json',
        'facebook/bart-large': 'https://huggingface.co/facebook/bart-large/resolve/main/vocab.json',
        'facebook/bart-large-mnli': 'https://huggingface.co/facebook/bart-large-mnli/resolve/main/vocab.json',
        'facebook/bart-large-cnn': 'https://huggingface.co/facebook/bart-large-cnn/resolve/main/vocab.json',
        'facebook/bart-large-xsum': 'https://huggingface.co/facebook/bart-large-xsum/resolve/main/vocab.json',
        'yjernite/bart_eli5': 'https://huggingface.co/yjernite/bart_eli5/resolve/main/vocab.json',
    },
    'merges_file': {
        'facebook/bart-base': 'https://huggingface.co/facebook/bart-base/resolve/main/merges.txt',
        'facebook/bart-large': 'https://huggingface.co/facebook/bart-large/resolve/main/merges.txt',
        'facebook/bart-large-mnli': 'https://huggingface.co/facebook/bart-large-mnli/resolve/main/merges.txt',
        'facebook/bart-large-cnn': 'https://huggingface.co/facebook/bart-large-cnn/resolve/main/merges.txt',
        'facebook/bart-large-xsum': 'https://huggingface.co/facebook/bart-large-xsum/resolve/main/merges.txt',
        'yjernite/bart_eli5': 'https://huggingface.co/yjernite/bart_eli5/resolve/main/merges.txt',
    },
}

UpperCamelCase__    							= {
    'facebook/bart-base': 1_0_2_4,
    'facebook/bart-large': 1_0_2_4,
    'facebook/bart-large-mnli': 1_0_2_4,
    'facebook/bart-large-cnn': 1_0_2_4,
    'facebook/bart-large-xsum': 1_0_2_4,
    'yjernite/bart_eli5': 1_0_2_4,
}




@lru_cache()
def        lowerCAmelCase_			(					)					->    List[Any]:







						'''simple docstring'''


						UpperCAmelCase__								=  (
						    list(range(ord("!"							),  ord("~"							) + 1							)							) + list(range(ord("¡"							),  ord("¬"							) + 1							)							) + list(range(ord("®"							),  ord("ÿ"							) + 1							)							)
						)
						UpperCAmelCase__								=  bs[:]
						UpperCAmelCase__								=  0
						for b in range(2**8							):
												if b not in bs:
																		bs.append(__A							)
																		cs.append(2**8 + n							)
																		n += 1
						UpperCAmelCase__								=  [chr(__A							) for n in cs]
						return dict(zip(__A,  __A							)							)




def        lowerCAmelCase_			(					__A							)					->    Dict:







						'''simple docstring'''


						UpperCAmelCase__								=  set()
						UpperCAmelCase__								=  word[0]
						for char in word[1:]:
												pairs.add((prev_char, char)							)
												UpperCAmelCase__								=  char
						return pairs







class 					A							(    UpperCAmelCase_					):
			__UpperCAmelCase			:			Tuple              =      VOCAB_FILES_NAMES
			__UpperCAmelCase			:			Any              =      PRETRAINED_VOCAB_FILES_MAP
			__UpperCAmelCase			:			Optional[int]              =      PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
			__UpperCAmelCase			:			int              =      ['input_ids', 'attention_mask']


			def __init__(self					:						Optional[int]	,  __UpperCAmelCase					:						Tuple	,  __UpperCAmelCase					:						List[str]	,  __UpperCAmelCase					:						Tuple="replace"	,  __UpperCAmelCase					:						Tuple="<s>"	,  __UpperCAmelCase					:						List[Any]="</s>"	,  __UpperCAmelCase					:						int="</s>"	,  __UpperCAmelCase					:						Optional[int]="<s>"	,  __UpperCAmelCase					:						int="<unk>"	,  __UpperCAmelCase					:						int="<pad>"	,  __UpperCAmelCase					:						Tuple="<mask>"	,  __UpperCAmelCase					:						Optional[int]=False	,  **__UpperCAmelCase					:						Any	,  )						->    Optional[int]:
									"""simple docstring"""



									UpperCAmelCase__								=  AddedToken(__UpperCAmelCase	,  lstrip=__UpperCAmelCase	,  rstrip=__UpperCAmelCase		) if isinstance(__UpperCAmelCase	,  __UpperCAmelCase		) else bos_token
									UpperCAmelCase__								=  AddedToken(__UpperCAmelCase	,  lstrip=__UpperCAmelCase	,  rstrip=__UpperCAmelCase		) if isinstance(__UpperCAmelCase	,  __UpperCAmelCase		) else eos_token
									UpperCAmelCase__								=  AddedToken(__UpperCAmelCase	,  lstrip=__UpperCAmelCase	,  rstrip=__UpperCAmelCase		) if isinstance(__UpperCAmelCase	,  __UpperCAmelCase		) else sep_token
									UpperCAmelCase__								=  AddedToken(__UpperCAmelCase	,  lstrip=__UpperCAmelCase	,  rstrip=__UpperCAmelCase		) if isinstance(__UpperCAmelCase	,  __UpperCAmelCase		) else cls_token
									UpperCAmelCase__								=  AddedToken(__UpperCAmelCase	,  lstrip=__UpperCAmelCase	,  rstrip=__UpperCAmelCase		) if isinstance(__UpperCAmelCase	,  __UpperCAmelCase		) else unk_token
									UpperCAmelCase__								=  AddedToken(__UpperCAmelCase	,  lstrip=__UpperCAmelCase	,  rstrip=__UpperCAmelCase		) if isinstance(__UpperCAmelCase	,  __UpperCAmelCase		) else pad_token

									# Mask token behave like a normal word, i.e. include the space before it
									UpperCAmelCase__								=  AddedToken(__UpperCAmelCase	,  lstrip=__UpperCAmelCase	,  rstrip=__UpperCAmelCase		) if isinstance(__UpperCAmelCase	,  __UpperCAmelCase		) else mask_token

									super().__init__(
									    errors=__UpperCAmelCase	,  bos_token=__UpperCAmelCase	,  eos_token=__UpperCAmelCase	,  unk_token=__UpperCAmelCase	,  sep_token=__UpperCAmelCase	,  cls_token=__UpperCAmelCase	,  pad_token=__UpperCAmelCase	,  mask_token=__UpperCAmelCase	,  add_prefix_space=__UpperCAmelCase	,  **__UpperCAmelCase	,  )

									with open(__UpperCAmelCase	,  encoding="utf-8"		) as vocab_handle:
															UpperCAmelCase__								=  json.load(__UpperCAmelCase		)
									UpperCAmelCase__								=  {v: k for k, v in self.encoder.items()}
									UpperCAmelCase__								=  errors  # how to handle errors in decoding
									UpperCAmelCase__								=  bytes_to_unicode()
									UpperCAmelCase__								=  {v: k for k, v in self.byte_encoder.items()}
									with open(__UpperCAmelCase	,  encoding="utf-8"		) as merges_handle:
															UpperCAmelCase__								=  merges_handle.read().split("\n"		)[1:-1]
									UpperCAmelCase__								=  [tuple(merge.split()		) for merge in bpe_merges]
									UpperCAmelCase__								=  dict(zip(__UpperCAmelCase	,  range(len(__UpperCAmelCase		)		)		)		)
									UpperCAmelCase__								=  {}
									UpperCAmelCase__								=  add_prefix_space

									# Should have added re.IGNORECASE so BPE merges can happen for capitalized versions of contractions
									UpperCAmelCase__								=  re.compile(r"'s|'t|'re|'ve|'m|'ll|'d| ?\p{L}+| ?\p{N}+| ?[^\s\p{L}\p{N}]+|\s+(?!\S)|\s+"		)


			@property
			def       lowercase_				(self					:						Any		)						->    Tuple:
									"""simple docstring"""



									return len(self.encoder		)


			def       lowercase_				(self					:						List[Any]		)						->    Dict:
									"""simple docstring"""



									return dict(self.encoder	,  **self.added_tokens_encoder		)


			def       lowercase_				(self					:						Optional[Any]	,  __UpperCAmelCase					:						Tuple		)						->    Optional[Any]:
									"""simple docstring"""



									if token in self.cache:
															return self.cache[token]
									UpperCAmelCase__								=  tuple(__UpperCAmelCase		)
									UpperCAmelCase__								=  get_pairs(__UpperCAmelCase		)

									if not pairs:
															return token

									while True:
															UpperCAmelCase__								=  min(__UpperCAmelCase	,  key=lambda __UpperCAmelCase		: self.bpe_ranks.get(__UpperCAmelCase	,  float("inf"		)		)		)
															if bigram not in self.bpe_ranks:
																					break
															UpperCAmelCase__		,				UpperCAmelCase__								=  bigram
															UpperCAmelCase__								=  []
															UpperCAmelCase__								=  0
															while i < len(__UpperCAmelCase		):
																					try:
																											UpperCAmelCase__								=  word.index(__UpperCAmelCase	,  __UpperCAmelCase		)
																					except ValueError:
																											new_word.extend(word[i:]		)
																											break
																					else:
																											new_word.extend(word[i:j]		)
																											UpperCAmelCase__								=  j

																					if word[i] == first and i < len(__UpperCAmelCase		) - 1 and word[i + 1] == second:
																											new_word.append(first + second		)
																											i += 2
																					else:
																											new_word.append(word[i]		)
																											i += 1
															UpperCAmelCase__								=  tuple(__UpperCAmelCase		)
															UpperCAmelCase__								=  new_word
															if len(__UpperCAmelCase		) == 1:
																					break
															else:
																					UpperCAmelCase__								=  get_pairs(__UpperCAmelCase		)
									UpperCAmelCase__								=  " ".join(__UpperCAmelCase		)
									UpperCAmelCase__								=  word
									return word


			def       lowercase_				(self					:						List[str]	,  __UpperCAmelCase					:						int		)						->    Any:
									"""simple docstring"""



									UpperCAmelCase__								=  []
									for token in re.findall(self.pat	,  __UpperCAmelCase		):
															UpperCAmelCase__								=  "".join(
															    self.byte_encoder[b] for b in token.encode("utf-8"		)		)  # Maps all our bytes to unicode strings, avoiding control tokens of the BPE (spaces in our case)
															bpe_tokens.extend(bpe_token for bpe_token in self.bpe(__UpperCAmelCase		).split(" "		)		)
									return bpe_tokens


			def       lowercase_				(self					:						Tuple	,  __UpperCAmelCase					:						int		)						->    Optional[Any]:
									"""simple docstring"""



									return self.encoder.get(__UpperCAmelCase	,  self.encoder.get(self.unk_token		)		)


			def       lowercase_				(self					:						str	,  __UpperCAmelCase					:						int		)						->    Optional[Any]:
									"""simple docstring"""



									return self.decoder.get(__UpperCAmelCase		)


			def       lowercase_				(self					:						Optional[Any]	,  __UpperCAmelCase					:						str		)						->    Dict:
									"""simple docstring"""



									UpperCAmelCase__								=  "".join(__UpperCAmelCase		)
									UpperCAmelCase__								=  bytearray([self.byte_decoder[c] for c in text]		).decode("utf-8"	,  errors=self.errors		)
									return text


			def       lowercase_				(self					:						Any	,  __UpperCAmelCase					:						str	,  __UpperCAmelCase					:						Optional[str] = None		)						->    Tuple[str]:
									"""simple docstring"""



									if not os.path.isdir(__UpperCAmelCase		):
															logger.error(f"""Vocabulary path ({save_directory}) should be a directory"""		)
															return
									UpperCAmelCase__								=  os.path.join(
									    __UpperCAmelCase	,  (filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["vocab_file"]		)
									UpperCAmelCase__								=  os.path.join(
									    __UpperCAmelCase	,  (filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["merges_file"]		)

									with open(__UpperCAmelCase	,  "w"	,  encoding="utf-8"		) as f:
															f.write(json.dumps(self.encoder	,  indent=2	,  sort_keys=__UpperCAmelCase	,  ensure_ascii=__UpperCAmelCase		) + "\n"		)

									UpperCAmelCase__								=  0
									with open(__UpperCAmelCase	,  "w"	,  encoding="utf-8"		) as writer:
															writer.write("#version: 0.2\n"		)
															for bpe_tokens, token_index in sorted(self.bpe_ranks.items()	,  key=lambda __UpperCAmelCase		: kv[1]		):
																					if index != token_index:
																											logger.warning(
																											    f"""Saving vocabulary to {merge_file}: BPE merge indices are not consecutive."""
																											    " Please check that the tokenizer is not corrupted!"		)
																											UpperCAmelCase__								=  token_index
																					writer.write(" ".join(__UpperCAmelCase		) + "\n"		)
																					index += 1

									return vocab_file, merge_file


			def       lowercase_				(self					:						Dict	,  __UpperCAmelCase					:						List[int]	,  __UpperCAmelCase					:						Optional[List[int]] = None		)						->    List[int]:
									"""simple docstring"""



									if token_ids_a is None:
															return [self.cls_token_id] + token_ids_a + [self.sep_token_id]
									UpperCAmelCase__								=  [self.cls_token_id]
									UpperCAmelCase__								=  [self.sep_token_id]
									return cls + token_ids_a + sep + sep + token_ids_a + sep


			def       lowercase_				(self					:						Dict	,  __UpperCAmelCase					:						List[int]	,  __UpperCAmelCase					:						Optional[List[int]] = None	,  __UpperCAmelCase					:						bool = False		)						->    List[int]:
									"""simple docstring"""



									if already_has_special_tokens:
															return super().get_special_tokens_mask(
															    token_ids_a=__UpperCAmelCase	,  token_ids_a=__UpperCAmelCase	,  already_has_special_tokens=__UpperCAmelCase		)

									if token_ids_a is None:
															return [1] + ([0] * len(__UpperCAmelCase		)) + [1]
									return [1] + ([0] * len(__UpperCAmelCase		)) + [1, 1] + ([0] * len(__UpperCAmelCase		)) + [1]


			def       lowercase_				(self					:						Union[str, Any]	,  __UpperCAmelCase					:						List[int]	,  __UpperCAmelCase					:						Optional[List[int]] = None		)						->    List[int]:
									"""simple docstring"""



									UpperCAmelCase__								=  [self.sep_token_id]
									UpperCAmelCase__								=  [self.cls_token_id]

									if token_ids_a is None:
															return len(cls + token_ids_a + sep		) * [0]
									return len(cls + token_ids_a + sep + sep + token_ids_a + sep		) * [0]





			def       lowercase_				(self					:						Union[str, Any]	,  __UpperCAmelCase					:						Dict	,  __UpperCAmelCase					:						Optional[Any]=False	,  **__UpperCAmelCase					:						Union[str, Any]		)						->    int:
									"""simple docstring"""



									UpperCAmelCase__								=  kwargs.pop("add_prefix_space"	,  self.add_prefix_space		)
									if (is_split_into_words or add_prefix_space) and (len(__UpperCAmelCase		) > 0 and not text[0].isspace()):
															UpperCAmelCase__								=  " " + text
									return (text, kwargs)




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							:


   def __init__(self					:						Tuple	,  __UpperCAmelCase					:						str	,  )						->    Dict:
         """simple docstring"""



         UpperCAmelCase__								=  parent
         UpperCAmelCase__								=  1_3
         UpperCAmelCase__								=  7
         UpperCAmelCase__								=  True
         UpperCAmelCase__								=  True
         UpperCAmelCase__								=  False
         UpperCAmelCase__								=  True
         UpperCAmelCase__								=  9_9
         UpperCAmelCase__								=  3_2
         UpperCAmelCase__								=  2
         UpperCAmelCase__								=  4
         UpperCAmelCase__								=  3_7
         UpperCAmelCase__								=  "gelu"
         UpperCAmelCase__								=  0.1
         UpperCAmelCase__								=  0.1
         UpperCAmelCase__								=  5_1_2
         UpperCAmelCase__								=  1_6
         UpperCAmelCase__								=  2
         UpperCAmelCase__								=  0.02
         UpperCAmelCase__								=  3
         UpperCAmelCase__								=  4
         UpperCAmelCase__								=  None


   def       lowercase_				(self					:						int		)						->    Union[str, Any]:
         """simple docstring"""



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

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

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

         UpperCAmelCase__								=  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       lowercase_				(self					:						int	,  __UpperCAmelCase					:						int	,  __UpperCAmelCase					:						Tuple	,  __UpperCAmelCase					:						Optional[Any]	,  __UpperCAmelCase					:						Union[str, Any]	,  __UpperCAmelCase					:						Tuple	,  __UpperCAmelCase					:						Tuple		)						->    Tuple:
         """simple docstring"""



         UpperCAmelCase__								=  TFDistilBertModel(config=__UpperCAmelCase		)
         UpperCAmelCase__								=  {"input_ids": input_ids, "attention_mask": input_mask}

         UpperCAmelCase__								=  model(__UpperCAmelCase		)

         UpperCAmelCase__								=  [input_ids, input_mask]

         UpperCAmelCase__								=  model(__UpperCAmelCase		)

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


   def       lowercase_				(self					:						str	,  __UpperCAmelCase					:						int	,  __UpperCAmelCase					:						Optional[Any]	,  __UpperCAmelCase					:						Union[str, Any]	,  __UpperCAmelCase					:						List[Any]	,  __UpperCAmelCase					:						Any	,  __UpperCAmelCase					:						Dict		)						->    List[Any]:
         """simple docstring"""



         UpperCAmelCase__								=  TFDistilBertForMaskedLM(config=__UpperCAmelCase		)
         UpperCAmelCase__								=  {"input_ids": input_ids, "attention_mask": input_mask}
         UpperCAmelCase__								=  model(__UpperCAmelCase		)
         self.parent.assertEqual(result.logits.shape	,  (self.batch_size, self.seq_length, self.vocab_size)		)


   def       lowercase_				(self					:						int	,  __UpperCAmelCase					:						Dict	,  __UpperCAmelCase					:						Optional[Any]	,  __UpperCAmelCase					:						str	,  __UpperCAmelCase					:						Optional[Any]	,  __UpperCAmelCase					:						List[Any]	,  __UpperCAmelCase					:						List[str]		)						->    List[Any]:
         """simple docstring"""



         UpperCAmelCase__								=  TFDistilBertForQuestionAnswering(config=__UpperCAmelCase		)
         UpperCAmelCase__								=  {
             "input_ids": input_ids,
             "attention_mask": input_mask,
         }
         UpperCAmelCase__								=  model(__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)		)


   def       lowercase_				(self					:						Optional[int]	,  __UpperCAmelCase					:						str	,  __UpperCAmelCase					:						Optional[Any]	,  __UpperCAmelCase					:						List[str]	,  __UpperCAmelCase					:						Dict	,  __UpperCAmelCase					:						Optional[int]	,  __UpperCAmelCase					:						List[str]		)						->    str:
         """simple docstring"""



         UpperCAmelCase__								=  self.num_labels
         UpperCAmelCase__								=  TFDistilBertForSequenceClassification(__UpperCAmelCase		)
         UpperCAmelCase__								=  {"input_ids": input_ids, "attention_mask": input_mask}
         UpperCAmelCase__								=  model(__UpperCAmelCase		)
         self.parent.assertEqual(result.logits.shape	,  (self.batch_size, self.num_labels)		)


   def       lowercase_				(self					:						Optional[int]	,  __UpperCAmelCase					:						List[Any]	,  __UpperCAmelCase					:						Optional[Any]	,  __UpperCAmelCase					:						Dict	,  __UpperCAmelCase					:						List[Any]	,  __UpperCAmelCase					:						str	,  __UpperCAmelCase					:						Any		)						->    int:
         """simple docstring"""



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


   def       lowercase_				(self					:						Dict	,  __UpperCAmelCase					:						Tuple	,  __UpperCAmelCase					:						Optional[int]	,  __UpperCAmelCase					:						Tuple	,  __UpperCAmelCase					:						List[str]	,  __UpperCAmelCase					:						Any	,  __UpperCAmelCase					:						Optional[int]		)						->    List[Any]:
         """simple docstring"""



         UpperCAmelCase__								=  self.num_labels
         UpperCAmelCase__								=  TFDistilBertForTokenClassification(__UpperCAmelCase		)
         UpperCAmelCase__								=  {"input_ids": input_ids, "attention_mask": input_mask}
         UpperCAmelCase__								=  model(__UpperCAmelCase		)
         self.parent.assertEqual(result.logits.shape	,  (self.batch_size, self.seq_length, self.num_labels)		)





   def       lowercase_				(self					:						Any		)						->    Dict:
         """simple docstring"""



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





@require_tf
class 					A							(    UpperCAmelCase_		,    UpperCAmelCase_		,    unittest.TestCase					):
   __UpperCAmelCase			:			Union[str, Any]              =      (
       (
           TFDistilBertModel,
           TFDistilBertForMaskedLM,
           TFDistilBertForQuestionAnswering,
           TFDistilBertForSequenceClassification,
           TFDistilBertForTokenClassification,
           TFDistilBertForMultipleChoice,
       )
       if is_tf_available()
       else None
   )
   __UpperCAmelCase			:			Optional[int]              =      (
       {
           'feature-extraction': TFDistilBertModel,
           'fill-mask': TFDistilBertForMaskedLM,
           'question-answering': TFDistilBertForQuestionAnswering,
           'text-classification': TFDistilBertForSequenceClassification,
           'token-classification': TFDistilBertForTokenClassification,
           'zero-shot': TFDistilBertForSequenceClassification,
       }
       if is_tf_available()
       else {}
   )
   __UpperCAmelCase			:			Tuple              =      False
   __UpperCAmelCase			:			str              =      False


   def       lowercase_				(self					:						Union[str, Any]		)						->    str:
         """simple docstring"""



         UpperCAmelCase__								=  TFDistilBertModelTester(self		)
         UpperCAmelCase__								=  ConfigTester(self	,  config_class=__UpperCAmelCase	,  dim=3_7		)


   def       lowercase_				(self					:						Any		)						->    int:
         """simple docstring"""



         self.config_tester.run_common_tests()


   def       lowercase_				(self					:						int		)						->    int:
         """simple docstring"""



         UpperCAmelCase__								=  self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_distilbert_model(*__UpperCAmelCase		)


   def       lowercase_				(self					:						Optional[int]		)						->    int:
         """simple docstring"""



         UpperCAmelCase__								=  self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_distilbert_for_masked_lm(*__UpperCAmelCase		)


   def       lowercase_				(self					:						Any		)						->    Optional[int]:
         """simple docstring"""



         UpperCAmelCase__								=  self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_distilbert_for_question_answering(*__UpperCAmelCase		)


   def       lowercase_				(self					:						List[str]		)						->    str:
         """simple docstring"""



         UpperCAmelCase__								=  self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_distilbert_for_sequence_classification(*__UpperCAmelCase		)


   def       lowercase_				(self					:						Dict		)						->    List[str]:
         """simple docstring"""



         UpperCAmelCase__								=  self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_distilbert_for_multiple_choice(*__UpperCAmelCase		)


   def       lowercase_				(self					:						str		)						->    List[Any]:
         """simple docstring"""



         UpperCAmelCase__								=  self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_distilbert_for_token_classification(*__UpperCAmelCase		)





   @slow
   def       lowercase_				(self					:						Optional[int]		)						->    Optional[int]:
         """simple docstring"""



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





@require_tf
class 					A							(    unittest.TestCase					):


   @slow
   def       lowercase_				(self					:						List[Any]		)						->    Dict:
         """simple docstring"""



         UpperCAmelCase__								=  TFDistilBertModel.from_pretrained("distilbert-base-uncased"		)
         UpperCAmelCase__								=  tf.constant([[0, 1, 2, 3, 4, 5]]		)
         UpperCAmelCase__								=  model(__UpperCAmelCase		)[0]

         UpperCAmelCase__								=  [1, 6, 7_6_8]
         self.assertEqual(output.shape	,  __UpperCAmelCase		)

         UpperCAmelCase__								=  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]	,  __UpperCAmelCase	,  atol=1E-4		)



