





"""simple docstring"""






import unittest

import numpy as np

from transformers import RobertaConfig, is_flax_available
from transformers.testing_utils import require_flax, slow

from ...test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask


if is_flax_available():
		from transformers.models.roberta.modeling_flax_roberta import (
		    FlaxRobertaForCausalLM,
		    FlaxRobertaForMaskedLM,
		    FlaxRobertaForMultipleChoice,
		    FlaxRobertaForQuestionAnswering,
		    FlaxRobertaForSequenceClassification,
		    FlaxRobertaForTokenClassification,
		    FlaxRobertaModel,
		)




class 				__lowercase			(			unittest.TestCase							):







					'''simple docstring'''




					def __init__(						self	,			_UpperCAmelCase	,			_UpperCAmelCase=13	,			_UpperCAmelCase=7	,			_UpperCAmelCase=True	,			_UpperCAmelCase=True	,			_UpperCAmelCase=True	,			_UpperCAmelCase=True	,			_UpperCAmelCase=99	,			_UpperCAmelCase=32	,			_UpperCAmelCase=5	,			_UpperCAmelCase=4	,			_UpperCAmelCase=37	,			_UpperCAmelCase="gelu"	,			_UpperCAmelCase=0.1	,			_UpperCAmelCase=0.1	,			_UpperCAmelCase=512	,			_UpperCAmelCase=16	,			_UpperCAmelCase=2	,			_UpperCAmelCase=0.0_2	,			_UpperCAmelCase=4	,			):
									__a :						Optional[int]			       =  parent
									__a :						Union[str, Any]			       =  batch_size
									__a :						str			       =  seq_length
									__a :						Tuple			       =  is_training
									__a :						List[str]			       =  use_attention_mask
									__a :						Dict			       =  use_token_type_ids
									__a :						List[Any]			       =  use_labels
									__a :						str			       =  vocab_size
									__a :						int			       =  hidden_size
									__a :						Optional[int]			       =  num_hidden_layers
									__a :						str			       =  num_attention_heads
									__a :						Optional[Any]			       =  intermediate_size
									__a :						Dict			       =  hidden_act
									__a :						Any			       =  hidden_dropout_prob
									__a :						str			       =  attention_probs_dropout_prob
									__a :						str			       =  max_position_embeddings
									__a :						Union[str, Any]			       =  type_vocab_size
									__a :						Tuple			       =  type_sequence_label_size
									__a :						Any			       =  initializer_range
									__a :						Optional[Any]			       =  num_choices







					def  _lowerCamelCase		(						self     ):
									__a :						str			       =  ids_tensor([self.batch_size, self.seq_length]	,			self.vocab_size     )

									__a :						List[str]			       =  None
									if self.use_attention_mask:
													__a :						str			       =  random_attention_mask([self.batch_size, self.seq_length]     )

									__a :						List[Any]			       =  None
									if self.use_token_type_ids:
													__a :						str			       =  ids_tensor([self.batch_size, self.seq_length]	,			self.type_vocab_size     )

									__a :						Dict			       =  RobertaConfig(
									    vocab_size=self.vocab_size	,			hidden_size=self.hidden_size	,			num_hidden_layers=self.num_hidden_layers	,			num_attention_heads=self.num_attention_heads	,			intermediate_size=self.intermediate_size	,			hidden_act=self.hidden_act	,			hidden_dropout_prob=self.hidden_dropout_prob	,			attention_probs_dropout_prob=self.attention_probs_dropout_prob	,			max_position_embeddings=self.max_position_embeddings	,			type_vocab_size=self.type_vocab_size	,			is_decoder=_UpperCAmelCase	,			initializer_range=self.initializer_range	,			)

									return config, input_ids, token_type_ids, attention_mask







					def  _lowerCamelCase		(						self     ):
									__a :						int			       =  self.prepare_config_and_inputs()
									__a       ,						__a       ,						__a       ,						__a :						Optional[Any]			       =  config_and_inputs
									__a :						int			       =  {'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': attention_mask}
									return config, inputs_dict







					def  _lowerCamelCase		(						self     ):
									__a :						Tuple			       =  self.prepare_config_and_inputs()
									__a       ,						__a       ,						__a       ,						__a :						Any			       =  config_and_inputs

									__a :						List[Any]			       =  True
									__a :						Optional[int]			       =  floats_tensor([self.batch_size, self.seq_length, self.hidden_size]     )
									__a :						Tuple			       =  ids_tensor([self.batch_size, self.seq_length]	,			vocab_size=2     )

									return (
									    config,
									    input_ids,
									    token_type_ids,
									    encoder_hidden_states,
									    encoder_attention_mask,
									)






@require_flax
class 				__lowercase			(			_UpperCamelCase   ,      unittest.TestCase							):







					'''simple docstring'''




					__lowerCAmelCase  =  True

					__lowerCAmelCase  =  (
					    (
					        FlaxRobertaModel,
					        FlaxRobertaForCausalLM,
					        FlaxRobertaForMaskedLM,
					        FlaxRobertaForSequenceClassification,
					        FlaxRobertaForTokenClassification,
					        FlaxRobertaForMultipleChoice,
					        FlaxRobertaForQuestionAnswering,
					    )
					    if is_flax_available()
					    else ()
					)







					def  _lowerCamelCase		(						self     ):
									__a :						Any			       =  FlaxRobertaModelTester(self     )







					@slow
					def  _lowerCamelCase		(						self     ):
									for model_class_name in self.all_model_classes:
													__a :						Any			       =  model_class_name.from_pretrained('''roberta-base'''	,			from_pt=_UpperCAmelCase     )
													__a :						List[str]			       =  model(np.ones((1, 1)     )     )
													self.assertIsNotNone(_UpperCAmelCase     )






"""simple docstring"""






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 				__lowercase			(			_UpperCamelCase							):







					'''simple docstring'''




					__lowerCAmelCase  =  '''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	,			):
									super().__init__(**_UpperCAmelCase     )

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







					@classmethod
					def  _lowerCamelCase		(						cls	,			_UpperCAmelCase	,			**_UpperCAmelCase     ):
									cls._set_token_in_kwargs(_UpperCAmelCase     )

									__a       ,						__a :						Dict			       =  cls.get_config_dict(_UpperCAmelCase	,			**_UpperCAmelCase     )

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







					'''simple docstring'''




					__lowerCAmelCase  =  '''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-1_2	,			_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:
													__a :						Union[str, Any]			       =  {}
													logger.info('''vision_config is None. initializing the GitVisionConfig with default values.'''     )

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

									__a :						str			       =  bos_token_id
									__a :						Dict			       =  eos_token_id







					def  _lowerCamelCase		(						self     ):
									__a :						Optional[int]			       =  copy.deepcopy(self.__dict__     )
									__a :						int			       =  self.vision_config.to_dict()
									__a :						Tuple			       =  self.__class__.model_type
									return output