




'''simple docstring'''


from __future__ import annotations

import unittest

from transformers import DistilBertConfig, is_tf_available
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
				import tensorflow as tf

				from transformers.models.distilbert.modeling_tf_distilbert import (
				    TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
				    TFDistilBertForMaskedLM,
				    TFDistilBertForMultipleChoice,
				    TFDistilBertForQuestionAnswering,
				    TFDistilBertForSequenceClassification,
				    TFDistilBertForTokenClassification,
				    TFDistilBertModel,
				)

class      A       :







							def __init__(    self			:    List[str]				,     lowerCAmelCase_			:    Any				,     )     ->				Tuple:


														"""simple docstring"""


														_a      	=							parent
														_a      	=							13
														_a      	=							7
														_a      	=							True
														_a      	=							True
														_a      	=							False
														_a      	=							True
														_a      	=							99
														_a      	=							32
														_a      	=							2
														_a      	=							4
														_a      	=							37
														_a      	=							'''gelu'''
														_a      	=							0.1
														_a      	=							0.1
														_a      	=							5_12
														_a      	=							16
														_a      	=							2
														_a      	=							0.0_2
														_a      	=							3
														_a      	=							4
														_a      	=							None







							def   __lowerCAmelCase     (    self			:    List[Any]   )     ->				str:


														"""simple docstring"""


														_a      	=							ids_tensor([self.batch_size, self.seq_length]				,     self.vocab_size   )

														_a      	=							None
														if self.use_input_mask:
																					_a      	=							random_attention_mask([self.batch_size, self.seq_length]   )

														_a      	=							None
														_a      	=							None
														_a      	=							None
														if self.use_labels:
																					_a      	=							ids_tensor([self.batch_size]				,     self.type_sequence_label_size   )
																					_a      	=							ids_tensor([self.batch_size, self.seq_length]				,     self.num_labels   )
																					_a      	=							ids_tensor([self.batch_size]				,     self.num_choices   )

														_a      	=							DistilBertConfig(
														    vocab_size=self.vocab_size				,     dim=self.hidden_size				,     n_layers=self.num_hidden_layers				,     n_heads=self.num_attention_heads				,     hidden_dim=self.intermediate_size				,     hidden_act=self.hidden_act				,     dropout=self.hidden_dropout_prob				,     attention_dropout=self.attention_probs_dropout_prob				,     max_position_embeddings=self.max_position_embeddings				,     initializer_range=self.initializer_range				,     )

														return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels







							def   __lowerCAmelCase     (    self			:    Optional[Any]				,     lowerCAmelCase_			:    int				,     lowerCAmelCase_			:    int				,     lowerCAmelCase_			:    List[Any]				,     lowerCAmelCase_			:    Any				,     lowerCAmelCase_			:    str				,     lowerCAmelCase_			:    Optional[Any]   )     ->				List[Any]:


														"""simple docstring"""


														_a      	=							TFDistilBertModel(config=lowerCAmelCase_   )
														_a      	=							{'''input_ids''': input_ids, '''attention_mask''': input_mask}

														_a      	=							model(lowerCAmelCase_   )

														_a      	=							[input_ids, input_mask]

														_a      	=							model(lowerCAmelCase_   )

														self.parent.assertEqual(result.last_hidden_state.shape				,     (self.batch_size, self.seq_length, self.hidden_size)   )







							def   __lowerCAmelCase     (    self			:    Dict				,     lowerCAmelCase_			:    Any				,     lowerCAmelCase_			:    List[Any]				,     lowerCAmelCase_			:    Tuple				,     lowerCAmelCase_			:    Dict				,     lowerCAmelCase_			:    Dict				,     lowerCAmelCase_			:    Optional[int]   )     ->				Union[str, Any]:


														"""simple docstring"""


														_a      	=							TFDistilBertForMaskedLM(config=lowerCAmelCase_   )
														_a      	=							{'''input_ids''': input_ids, '''attention_mask''': input_mask}
														_a      	=							model(lowerCAmelCase_   )
														self.parent.assertEqual(result.logits.shape				,     (self.batch_size, self.seq_length, self.vocab_size)   )







							def   __lowerCAmelCase     (    self			:    str				,     lowerCAmelCase_			:    Optional[int]				,     lowerCAmelCase_			:    Tuple				,     lowerCAmelCase_			:    List[Any]				,     lowerCAmelCase_			:    Dict				,     lowerCAmelCase_			:    Optional[Any]				,     lowerCAmelCase_			:    str   )     ->				List[Any]:


														"""simple docstring"""


														_a      	=							TFDistilBertForQuestionAnswering(config=lowerCAmelCase_   )
														_a      	=							{
														    '''input_ids''': input_ids,
														    '''attention_mask''': input_mask,
														}
														_a      	=							model(lowerCAmelCase_   )
														self.parent.assertEqual(result.start_logits.shape				,     (self.batch_size, self.seq_length)   )
														self.parent.assertEqual(result.end_logits.shape				,     (self.batch_size, self.seq_length)   )







							def   __lowerCAmelCase     (    self			:    Any				,     lowerCAmelCase_			:    Tuple				,     lowerCAmelCase_			:    Optional[int]				,     lowerCAmelCase_			:    Any				,     lowerCAmelCase_			:    Optional[Any]				,     lowerCAmelCase_			:    str				,     lowerCAmelCase_			:    Union[str, Any]   )     ->				Optional[int]:


														"""simple docstring"""


														_a      	=							self.num_labels
														_a      	=							TFDistilBertForSequenceClassification(lowerCAmelCase_   )
														_a      	=							{'''input_ids''': input_ids, '''attention_mask''': input_mask}
														_a      	=							model(lowerCAmelCase_   )
														self.parent.assertEqual(result.logits.shape				,     (self.batch_size, self.num_labels)   )







							def   __lowerCAmelCase     (    self			:    Optional[Any]				,     lowerCAmelCase_			:    Tuple				,     lowerCAmelCase_			:    List[str]				,     lowerCAmelCase_			:    int				,     lowerCAmelCase_			:    Optional[int]				,     lowerCAmelCase_			:    List[str]				,     lowerCAmelCase_			:    List[str]   )     ->				Dict:


														"""simple docstring"""


														_a      	=							self.num_choices
														_a      	=							TFDistilBertForMultipleChoice(lowerCAmelCase_   )
														_a      	=							tf.tile(tf.expand_dims(lowerCAmelCase_				,     1   )				,     (1, self.num_choices, 1)   )
														_a      	=							tf.tile(tf.expand_dims(lowerCAmelCase_				,     1   )				,     (1, self.num_choices, 1)   )
														_a      	=							{
														    '''input_ids''': multiple_choice_inputs_ids,
														    '''attention_mask''': multiple_choice_input_mask,
														}
														_a      	=							model(lowerCAmelCase_   )
														self.parent.assertEqual(result.logits.shape				,     (self.batch_size, self.num_choices)   )







							def   __lowerCAmelCase     (    self			:    Dict				,     lowerCAmelCase_			:    int				,     lowerCAmelCase_			:    List[Any]				,     lowerCAmelCase_			:    Any				,     lowerCAmelCase_			:    Tuple				,     lowerCAmelCase_			:    List[str]				,     lowerCAmelCase_			:    Optional[Any]   )     ->				Optional[Any]:


														"""simple docstring"""


														_a      	=							self.num_labels
														_a      	=							TFDistilBertForTokenClassification(lowerCAmelCase_   )
														_a      	=							{'''input_ids''': input_ids, '''attention_mask''': input_mask}
														_a      	=							model(lowerCAmelCase_   )
														self.parent.assertEqual(result.logits.shape				,     (self.batch_size, self.seq_length, self.num_labels)   )







							def   __lowerCAmelCase     (    self			:    Optional[int]   )     ->				Union[str, Any]:


														"""simple docstring"""


														_a      	=							self.prepare_config_and_inputs()
														((_a)	,				(_a)	,				(_a)	,				(_a)	,				(_a)	,				(_a))      	=							config_and_inputs
														_a      	=							{'''input_ids''': input_ids, '''attention_mask''': input_mask}
														return config, inputs_dict



@require_tf
class      A       (						_a	,_a	,unittest.TestCase       ):
							lowercase_							     =							(
							    (
							        TFDistilBertModel,
							        TFDistilBertForMaskedLM,
							        TFDistilBertForQuestionAnswering,
							        TFDistilBertForSequenceClassification,
							        TFDistilBertForTokenClassification,
							        TFDistilBertForMultipleChoice,
							    )
							    if is_tf_available()
							    else None
							)
							lowercase_							     =							(
							    {
							        'feature-extraction': TFDistilBertModel,
							        'fill-mask': TFDistilBertForMaskedLM,
							        'question-answering': TFDistilBertForQuestionAnswering,
							        'text-classification': TFDistilBertForSequenceClassification,
							        'token-classification': TFDistilBertForTokenClassification,
							        'zero-shot': TFDistilBertForSequenceClassification,
							    }
							    if is_tf_available()
							    else {}
							)
							lowercase_							     =							False
							lowercase_							     =							False







							def   __lowerCAmelCase     (    self			:    List[str]   )     ->				Dict:


														"""simple docstring"""


														_a      	=							TFDistilBertModelTester(self   )
														_a      	=							ConfigTester(self				,     config_class=lowerCAmelCase_				,     dim=37   )







							def   __lowerCAmelCase     (    self			:    Any   )     ->				int:


														"""simple docstring"""


														self.config_tester.run_common_tests()







							def   __lowerCAmelCase     (    self			:    Tuple   )     ->				str:


														"""simple docstring"""


														_a      	=							self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_distilbert_model(*lowerCAmelCase_   )







							def   __lowerCAmelCase     (    self			:    Any   )     ->				Union[str, Any]:


														"""simple docstring"""


														_a      	=							self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_distilbert_for_masked_lm(*lowerCAmelCase_   )







							def   __lowerCAmelCase     (    self			:    Tuple   )     ->				List[str]:


														"""simple docstring"""


														_a      	=							self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_distilbert_for_question_answering(*lowerCAmelCase_   )







							def   __lowerCAmelCase     (    self			:    Dict   )     ->				Any:


														"""simple docstring"""


														_a      	=							self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_distilbert_for_sequence_classification(*lowerCAmelCase_   )







							def   __lowerCAmelCase     (    self			:    Optional[Any]   )     ->				str:


														"""simple docstring"""


														_a      	=							self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_distilbert_for_multiple_choice(*lowerCAmelCase_   )







							def   __lowerCAmelCase     (    self			:    Tuple   )     ->				Union[str, Any]:


														"""simple docstring"""


														_a      	=							self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_distilbert_for_token_classification(*lowerCAmelCase_   )







							@slow
							def   __lowerCAmelCase     (    self			:    str   )     ->				Optional[Any]:


														"""simple docstring"""


														for model_name in list(TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]   ):
																					_a      	=							TFDistilBertModel.from_pretrained(lowerCAmelCase_   )
																					self.assertIsNotNone(lowerCAmelCase_   )



@require_tf
class      A       (						unittest.TestCase       ):







							@slow
							def   __lowerCAmelCase     (    self			:    int   )     ->				Optional[int]:


														"""simple docstring"""


														_a      	=							TFDistilBertModel.from_pretrained('''distilbert-base-uncased'''   )
														_a      	=							tf.constant([[0, 1, 2, 3, 4, 5]]   )
														_a      	=							model(lowerCAmelCase_   )[0]

														_a      	=							[1, 6, 7_68]
														self.assertEqual(output.shape				,     lowerCAmelCase_   )

														_a      	=							tf.constant(
														    [
														        [
														            [0.1_9_2_6_1_8_8_5, -0.1_3_7_3_2_9_5_5, 0.4_1_1_9_7_9_9],
														            [0.2_2_1_5_0_1_5_6, -0.0_7_4_2_2_6_6_1, 0.3_9_0_3_7_2_0_4],
														            [0.2_2_7_5_6_0_1_8, -0.0_8_9_6_4_1_4, 0.3_7_0_1_4_6_7],
														        ]
														    ]   )
														tf.debugging.assert_near(output[:, :3, :3]				,     lowerCAmelCase_				,     atol=1e-4   )






"""simple docstring"""






import copy
import os
from typing import Union

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


__snake_case				:  str =       logging.get_logger(__name__)

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



class      A__  (    __SCREAMING_SNAKE_CASE				):




	'''simple docstring'''





	SCREAMING_SNAKE_CASE        =      'git_vision_model'

	def __init__(	self:						Optional[int]			,     _SCREAMING_SNAKE_CASE:						List[Any]=768			,     _SCREAMING_SNAKE_CASE:						Optional[Any]=3072			,     _SCREAMING_SNAKE_CASE:						str=12			,     _SCREAMING_SNAKE_CASE:						Any=12			,     _SCREAMING_SNAKE_CASE:						Dict=3			,     _SCREAMING_SNAKE_CASE:						List[Any]=224			,     _SCREAMING_SNAKE_CASE:						List[str]=16			,     _SCREAMING_SNAKE_CASE:						str="quick_gelu"			,     _SCREAMING_SNAKE_CASE:						Any=1e-5			,     _SCREAMING_SNAKE_CASE:						List[str]=0.0			,     _SCREAMING_SNAKE_CASE:						Dict=0.02			,     **_SCREAMING_SNAKE_CASE:						str			,     )							->			Optional[Any]:

				"""simple docstring"""

				super().__init__(**_SCREAMING_SNAKE_CASE)

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







	@classmethod
	def 				_SCREAMING_SNAKE_CASE  (	cls:						Dict			,     _SCREAMING_SNAKE_CASE:						Union[str, os.PathLike]			,     **_SCREAMING_SNAKE_CASE:						Dict)							->			"PretrainedConfig":

				"""simple docstring"""

				cls._set_token_in_kwargs(_SCREAMING_SNAKE_CASE)

				__lowerCAmelCase		,      __lowerCAmelCase :    List[Any]				=			cls.get_config_dict(_SCREAMING_SNAKE_CASE			,     **_SCREAMING_SNAKE_CASE)

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






class      A__  (    __SCREAMING_SNAKE_CASE				):




	'''simple docstring'''





	SCREAMING_SNAKE_CASE        =      'git'

	def __init__(	self:						Union[str, Any]			,     _SCREAMING_SNAKE_CASE:						Tuple=None			,     _SCREAMING_SNAKE_CASE:						Dict=3_0522			,     _SCREAMING_SNAKE_CASE:						Any=768			,     _SCREAMING_SNAKE_CASE:						str=6			,     _SCREAMING_SNAKE_CASE:						int=12			,     _SCREAMING_SNAKE_CASE:						Dict=3072			,     _SCREAMING_SNAKE_CASE:						Optional[Any]="gelu"			,     _SCREAMING_SNAKE_CASE:						Union[str, Any]=0.1			,     _SCREAMING_SNAKE_CASE:						Any=0.1			,     _SCREAMING_SNAKE_CASE:						Union[str, Any]=1024			,     _SCREAMING_SNAKE_CASE:						str=0.02			,     _SCREAMING_SNAKE_CASE:						Tuple=1e-12			,     _SCREAMING_SNAKE_CASE:						List[str]=0			,     _SCREAMING_SNAKE_CASE:						Union[str, Any]="absolute"			,     _SCREAMING_SNAKE_CASE:						Union[str, Any]=True			,     _SCREAMING_SNAKE_CASE:						Tuple=False			,     _SCREAMING_SNAKE_CASE:						Dict=101			,     _SCREAMING_SNAKE_CASE:						Tuple=102			,     _SCREAMING_SNAKE_CASE:						Any=None			,     **_SCREAMING_SNAKE_CASE:						List[Any]			,     )							->			List[Any]:

				"""simple docstring"""

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

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

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

				__lowerCAmelCase :    Optional[Any]				=			bos_token_id
				__lowerCAmelCase :    Any				=			eos_token_id







	def 				_SCREAMING_SNAKE_CASE  (	self:						Dict)							->			List[str]:

				"""simple docstring"""

				__lowerCAmelCase :    Optional[int]				=			copy.deepcopy(self.__dict__)
				__lowerCAmelCase :    List[Any]				=			self.vision_config.to_dict()
				__lowerCAmelCase :    Tuple				=			self.__class__.model_type
				return output