

'''simple docstring'''




import inspect
import unittest
import warnings

from transformers import DeiTConfig
from transformers.models.auto import get_values
from transformers.testing_utils import (
    require_accelerate,
    require_torch,
    require_torch_gpu,
    require_vision,
    slow,
    torch_device,
)
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
      import torch
      from torch import nn

      from transformers import (
          MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING,
          MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING,
          MODEL_MAPPING,
          DeiTForImageClassification,
          DeiTForImageClassificationWithTeacher,
          DeiTForMaskedImageModeling,
          DeiTModel,
      )
      from transformers.models.deit.modeling_deit import DEIT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
      from PIL import Image

      from transformers import DeiTImageProcessor






class   _SCREAMING_SNAKE_CASE   :



 def __init__(   self		:   Tuple			,				a__		:   List[Any]			,				a__		:   Tuple=13			,				a__		:   Any=30			,				a__		:   Any=2			,				a__		:   List[str]=3			,				a__		:   Any=True			,				a__		:   Union[str, Any]=True			,				a__		:   Any=32			,				a__		:   Dict=5			,				a__		:   Optional[int]=4			,				a__		:   List[Any]=37			,				a__		:   Any="gelu"			,				a__		:   Tuple=0.1			,				a__		:   str=0.1			,				a__		:   int=10			,				a__		:   str=0.02			,				a__		:   Tuple=3			,				a__		:   Tuple=None			,				a__		:   str=2			,				):
      __magic_name__						       =    parent
      __magic_name__						       =    batch_size
      __magic_name__						       =    image_size
      __magic_name__						       =    patch_size
      __magic_name__						       =    num_channels
      __magic_name__						       =    is_training
      __magic_name__						       =    use_labels
      __magic_name__						       =    hidden_size
      __magic_name__						       =    num_hidden_layers
      __magic_name__						       =    num_attention_heads
      __magic_name__						       =    intermediate_size
      __magic_name__						       =    hidden_act
      __magic_name__						       =    hidden_dropout_prob
      __magic_name__						       =    attention_probs_dropout_prob
      __magic_name__						       =    type_sequence_label_size
      __magic_name__						       =    initializer_range
      __magic_name__						       =    scope
      __magic_name__						       =    encoder_stride

      # in DeiT, the seq length equals the number of patches + 2 (we add 2 for the [CLS] and distilation tokens)
      __magic_name__						       =    (image_size // patch_size) ** 2
      __magic_name__						       =    num_patches + 2



 def 			snake_case__  (   self		:   List[str]      ):
      __magic_name__						       =    floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]      )

      __magic_name__						       =    None
      if self.use_labels:
           __magic_name__						       =    ids_tensor([self.batch_size]			,				self.type_sequence_label_size      )

      __magic_name__						       =    self.get_config()

      return config, pixel_values, labels



 def 			snake_case__  (   self		:   Optional[Any]      ):
      return DeiTConfig(
          image_size=self.image_size			,				patch_size=self.patch_size			,				num_channels=self.num_channels			,				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			,				is_decoder=a__			,				initializer_range=self.initializer_range			,				encoder_stride=self.encoder_stride			,				)



 def 			snake_case__  (   self		:   List[str]			,				a__		:   str			,				a__		:   str			,				a__		:   int      ):
      __magic_name__						       =    DeiTModel(config=a__      )
      model.to(a__      )
      model.eval()
      __magic_name__						       =    model(a__      )
      self.parent.assertEqual(result.last_hidden_state.shape			,				(self.batch_size, self.seq_length, self.hidden_size)      )



 def 			snake_case__  (   self		:   str			,				a__		:   Union[str, Any]			,				a__		:   Optional[Any]			,				a__		:   Union[str, Any]      ):
      __magic_name__						       =    DeiTForMaskedImageModeling(config=a__      )
      model.to(a__      )
      model.eval()
      __magic_name__						       =    model(a__      )
      self.parent.assertEqual(
          result.reconstruction.shape			,				(self.batch_size, self.num_channels, self.image_size, self.image_size)      )

      # test greyscale images
      __magic_name__						       =    1
      __magic_name__						       =    DeiTForMaskedImageModeling(a__      )
      model.to(a__      )
      model.eval()

      __magic_name__						       =    floats_tensor([self.batch_size, 1, self.image_size, self.image_size]      )
      __magic_name__						       =    model(a__      )
      self.parent.assertEqual(result.reconstruction.shape			,				(self.batch_size, 1, self.image_size, self.image_size)      )



 def 			snake_case__  (   self		:   Dict			,				a__		:   List[str]			,				a__		:   str			,				a__		:   int      ):
      __magic_name__						       =    self.type_sequence_label_size
      __magic_name__						       =    DeiTForImageClassification(a__      )
      model.to(a__      )
      model.eval()
      __magic_name__						       =    model(a__			,				labels=a__      )
      self.parent.assertEqual(result.logits.shape			,				(self.batch_size, self.type_sequence_label_size)      )

      # test greyscale images
      __magic_name__						       =    1
      __magic_name__						       =    DeiTForImageClassification(a__      )
      model.to(a__      )
      model.eval()

      __magic_name__						       =    floats_tensor([self.batch_size, 1, self.image_size, self.image_size]      )
      __magic_name__						       =    model(a__			,				labels=a__      )
      self.parent.assertEqual(result.logits.shape			,				(self.batch_size, self.type_sequence_label_size)      )



 def 			snake_case__  (   self		:   List[Any]      ):
      __magic_name__						       =    self.prepare_config_and_inputs()
      (
          (
          __magic_name__
      )       ,  (
          __magic_name__
      )       ,  (
          __magic_name__
      )       ,  
      )						       =    config_and_inputs
      __magic_name__						       =    {'''pixel_values''': pixel_values}
      return config, inputs_dict






@require_torch
class   _SCREAMING_SNAKE_CASE   (   __a		,__a		,unittest.TestCase     ):
 __SCREAMING_SNAKE_CASE					:Optional[Any]      	=					(
     (
         DeiTModel,
         DeiTForImageClassification,
         DeiTForImageClassificationWithTeacher,
         DeiTForMaskedImageModeling,
     )
     if is_torch_available()
     else ()
 )
 __SCREAMING_SNAKE_CASE					:Optional[Any]      	=					(
     {
         """feature-extraction""": DeiTModel,
         """image-classification""": (DeiTForImageClassification, DeiTForImageClassificationWithTeacher),
     }
     if is_torch_available()
     else {}
 )

 __SCREAMING_SNAKE_CASE					:Tuple      	=					False
 __SCREAMING_SNAKE_CASE					:str      	=					False
 __SCREAMING_SNAKE_CASE					:Union[str, Any]      	=					False



 def 			snake_case__  (   self		:   Optional[Any]      ):
      __magic_name__						       =    DeiTModelTester(self      )
      __magic_name__						       =    ConfigTester(self			,				config_class=a__			,				has_text_modality=a__			,				hidden_size=37      )



 def 			snake_case__  (   self		:   Optional[int]      ):
      self.config_tester.run_common_tests()



 @unittest.skip(reason='''DeiT does not use inputs_embeds'''      )
 def 			snake_case__  (   self		:   List[Any]      ):
      pass



 def 			snake_case__  (   self		:   Union[str, Any]      ):
      __magic_name__       ,  __magic_name__						       =    self.model_tester.prepare_config_and_inputs_for_common()

      for model_class in self.all_model_classes:
           __magic_name__						       =    model_class(a__      )
           self.assertIsInstance(model.get_input_embeddings()			,				(nn.Module)      )
           __magic_name__						       =    model.get_output_embeddings()
           self.assertTrue(x is None or isinstance(a__			,				nn.Linear      )      )



 def 			snake_case__  (   self		:   Dict      ):
      __magic_name__       ,  __magic_name__						       =    self.model_tester.prepare_config_and_inputs_for_common()

      for model_class in self.all_model_classes:
           __magic_name__						       =    model_class(a__      )
           __magic_name__						       =    inspect.signature(model.forward      )
           # signature.parameters is an OrderedDict => so arg_names order is deterministic
           __magic_name__						       =    [*signature.parameters.keys()]

           __magic_name__						       =    ['''pixel_values''']
           self.assertListEqual(arg_names[:1]			,				a__      )



 def 			snake_case__  (   self		:   Dict      ):
      __magic_name__						       =    self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_model(*a__      )



 def 			snake_case__  (   self		:   Dict      ):
      __magic_name__						       =    self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_masked_image_modeling(*a__      )



 def 			snake_case__  (   self		:   List[Any]      ):
      __magic_name__						       =    self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_image_classification(*a__      )



 def 			snake_case__  (   self		:   int			,				a__		:   Tuple			,				a__		:   Tuple			,				a__		:   Dict=False      ):
      __magic_name__						       =    super()._prepare_for_class(a__			,				a__			,				return_labels=a__      )

      if return_labels:
           if model_class.__name__ == "DeiTForImageClassificationWithTeacher":
                del inputs_dict["labels"]

      return inputs_dict



 def 			snake_case__  (   self		:   Dict      ):
      if not self.model_tester.is_training:
           return

      __magic_name__       ,  __magic_name__						       =    self.model_tester.prepare_config_and_inputs_for_common()
      __magic_name__						       =    True

      for model_class in self.all_model_classes:
           # DeiTForImageClassificationWithTeacher supports inference-only
           if (
               model_class in get_values(a__      )
               or model_class.__name__ == "DeiTForImageClassificationWithTeacher"
           ):
                continue
           __magic_name__						       =    model_class(a__      )
           model.to(a__      )
           model.train()
           __magic_name__						       =    self._prepare_for_class(a__			,				a__			,				return_labels=a__      )
           __magic_name__						       =    model(**a__      ).loss
           loss.backward()



 def 			snake_case__  (   self		:   Optional[Any]      ):
      __magic_name__       ,  __magic_name__						       =    self.model_tester.prepare_config_and_inputs_for_common()
      if not self.model_tester.is_training:
           return

      __magic_name__						       =    False
      __magic_name__						       =    True

      for model_class in self.all_model_classes:
           if model_class in get_values(a__      ) or not model_class.supports_gradient_checkpointing:
                continue
           # DeiTForImageClassificationWithTeacher supports inference-only
           if model_class.__name__ == "DeiTForImageClassificationWithTeacher":
                continue
           __magic_name__						       =    model_class(a__      )
           model.gradient_checkpointing_enable()
           model.to(a__      )
           model.train()
           __magic_name__						       =    self._prepare_for_class(a__			,				a__			,				return_labels=a__      )
           __magic_name__						       =    model(**a__      ).loss
           loss.backward()



 def 			snake_case__  (   self		:   Any      ):
      __magic_name__       ,  __magic_name__						       =    self.model_tester.prepare_config_and_inputs_for_common()

      __magic_name__						       =    [
          {'''title''': '''multi_label_classification''', '''num_labels''': 2, '''dtype''': torch.float},
          {'''title''': '''single_label_classification''', '''num_labels''': 1, '''dtype''': torch.long},
          {'''title''': '''regression''', '''num_labels''': 1, '''dtype''': torch.float},
      ]

      for model_class in self.all_model_classes:
           if (
               model_class
               not in [
                   *get_values(a__      ),
                   *get_values(a__      ),
               ]
               or model_class.__name__ == "DeiTForImageClassificationWithTeacher"
           ):
                continue

           for problem_type in problem_types:
                with self.subTest(msg=F'''Testing {model_class} with {problem_type["title"]}'''      ):
                     __magic_name__						       =    problem_type['''title''']
                     __magic_name__						       =    problem_type['''num_labels''']

                     __magic_name__						       =    model_class(a__      )
                     model.to(a__      )
                     model.train()

                     __magic_name__						       =    self._prepare_for_class(a__			,				a__			,				return_labels=a__      )

                     if problem_type["num_labels"] > 1:
                          __magic_name__						       =    inputs['''labels'''].unsqueeze(1      ).repeat(1			,				problem_type['''num_labels''']      )

                     __magic_name__						       =    inputs['''labels'''].to(problem_type['''dtype''']      )

                     # This tests that we do not trigger the warning form PyTorch "Using a target size that is different
                     # to the input size. This will likely lead to incorrect results due to broadcasting. Please ensure
                     # they have the same size." which is a symptom something in wrong for the regression problem.
                     # See https://github.com/huggingface/transformers/issues/11780
                     with warnings.catch_warnings(record=a__      ) as warning_list:
                          __magic_name__						       =    model(**a__      ).loss
                     for w in warning_list:
                          if "Using a target size that is different to the input size" in str(w.message      ):
                               raise ValueError(
                                   F'''Something is going wrong in the regression problem: intercepted {w.message}'''      )

                     loss.backward()



 @slow
 def 			snake_case__  (   self		:   Optional[Any]      ):
      for model_name in DEIT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
           __magic_name__						       =    DeiTModel.from_pretrained(a__      )
           self.assertIsNotNone(a__      )




def 						UpperCamelCase	(			)				->     Optional[int]:






     '''simple docstring'''
     __magic_name__						       =    Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''			)
     return image






@require_torch
@require_vision
class   _SCREAMING_SNAKE_CASE   (   unittest.TestCase     ):



 @cached_property
 def 			snake_case__  (   self		:   List[Any]      ):
      return (
          DeiTImageProcessor.from_pretrained('''facebook/deit-base-distilled-patch16-224'''      )
          if is_vision_available()
          else None
      )



 @slow
 def 			snake_case__  (   self		:   Optional[Any]      ):
      __magic_name__						       =    DeiTForImageClassificationWithTeacher.from_pretrained('''facebook/deit-base-distilled-patch16-224'''      ).to(
          a__      )

      __magic_name__						       =    self.default_image_processor
      __magic_name__						       =    prepare_img()
      __magic_name__						       =    image_processor(images=a__			,				return_tensors='''pt'''      ).to(a__      )

      # forward pass
      with torch.no_grad():
           __magic_name__						       =    model(**a__      )

      # verify the logits
      __magic_name__						       =    torch.Size((1, 1000)      )
      self.assertEqual(outputs.logits.shape			,				a__      )

      __magic_name__						       =    torch.tensor([-1.0_266, 0.1_912, -1.2_861]      ).to(a__      )

      self.assertTrue(torch.allclose(outputs.logits[0, :3]			,				a__			,				atol=1E-4      )      )



 @slow
 @require_accelerate
 @require_torch_gpu
 def 			snake_case__  (   self		:   Union[str, Any]      ):
      __magic_name__						       =    DeiTModel.from_pretrained(
          '''facebook/deit-base-distilled-patch16-224'''			,				torch_dtype=torch.floataa			,				device_map='''auto'''      )
      __magic_name__						       =    self.default_image_processor

      __magic_name__						       =    prepare_img()
      __magic_name__						       =    image_processor(images=a__			,				return_tensors='''pt'''      )
      __magic_name__						       =    inputs.pixel_values.to(a__      )

      # forward pass to make sure inference works in fp16
      with torch.no_grad():
           __magic_name__						       =    model(a__      )









'''simple docstring'''




import importlib
import inspect
import json
import os
import re
import shutil
import sys
from pathlib import Path
from typing import Dict, Optional, Union
from urllib import request

from huggingface_hub import HfFolder, cached_download, hf_hub_download, model_info
from packaging import version

from .. import __version__
from . import DIFFUSERS_DYNAMIC_MODULE_NAME, HF_MODULES_CACHE, logging


_lowerCAmelCase         =						(
    "https://raw.githubusercontent.com/huggingface/diffusers/{revision}/examples/community/{pipeline}.py"
)


_lowerCAmelCase         =						logging.get_logger(__name__)  # pylint: disable=invalid-name




def 						UpperCamelCase	(			)				->     Optional[Any]:






     '''simple docstring'''
     __magic_name__						       =    '''https://pypi.org/pypi/diffusers/json'''
     __magic_name__						       =    json.loads(request.urlopen(a			).read()			)['''releases'''].keys()
     return sorted(a		,						key=lambda a			: version.Version(a			)			)




def 						UpperCamelCase	(			)				->     Any:






     '''simple docstring'''
     # This function has already been executed if HF_MODULES_CACHE already is in the Python path.
     if HF_MODULES_CACHE in sys.path:
          return

     sys.path.append(a			)
     os.makedirs(a		,						exist_ok=a			)
     __magic_name__						       =    Path(a			) / '''__init__.py'''
     if not init_path.exists():
          init_path.touch()




def 						UpperCamelCase	(			a			)				->     Tuple:






     '''simple docstring'''
     init_hf_modules()
     __magic_name__						       =    Path(a			) / name
     # If the parent module does not exist yet, recursively create it.
     if not dynamic_module_path.parent.exists():
          create_dynamic_module(dynamic_module_path.parent			)
     os.makedirs(a		,						exist_ok=a			)
     __magic_name__						       =    dynamic_module_path / '''__init__.py'''
     if not init_path.exists():
          init_path.touch()




def 						UpperCamelCase	(			a			)				->     List[str]:






     '''simple docstring'''
     with open(a		,						'''r'''		,						encoding='''utf-8'''			) as f:
          __magic_name__						       =    f.read()

     # Imports of the form `import .xxx`
     __magic_name__						       =    re.findall('''^\s*import\s+\.(\S+)\s*$'''		,						a		,						flags=re.MULTILINE			)
     # Imports of the form `from .xxx import yyy`
     relative_imports += re.findall('''^\s*from\s+\.(\S+)\s+import'''		,						a		,						flags=re.MULTILINE			)
     # Unique-ify
     return list(set(a			)			)




def 						UpperCamelCase	(			a			)				->     str:






     '''simple docstring'''
     __magic_name__						       =    False
     __magic_name__						       =    [module_file]
     __magic_name__						       =    []

     # Let's recurse through all relative imports
     while not no_change:
          __magic_name__						       =    []
          for f in files_to_check:
               new_imports.extend(get_relative_imports(a			)			)

          __magic_name__						       =    Path(a			).parent
          __magic_name__						       =    [str(module_path / m			) for m in new_imports]
          __magic_name__						       =    [f for f in new_import_files if f not in all_relative_imports]
          __magic_name__						       =    [F'''{f}.py''' for f in new_import_files]

          __magic_name__						       =    len(a			) == 0
          all_relative_imports.extend(a			)

     return all_relative_imports




def 						UpperCamelCase	(			a			)				->     List[str]:






     '''simple docstring'''
     with open(a		,						'''r'''		,						encoding='''utf-8'''			) as f:
          __magic_name__						       =    f.read()

     # Imports of the form `import xxx`
     __magic_name__						       =    re.findall('''^\s*import\s+(\S+)\s*$'''		,						a		,						flags=re.MULTILINE			)
     # Imports of the form `from xxx import yyy`
     imports += re.findall('''^\s*from\s+(\S+)\s+import'''		,						a		,						flags=re.MULTILINE			)
     # Only keep the top-level module
     __magic_name__						       =    [imp.split('''.'''			)[0] for imp in imports if not imp.startswith('''.'''			)]

     # Unique-ify and test we got them all
     __magic_name__						       =    list(set(a			)			)
     __magic_name__						       =    []
     for imp in imports:
          try:
               importlib.import_module(a			)
          except ImportError:
               missing_packages.append(a			)

     if len(a			) > 0:
          raise ImportError(
              '''This modeling file requires the following packages that were not found in your environment: '''
              F'''{", ".join(a			)}. Run `pip install {" ".join(a			)}`'''			)

     return get_relative_imports(a			)




def 						UpperCamelCase	(			a		,						a			)				->     Optional[int]:






     '''simple docstring'''
     __magic_name__						       =    module_path.replace(os.path.sep		,						'''.'''			)
     __magic_name__						       =    importlib.import_module(a			)

     if class_name is None:
          return find_pipeline_class(a			)
     return getattr(a		,						a			)




def 						UpperCamelCase	(			a			)				->     Tuple:






     '''simple docstring'''
     from ..pipelines import DiffusionPipeline

     __magic_name__						       =    dict(inspect.getmembers(a		,						inspect.isclass			)			)

     __magic_name__						       =    None
     for cls_name, cls in cls_members.items():
          if (
              cls_name != DiffusionPipeline.__name__
              and issubclass(cls		,						a			)
              and cls.__module__.split('''.'''			)[0] != "diffusers"
          ):
               if pipeline_class is not None:
                    raise ValueError(
                        F'''Multiple classes that inherit from {DiffusionPipeline.__name__} have been found:'''
                        F''' {pipeline_class.__name__}, and {cls_name}. Please make sure to define only one in'''
                        F''' {loaded_module}.'''			)
               __magic_name__						       =    cls

     return pipeline_class




def 						UpperCamelCase	(			a		,						a		,						a = None		,						a = False		,						a = False		,						a = None		,						a = None		,						a = None		,						a = False		,						)				->     List[Any]:






     '''simple docstring'''
     __magic_name__						       =    str(a			)

     __magic_name__						       =    os.path.join(a		,						a			)

     if os.path.isfile(a			):
          __magic_name__						       =    module_file_or_url
          __magic_name__						       =    '''local'''
     elif pretrained_model_name_or_path.count('''/'''			) == 0:
          __magic_name__						       =    get_diffusers_versions()
          # cut ".dev0"
          __magic_name__						       =    '''v''' + '''.'''.join(__version__.split('''.'''			)[:3]			)

          # retrieve github version that matches
          if revision is None:
               __magic_name__						       =    latest_version if latest_version[1:] in available_versions else '''main'''
               logger.info(F'''Defaulting to latest_version: {revision}.'''			)
          elif revision in available_versions:
               __magic_name__						       =    F'''v{revision}'''
          elif revision == "main":
               __magic_name__						       =    revision
          else:
               raise ValueError(
                   F'''`custom_revision`: {revision} does not exist. Please make sure to choose one of'''
                   F''' {", ".join(available_versions + ["main"]			)}.'''			)

          # community pipeline on GitHub
          __magic_name__						       =    COMMUNITY_PIPELINES_URL.format(revision=a		,						pipeline=a			)
          try:
               __magic_name__						       =    cached_download(
                   a		,						cache_dir=a		,						force_download=a		,						proxies=a		,						resume_download=a		,						local_files_only=a		,						use_auth_token=a		,						)
               __magic_name__						       =    '''git'''
               __magic_name__						       =    pretrained_model_name_or_path + '''.py'''
          except EnvironmentError:
               logger.error(F'''Could not locate the {module_file} inside {pretrained_model_name_or_path}.'''			)
               raise
     else:
          try:
               # Load from URL or cache if already cached
               __magic_name__						       =    hf_hub_download(
                   a		,						a		,						cache_dir=a		,						force_download=a		,						proxies=a		,						resume_download=a		,						local_files_only=a		,						use_auth_token=a		,						)
               __magic_name__						       =    os.path.join('''local'''		,						'''--'''.join(pretrained_model_name_or_path.split('''/'''			)			)			)
          except EnvironmentError:
               logger.error(F'''Could not locate the {module_file} inside {pretrained_model_name_or_path}.'''			)
               raise

    # Check we have all the requirements in our environment
     __magic_name__						       =    check_imports(a			)

     # Now we move the module inside our cached dynamic modules.
     __magic_name__						       =    DIFFUSERS_DYNAMIC_MODULE_NAME + os.path.sep + submodule
     create_dynamic_module(a			)
     __magic_name__						       =    Path(a			) / full_submodule
     if submodule == "local" or submodule == "git":
          # We always copy local files (we could hash the file to see if there was a change, and give them the name of
          # that hash, to only copy when there is a modification but it seems overkill for now).
          # The only reason we do the copy is to avoid putting too many folders in sys.path.
          shutil.copy(a		,						submodule_path / module_file			)
          for module_needed in modules_needed:
               __magic_name__						       =    F'''{module_needed}.py'''
               shutil.copy(os.path.join(a		,						a			)		,						submodule_path / module_needed			)
     else:
          # Get the commit hash
          # TODO: we will get this info in the etag soon, so retrieve it from there and not here.
          if isinstance(a		,						a			):
               __magic_name__						       =    use_auth_token
          elif use_auth_token is True:
               __magic_name__						       =    HfFolder.get_token()
          else:
               __magic_name__						       =    None

          __magic_name__						       =    model_info(a		,						revision=a		,						token=a			).sha

          # The module file will end up being placed in a subfolder with the git hash of the repo. This way we get the
          # benefit of versioning.
          __magic_name__						       =    submodule_path / commit_hash
          __magic_name__						       =    full_submodule + os.path.sep + commit_hash
          create_dynamic_module(a			)

          if not (submodule_path / module_file).exists():
               shutil.copy(a		,						submodule_path / module_file			)
          # Make sure we also have every file with relative
          for module_needed in modules_needed:
               if not (submodule_path / module_needed).exists():
                    get_cached_module_file(
                        a		,						F'''{module_needed}.py'''		,						cache_dir=a		,						force_download=a		,						resume_download=a		,						proxies=a		,						use_auth_token=a		,						revision=a		,						local_files_only=a		,						)
     return os.path.join(a		,						a			)




def 						UpperCamelCase	(			a		,						a		,						a = None		,						a = None		,						a = False		,						a = False		,						a = None		,						a = None		,						a = None		,						a = False		,						**a		,						)				->     List[Any]:






     '''simple docstring'''
     __magic_name__						       =    get_cached_module_file(
         a		,						a		,						cache_dir=a		,						force_download=a		,						resume_download=a		,						proxies=a		,						use_auth_token=a		,						revision=a		,						local_files_only=a		,						)
     return get_class_in_module(a		,						final_module.replace('''.py'''		,						''''''			)			)






