






# flake8: noqa
# Lint as: python3

from typing import Dict, List, Optional, Type

from .. import config
from ..utils import logging
from .formatting import (
    ArrowFormatter,
    CustomFormatter,
    Formatter,
    PandasFormatter,
    PythonFormatter,
    TensorFormatter,
    format_table,
    query_table,
)
from .np_formatter import NumpyFormatter


snake_case__      :	Any       	=      logging.get_logger(__name__)

snake_case__      :	Dict[Optional[str], Type[Formatter]]       	=      {}
snake_case__      :	Dict[Optional[str], str]       	=      {}
snake_case__      :	Dict[Optional[str], Exception]       	=      {}






def     _snake_case    (__lowercase    ,      __lowercase    ,      __lowercase = None    ,      ):
   UpperCamelCase_									=     aliases if aliases is not None else []
   if format_type in _FORMAT_TYPES:
      logger.warning(
          f"""Overwriting format type '{format_type}' ({_FORMAT_TYPES[format_type].__name__} -> {formatter_cls.__name__})""")
   UpperCamelCase_									=     formatter_cls
   for alias in set(aliases + [format_type]):
      if alias in _FORMAT_TYPES_ALIASES:
         logger.warning(
             f"""Overwriting format type alias '{alias}' ({_FORMAT_TYPES_ALIASES[alias]} -> {format_type})""")
      UpperCamelCase_									=     format_type






def     _snake_case    (__lowercase    ,      __lowercase    ,      __lowercase = None):
   UpperCamelCase_									=     aliases if aliases is not None else []
   for alias in set(aliases + [format_type]):
      UpperCamelCase_									=     unavailable_error


# Here we define all the available formatting functions that can be used by `Dataset.set_format`
_register_formatter(PythonFormatter, None, aliases=["""python"""])
_register_formatter(ArrowFormatter, """arrow""", aliases=["""pa""", """pyarrow"""])
_register_formatter(NumpyFormatter, """numpy""", aliases=["""np"""])
_register_formatter(PandasFormatter, """pandas""", aliases=["""pd"""])
_register_formatter(CustomFormatter, """custom""")

if config.TORCH_AVAILABLE:
 from .torch_formatter import TorchFormatter

 _register_formatter(TorchFormatter, """torch""", aliases=["""pt""", """pytorch"""])
else:
 snake_case__      :	Optional[int]       	=      ValueError("""PyTorch needs to be installed to be able to return PyTorch tensors.""")
 _register_unavailable_formatter(_torch_error, """torch""", aliases=["""pt""", """pytorch"""])

if config.TF_AVAILABLE:
 from .tf_formatter import TFFormatter

 _register_formatter(TFFormatter, """tensorflow""", aliases=["""tf"""])
else:
 snake_case__      :	int       	=      ValueError("""Tensorflow needs to be installed to be able to return Tensorflow tensors.""")
 _register_unavailable_formatter(_tf_error, """tensorflow""", aliases=["""tf"""])

if config.JAX_AVAILABLE:
 from .jax_formatter import JaxFormatter

 _register_formatter(JaxFormatter, """jax""", aliases=[])
else:
 snake_case__      :	Optional[int]       	=      ValueError("""JAX needs to be installed to be able to return JAX arrays.""")
 _register_unavailable_formatter(_jax_error, """jax""", aliases=[])






def     _snake_case    (__lowercase):
   if format_type in _FORMAT_TYPES_ALIASES:
      return _FORMAT_TYPES_ALIASES[format_type]
   else:
      return format_type






def     _snake_case    (__lowercase    ,      **__lowercase):
   UpperCamelCase_									=     get_format_type_from_alias(__lowercase)
   if format_type in _FORMAT_TYPES:
      return _FORMAT_TYPES[format_type](**__lowercase)
   if format_type in _FORMAT_TYPES_ALIASES_UNAVAILABLE:
      raise _FORMAT_TYPES_ALIASES_UNAVAILABLE[format_type]
   else:
      raise ValueError(
          f"""Return type should be None or selected in {list(type for type in _FORMAT_TYPES.keys() if type != None)}, but got '{format_type}'""")













import copy
import os
from typing import Union

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


snake_case__      :	Optional[int]       	=      logging.get_logger(__name__)

snake_case__      :	List[Any]       	=      {
    """microsoft/git-base""": """https://huggingface.co/microsoft/git-base/resolve/main/config.json""",
}


class 						_a       (  UpperCAmelCase__    ):






  """simple docstring"""





  A_						=   """git_vision_model"""




  def __init__(     self		,		_UpperCAmelCase=768		,		_UpperCAmelCase=3072		,		_UpperCAmelCase=12		,		_UpperCAmelCase=12		,		_UpperCAmelCase=3		,		_UpperCAmelCase=224		,		_UpperCAmelCase=16		,		_UpperCAmelCase="quick_gelu"		,		_UpperCAmelCase=1e-5		,		_UpperCAmelCase=0.0		,		_UpperCAmelCase=0.0_2		,		**_UpperCAmelCase		,		)			-> Optional[Any]:
     super().__init__(**_UpperCAmelCase )

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




  @classmethod
  def    _UpperCAmelCase     (     cls		,		_UpperCAmelCase		,		**_UpperCAmelCase )			-> "PretrainedConfig":
     cls._set_token_in_kwargs(_UpperCAmelCase )

     UpperCamelCase_		,      UpperCamelCase_									=     cls.get_config_dict(_UpperCAmelCase		,		**_UpperCAmelCase )

     # get the vision config dict if we are loading from GITConfig
     if config_dict.get('model_type' ) == "git":
        UpperCamelCase_									=     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(_UpperCAmelCase		,		**_UpperCAmelCase )




class 						_a       (  UpperCAmelCase__    ):






  """simple docstring"""





  A_						=   """git"""




  def __init__(     self		,		_UpperCAmelCase=None		,		_UpperCAmelCase=30522		,		_UpperCAmelCase=768		,		_UpperCAmelCase=6		,		_UpperCAmelCase=12		,		_UpperCAmelCase=3072		,		_UpperCAmelCase="gelu"		,		_UpperCAmelCase=0.1		,		_UpperCAmelCase=0.1		,		_UpperCAmelCase=1024		,		_UpperCAmelCase=0.0_2		,		_UpperCAmelCase=1e-12		,		_UpperCAmelCase=0		,		_UpperCAmelCase="absolute"		,		_UpperCAmelCase=True		,		_UpperCAmelCase=False		,		_UpperCAmelCase=101		,		_UpperCAmelCase=102		,		_UpperCAmelCase=None		,		**_UpperCAmelCase		,		)			-> Optional[int]:
     super().__init__(bos_token_id=_UpperCAmelCase		,		eos_token_id=_UpperCAmelCase		,		pad_token_id=_UpperCAmelCase		,		**_UpperCAmelCase )

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

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

     UpperCamelCase_									=     bos_token_id
     UpperCamelCase_									=     eos_token_id




  def    _UpperCAmelCase     (     self )			-> str:
     UpperCamelCase_									=     copy.deepcopy(self.__dict__ )
     UpperCamelCase_									=     self.vision_config.to_dict()
     UpperCamelCase_									=     self.__class__.model_type
     return output





