





import collections
import importlib.util
import os
import re
from pathlib import Path


UpperCAmelCase_     							= 'src/transformers'


# Matches is_xxx_available()
UpperCAmelCase_     							= re.compile(R'is\_([a-z_]*)_available()')
# Catches a one-line _import_struct = {xxx}
UpperCAmelCase_     							= re.compile(R'^_import_structure\s+=\s+\{([^\}]+)\}')
# Catches a line with a key-values pattern: "bla": ["foo", "bar"]
UpperCAmelCase_     							= re.compile(R'\s+"\S*":\s+\[([^\]]*)\]')
# Catches a line if not is_foo_available
UpperCAmelCase_     							= re.compile(R'^\s*if\s+not\s+is\_[a-z_]*\_available\(\)')
# Catches a line _import_struct["bla"].append("foo")
UpperCAmelCase_     							= re.compile(R'^\s*_import_structure\["\S*"\]\.append\("(\S*)"\)')
# Catches a line _import_struct["bla"].extend(["foo", "bar"]) or _import_struct["bla"] = ["foo", "bar"]
UpperCAmelCase_     							= re.compile(R'^\s*_import_structure\[\S*\](?:\.extend\(|\s*=\s+)\[([^\]]*)\]')
# Catches a line with an object between quotes and a comma:     "MyModel",
UpperCAmelCase_     							= re.compile('^\s+"([^"]+)",')
# Catches a line with objects between brackets only:    ["foo", "bar"],
UpperCAmelCase_     							= re.compile('^\s+\[([^\]]+)\]')
# Catches a line with from foo import bar, bla, boo
UpperCAmelCase_     							= re.compile(R'\s+from\s+\S*\s+import\s+([^\(\s].*)\n')
# Catches a line with try:
UpperCAmelCase_     							= re.compile(R'^\s*try:')
# Catches a line with else:
UpperCAmelCase_     							= re.compile(R'^\s*else:')




def 		lowerCAmelCase_    (  __UpperCAmelCase:			Any      )      ->	Union[str, Any]:
    if _re_test_backend.search(__UpperCAmelCase      ) is None:
        return None
    UpperCamelCase__							:				List[str]          =      [b[0] for b in _re_backend.findall(__UpperCAmelCase      )]
    backends.sort()
    return "_and_".join(__UpperCAmelCase      )




def 		lowerCAmelCase_    (  __UpperCAmelCase:			Any      )      ->	str:
    with open(__UpperCAmelCase		,   '''r'''		,   encoding='''utf-8'''		,   newline='''\n'''      ) as f:
        UpperCamelCase__							:				Optional[Any]          =      f.readlines()

    UpperCamelCase__							:				Union[str, Any]          =      0
    while line_index < len(__UpperCAmelCase      ) and not lines[line_index].startswith('''_import_structure = {'''      ):
        line_index += 1

    # If this is a traditional init, just return.
    if line_index >= len(__UpperCAmelCase      ):
        return None

    # First grab the objects without a specific backend in _import_structure
    UpperCamelCase__							:				Optional[Any]          =      []
    while not lines[line_index].startswith('''if TYPE_CHECKING'''      ) and find_backend(lines[line_index]      ) is None:
        UpperCamelCase__							:				Optional[Any]          =      lines[line_index]
        # If we have everything on a single line, let's deal with it.
        if _re_one_line_import_struct.search(__UpperCAmelCase      ):
            UpperCamelCase__							:				List[Any]          =      _re_one_line_import_struct.search(__UpperCAmelCase      ).groups()[0]
            UpperCamelCase__							:				Union[str, Any]          =      re.findall('''\[([^\]]+)\]'''		,   __UpperCAmelCase      )
            for imp in imports:
                objects.extend([obj[1:-1] for obj in imp.split(''', '''      )]      )
            line_index += 1
            continue
        UpperCamelCase__							:				Optional[Any]          =      _re_import_struct_key_value.search(__UpperCAmelCase      )
        if single_line_import_search is not None:
            UpperCamelCase__							:				int          =      [obj[1:-1] for obj in single_line_import_search.groups()[0].split(''', '''      ) if len(__UpperCAmelCase      ) > 0]
            objects.extend(__UpperCAmelCase      )
        elif line.startswith(''' ''' * 8 + '''"'''      ):
            objects.append(line[9:-3]      )
        line_index += 1

    UpperCamelCase__							:				Optional[int]          =      {'''none''': objects}
    # Let's continue with backend-specific objects in _import_structure
    while not lines[line_index].startswith('''if TYPE_CHECKING'''      ):
        # If the line is an if not is_backend_available, we grab all objects associated.
        UpperCamelCase__							:				Optional[int]          =      find_backend(lines[line_index]      )
        # Check if the backend declaration is inside a try block:
        if _re_try.search(lines[line_index - 1]      ) is None:
            UpperCamelCase__							:				List[str]          =      None

        if backend is not None:
            line_index += 1

            # Scroll until we hit the else block of try-except-else
            while _re_else.search(lines[line_index]      ) is None:
                line_index += 1

            line_index += 1

            UpperCamelCase__							:				Union[str, Any]          =      []
            # Until we unindent, add backend objects to the list
            while len(lines[line_index]      ) <= 1 or lines[line_index].startswith(''' ''' * 4      ):
                UpperCamelCase__							:				Optional[Any]          =      lines[line_index]
                if _re_import_struct_add_one.search(__UpperCAmelCase      ) is not None:
                    objects.append(_re_import_struct_add_one.search(__UpperCAmelCase      ).groups()[0]      )
                elif _re_import_struct_add_many.search(__UpperCAmelCase      ) is not None:
                    UpperCamelCase__							:				Optional[Any]          =      _re_import_struct_add_many.search(__UpperCAmelCase      ).groups()[0].split(''', '''      )
                    UpperCamelCase__							:				str          =      [obj[1:-1] for obj in imports if len(__UpperCAmelCase      ) > 0]
                    objects.extend(__UpperCAmelCase      )
                elif _re_between_brackets.search(__UpperCAmelCase      ) is not None:
                    UpperCamelCase__							:				List[str]          =      _re_between_brackets.search(__UpperCAmelCase      ).groups()[0].split(''', '''      )
                    UpperCamelCase__							:				List[Any]          =      [obj[1:-1] for obj in imports if len(__UpperCAmelCase      ) > 0]
                    objects.extend(__UpperCAmelCase      )
                elif _re_quote_object.search(__UpperCAmelCase      ) is not None:
                    objects.append(_re_quote_object.search(__UpperCAmelCase      ).groups()[0]      )
                elif line.startswith(''' ''' * 8 + '''"'''      ):
                    objects.append(line[9:-3]      )
                elif line.startswith(''' ''' * 12 + '''"'''      ):
                    objects.append(line[13:-3]      )
                line_index += 1

            UpperCamelCase__							:				Optional[Any]          =      objects
        else:
            line_index += 1

    # At this stage we are in the TYPE_CHECKING part, first grab the objects without a specific backend
    UpperCamelCase__							:				List[Any]          =      []
    while (
        line_index < len(__UpperCAmelCase      )
        and find_backend(lines[line_index]      ) is None
        and not lines[line_index].startswith('''else'''      )
    ):
        UpperCamelCase__							:				Any          =      lines[line_index]
        UpperCamelCase__							:				int          =      _re_import.search(__UpperCAmelCase      )
        if single_line_import_search is not None:
            objects.extend(single_line_import_search.groups()[0].split(''', '''      )      )
        elif line.startswith(''' ''' * 8      ):
            objects.append(line[8:-2]      )
        line_index += 1

    UpperCamelCase__							:				str          =      {'''none''': objects}
    # Let's continue with backend-specific objects
    while line_index < len(__UpperCAmelCase      ):
        # If the line is an if is_backend_available, we grab all objects associated.
        UpperCamelCase__							:				str          =      find_backend(lines[line_index]      )
        # Check if the backend declaration is inside a try block:
        if _re_try.search(lines[line_index - 1]      ) is None:
            UpperCamelCase__							:				int          =      None

        if backend is not None:
            line_index += 1

            # Scroll until we hit the else block of try-except-else
            while _re_else.search(lines[line_index]      ) is None:
                line_index += 1

            line_index += 1

            UpperCamelCase__							:				Tuple          =      []
            # Until we unindent, add backend objects to the list
            while len(lines[line_index]      ) <= 1 or lines[line_index].startswith(''' ''' * 8      ):
                UpperCamelCase__							:				int          =      lines[line_index]
                UpperCamelCase__							:				List[str]          =      _re_import.search(__UpperCAmelCase      )
                if single_line_import_search is not None:
                    objects.extend(single_line_import_search.groups()[0].split(''', '''      )      )
                elif line.startswith(''' ''' * 12      ):
                    objects.append(line[12:-2]      )
                line_index += 1

            UpperCamelCase__							:				Tuple          =      objects
        else:
            line_index += 1

    return import_dict_objects, type_hint_objects




def 		lowerCAmelCase_    (  __UpperCAmelCase:			List[str]		,   __UpperCAmelCase:			str      )      ->	Optional[Any]:

    def find_duplicates(__UpperCAmelCase:			Optional[int]      ):
        return [k for k, v in collections.Counter(__UpperCAmelCase      ).items() if v > 1]

    if list(import_dict_objects.keys()      ) != list(type_hint_objects.keys()      ):
        return ["Both sides of the init do not have the same backends!"]

    UpperCamelCase__							:				int          =      []
    for key in import_dict_objects.keys():
        UpperCamelCase__							:				int          =      find_duplicates(import_dict_objects[key]      )
        if duplicate_imports:
            errors.append(f"Duplicate _import_structure definitions for: {duplicate_imports}"      )
        UpperCamelCase__							:				List[Any]          =      find_duplicates(type_hint_objects[key]      )
        if duplicate_type_hints:
            errors.append(f"Duplicate TYPE_CHECKING objects for: {duplicate_type_hints}"      )

        if sorted(set(import_dict_objects[key]      )      ) != sorted(set(type_hint_objects[key]      )      ):
            UpperCamelCase__							:				List[Any]          =      '''base imports''' if key == '''none''' else f"{key} backend"
            errors.append(f"Differences for {name}:"      )
            for a in type_hint_objects[key]:
                if a not in import_dict_objects[key]:
                    errors.append(f"  {a} in TYPE_HINT but not in _import_structure."      )
            for a in import_dict_objects[key]:
                if a not in type_hint_objects[key]:
                    errors.append(f"  {a} in _import_structure but not in TYPE_HINT."      )
    return errors




def 		lowerCAmelCase_    (  )      ->	List[str]:
    UpperCamelCase__							:				List[str]          =      []
    for root, _, files in os.walk(__UpperCAmelCase      ):
        if "__init__.py" in files:
            UpperCamelCase__							:				List[Any]          =      os.path.join(__UpperCAmelCase		,   '''__init__.py'''      )
            UpperCamelCase__							:				Optional[int]          =      parse_init(__UpperCAmelCase      )
            if objects is not None:
                UpperCamelCase__							:				List[Any]          =      analyze_results(*__UpperCAmelCase      )
                if len(__UpperCAmelCase      ) > 0:
                    UpperCamelCase__							:				Union[str, Any]          =      f"Problem in {fname}, both halves do not define the same objects.\n{errors[0]}"
                    failures.append('''\n'''.join(__UpperCAmelCase      )      )
    if len(__UpperCAmelCase      ) > 0:
        raise ValueError('''\n\n'''.join(__UpperCAmelCase      )      )




def 		lowerCAmelCase_    (  )      ->	Any:
    UpperCamelCase__							:				Optional[Any]          =      []
    for path, directories, files in os.walk(__UpperCAmelCase      ):
        for folder in directories:
            # Ignore private modules
            if folder.startswith('''_'''      ):
                directories.remove(__UpperCAmelCase      )
                continue
            # Ignore leftovers from branches (empty folders apart from pycache)
            if len(list((Path(__UpperCAmelCase      ) / folder).glob('''*.py'''      )      )      ) == 0:
                continue
            UpperCamelCase__							:				List[Any]          =      str((Path(__UpperCAmelCase      ) / folder).relative_to(__UpperCAmelCase      )      )
            UpperCamelCase__							:				Optional[Any]          =      short_path.replace(os.path.sep		,   '''.'''      )
            submodules.append(__UpperCAmelCase      )
        for fname in files:
            if fname == "__init__.py":
                continue
            UpperCamelCase__							:				Tuple          =      str((Path(__UpperCAmelCase      ) / fname).relative_to(__UpperCAmelCase      )      )
            UpperCamelCase__							:				Union[str, Any]          =      short_path.replace('''.py'''		,   ''''''      ).replace(os.path.sep		,   '''.'''      )
            if len(submodule.split('''.'''      )      ) == 1:
                submodules.append(__UpperCAmelCase      )
    return submodules


UpperCAmelCase_     							= [
    'convert_pytorch_checkpoint_to_tf2',
    'modeling_flax_pytorch_utils',
]




def 		lowerCAmelCase_    (  )      ->	List[str]:
    # This is to make sure the transformers module imported is the one in the repo.
    UpperCamelCase__							:				Any          =      importlib.util.spec_from_file_location(
        '''transformers'''		,   os.path.join(__UpperCAmelCase		,   '''__init__.py'''      )		,   submodule_search_locations=[PATH_TO_TRANSFORMERS]		,   )
    UpperCamelCase__							:				Union[str, Any]          =      spec.loader.load_module()

    UpperCamelCase__							:				Union[str, Any]          =      [
        module
        for module in get_transformers_submodules()
        if module not in IGNORE_SUBMODULES and module not in transformers._import_structure.keys()
    ]
    if len(__UpperCAmelCase      ) > 0:
        UpperCamelCase__							:				Any          =      '''\n'''.join(f"- {module}" for module in module_not_registered      )
        raise ValueError(
            '''The following submodules are not properly registered in the main init of Transformers:\n'''
            f"{list_of_modules}\n"
            '''Make sure they appear somewhere in the keys of `_import_structure` with an empty list as value.'''      )


if __name__ == "__main__":
  check_all_inits()
  check_submodules()








from __future__ import annotations

import os
import tempfile
import unittest

from transformers import ConvBertConfig, 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 import (
      TFConvBertForMaskedLM,
      TFConvBertForMultipleChoice,
      TFConvBertForQuestionAnswering,
      TFConvBertForSequenceClassification,
      TFConvBertForTokenClassification,
      TFConvBertModel,
  )






class     lowercase__       :

   '''simple docstring'''


   def __init__(    self,		__magic_name__,		__magic_name__=13,		__magic_name__=7,		__magic_name__=True,		__magic_name__=True,		__magic_name__=True,		__magic_name__=True,		__magic_name__=99,		__magic_name__=32,		__magic_name__=2,		__magic_name__=4,		__magic_name__=37,		__magic_name__="gelu",		__magic_name__=0.1,		__magic_name__=0.1,		__magic_name__=512,		__magic_name__=16,		__magic_name__=2,		__magic_name__=0.02,		__magic_name__=3,		__magic_name__=4,		__magic_name__=None,		) ->      List[str]:






       """simple docstring"""
       UpperCamelCase__							:				List[Any]          =      parent
       UpperCamelCase__							:				int          =      13
       UpperCamelCase__							:				Optional[Any]          =      7
       UpperCamelCase__							:				Dict          =      True
       UpperCamelCase__							:				Dict          =      True
       UpperCamelCase__							:				str          =      True
       UpperCamelCase__							:				List[str]          =      True
       UpperCamelCase__							:				Tuple          =      99
       UpperCamelCase__							:				Any          =      384
       UpperCamelCase__							:				Tuple          =      2
       UpperCamelCase__							:				int          =      4
       UpperCamelCase__							:				Optional[int]          =      37
       UpperCamelCase__							:				str          =      '''gelu'''
       UpperCamelCase__							:				Any          =      0.1
       UpperCamelCase__							:				Dict          =      0.1
       UpperCamelCase__							:				Tuple          =      512
       UpperCamelCase__							:				int          =      16
       UpperCamelCase__							:				int          =      2
       UpperCamelCase__							:				Any          =      0.02
       UpperCamelCase__							:				Optional[Any]          =      3
       UpperCamelCase__							:				Any          =      4
       UpperCamelCase__							:				Any          =      128
       UpperCamelCase__							:				List[str]          =      2
       UpperCamelCase__							:				List[str]          =      9
       UpperCamelCase__							:				Optional[int]          =      1
       UpperCamelCase__							:				List[Any]          =      None




   def       UpperCamelCase__  (    self							) ->      Dict:






       """simple docstring"""
       UpperCamelCase__							:				Tuple          =      ids_tensor([self.batch_size, self.seq_length],		self.vocab_size							)

       UpperCamelCase__							:				Optional[int]          =      None
       if self.use_input_mask:
           UpperCamelCase__							:				Dict          =      random_attention_mask([self.batch_size, self.seq_length]							)

       UpperCamelCase__							:				Dict          =      None
       if self.use_token_type_ids:
           UpperCamelCase__							:				List[str]          =      ids_tensor([self.batch_size, self.seq_length],		self.type_vocab_size							)

       UpperCamelCase__							:				str          =      None
       UpperCamelCase__							:				Union[str, Any]          =      None
       UpperCamelCase__							:				Dict          =      None
       if self.use_labels:
           UpperCamelCase__							:				str          =      ids_tensor([self.batch_size],		self.type_sequence_label_size							)
           UpperCamelCase__							:				List[str]          =      ids_tensor([self.batch_size, self.seq_length],		self.num_labels							)
           UpperCamelCase__							:				Tuple          =      ids_tensor([self.batch_size],		self.num_choices							)

       UpperCamelCase__							:				Any          =      ConvBertConfig(
           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,		initializer_range=self.initializer_range,		return_dict=__magic_name__,		)

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




   def       UpperCamelCase__  (    self,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__							) ->      Tuple:






       """simple docstring"""
       UpperCamelCase__							:				Tuple          =      TFConvBertModel(config=__magic_name__							)
       UpperCamelCase__							:				str          =      {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}

       UpperCamelCase__							:				Any          =      [input_ids, input_mask]
       UpperCamelCase__							:				int          =      model(__magic_name__							)

       UpperCamelCase__							:				int          =      model(__magic_name__							)

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




   def       UpperCamelCase__  (    self,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__							) ->      int:






       """simple docstring"""
       UpperCamelCase__							:				Any          =      TFConvBertForMaskedLM(config=__magic_name__							)
       UpperCamelCase__							:				List[str]          =      {
           '''input_ids''': input_ids,
           '''attention_mask''': input_mask,
           '''token_type_ids''': token_type_ids,
       }
       UpperCamelCase__							:				Tuple          =      model(__magic_name__							)
       self.parent.assertEqual(result.logits.shape,		(self.batch_size, self.seq_length, self.vocab_size)							)




   def       UpperCamelCase__  (    self,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__							) ->      Dict:






       """simple docstring"""
       UpperCamelCase__							:				str          =      self.num_labels
       UpperCamelCase__							:				Optional[int]          =      TFConvBertForSequenceClassification(config=__magic_name__							)
       UpperCamelCase__							:				str          =      {
           '''input_ids''': input_ids,
           '''attention_mask''': input_mask,
           '''token_type_ids''': token_type_ids,
       }

       UpperCamelCase__							:				Any          =      model(__magic_name__							)
       self.parent.assertEqual(result.logits.shape,		(self.batch_size, self.num_labels)							)




   def       UpperCamelCase__  (    self,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__							) ->      Tuple:






       """simple docstring"""
       UpperCamelCase__							:				int          =      self.num_choices
       UpperCamelCase__							:				str          =      TFConvBertForMultipleChoice(config=__magic_name__							)
       UpperCamelCase__							:				Optional[int]          =      tf.tile(tf.expand_dims(__magic_name__,		1							),		(1, self.num_choices, 1)							)
       UpperCamelCase__							:				Any          =      tf.tile(tf.expand_dims(__magic_name__,		1							),		(1, self.num_choices, 1)							)
       UpperCamelCase__							:				Tuple          =      tf.tile(tf.expand_dims(__magic_name__,		1							),		(1, self.num_choices, 1)							)
       UpperCamelCase__							:				int          =      {
           '''input_ids''': multiple_choice_inputs_ids,
           '''attention_mask''': multiple_choice_input_mask,
           '''token_type_ids''': multiple_choice_token_type_ids,
       }
       UpperCamelCase__							:				Tuple          =      model(__magic_name__							)
       self.parent.assertEqual(result.logits.shape,		(self.batch_size, self.num_choices)							)




   def       UpperCamelCase__  (    self,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__							) ->      Optional[int]:






       """simple docstring"""
       UpperCamelCase__							:				Optional[Any]          =      self.num_labels
       UpperCamelCase__							:				Any          =      TFConvBertForTokenClassification(config=__magic_name__							)
       UpperCamelCase__							:				str          =      {
           '''input_ids''': input_ids,
           '''attention_mask''': input_mask,
           '''token_type_ids''': token_type_ids,
       }
       UpperCamelCase__							:				Dict          =      model(__magic_name__							)
       self.parent.assertEqual(result.logits.shape,		(self.batch_size, self.seq_length, self.num_labels)							)




   def       UpperCamelCase__  (    self,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__							) ->      str:






       """simple docstring"""
       UpperCamelCase__							:				Union[str, Any]          =      TFConvBertForQuestionAnswering(config=__magic_name__							)
       UpperCamelCase__							:				Optional[Any]          =      {
           '''input_ids''': input_ids,
           '''attention_mask''': input_mask,
           '''token_type_ids''': token_type_ids,
       }

       UpperCamelCase__							:				List[str]          =      model(__magic_name__							)
       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       UpperCamelCase__  (    self							) ->      str:






       """simple docstring"""
       UpperCamelCase__							:				Any          =      self.prepare_config_and_inputs()
       (
           (
           UpperCamelCase__
       )   ,(
           UpperCamelCase__
       )   ,(
           UpperCamelCase__
       )   ,(
           UpperCamelCase__
       )   ,(
           UpperCamelCase__
       )   ,(
           UpperCamelCase__
       )   ,(
           UpperCamelCase__
       )   ,
       )							:				Any          =      config_and_inputs
       UpperCamelCase__							:				List[str]          =      {'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
       return config, inputs_dict






@require_tf
class     lowercase__       (	__lowerCamelCase			,				__lowerCamelCase			,				unittest.TestCase				):

   '''simple docstring'''


   a						:							Union[str, Any]   		=		(
       (
           TFConvBertModel,
           TFConvBertForMaskedLM,
           TFConvBertForQuestionAnswering,
           TFConvBertForSequenceClassification,
           TFConvBertForTokenClassification,
           TFConvBertForMultipleChoice,
       )
       if is_tf_available()
       else ()
   )
   a						:							int   		=		(
       {
           "feature-extraction": TFConvBertModel,
           "fill-mask": TFConvBertForMaskedLM,
           "question-answering": TFConvBertForQuestionAnswering,
           "text-classification": TFConvBertForSequenceClassification,
           "token-classification": TFConvBertForTokenClassification,
           "zero-shot": TFConvBertForSequenceClassification,
       }
       if is_tf_available()
       else {}
   )
   a						:							Optional[Any]   		=		False
   a						:							List[str]   		=		False
   a						:							List[Any]   		=		False




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






       """simple docstring"""
       UpperCamelCase__							:				List[str]          =      TFConvBertModelTester(self							)
       UpperCamelCase__							:				Optional[int]          =      ConfigTester(self,		config_class=__magic_name__,		hidden_size=37							)




   def       UpperCamelCase__  (    self							) ->      int:






       """simple docstring"""
       self.config_tester.run_common_tests()




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






       """simple docstring"""
       UpperCamelCase__							:				Any          =      self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_model(*__magic_name__							)




   def       UpperCamelCase__  (    self							) ->      Tuple:






       """simple docstring"""
       UpperCamelCase__							:				str          =      self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_masked_lm(*__magic_name__							)




   def       UpperCamelCase__  (    self							) ->      Dict:






       """simple docstring"""
       UpperCamelCase__							:				List[Any]          =      self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_multiple_choice(*__magic_name__							)




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






       """simple docstring"""
       UpperCamelCase__							:				str          =      self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_question_answering(*__magic_name__							)




   def       UpperCamelCase__  (    self							) ->      Tuple:






       """simple docstring"""
       UpperCamelCase__							:				Optional[int]          =      self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_sequence_classification(*__magic_name__							)




   def       UpperCamelCase__  (    self							) ->      Dict:






       """simple docstring"""
       UpperCamelCase__							:				str          =      self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_token_classification(*__magic_name__							)




   @slow
   def       UpperCamelCase__  (    self							) ->      Optional[int]:






       """simple docstring"""
       UpperCamelCase__   ,UpperCamelCase__							:				Tuple          =      self.model_tester.prepare_config_and_inputs_for_common()
       UpperCamelCase__							:				Union[str, Any]          =      True
       UpperCamelCase__							:				Optional[int]          =      True

       if hasattr(__magic_name__,		'''use_cache'''							):
           UpperCamelCase__							:				Union[str, Any]          =      True

       UpperCamelCase__							:				Tuple          =      getattr(self.model_tester,		'''encoder_seq_length''',		self.model_tester.seq_length							)
       UpperCamelCase__							:				Any          =      getattr(self.model_tester,		'''key_length''',		__magic_name__							)

       for model_class in self.all_model_classes:
           UpperCamelCase__							:				Optional[int]          =      self._prepare_for_class(__magic_name__,		__magic_name__							)
           UpperCamelCase__							:				Any          =      model_class(__magic_name__							)
           UpperCamelCase__							:				List[str]          =      len(model(__magic_name__							)							)

           with tempfile.TemporaryDirectory() as tmpdirname:
               model.save_pretrained(__magic_name__,		saved_model=__magic_name__							)
               UpperCamelCase__							:				List[Any]          =      os.path.join(__magic_name__,		'''saved_model''',		'''1'''							)
               UpperCamelCase__							:				Dict          =      tf.keras.models.load_model(__magic_name__							)
               UpperCamelCase__							:				Optional[int]          =      model(__magic_name__							)

               if self.is_encoder_decoder:
                   UpperCamelCase__							:				Union[str, Any]          =      outputs['''encoder_hidden_states''']
                   UpperCamelCase__							:				Any          =      outputs['''encoder_attentions''']
               else:
                   UpperCamelCase__							:				Optional[Any]          =      outputs['''hidden_states''']
                   UpperCamelCase__							:				Dict          =      outputs['''attentions''']

               self.assertEqual(len(__magic_name__							),		__magic_name__							)

               UpperCamelCase__							:				Optional[Any]          =      getattr(
                   self.model_tester,		'''expected_num_hidden_layers''',		self.model_tester.num_hidden_layers + 1							)

               self.assertEqual(len(__magic_name__							),		__magic_name__							)
               self.assertListEqual(
                   list(output_hidden_states[0].shape[-2:]							),		[self.model_tester.seq_length, self.model_tester.hidden_size],		)

               self.assertEqual(len(__magic_name__							),		self.model_tester.num_hidden_layers							)
               self.assertListEqual(
                   list(output_attentions[0].shape[-3:]							),		[self.model_tester.num_attention_heads / 2, encoder_seq_length, encoder_key_length],		)




   @slow
   def       UpperCamelCase__  (    self							) ->      str:






       """simple docstring"""
       UpperCamelCase__							:				str          =      TFConvBertModel.from_pretrained('''YituTech/conv-bert-base'''							)
       self.assertIsNotNone(__magic_name__							)




   def       UpperCamelCase__  (    self							) ->      Dict:






       """simple docstring"""
       UpperCamelCase__   ,UpperCamelCase__							:				int          =      self.model_tester.prepare_config_and_inputs_for_common()
       UpperCamelCase__							:				str          =      True
       UpperCamelCase__							:				Union[str, Any]          =      getattr(self.model_tester,		'''decoder_seq_length''',		self.model_tester.seq_length							)
       UpperCamelCase__							:				str          =      getattr(self.model_tester,		'''encoder_seq_length''',		self.model_tester.seq_length							)
       UpperCamelCase__							:				List[str]          =      getattr(self.model_tester,		'''key_length''',		__magic_name__							)
       UpperCamelCase__							:				int          =      getattr(self.model_tester,		'''key_length''',		__magic_name__							)

       def check_decoder_attentions_output(__magic_name__							):
           UpperCamelCase__							:				List[str]          =      len(__magic_name__							)
           self.assertEqual(out_len % 2,		0							)
           UpperCamelCase__							:				Optional[Any]          =      outputs.decoder_attentions
           self.assertEqual(len(__magic_name__							),		self.model_tester.num_hidden_layers							)
           self.assertListEqual(
               list(decoder_attentions[0].shape[-3:]							),		[self.model_tester.num_attention_heads / 2, decoder_seq_length, decoder_key_length],		)

       def check_encoder_attentions_output(__magic_name__							):
           UpperCamelCase__							:				int          =      [
               t.numpy() for t in (outputs.encoder_attentions if config.is_encoder_decoder else outputs.attentions)
           ]
           self.assertEqual(len(__magic_name__							),		self.model_tester.num_hidden_layers							)
           self.assertListEqual(
               list(attentions[0].shape[-3:]							),		[self.model_tester.num_attention_heads / 2, encoder_seq_length, encoder_key_length],		)

       for model_class in self.all_model_classes:
           UpperCamelCase__							:				Dict          =      True
           UpperCamelCase__							:				str          =      False
           UpperCamelCase__							:				Optional[Any]          =      model_class(__magic_name__							)
           UpperCamelCase__							:				Dict          =      model(self._prepare_for_class(__magic_name__,		__magic_name__							)							)
           UpperCamelCase__							:				int          =      len(__magic_name__							)
           self.assertEqual(config.output_hidden_states,		__magic_name__							)
           check_encoder_attentions_output(__magic_name__							)

           if self.is_encoder_decoder:
               UpperCamelCase__							:				str          =      model_class(__magic_name__							)
               UpperCamelCase__							:				List[str]          =      model(self._prepare_for_class(__magic_name__,		__magic_name__							)							)
               self.assertEqual(config.output_hidden_states,		__magic_name__							)
               check_decoder_attentions_output(__magic_name__							)

           # Check that output attentions can also be changed via the config
           del inputs_dict["output_attentions"]
           UpperCamelCase__							:				List[Any]          =      True
           UpperCamelCase__							:				Dict          =      model_class(__magic_name__							)
           UpperCamelCase__							:				Optional[Any]          =      model(self._prepare_for_class(__magic_name__,		__magic_name__							)							)
           self.assertEqual(config.output_hidden_states,		__magic_name__							)
           check_encoder_attentions_output(__magic_name__							)

           # Check attention is always last and order is fine
           UpperCamelCase__							:				List[Any]          =      True
           UpperCamelCase__							:				List[Any]          =      True
           UpperCamelCase__							:				Dict          =      model_class(__magic_name__							)
           UpperCamelCase__							:				List[Any]          =      model(self._prepare_for_class(__magic_name__,		__magic_name__							)							)

           self.assertEqual(out_len + (2 if self.is_encoder_decoder else 1),		len(__magic_name__							)							)
           self.assertEqual(model.config.output_hidden_states,		__magic_name__							)
           check_encoder_attentions_output(__magic_name__							)






@require_tf
class     lowercase__       (	unittest.TestCase				):

   '''simple docstring'''


   @slow
   def       UpperCamelCase__  (    self							) ->      int:






       """simple docstring"""
       UpperCamelCase__							:				Union[str, Any]          =      TFConvBertModel.from_pretrained('''YituTech/conv-bert-base'''							)
       UpperCamelCase__							:				Tuple          =      tf.constant([[0, 1, 2, 3, 4, 5]]							)
       UpperCamelCase__							:				int          =      model(__magic_name__							)[0]

       UpperCamelCase__							:				Dict          =      [1, 6, 768]
       self.assertEqual(output.shape,		__magic_name__							)

       UpperCamelCase__							:				Union[str, Any]          =      tf.constant(
           [
               [
                   [-0.0347_5493, -0.468_6034, -0.3063_8832],
                   [0.2263_7248, -0.2698_8646, -0.742_3424],
                   [0.1032_4868, -0.4501_3508, -0.5828_0784],
               ]
           ]							)
       tf.debugging.assert_near(output[:, :3, :3],		__magic_name__,		atol=1E-4							)

