import importlib
import os
import sys


# This is required to make the module import works (when the python process is running from the root of the repo)
sys.path.append(""".""")





def        lowercase(     UpperCamelCase_    )						->     Tuple:







 '''simple docstring'''
 UpperCamelCase          =	test_file.split(os.path.sep    )
 if components[0:2] != ["tests", "models"]:
  raise ValueError(
      """`test_file` should start with `tests/models/` (with `/` being the OS specific path separator). Got """
      f"""{test_file} instead."""    )
 UpperCamelCase          =	components[-1]
 if not test_fn.endswith("""py"""    ):
  raise ValueError(f"""`test_file` should be a python file. Got {test_fn} instead."""    )
 if not test_fn.startswith("""test_modeling_"""    ):
  raise ValueError(
      f"""`test_file` should point to a file name of the form `test_modeling_*.py`. Got {test_fn} instead."""    )

 UpperCamelCase          =	components[:-1] + [test_fn.replace(""".py"""				, """"""    )]
 UpperCamelCase          =	'.'.join(UpperCamelCase_    )

 return test_module_path





def        lowercase(     UpperCamelCase_    )						->     Tuple:







 '''simple docstring'''
 UpperCamelCase          =	get_module_path(UpperCamelCase_    )
 UpperCamelCase          =	importlib.import_module(UpperCamelCase_    )

 return test_module





def        lowercase(     UpperCamelCase_    )						->     Optional[int]:







 '''simple docstring'''
 UpperCamelCase          =	[]
 UpperCamelCase          =	get_test_module(UpperCamelCase_    )
 for attr in dir(UpperCamelCase_    ):
  if attr.endswith("""ModelTester"""    ):
   tester_classes.append(getattr(UpperCamelCase_				, UpperCamelCase_    )    )

    # sort with class names
 return sorted(UpperCamelCase_				, key=lambda UpperCamelCase_    : x.__name__    )





def        lowercase(     UpperCamelCase_    )						->     List[Any]:







 '''simple docstring'''
 UpperCamelCase          =	[]
 UpperCamelCase          =	get_test_module(UpperCamelCase_    )
 for attr in dir(UpperCamelCase_    ):
  UpperCamelCase          =	getattr(UpperCamelCase_				, UpperCamelCase_    )
  # (TF/Flax)ModelTesterMixin is also an attribute in specific model test module. Let's exclude them by checking
  # `all_model_classes` is not empty (which also excludes other special classes).
  UpperCamelCase          =	getattr(UpperCamelCase_				, """all_model_classes"""				, []    )
  if len(UpperCamelCase_    ) > 0:
   test_classes.append(UpperCamelCase_    )

    # sort with class names
 return sorted(UpperCamelCase_				, key=lambda UpperCamelCase_    : x.__name__    )





def        lowercase(     UpperCamelCase_    )						->     str:







 '''simple docstring'''
 UpperCamelCase          =	get_test_classes(UpperCamelCase_    )
 UpperCamelCase          =	set()
 for test_class in test_classes:
  model_classes.update(test_class.all_model_classes    )

 # sort with class names
 return sorted(UpperCamelCase_				, key=lambda UpperCamelCase_    : x.__name__    )





def        lowercase(     UpperCamelCase_    )						->     Union[str, Any]:







 '''simple docstring'''
 UpperCamelCase          =	test_class()
 if hasattr(UpperCamelCase_				, """setUp"""    ):
  test.setUp()

 UpperCamelCase          =	None
 if hasattr(UpperCamelCase_				, """model_tester"""    ):
  # `(TF/Flax)ModelTesterMixin` has this attribute default to `None`. Let's skip this case.
  if test.model_tester is not None:
   UpperCamelCase          =	test.model_tester.__class__

 return model_tester





def        lowercase(     UpperCamelCase_				, UpperCamelCase_    )						->     Optional[int]:







 '''simple docstring'''
 UpperCamelCase          =	get_test_classes(UpperCamelCase_    )

 UpperCamelCase          =	[]
 for test_class in test_classes:
  if model_class in test_class.all_model_classes:
   target_test_classes.append(UpperCamelCase_    )

    # sort with class names
 return sorted(UpperCamelCase_				, key=lambda UpperCamelCase_    : x.__name__    )





def        lowercase(     UpperCamelCase_				, UpperCamelCase_    )						->     Optional[Any]:







 '''simple docstring'''
 UpperCamelCase          =	get_test_classes_for_model(UpperCamelCase_				, UpperCamelCase_    )

 UpperCamelCase          =	[]
 for test_class in test_classes:
  UpperCamelCase          =	get_model_tester_from_test_class(UpperCamelCase_    )
  if tester_class is not None:
   tester_classes.append(UpperCamelCase_    )

    # sort with class names
 return sorted(UpperCamelCase_				, key=lambda UpperCamelCase_    : x.__name__    )





def        lowercase(     UpperCamelCase_    )						->     List[str]:







 '''simple docstring'''
 UpperCamelCase          =	get_test_classes(UpperCamelCase_    )
 UpperCamelCase          =	{test_class: get_model_tester_from_test_class(UpperCamelCase_    ) for test_class in test_classes}
 return test_tester_mapping





def        lowercase(     UpperCamelCase_    )						->     Any:







 '''simple docstring'''
 UpperCamelCase          =	get_model_classes(UpperCamelCase_    )
 UpperCamelCase          =	{
     model_class: get_test_classes_for_model(UpperCamelCase_				, UpperCamelCase_    ) for model_class in model_classes
 }
 return model_test_mapping





def        lowercase(     UpperCamelCase_    )						->     str:







 '''simple docstring'''
 UpperCamelCase          =	get_model_classes(UpperCamelCase_    )
 UpperCamelCase          =	{
     model_class: get_tester_classes_for_model(UpperCamelCase_				, UpperCamelCase_    ) for model_class in model_classes
 }
 return model_to_tester_mapping





def        lowercase(     UpperCamelCase_    )						->     Tuple:







 '''simple docstring'''
 if isinstance(UpperCamelCase_				, UpperCamelCase_    ):
  return o
 elif isinstance(UpperCamelCase_				, UpperCamelCase_    ):
  return o.__name__
 elif isinstance(UpperCamelCase_				, (list, tuple)    ):
  return [to_json(UpperCamelCase_    ) for x in o]
 elif isinstance(UpperCamelCase_				, UpperCamelCase_    ):
  return {to_json(UpperCamelCase_    ): to_json(UpperCamelCase_    ) for k, v in o.items()}
 else:
  return o

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


a_    					=       logging.get_logger(__name__)

a_    					=       {
    # See all MEGATRON_BERT models at https://huggingface.co/models?filter=bert
}





class 		_lowercase						(					snake_case_       ):
 lowercase				     =   'megatron-bert'

 def __init__( self	:							List[str]   ,      snake_case	:							Tuple=2_9_0_5_6   ,      snake_case	:							Dict=1_0_2_4   ,      snake_case	:							Dict=2_4   ,      snake_case	:							Union[str, Any]=1_6   ,      snake_case	:							Optional[int]=4_0_9_6   ,      snake_case	:							Optional[int]="gelu"   ,      snake_case	:							Any=0.1   ,      snake_case	:							Tuple=0.1   ,      snake_case	:							Optional[int]=5_1_2   ,      snake_case	:							List[Any]=2   ,      snake_case	:							Tuple=0.02   ,      snake_case	:							Optional[Any]=1e-12   ,      snake_case	:							str=0   ,      snake_case	:							Optional[int]="absolute"   ,      snake_case	:							Union[str, Any]=True   ,      **snake_case	:							Any   ,      )   ->						List[Any]:

  """simple docstring"""





  super().__init__(pad_token_id=snake_case   ,      **snake_case			)

  UpperCamelCase_					:						Optional[Any] =					vocab_size
  UpperCamelCase_					:						Any =					hidden_size
  UpperCamelCase_					:						Union[str, Any] =					num_hidden_layers
  UpperCamelCase_					:						List[Any] =					num_attention_heads
  UpperCamelCase_					:						str =					hidden_act
  UpperCamelCase_					:						List[str] =					intermediate_size
  UpperCamelCase_					:						List[Any] =					hidden_dropout_prob
  UpperCamelCase_					:						Any =					attention_probs_dropout_prob
  UpperCamelCase_					:						Tuple =					max_position_embeddings
  UpperCamelCase_					:						Dict =					type_vocab_size
  UpperCamelCase_					:						Optional[int] =					initializer_range
  UpperCamelCase_					:						Optional[Any] =					layer_norm_eps
  UpperCamelCase_					:						Dict =					position_embedding_type
  UpperCamelCase_					:						List[str] =					use_cache



