import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
    import torch

    from transformers import (
        OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST,
        OpenAIGPTConfig,
        OpenAIGPTDoubleHeadsModel,
        OpenAIGPTForSequenceClassification,
        OpenAIGPTLMHeadModel,
        OpenAIGPTModel,
    )



class  SCREAMING_SNAKE_CASE_ :
  '''simple docstring'''


  def __init__(				self    :					List[Any]      ,	SCREAMING_SNAKE_CASE__    :					List[Any]      ,	SCREAMING_SNAKE_CASE__    :					Optional[Any]=13      ,	SCREAMING_SNAKE_CASE__    :					Optional[Any]=7      ,	SCREAMING_SNAKE_CASE__    :					Dict=True      ,	SCREAMING_SNAKE_CASE__    :					Optional[int]=True      ,	SCREAMING_SNAKE_CASE__    :					Any=True      ,	SCREAMING_SNAKE_CASE__    :					List[str]=99      ,	SCREAMING_SNAKE_CASE__    :					Union[str, Any]=32      ,	SCREAMING_SNAKE_CASE__    :					List[Any]=5      ,	SCREAMING_SNAKE_CASE__    :					Any=4      ,	SCREAMING_SNAKE_CASE__    :					List[Any]=37      ,	SCREAMING_SNAKE_CASE__    :					Union[str, Any]="gelu"      ,	SCREAMING_SNAKE_CASE__    :					Optional[Any]=0.1      ,	SCREAMING_SNAKE_CASE__    :					Optional[Any]=0.1      ,	SCREAMING_SNAKE_CASE__    :					Any=5_12      ,	SCREAMING_SNAKE_CASE__    :					str=16      ,	SCREAMING_SNAKE_CASE__    :					str=2      ,	SCREAMING_SNAKE_CASE__    :					str=0.0_2      ,	SCREAMING_SNAKE_CASE__    :					Tuple=3      ,	SCREAMING_SNAKE_CASE__    :					str=4      ,	SCREAMING_SNAKE_CASE__    :					Union[str, Any]=None      ,	)    ->				Union[str, Any]:
         A						:     Union[str, Any]         =parent
         A						:     Dict         =batch_size
         A						:     str         =seq_length
         A						:     Union[str, Any]         =is_training
         A						:     Tuple         =use_token_type_ids
         A						:     Union[str, Any]         =use_labels
         A						:     str         =vocab_size
         A						:     Optional[Any]         =hidden_size
         A						:     Tuple         =num_hidden_layers
         A						:     Optional[Any]         =num_attention_heads
         A						:     int         =intermediate_size
         A						:     Optional[Any]         =hidden_act
         A						:     Dict         =hidden_dropout_prob
         A						:     List[str]         =attention_probs_dropout_prob
         A						:     Optional[Any]         =max_position_embeddings
         A						:     str         =type_vocab_size
         A						:     List[Any]         =type_sequence_label_size
         A						:     Optional[int]         =initializer_range
         A						:     int         =num_labels
         A						:     Any         =num_choices
         A						:     Dict         =scope
         A						:     str         =self.vocab_size - 1







  def 		SCREAMING_SNAKE_CASE_		(				self    :					Any     )    ->				List[Any]:
         A						:     List[str]         =ids_tensor([self.batch_size, self.seq_length]      ,	self.vocab_size     )

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

         A						:     Dict         =None
         A						:     Optional[int]         =None
         A						:     str         =None
         if self.use_labels:
                A						:     Union[str, Any]         =ids_tensor([self.batch_size]      ,	self.type_sequence_label_size     )
                A						:     Dict         =ids_tensor([self.batch_size, self.seq_length]      ,	self.num_labels     )
                A						:     Optional[Any]         =ids_tensor([self.batch_size]      ,	self.num_choices     )

         A						:     List[str]         =OpenAIGPTConfig(
             vocab_size=self.vocab_size      ,	n_embd=self.hidden_size      ,	n_layer=self.num_hidden_layers      ,	n_head=self.num_attention_heads      ,	n_positions=self.max_position_embeddings      ,	pad_token_id=self.pad_token_id      ,	)

         A						:     Optional[Any]         =ids_tensor([self.num_hidden_layers, self.num_attention_heads]      ,	2     )

         return (
             config,
             input_ids,
             head_mask,
             token_type_ids,
             sequence_labels,
             token_labels,
             choice_labels,
         )







  def 		SCREAMING_SNAKE_CASE_		(				self    :					List[Any]      ,	SCREAMING_SNAKE_CASE__    :					List[str]      ,	SCREAMING_SNAKE_CASE__    :					str      ,	SCREAMING_SNAKE_CASE__    :					str      ,	SCREAMING_SNAKE_CASE__    :					Any      ,	*SCREAMING_SNAKE_CASE__    :					Optional[int]     )    ->				Optional[Any]:
         A						:     str         =OpenAIGPTModel(config=UpperCamelCase_     )
         model.to(UpperCamelCase_     )
         model.eval()

         A						:     List[str]         =model(UpperCamelCase_      ,	token_type_ids=UpperCamelCase_      ,	head_mask=UpperCamelCase_     )
         A						:     Any         =model(UpperCamelCase_      ,	token_type_ids=UpperCamelCase_     )
         A						:     Union[str, Any]         =model(UpperCamelCase_     )

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







  def 		SCREAMING_SNAKE_CASE_		(				self    :					Optional[Any]      ,	SCREAMING_SNAKE_CASE__    :					str      ,	SCREAMING_SNAKE_CASE__    :					Tuple      ,	SCREAMING_SNAKE_CASE__    :					str      ,	SCREAMING_SNAKE_CASE__    :					Union[str, Any]      ,	*SCREAMING_SNAKE_CASE__    :					Any     )    ->				str:
         A						:     Any         =OpenAIGPTLMHeadModel(UpperCamelCase_     )
         model.to(UpperCamelCase_     )
         model.eval()

         A						:     List[Any]         =model(UpperCamelCase_      ,	token_type_ids=UpperCamelCase_      ,	labels=UpperCamelCase_     )
         self.parent.assertEqual(result.loss.shape      ,	()     )
         self.parent.assertEqual(result.logits.shape      ,	(self.batch_size, self.seq_length, self.vocab_size)     )







  def 		SCREAMING_SNAKE_CASE_		(				self    :					Tuple      ,	SCREAMING_SNAKE_CASE__    :					Dict      ,	SCREAMING_SNAKE_CASE__    :					List[Any]      ,	SCREAMING_SNAKE_CASE__    :					Any      ,	SCREAMING_SNAKE_CASE__    :					Any      ,	*SCREAMING_SNAKE_CASE__    :					Tuple     )    ->				int:
         A						:     Any         =OpenAIGPTDoubleHeadsModel(UpperCamelCase_     )
         model.to(UpperCamelCase_     )
         model.eval()

         A						:     str         =model(UpperCamelCase_      ,	token_type_ids=UpperCamelCase_      ,	labels=UpperCamelCase_     )
         self.parent.assertEqual(result.loss.shape      ,	()     )
         self.parent.assertEqual(result.logits.shape      ,	(self.batch_size, self.seq_length, self.vocab_size)     )







  def 		SCREAMING_SNAKE_CASE_		(				self    :					Optional[Any]      ,	SCREAMING_SNAKE_CASE__    :					Optional[Any]      ,	SCREAMING_SNAKE_CASE__    :					str      ,	SCREAMING_SNAKE_CASE__    :					Dict      ,	SCREAMING_SNAKE_CASE__    :					List[str]      ,	*SCREAMING_SNAKE_CASE__    :					int     )    ->				Optional[int]:
         A						:     Tuple         =self.num_labels
         A						:     int         =OpenAIGPTForSequenceClassification(UpperCamelCase_     )
         model.to(UpperCamelCase_     )
         model.eval()

         A						:     str         =ids_tensor([self.batch_size]      ,	self.type_sequence_label_size     )
         A						:     Tuple         =model(UpperCamelCase_      ,	token_type_ids=UpperCamelCase_      ,	labels=UpperCamelCase_     )
         self.parent.assertEqual(result.logits.shape      ,	(self.batch_size, self.num_labels)     )







  def 		SCREAMING_SNAKE_CASE_		(				self    :					int     )    ->				List[str]:
         A						:     int         =self.prepare_config_and_inputs()
         (
             A 
         )						:     Union[str, Any]         =config_and_inputs
         A						:     List[str]         ={
             "input_ids": input_ids,
             "token_type_ids": token_type_ids,
             "head_mask": head_mask,
         }

         return config, inputs_dict







@require_torch
class  SCREAMING_SNAKE_CASE_ (					lowerCAmelCase_   ,						lowerCAmelCase_   ,						lowerCAmelCase_   ,						unittest.TestCase			):
  '''simple docstring'''


  lowercase		:     Union[str, Any]            =				(
      (OpenAIGPTModel, OpenAIGPTLMHeadModel, OpenAIGPTDoubleHeadsModel, OpenAIGPTForSequenceClassification)
      if is_torch_available()
      else ()
  )
  lowercase		:     List[str]            =				(
      (OpenAIGPTLMHeadModel,) if is_torch_available() else ()
  )  # TODO (PVP): Add Double HeadsModel when generate() function is changed accordingly
  lowercase		:     Optional[int]            =				(
      {
          "feature-extraction": OpenAIGPTModel,
          "text-classification": OpenAIGPTForSequenceClassification,
          "text-generation": OpenAIGPTLMHeadModel,
          "zero-shot": OpenAIGPTForSequenceClassification,
      }
      if is_torch_available()
      else {}
  )







  def 		SCREAMING_SNAKE_CASE_		(				self    :					Optional[int]      ,	SCREAMING_SNAKE_CASE__    :					int      ,	SCREAMING_SNAKE_CASE__    :					Optional[int]      ,	SCREAMING_SNAKE_CASE__    :					Tuple      ,	SCREAMING_SNAKE_CASE__    :					Optional[int]      ,	SCREAMING_SNAKE_CASE__    :					List[str]     )    ->				Union[str, Any]:
         if pipeline_test_casse_name == "ZeroShotClassificationPipelineTests":
                # Get `tokenizer does not have a padding token` error for both fast/slow tokenizers.
                # `OpenAIGPTConfig` was never used in pipeline tests, either because of a missing checkpoint or because a
                # tiny config could not be created.
                return True

         return False







  def 		SCREAMING_SNAKE_CASE_		(				self    :					List[str]      ,	SCREAMING_SNAKE_CASE__    :					Any      ,	SCREAMING_SNAKE_CASE__    :					Optional[int]      ,	SCREAMING_SNAKE_CASE__    :					Union[str, Any]=False     )    ->				str:
         A						:     Union[str, Any]         =super()._prepare_for_class(UpperCamelCase_      ,	UpperCamelCase_      ,	return_labels=UpperCamelCase_     )

         if return_labels:
                if model_class.__name__ == "OpenAIGPTDoubleHeadsModel":
                       A						:     List[str]         =torch.zeros(
                           (self.model_tester.batch_size, self.model_tester.num_choices, self.model_tester.seq_length)      ,	dtype=torch.long      ,	device=UpperCamelCase_      ,	)
                       A						:     str         =inputs_dict["labels"]
                       A						:     int         =inputs_dict["labels"]
                       A						:     List[Any]         =torch.zeros(
                           (self.model_tester.batch_size, self.model_tester.num_choices)      ,	dtype=torch.long      ,	device=UpperCamelCase_      ,	)
                       A						:     Any         =torch.zeros(
                           self.model_tester.batch_size      ,	dtype=torch.long      ,	device=UpperCamelCase_     )
         return inputs_dict







  def 		SCREAMING_SNAKE_CASE_		(				self    :					List[Any]     )    ->				List[str]:
         A						:     Union[str, Any]         =OpenAIGPTModelTester(self     )
         A						:     Optional[int]         =ConfigTester(self      ,	config_class=UpperCamelCase_      ,	n_embd=37     )







  def 		SCREAMING_SNAKE_CASE_		(				self    :					Optional[int]     )    ->				Union[str, Any]:
         self.config_tester.run_common_tests()







  def 		SCREAMING_SNAKE_CASE_		(				self    :					Optional[int]     )    ->				Optional[int]:
         A						:     int         =self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_openai_gpt_model(*UpperCamelCase_     )







  def 		SCREAMING_SNAKE_CASE_		(				self    :					Tuple     )    ->				Tuple:
         A						:     Union[str, Any]         =self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_lm_head_model(*UpperCamelCase_     )







  def 		SCREAMING_SNAKE_CASE_		(				self    :					Optional[Any]     )    ->				Optional[int]:
         A						:     Tuple         =self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_double_lm_head_model(*UpperCamelCase_     )







  def 		SCREAMING_SNAKE_CASE_		(				self    :					Optional[Any]     )    ->				Union[str, Any]:
         A						:     Optional[Any]         =self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_openai_gpt_for_sequence_classification(*UpperCamelCase_     )







  @slow
  def 		SCREAMING_SNAKE_CASE_		(				self    :					str     )    ->				Optional[Any]:
         for model_name in OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                A						:     Dict         =OpenAIGPTModel.from_pretrained(UpperCamelCase_     )
                self.assertIsNotNone(UpperCamelCase_     )







@require_torch
class  SCREAMING_SNAKE_CASE_ (					unittest.TestCase			):
  '''simple docstring'''


  @slow
  def 		SCREAMING_SNAKE_CASE_		(				self    :					Optional[int]     )    ->				Any:
         A						:     Any         =OpenAIGPTLMHeadModel.from_pretrained('openai-gpt'     )
         model.to(UpperCamelCase_     )
         A						:     Any         =torch.tensor([[4_81, 47_35, 5_44]]      ,	dtype=torch.long      ,	device=UpperCamelCase_     )  # the president is
         A						:     List[str]         =[
             4_81,
             47_35,
             5_44,
             2_46,
             9_63,
             8_70,
             7_62,
             2_39,
             2_44,
             4_04_77,
             2_44,
             2_49,
             7_19,
             8_81,
             4_87,
             5_44,
             2_40,
             2_44,
             6_03,
             4_81,
         ]  # the president is a very good man. " \n " i\'m sure he is, " said the

         A						:     Tuple         =model.generate(UpperCamelCase_      ,	do_sample=UpperCamelCase_     )
         self.assertListEqual(output_ids[0].tolist()      ,	UpperCamelCase_     )







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


_lowercase							:      List[str]      							='''src/transformers'''


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



def A__  (			lowercase:     Dict					)				->		int:
       if _re_test_backend.search(lowercase					) is None:
              return None
       A						:     Any         =[b[0] for b in _re_backend.findall(lowercase					)]
       backends.sort()
       return "_and_".join(lowercase					)



def A__  (			lowercase:     Any					)				->		List[Any]:
       with open(lowercase,		'r',		encoding='utf-8',		newline='\n'					) as f:
              A						:     Optional[Any]         =f.readlines()

       A						:     Dict         =0
       while line_index < len(lowercase					) and not lines[line_index].startswith('_import_structure = {'					):
              line_index += 1

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

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

       A						:     str         ={'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.
              A						:     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:
                     A						:     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

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

                     A						:     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
       A						:     Optional[Any]         =[]
       while (
           line_index < len(lowercase					)
           and find_backend(lines[line_index]					) is None
           and not lines[line_index].startswith('else'					)
       ):
              A						:     Any         =lines[line_index]
              A						:     Optional[int]         =_re_import.search(lowercase					)
              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

       A						:     Optional[Any]         ={'none': objects}
       # Let's continue with backend-specific objects
       while line_index < len(lowercase					):
              # If the line is an if is_backend_available, we grab all objects associated.
              A						:     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:
                     A						:     Optional[Any]         =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

                     A						:     List[str]         =[]
                     # Until we unindent, add backend objects to the list
                     while len(lines[line_index]					) <= 1 or lines[line_index].startswith(' ' * 8					):
                            A						:     Any         =lines[line_index]
                            A						:     Any         =_re_import.search(lowercase					)
                            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

                     A						:     Dict         =objects
              else:
                     line_index += 1

       return import_dict_objects, type_hint_objects



def A__  (			lowercase:     Any,		lowercase:     int					)				->		Dict:

       def find_duplicates(lowercase:     List[str]					):
              return [k for k, v in collections.Counter(lowercase					).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!"]

       A						:     List[Any]         =[]
       for key in import_dict_objects.keys():
              A						:     List[Any]         =find_duplicates(import_dict_objects[key]					)
              if duplicate_imports:
                     errors.append(F'Duplicate _import_structure definitions for: {duplicate_imports}'					)
              A						:     Tuple         =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]					)					):
                     A						:     Tuple         ='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 A__  (			)				->		List[str]:
       A						:     Dict         =[]
       for root, _, files in os.walk(lowercase					):
              if "__init__.py" in files:
                     A						:     Any         =os.path.join(lowercase,		'__init__.py'					)
                     A						:     Union[str, Any]         =parse_init(lowercase					)
                     if objects is not None:
                            A						:     str         =analyze_results(*lowercase					)
                            if len(lowercase					) > 0:
                                   A						:     Any         =F'Problem in {fname}, both halves do not define the same objects.\n{errors[0]}'
                                   failures.append('\n'.join(lowercase					)					)
       if len(lowercase					) > 0:
              raise ValueError('\n\n'.join(lowercase					)					)



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


_lowercase							:      Tuple      							=[
    '''convert_pytorch_checkpoint_to_tf2''',
    '''modeling_flax_pytorch_utils''',
]



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

       A						:     Any         =[
           module
           for module in get_transformers_submodules()
           if module not in IGNORE_SUBMODULES and module not in transformers._import_structure.keys()
       ]
       if len(lowercase					) > 0:
              A						:     Dict         ='\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()






