



import copy
import os
from typing import Union

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


a_    :  List[str]						  =		logging.get_logger(__name__)

a_    :  Optional[Any]						  =		{
    'microsoft/git-base': 'https://huggingface.co/microsoft/git-base/resolve/main/config.json',
}





class  lowerCamelCase__	(    UpperCAmelCase_):
     """simple docstring"""



     _A      =      'git_vision_model'







     def __init__(self					,      __a=7_68					,      __a=30_72					,      __a=12					,      __a=12					,      __a=3					,      __a=2_24					,      __a=16					,      __a="quick_gelu"					,      __a=1E-5					,      __a=0.0					,      __a=0.02					,      **__a					,      ):






           '''simple docstring'''



           super().__init__(**__a     )

           lowerCamelCase             =		hidden_size
           lowerCamelCase             =		intermediate_size
           lowerCamelCase             =		num_hidden_layers
           lowerCamelCase             =		num_attention_heads
           lowerCamelCase             =		num_channels
           lowerCamelCase             =		patch_size
           lowerCamelCase             =		image_size
           lowerCamelCase             =		initializer_range
           lowerCamelCase             =		attention_dropout
           lowerCamelCase             =		layer_norm_eps
           lowerCamelCase             =		hidden_act







     @classmethod
     def     _a   (cls					,      __a					,      **__a     ):






           '''simple docstring'''



           cls._set_token_in_kwargs(__a     )

           lowerCamelCase      ,				lowerCamelCase             =		cls.get_config_dict(__a					,      **__a     )

           # get the vision config dict if we are loading from GITConfig
           if config_dict.get("model_type"     ) == "git":
                 lowerCamelCase             =		config_dict["vision_config"]

           if "model_type" in config_dict and hasattr(cls					,      "model_type"     ) and config_dict["model_type"] != cls.model_type:
                 logger.warning(
                     F"""You are using a model of type {config_dict["model_type"]} to instantiate a model of type """
                     F"""{cls.model_type}. This is not supported for all configurations of models and can yield errors."""     )

           return cls.from_dict(__a					,      **__a     )





class  lowerCamelCase__	(    UpperCAmelCase_):
     """simple docstring"""



     _A      =      'git'







     def __init__(self					,      __a=None					,      __a=3_05_22					,      __a=7_68					,      __a=6					,      __a=12					,      __a=30_72					,      __a="gelu"					,      __a=0.1					,      __a=0.1					,      __a=10_24					,      __a=0.02					,      __a=1E-12					,      __a=0					,      __a="absolute"					,      __a=True					,      __a=False					,      __a=1_01					,      __a=1_02					,      __a=None					,      **__a					,      ):






           '''simple docstring'''



           super().__init__(bos_token_id=__a					,      eos_token_id=__a					,      pad_token_id=__a					,      **__a     )

           if vision_config is None:
                 lowerCamelCase             =		{}
                 logger.info("vision_config is None. initializing the GitVisionConfig with default values."     )

           lowerCamelCase             =		GitVisionConfig(**__a     )
           lowerCamelCase             =		vocab_size
           lowerCamelCase             =		hidden_size
           lowerCamelCase             =		num_hidden_layers
           lowerCamelCase             =		num_attention_heads
           lowerCamelCase             =		hidden_act
           lowerCamelCase             =		intermediate_size
           lowerCamelCase             =		hidden_dropout_prob
           lowerCamelCase             =		attention_probs_dropout_prob
           lowerCamelCase             =		max_position_embeddings
           lowerCamelCase             =		initializer_range
           lowerCamelCase             =		layer_norm_eps
           lowerCamelCase             =		position_embedding_type
           lowerCamelCase             =		use_cache
           lowerCamelCase             =		tie_word_embeddings
           lowerCamelCase             =		num_image_with_embedding

           lowerCamelCase             =		bos_token_id
           lowerCamelCase             =		eos_token_id







     def     _a   (self     ):






           '''simple docstring'''



           lowerCamelCase             =		copy.deepcopy(self.__dict__     )
           lowerCamelCase             =		self.vision_config.to_dict()
           lowerCamelCase             =		self.__class__.model_type
           return output




from dataclasses import dataclass, field
from typing import Tuple

from ..utils import cached_property, is_tf_available, logging, requires_backends
from .benchmark_args_utils import BenchmarkArguments


if is_tf_available():
     import tensorflow as tf


a_    :  Any						  =		logging.get_logger(__name__)





@dataclass
class  lowerCamelCase__	(    UpperCAmelCase_):
     """simple docstring"""



     _A      =      [
         'no_inference',
         'no_cuda',
         'no_tpu',
         'no_speed',
         'no_memory',
         'no_env_print',
         'no_multi_process',
     ]







     def __init__(self					,      **__a     ):






           '''simple docstring'''



           for deprecated_arg in self.deprecated_args:
                 if deprecated_arg in kwargs:
                       lowerCamelCase             =		deprecated_arg[3:]
                       lowerCamelCase             =		not kwargs.pop(__a     )
                       logger.warning(
                           F"""{deprecated_arg} is depreciated. Please use --no-{positive_arg} or"""
                           F""" {positive_arg}={kwargs[positive_arg]}"""     )
           lowerCamelCase             =		kwargs.pop("tpu_name"					,      self.tpu_name     )
           lowerCamelCase             =		kwargs.pop("device_idx"					,      self.device_idx     )
           lowerCamelCase             =		kwargs.pop("eager_mode"					,      self.eager_mode     )
           lowerCamelCase             =		kwargs.pop("use_xla"					,      self.use_xla     )
           super().__init__(**__a     )

     _A      =      field(
         default=UpperCAmelCase_							,     metadata={'help': 'Name of TPU'}							,     )
     _A      =      field(
         default=0							,     metadata={'help': 'CPU / GPU device index. Defaults to 0.'}							,     )
     _A      =      field(default=UpperCAmelCase_							,     metadata={'help': 'Benchmark models in eager model.'})
     _A      =      field(
         default=UpperCAmelCase_							,     metadata={
             'help': 'Benchmark models using XLA JIT compilation. Note that `eager_model` has to be set to `False`.'
         }							,     )







     @cached_property
     def     _a   (self     ):






           '''simple docstring'''



           requires_backends(self					,      ["tf"]     )
           lowerCamelCase             =		None
           if self.tpu:
                 try:
                       if self.tpu_name:
                             lowerCamelCase             =		tf.distribute.cluster_resolver.TPUClusterResolver(self.tpu_name     )
                       else:
                             lowerCamelCase             =		tf.distribute.cluster_resolver.TPUClusterResolver()
                 except ValueError:
                       lowerCamelCase             =		None
           return tpu







     @cached_property
     def     _a   (self     ):






           '''simple docstring'''



           requires_backends(self					,      ["tf"]     )
           if self.is_tpu:
                 tf.config.experimental_connect_to_cluster(self._setup_tpu     )
                 tf.tpu.experimental.initialize_tpu_system(self._setup_tpu     )

                 lowerCamelCase             =		tf.distribute.TPUStrategy(self._setup_tpu     )
           else:
                 # currently no multi gpu is allowed
                 if self.is_gpu:
                       # TODO: Currently only single GPU is supported
                       tf.config.set_visible_devices(self.gpu_list[self.device_idx]					,      "GPU"     )
                       lowerCamelCase             =		tf.distribute.OneDeviceStrategy(device=F"""/gpu:{self.device_idx}"""     )
                 else:
                       tf.config.set_visible_devices([]					,      "GPU"     )  # disable GPU
                       lowerCamelCase             =		tf.distribute.OneDeviceStrategy(device=F"""/cpu:{self.device_idx}"""     )

           return strategy







     @property
     def     _a   (self     ):






           '''simple docstring'''



           requires_backends(self					,      ["tf"]     )
           return self._setup_tpu is not None







     @property
     def     _a   (self     ):






           '''simple docstring'''



           requires_backends(self					,      ["tf"]     )
           return self._setup_strategy







     @property
     def     _a   (self     ):






           '''simple docstring'''



           requires_backends(self					,      ["tf"]     )
           return tf.config.list_physical_devices("GPU"     )







     @property
     def     _a   (self     ):






           '''simple docstring'''



           requires_backends(self					,      ["tf"]     )
           if self.cuda:
                 return len(self.gpu_list     )
           return 0







     @property
     def     _a   (self     ):






           '''simple docstring'''



           return self.n_gpu > 0