






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 							__a							(  __A						):





		'''simple docstring'''



		UpperCAmelCase__      :				Tuple				    =						"""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.02 ,    **UpperCamelCase__ ,    ):
						super().__init__(**UpperCamelCase__       )

						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   hidden_size
						SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   intermediate_size
						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   num_hidden_layers
						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   num_attention_heads
						SCREAMING_SNAKE_CASE_   :	List[str]													=   num_channels
						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   patch_size
						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   image_size
						SCREAMING_SNAKE_CASE_   :	int													=   initializer_range
						SCREAMING_SNAKE_CASE_   :	int													=   attention_dropout
						SCREAMING_SNAKE_CASE_   :	int													=   layer_norm_eps
						SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   hidden_act






		@classmethod
		def   __snake_case			(						cls ,    UpperCamelCase__ ,    **UpperCamelCase__       ):
						cls._set_token_in_kwargs(UpperCamelCase__       )

						SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_   :	Any													=   cls.get_config_dict(UpperCamelCase__ ,    **UpperCamelCase__       )

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





		'''simple docstring'''



		UpperCAmelCase__      :				List[str]				    =						"""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.02 ,    UpperCamelCase__=1E-12 ,    UpperCamelCase__=0 ,    UpperCamelCase__="absolute" ,    UpperCamelCase__=True ,    UpperCamelCase__=False ,    UpperCamelCase__=101 ,    UpperCamelCase__=102 ,    UpperCamelCase__=None ,    **UpperCamelCase__ ,    ):
						super().__init__(bos_token_id=UpperCamelCase__ ,    eos_token_id=UpperCamelCase__ ,    pad_token_id=UpperCamelCase__ ,    **UpperCamelCase__       )

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

						SCREAMING_SNAKE_CASE_   :	List[Any]													=   GitVisionConfig(**UpperCamelCase__       )
						SCREAMING_SNAKE_CASE_   :	str													=   vocab_size
						SCREAMING_SNAKE_CASE_   :	Tuple													=   hidden_size
						SCREAMING_SNAKE_CASE_   :	List[Any]													=   num_hidden_layers
						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   num_attention_heads
						SCREAMING_SNAKE_CASE_   :	str													=   hidden_act
						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   intermediate_size
						SCREAMING_SNAKE_CASE_   :	List[str]													=   hidden_dropout_prob
						SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   attention_probs_dropout_prob
						SCREAMING_SNAKE_CASE_   :	Tuple													=   max_position_embeddings
						SCREAMING_SNAKE_CASE_   :	Tuple													=   initializer_range
						SCREAMING_SNAKE_CASE_   :	Any													=   layer_norm_eps
						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   position_embedding_type
						SCREAMING_SNAKE_CASE_   :	str													=   use_cache
						SCREAMING_SNAKE_CASE_   :	Tuple													=   tie_word_embeddings
						SCREAMING_SNAKE_CASE_   :	str													=   num_image_with_embedding

						SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   bos_token_id
						SCREAMING_SNAKE_CASE_   :	Tuple													=   eos_token_id






		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   copy.deepcopy(self.__dict__       )
						SCREAMING_SNAKE_CASE_   :	Dict													=   self.vision_config.to_dict()
						SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   self.__class__.model_type
						return output







from tempfile import TemporaryDirectory
from unittest import TestCase
from unittest.mock import MagicMock, patch

from transformers import AutoModel, TFAutoModel
from transformers.onnx import FeaturesManager
from transformers.testing_utils import SMALL_MODEL_IDENTIFIER, require_tf, require_torch


@require_torch
@require_tf
class 							__a							(  __A						):





		'''simple docstring'''



		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	Any													=   SMALL_MODEL_IDENTIFIER
						SCREAMING_SNAKE_CASE_   :	List[Any]													=   'pt'
						SCREAMING_SNAKE_CASE_   :	Tuple													=   'tf'


		def   __snake_case			(						self ,    UpperCamelCase__       ):
						SCREAMING_SNAKE_CASE_   :	Dict													=   AutoModel.from_pretrained(self.test_model       )
						model_pt.save_pretrained(UpperCamelCase__       )


		def   __snake_case			(						self ,    UpperCamelCase__       ):
						SCREAMING_SNAKE_CASE_   :	int													=   TFAutoModel.from_pretrained(self.test_model ,    from_pt=UpperCamelCase__       )
						model_tf.save_pretrained(UpperCamelCase__       )


		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   'mock_framework'

						# Framework provided - return whatever the user provides
						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   FeaturesManager.determine_framework(self.test_model ,    UpperCamelCase__       )
						self.assertEqual(UpperCamelCase__ ,    UpperCamelCase__       )

						# Local checkpoint and framework provided - return provided framework
						# PyTorch checkpoint
						with TemporaryDirectory() as local_pt_ckpt:
										self._setup_pt_ckpt(UpperCamelCase__       )
										SCREAMING_SNAKE_CASE_   :	Dict													=   FeaturesManager.determine_framework(UpperCamelCase__ ,    UpperCamelCase__       )
										self.assertEqual(UpperCamelCase__ ,    UpperCamelCase__       )

						# TensorFlow checkpoint
						with TemporaryDirectory() as local_tf_ckpt:
										self._setup_tf_ckpt(UpperCamelCase__       )
										SCREAMING_SNAKE_CASE_   :	List[str]													=   FeaturesManager.determine_framework(UpperCamelCase__ ,    UpperCamelCase__       )
										self.assertEqual(UpperCamelCase__ ,    UpperCamelCase__       )


		def   __snake_case			(						self       ):
						# PyTorch checkpoint
						with TemporaryDirectory() as local_pt_ckpt:
										self._setup_pt_ckpt(UpperCamelCase__       )
										SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   FeaturesManager.determine_framework(UpperCamelCase__       )
										self.assertEqual(UpperCamelCase__ ,    self.framework_pt       )

						# TensorFlow checkpoint
						with TemporaryDirectory() as local_tf_ckpt:
										self._setup_tf_ckpt(UpperCamelCase__       )
										SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   FeaturesManager.determine_framework(UpperCamelCase__       )
										self.assertEqual(UpperCamelCase__ ,    self.framework_tf       )

						# Invalid local checkpoint
						with TemporaryDirectory() as local_invalid_ckpt:
										with self.assertRaises(UpperCamelCase__       ):
														SCREAMING_SNAKE_CASE_   :	Any													=   FeaturesManager.determine_framework(UpperCamelCase__       )






		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   MagicMock(return_value=UpperCamelCase__       )
						with patch('transformers.onnx.features.is_tf_available' ,    UpperCamelCase__       ):
										SCREAMING_SNAKE_CASE_   :	str													=   FeaturesManager.determine_framework(self.test_model       )
										self.assertEqual(UpperCamelCase__ ,    self.framework_pt       )

						# PyTorch not in environment -> use TensorFlow
						SCREAMING_SNAKE_CASE_   :	List[str]													=   MagicMock(return_value=UpperCamelCase__       )
						with patch('transformers.onnx.features.is_torch_available' ,    UpperCamelCase__       ):
										SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   FeaturesManager.determine_framework(self.test_model       )
										self.assertEqual(UpperCamelCase__ ,    self.framework_tf       )

						# Both in environment -> use PyTorch
						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   MagicMock(return_value=UpperCamelCase__       )
						SCREAMING_SNAKE_CASE_   :	Tuple													=   MagicMock(return_value=UpperCamelCase__       )
						with patch('transformers.onnx.features.is_tf_available' ,    UpperCamelCase__       ), patch(
						    'transformers.onnx.features.is_torch_available' ,    UpperCamelCase__       ):
										SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   FeaturesManager.determine_framework(self.test_model       )
										self.assertEqual(UpperCamelCase__ ,    self.framework_pt       )

						# Both not in environment -> raise error
						SCREAMING_SNAKE_CASE_   :	Tuple													=   MagicMock(return_value=UpperCamelCase__       )
						SCREAMING_SNAKE_CASE_   :	Any													=   MagicMock(return_value=UpperCamelCase__       )
						with patch('transformers.onnx.features.is_tf_available' ,    UpperCamelCase__       ), patch(
						    'transformers.onnx.features.is_torch_available' ,    UpperCamelCase__       ):
										with self.assertRaises(UpperCamelCase__       ):
														SCREAMING_SNAKE_CASE_   :	Optional[int]													=   FeaturesManager.determine_framework(self.test_model       )