

import copy
import os
from typing import Union

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


A__						=							logging.get_logger(__name__)

A__						=							{
    "microsoft/git-base": "https://huggingface.co/microsoft/git-base/resolve/main/config.json",
}

class 				__UpperCamelCase				(					SCREAMING_SNAKE_CASE			):
 _lowercase  :   Tuple       				=  "git_vision_model"







 def __init__(   self: int  , __UpperCamelCase: Dict=7_68  , __UpperCamelCase: Optional[Any]=30_72  , __UpperCamelCase: Any=12  , __UpperCamelCase: Union[str, Any]=12  , __UpperCamelCase: Optional[int]=3  , __UpperCamelCase: str=2_24  , __UpperCamelCase: int=16  , __UpperCamelCase: Optional[Any]="quick_gelu"  , __UpperCamelCase: Union[str, Any]=1E-5  , __UpperCamelCase: Dict=0.0  , __UpperCamelCase: List[Any]=0.02  , **__UpperCamelCase: List[str]  , ):

      '''simple docstring'''





      super().__init__(**__UpperCamelCase      )

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







 @classmethod
 def 	_SCREAMING_SNAKE_CASE							(   cls: Union[str, Any]  , __UpperCamelCase: Union[str, os.PathLike]  , **__UpperCamelCase: str      ):

      '''simple docstring'''





      cls._set_token_in_kwargs(__UpperCamelCase      )

      __magic_name__,	__magic_name__							=    cls.get_config_dict(__UpperCamelCase  , **__UpperCamelCase      )

      # get the vision config dict if we are loading from GITConfig
      if config_dict.get('model_type'      ) == "git":
           __magic_name__							=    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 				__UpperCamelCase				(					SCREAMING_SNAKE_CASE			):
 _lowercase  :   str       				=  "git"







 def __init__(   self: str  , __UpperCamelCase: Union[str, Any]=None  , __UpperCamelCase: Union[str, Any]=3_05_22  , __UpperCamelCase: Optional[int]=7_68  , __UpperCamelCase: Any=6  , __UpperCamelCase: Optional[int]=12  , __UpperCamelCase: str=30_72  , __UpperCamelCase: Optional[int]="gelu"  , __UpperCamelCase: int=0.1  , __UpperCamelCase: int=0.1  , __UpperCamelCase: List[Any]=10_24  , __UpperCamelCase: Optional[Any]=0.02  , __UpperCamelCase: Any=1E-12  , __UpperCamelCase: Tuple=0  , __UpperCamelCase: List[str]="absolute"  , __UpperCamelCase: List[Any]=True  , __UpperCamelCase: Optional[int]=False  , __UpperCamelCase: Dict=1_01  , __UpperCamelCase: int=1_02  , __UpperCamelCase: str=None  , **__UpperCamelCase: Any  , ):

      '''simple docstring'''





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

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

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

      __magic_name__							=    bos_token_id
      __magic_name__							=    eos_token_id







 def 	_SCREAMING_SNAKE_CASE							(   self: int      ):

      '''simple docstring'''





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







import unittest

from transformers import AutoConfig, AutoTokenizer, BertConfig, TensorType, is_flax_available
from transformers.testing_utils import DUMMY_UNKNOWN_IDENTIFIER, require_flax, slow


if is_flax_available():
						import jax

						from transformers.models.auto.modeling_flax_auto import FlaxAutoModel
						from transformers.models.bert.modeling_flax_bert import FlaxBertModel
						from transformers.models.roberta.modeling_flax_roberta import FlaxRobertaModel

@require_flax
class 				__UpperCamelCase				(					unittest.TestCase			):







	@slow
	def 	_SCREAMING_SNAKE_CASE							(   self: Any      ):

						'''simple docstring'''





						for model_name in ["bert-base-cased", "bert-large-uncased"]:
											with self.subTest(__UpperCamelCase      ):
																__magic_name__							=    AutoConfig.from_pretrained(__UpperCamelCase      )
																self.assertIsNotNone(__UpperCamelCase      )
																self.assertIsInstance(__UpperCamelCase  , __UpperCamelCase      )

																__magic_name__							=    FlaxAutoModel.from_pretrained(__UpperCamelCase      )
																self.assertIsNotNone(__UpperCamelCase      )
																self.assertIsInstance(__UpperCamelCase  , __UpperCamelCase      )







	@slow
	def 	_SCREAMING_SNAKE_CASE							(   self: Tuple      ):

						'''simple docstring'''





						for model_name in ["roberta-base", "roberta-large"]:
											with self.subTest(__UpperCamelCase      ):
																__magic_name__							=    AutoConfig.from_pretrained(__UpperCamelCase      )
																self.assertIsNotNone(__UpperCamelCase      )
																self.assertIsInstance(__UpperCamelCase  , __UpperCamelCase      )

																__magic_name__							=    FlaxAutoModel.from_pretrained(__UpperCamelCase      )
																self.assertIsNotNone(__UpperCamelCase      )
																self.assertIsInstance(__UpperCamelCase  , __UpperCamelCase      )







	@slow
	def 	_SCREAMING_SNAKE_CASE							(   self: Dict      ):

						'''simple docstring'''





						for model_name in ["bert-base-cased", "bert-large-uncased"]:
											__magic_name__							=    AutoTokenizer.from_pretrained(__UpperCamelCase      )
											__magic_name__							=    FlaxBertModel.from_pretrained(__UpperCamelCase      )
											__magic_name__							=    tokenizer('Do you support jax jitted function?'  , return_tensors=TensorType.JAX      )

											@jax.jit
											def eval(**__UpperCamelCase: Optional[Any]      ):
																return model(**__UpperCamelCase      )

											eval(**__UpperCamelCase      ).block_until_ready()







	@slow
	def 	_SCREAMING_SNAKE_CASE							(   self: int      ):

						'''simple docstring'''





						for model_name in ["roberta-base", "roberta-large"]:
											__magic_name__							=    AutoTokenizer.from_pretrained(__UpperCamelCase      )
											__magic_name__							=    FlaxRobertaModel.from_pretrained(__UpperCamelCase      )
											__magic_name__							=    tokenizer('Do you support jax jitted function?'  , return_tensors=TensorType.JAX      )

											@jax.jit
											def eval(**__UpperCamelCase: Any      ):
																return model(**__UpperCamelCase      )

											eval(**__UpperCamelCase      ).block_until_ready()







	def 	_SCREAMING_SNAKE_CASE							(   self: Tuple      ):

						'''simple docstring'''





						with self.assertRaisesRegex(
						    __UpperCamelCase  , 'bert-base is not a local folder and is not a valid model identifier'      ):
											__magic_name__							=    FlaxAutoModel.from_pretrained('bert-base'      )







	def 	_SCREAMING_SNAKE_CASE							(   self: List[Any]      ):

						'''simple docstring'''





						with self.assertRaisesRegex(
						    __UpperCamelCase  , r'aaaaaa is not a valid git identifier \(branch name, tag name or commit id\)'      ):
											__magic_name__							=    FlaxAutoModel.from_pretrained(__UpperCamelCase  , revision='aaaaaa'      )







	def 	_SCREAMING_SNAKE_CASE							(   self: str      ):

						'''simple docstring'''





						with self.assertRaisesRegex(
						    __UpperCamelCase  , 'hf-internal-testing/config-no-model does not appear to have a file named flax_model.msgpack'  , ):
											__magic_name__							=    FlaxAutoModel.from_pretrained('hf-internal-testing/config-no-model'      )







	def 	_SCREAMING_SNAKE_CASE							(   self: int      ):

						'''simple docstring'''





						with self.assertRaisesRegex(__UpperCamelCase  , 'Use `from_pt=True` to load this model'      ):
											__magic_name__							=    FlaxAutoModel.from_pretrained('hf-internal-testing/tiny-bert-pt-only'      )




