


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 	snake_case_       (unittest.TestCase				):
					def __init__(				self       :Tuple      ,__snake_case       :Optional[int]      ,__snake_case       :Tuple=13      ,__snake_case       :Any=7      ,__snake_case       :int=True      ,__snake_case       :Any=True      ,__snake_case       :List[str]=True      ,__snake_case       :Optional[Any]=True      ,__snake_case       :int=99      ,__snake_case       :str=32      ,__snake_case       :Optional[int]=5      ,__snake_case       :Optional[Any]=4      ,__snake_case       :Optional[int]=37      ,__snake_case       :Union[str, Any]="gelu"      ,__snake_case       :List[str]=0.1      ,__snake_case       :str=0.1      ,__snake_case       :Optional[Any]=5_12      ,__snake_case       :Dict=16      ,__snake_case       :Optional[int]=2      ,__snake_case       :Union[str, Any]=0.02      ,__snake_case       :Optional[Any]=4      ,) ->   List[Any]:
												a__					=					parent
												a__					=					batch_size
												a__					=					seq_length
												a__					=					is_training
												a__					=					use_attention_mask
												a__					=					use_token_type_ids
												a__					=					use_labels
												a__					=					vocab_size
												a__					=					hidden_size
												a__					=					num_hidden_layers
												a__					=					num_attention_heads
												a__					=					intermediate_size
												a__					=					hidden_act
												a__					=					hidden_dropout_prob
												a__					=					attention_probs_dropout_prob
												a__					=					max_position_embeddings
												a__					=					type_vocab_size
												a__					=					type_sequence_label_size
												a__					=					initializer_range
												a__					=					num_choices
					def 			lowerCamelCase__(				self       :int				) ->   Dict:
												a__					=					ids_tensor([self.batch_size, self.seq_length]      ,self.vocab_size				)

												a__					=					None
												if self.use_attention_mask:
																			a__					=					random_attention_mask([self.batch_size, self.seq_length]				)

												a__					=					None
												if self.use_token_type_ids:
																			a__					=					ids_tensor([self.batch_size, self.seq_length]      ,self.type_vocab_size				)

												a__					=					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=__snake_case      ,initializer_range=self.initializer_range      ,)

												return config, input_ids, token_type_ids, attention_mask
					def 			lowerCamelCase__(				self       :int				) ->   Union[str, Any]:
												a__					=					self.prepare_config_and_inputs()
												a__				, a__				, a__				, a__					=					config_and_inputs
												a__					=					{'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': attention_mask}
												return config, inputs_dict



					def 			lowerCamelCase__(				self       :Any				) ->   Union[str, Any]:
												a__					=					self.prepare_config_and_inputs()
												a__				, a__				, a__				, a__					=					config_and_inputs

												a__					=					True
												a__					=					floats_tensor([self.batch_size, self.seq_length, self.hidden_size]				)
												a__					=					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 	snake_case_       (lowerCamelCase_     ,						unittest.TestCase				):
					UpperCAmelCase__ :   Optional[Any]   				=      True

					UpperCAmelCase__ :   Dict   				=      (
					    (
					        FlaxRobertaModel,
					        FlaxRobertaForCausalLM,
					        FlaxRobertaForMaskedLM,
					        FlaxRobertaForSequenceClassification,
					        FlaxRobertaForTokenClassification,
					        FlaxRobertaForMultipleChoice,
					        FlaxRobertaForQuestionAnswering,
					    )
					    if is_flax_available()
					    else ()
					)
					def 			lowerCamelCase__(				self       :int				) ->   List[str]:
												a__					=					FlaxRobertaModelTester(self				)



					@slow
					def 			lowerCamelCase__(				self       :Optional[int]				) ->   Optional[Any]:
												for model_class_name in self.all_model_classes:
																			a__					=					model_class_name.from_pretrained('roberta-base'      ,from_pt=__snake_case				)
																			a__					=					model(np.ones((1, 1)				)				)
																			self.assertIsNotNone(__snake_case				)








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


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

snake_case							:	Union[str, Any]					      =				{
    '''uclanlp/visualbert-vqa''': '''https://huggingface.co/uclanlp/visualbert-vqa/resolve/main/config.json''',
    '''uclanlp/visualbert-vqa-pre''': '''https://huggingface.co/uclanlp/visualbert-vqa-pre/resolve/main/config.json''',
    '''uclanlp/visualbert-vqa-coco-pre''': (
        '''https://huggingface.co/uclanlp/visualbert-vqa-coco-pre/resolve/main/config.json'''
    ),
    '''uclanlp/visualbert-vcr''': '''https://huggingface.co/uclanlp/visualbert-vcr/resolve/main/config.json''',
    '''uclanlp/visualbert-vcr-pre''': '''https://huggingface.co/uclanlp/visualbert-vcr-pre/resolve/main/config.json''',
    '''uclanlp/visualbert-vcr-coco-pre''': (
        '''https://huggingface.co/uclanlp/visualbert-vcr-coco-pre/resolve/main/config.json'''
    ),
    '''uclanlp/visualbert-nlvr2''': '''https://huggingface.co/uclanlp/visualbert-nlvr2/resolve/main/config.json''',
    '''uclanlp/visualbert-nlvr2-pre''': '''https://huggingface.co/uclanlp/visualbert-nlvr2-pre/resolve/main/config.json''',
    '''uclanlp/visualbert-nlvr2-coco-pre''': (
        '''https://huggingface.co/uclanlp/visualbert-nlvr2-coco-pre/resolve/main/config.json'''
    )
    # See all VisualBERT models at https://huggingface.co/models?filter=visual_bert
}







class 	snake_case_       (lowerCamelCase_				):
					UpperCAmelCase__ :   Dict   				=      '''visual_bert'''
					def __init__(				self       :Optional[int]      ,__snake_case       :Any=3_05_22      ,__snake_case       :str=7_68      ,__snake_case       :Any=5_12      ,__snake_case       :Any=12      ,__snake_case       :int=12      ,__snake_case       :str=30_72      ,__snake_case       :int="gelu"      ,__snake_case       :Optional[int]=0.1      ,__snake_case       :str=0.1      ,__snake_case       :Union[str, Any]=5_12      ,__snake_case       :Tuple=2      ,__snake_case       :Union[str, Any]=0.02      ,__snake_case       :Optional[Any]=1E-12      ,__snake_case       :Optional[Any]=False      ,__snake_case       :int=True      ,__snake_case       :Any=1      ,__snake_case       :Optional[int]=0      ,__snake_case       :Tuple=2      ,**__snake_case       :Any      ,) ->   Union[str, Any]:
												super().__init__(pad_token_id=__snake_case      ,bos_token_id=__snake_case      ,eos_token_id=__snake_case      ,**__snake_case				)

												a__					=					vocab_size
												a__					=					max_position_embeddings
												a__					=					hidden_size
												a__					=					visual_embedding_dim
												a__					=					num_hidden_layers
												a__					=					num_attention_heads
												a__					=					intermediate_size
												a__					=					hidden_act
												a__					=					hidden_dropout_prob
												a__					=					attention_probs_dropout_prob
												a__					=					initializer_range
												a__					=					type_vocab_size
												a__					=					layer_norm_eps
												a__					=					bypass_transformer
												a__					=					special_visual_initialize




