


import os
import tempfile
import unittest

from transformers import FlaubertConfig, is_torch_available
from transformers.testing_utils import require_torch, require_torch_gpu, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
		import torch

		from transformers import (
		    FlaubertForMultipleChoice,
		    FlaubertForQuestionAnswering,
		    FlaubertForQuestionAnsweringSimple,
		    FlaubertForSequenceClassification,
		    FlaubertForTokenClassification,
		    FlaubertModel,
		    FlaubertWithLMHeadModel,
		)
		from transformers.models.flaubert.modeling_flaubert import FLAUBERT_PRETRAINED_MODEL_ARCHIVE_LIST





class  _a							(    _lowercase):




	def __init__( self						:		Optional[Any]		, _SCREAMING_SNAKE_CASE						:		str		, _SCREAMING_SNAKE_CASE						:		Tuple=13		, _SCREAMING_SNAKE_CASE						:		List[str]=7		, _SCREAMING_SNAKE_CASE						:		Tuple=True		, _SCREAMING_SNAKE_CASE						:		int=True		, _SCREAMING_SNAKE_CASE						:		Dict=True		, _SCREAMING_SNAKE_CASE						:		Dict=True		, _SCREAMING_SNAKE_CASE						:		List[Any]=True		, _SCREAMING_SNAKE_CASE						:		int=False		, _SCREAMING_SNAKE_CASE						:		Union[str, Any]=False		, _SCREAMING_SNAKE_CASE						:		str=False		, _SCREAMING_SNAKE_CASE						:		Optional[Any]=2		, _SCREAMING_SNAKE_CASE						:		Tuple=99		, _SCREAMING_SNAKE_CASE						:		Optional[Any]=0		, _SCREAMING_SNAKE_CASE						:		List[Any]=32		, _SCREAMING_SNAKE_CASE						:		Optional[int]=5		, _SCREAMING_SNAKE_CASE						:		List[str]=4		, _SCREAMING_SNAKE_CASE						:		List[Any]=0.1		, _SCREAMING_SNAKE_CASE						:		Dict=0.1		, _SCREAMING_SNAKE_CASE						:		Tuple=512		, _SCREAMING_SNAKE_CASE						:		Any=12		, _SCREAMING_SNAKE_CASE						:		Optional[Any]=2		, _SCREAMING_SNAKE_CASE						:		Tuple=0.02		, _SCREAMING_SNAKE_CASE						:		Tuple=3		, _SCREAMING_SNAKE_CASE						:		Tuple=4		, _SCREAMING_SNAKE_CASE						:		str="last"		, _SCREAMING_SNAKE_CASE						:		Union[str, Any]=None		, _SCREAMING_SNAKE_CASE						:		List[str]=None		, )->	Any:
			lowerCAmelCase__       :      Dict   					= parent
			lowerCAmelCase__       :      Any   					= batch_size
			lowerCAmelCase__       :      Optional[int]   					= seq_length
			lowerCAmelCase__       :      List[str]   					= is_training
			lowerCAmelCase__       :      Any   					= use_input_lengths
			lowerCAmelCase__       :      List[str]   					= use_token_type_ids
			lowerCAmelCase__       :      Optional[Any]   					= use_labels
			lowerCAmelCase__       :      Union[str, Any]   					= gelu_activation
			lowerCAmelCase__       :      Union[str, Any]   					= sinusoidal_embeddings
			lowerCAmelCase__       :      Union[str, Any]   					= causal
			lowerCAmelCase__       :      Any   					= asm
			lowerCAmelCase__       :      Union[str, Any]   					= n_langs
			lowerCAmelCase__       :      Any   					= vocab_size
			lowerCAmelCase__       :      List[Any]   					= n_special
			lowerCAmelCase__       :      Optional[Any]   					= hidden_size
			lowerCAmelCase__       :      Union[str, Any]   					= num_hidden_layers
			lowerCAmelCase__       :      Dict   					= num_attention_heads
			lowerCAmelCase__       :      int   					= hidden_dropout_prob
			lowerCAmelCase__       :      List[str]   					= attention_probs_dropout_prob
			lowerCAmelCase__       :      Dict   					= max_position_embeddings
			lowerCAmelCase__       :      str   					= type_vocab_size
			lowerCAmelCase__       :      Any   					= type_sequence_label_size
			lowerCAmelCase__       :      str   					= initializer_range
			lowerCAmelCase__       :      Any   					= num_labels
			lowerCAmelCase__       :      str   					= num_choices
			lowerCAmelCase__       :      List[Any]   					= summary_type
			lowerCAmelCase__       :      int   					= use_proj
			lowerCAmelCase__       :      Any   					= scope




	def 							UpperCAmelCase__( self						:		Tuple		)->	str:
			lowerCAmelCase__       :      str   					= ids_tensor([self.batch_size, self.seq_length]		, self.vocab_size		)
			lowerCAmelCase__       :      Optional[int]   					= random_attention_mask([self.batch_size, self.seq_length]		)

			lowerCAmelCase__       :      Dict   					= None
			if self.use_input_lengths:
					lowerCAmelCase__       :      Optional[int]   					= (
					    ids_tensor([self.batch_size]		, vocab_size=2		) + self.seq_length - 2
					)  # small variation of seq_length

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

			lowerCAmelCase__       :      Optional[int]   					= None
			lowerCAmelCase__       :      Dict   					= None
			lowerCAmelCase__       :      str   					= None
			if self.use_labels:
					lowerCAmelCase__       :      List[Any]   					= ids_tensor([self.batch_size]		, self.type_sequence_label_size		)
					lowerCAmelCase__       :      List[Any]   					= ids_tensor([self.batch_size, self.seq_length]		, self.num_labels		)
					lowerCAmelCase__       :      Optional[int]   					= ids_tensor([self.batch_size]		, 2		).float()
					lowerCAmelCase__       :      Optional[Any]   					= ids_tensor([self.batch_size]		, self.num_choices		)

			lowerCAmelCase__       :      Union[str, Any]   					= self.get_config()

			return (
			    config,
			    input_ids,
			    token_type_ids,
			    input_lengths,
			    sequence_labels,
			    token_labels,
			    is_impossible_labels,
			    choice_labels,
			    input_mask,
			)




	def 							UpperCAmelCase__( self						:		Dict		)->	int:
			return FlaubertConfig(
			    vocab_size=self.vocab_size		, n_special=self.n_special		, emb_dim=self.hidden_size		, n_layers=self.num_hidden_layers		, n_heads=self.num_attention_heads		, dropout=self.hidden_dropout_prob		, attention_dropout=self.attention_probs_dropout_prob		, gelu_activation=self.gelu_activation		, sinusoidal_embeddings=self.sinusoidal_embeddings		, asm=self.asm		, causal=self.causal		, n_langs=self.n_langs		, max_position_embeddings=self.max_position_embeddings		, initializer_range=self.initializer_range		, summary_type=self.summary_type		, use_proj=self.use_proj		, )




	def 							UpperCAmelCase__( self						:		Optional[Any]		, _SCREAMING_SNAKE_CASE						:		str		, _SCREAMING_SNAKE_CASE						:		Optional[int]		, _SCREAMING_SNAKE_CASE						:		List[str]		, _SCREAMING_SNAKE_CASE						:		Optional[int]		, _SCREAMING_SNAKE_CASE						:		int		, _SCREAMING_SNAKE_CASE						:		Tuple		, _SCREAMING_SNAKE_CASE						:		List[Any]		, _SCREAMING_SNAKE_CASE						:		int		, _SCREAMING_SNAKE_CASE						:		Tuple		, )->	Union[str, Any]:
			lowerCAmelCase__       :      List[str]   					= FlaubertModel(config=_SCREAMING_SNAKE_CASE		)
			model.to(_SCREAMING_SNAKE_CASE		)
			model.eval()
			lowerCAmelCase__       :      Optional[int]   					= model(_SCREAMING_SNAKE_CASE		, lengths=_SCREAMING_SNAKE_CASE		, langs=_SCREAMING_SNAKE_CASE		)
			lowerCAmelCase__       :      List[Any]   					= model(_SCREAMING_SNAKE_CASE		, langs=_SCREAMING_SNAKE_CASE		)
			lowerCAmelCase__       :      List[str]   					= model(_SCREAMING_SNAKE_CASE		)
			self.parent.assertEqual(result.last_hidden_state.shape		, (self.batch_size, self.seq_length, self.hidden_size)		)




	def 							UpperCAmelCase__( self						:		Tuple		, _SCREAMING_SNAKE_CASE						:		Optional[int]		, _SCREAMING_SNAKE_CASE						:		str		, _SCREAMING_SNAKE_CASE						:		Union[str, Any]		, _SCREAMING_SNAKE_CASE						:		Union[str, Any]		, _SCREAMING_SNAKE_CASE						:		str		, _SCREAMING_SNAKE_CASE						:		Union[str, Any]		, _SCREAMING_SNAKE_CASE						:		Union[str, Any]		, _SCREAMING_SNAKE_CASE						:		List[str]		, _SCREAMING_SNAKE_CASE						:		Optional[Any]		, )->	Optional[Any]:
			lowerCAmelCase__       :      int   					= FlaubertWithLMHeadModel(_SCREAMING_SNAKE_CASE		)
			model.to(_SCREAMING_SNAKE_CASE		)
			model.eval()

			lowerCAmelCase__       :      Optional[int]   					= model(_SCREAMING_SNAKE_CASE		, token_type_ids=_SCREAMING_SNAKE_CASE		, labels=_SCREAMING_SNAKE_CASE		)
			self.parent.assertEqual(result.loss.shape		, ()		)
			self.parent.assertEqual(result.logits.shape		, (self.batch_size, self.seq_length, self.vocab_size)		)




	def 							UpperCAmelCase__( self						:		Optional[int]		, _SCREAMING_SNAKE_CASE						:		Dict		, _SCREAMING_SNAKE_CASE						:		List[Any]		, _SCREAMING_SNAKE_CASE						:		List[str]		, _SCREAMING_SNAKE_CASE						:		str		, _SCREAMING_SNAKE_CASE						:		Union[str, Any]		, _SCREAMING_SNAKE_CASE						:		Tuple		, _SCREAMING_SNAKE_CASE						:		Dict		, _SCREAMING_SNAKE_CASE						:		Dict		, _SCREAMING_SNAKE_CASE						:		List[Any]		, )->	Tuple:
			lowerCAmelCase__       :      List[str]   					= FlaubertForQuestionAnsweringSimple(_SCREAMING_SNAKE_CASE		)
			model.to(_SCREAMING_SNAKE_CASE		)
			model.eval()

			lowerCAmelCase__       :      Tuple   					= model(_SCREAMING_SNAKE_CASE		)

			lowerCAmelCase__       :      str   					= model(_SCREAMING_SNAKE_CASE		, start_positions=_SCREAMING_SNAKE_CASE		, end_positions=_SCREAMING_SNAKE_CASE		)
			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 							UpperCAmelCase__( self						:		int		, _SCREAMING_SNAKE_CASE						:		Dict		, _SCREAMING_SNAKE_CASE						:		Any		, _SCREAMING_SNAKE_CASE						:		Optional[Any]		, _SCREAMING_SNAKE_CASE						:		Union[str, Any]		, _SCREAMING_SNAKE_CASE						:		List[Any]		, _SCREAMING_SNAKE_CASE						:		Optional[int]		, _SCREAMING_SNAKE_CASE						:		Union[str, Any]		, _SCREAMING_SNAKE_CASE						:		List[str]		, _SCREAMING_SNAKE_CASE						:		Any		, )->	Any:
			lowerCAmelCase__       :      Optional[int]   					= FlaubertForQuestionAnswering(_SCREAMING_SNAKE_CASE		)
			model.to(_SCREAMING_SNAKE_CASE		)
			model.eval()

			lowerCAmelCase__       :      List[str]   					= model(_SCREAMING_SNAKE_CASE		)

			lowerCAmelCase__       :      List[Any]   					= model(
			    _SCREAMING_SNAKE_CASE		, start_positions=_SCREAMING_SNAKE_CASE		, end_positions=_SCREAMING_SNAKE_CASE		, cls_index=_SCREAMING_SNAKE_CASE		, is_impossible=_SCREAMING_SNAKE_CASE		, p_mask=_SCREAMING_SNAKE_CASE		, )

			lowerCAmelCase__       :      Union[str, Any]   					= model(
			    _SCREAMING_SNAKE_CASE		, start_positions=_SCREAMING_SNAKE_CASE		, end_positions=_SCREAMING_SNAKE_CASE		, cls_index=_SCREAMING_SNAKE_CASE		, is_impossible=_SCREAMING_SNAKE_CASE		, )

			(lowerCAmelCase__     )       :      str   					= result_with_labels.to_tuple()

			lowerCAmelCase__       :      Optional[Any]   					= model(_SCREAMING_SNAKE_CASE		, start_positions=_SCREAMING_SNAKE_CASE		, end_positions=_SCREAMING_SNAKE_CASE		)

			(lowerCAmelCase__     )       :      str   					= result_with_labels.to_tuple()

			self.parent.assertEqual(result_with_labels.loss.shape		, ()		)
			self.parent.assertEqual(result.start_top_log_probs.shape		, (self.batch_size, model.config.start_n_top)		)
			self.parent.assertEqual(result.start_top_index.shape		, (self.batch_size, model.config.start_n_top)		)
			self.parent.assertEqual(
			    result.end_top_log_probs.shape		, (self.batch_size, model.config.start_n_top * model.config.end_n_top)		)
			self.parent.assertEqual(
			    result.end_top_index.shape		, (self.batch_size, model.config.start_n_top * model.config.end_n_top)		)
			self.parent.assertEqual(result.cls_logits.shape		, (self.batch_size,)		)




	def 							UpperCAmelCase__( self						:		Union[str, Any]		, _SCREAMING_SNAKE_CASE						:		Dict		, _SCREAMING_SNAKE_CASE						:		Union[str, Any]		, _SCREAMING_SNAKE_CASE						:		List[Any]		, _SCREAMING_SNAKE_CASE						:		Tuple		, _SCREAMING_SNAKE_CASE						:		List[Any]		, _SCREAMING_SNAKE_CASE						:		str		, _SCREAMING_SNAKE_CASE						:		Optional[Any]		, _SCREAMING_SNAKE_CASE						:		Optional[Any]		, _SCREAMING_SNAKE_CASE						:		Dict		, )->	Union[str, Any]:
			lowerCAmelCase__       :      List[Any]   					= FlaubertForSequenceClassification(_SCREAMING_SNAKE_CASE		)
			model.to(_SCREAMING_SNAKE_CASE		)
			model.eval()

			lowerCAmelCase__       :      Optional[int]   					= model(_SCREAMING_SNAKE_CASE		)
			lowerCAmelCase__       :      int   					= model(_SCREAMING_SNAKE_CASE		, labels=_SCREAMING_SNAKE_CASE		)

			self.parent.assertEqual(result.loss.shape		, ()		)
			self.parent.assertEqual(result.logits.shape		, (self.batch_size, self.type_sequence_label_size)		)




	def 							UpperCAmelCase__( self						:		Optional[int]		, _SCREAMING_SNAKE_CASE						:		List[Any]		, _SCREAMING_SNAKE_CASE						:		Optional[Any]		, _SCREAMING_SNAKE_CASE						:		Tuple		, _SCREAMING_SNAKE_CASE						:		Optional[Any]		, _SCREAMING_SNAKE_CASE						:		Dict		, _SCREAMING_SNAKE_CASE						:		List[str]		, _SCREAMING_SNAKE_CASE						:		Optional[Any]		, _SCREAMING_SNAKE_CASE						:		Union[str, Any]		, _SCREAMING_SNAKE_CASE						:		List[str]		, )->	List[str]:
			lowerCAmelCase__       :      Optional[Any]   					= self.num_labels
			lowerCAmelCase__       :      Dict   					= FlaubertForTokenClassification(_SCREAMING_SNAKE_CASE		)
			model.to(_SCREAMING_SNAKE_CASE		)
			model.eval()

			lowerCAmelCase__       :      Dict   					= model(_SCREAMING_SNAKE_CASE		, attention_mask=_SCREAMING_SNAKE_CASE		, labels=_SCREAMING_SNAKE_CASE		)
			self.parent.assertEqual(result.logits.shape		, (self.batch_size, self.seq_length, self.num_labels)		)




	def 							UpperCAmelCase__( self						:		Optional[int]		, _SCREAMING_SNAKE_CASE						:		int		, _SCREAMING_SNAKE_CASE						:		str		, _SCREAMING_SNAKE_CASE						:		Optional[int]		, _SCREAMING_SNAKE_CASE						:		List[str]		, _SCREAMING_SNAKE_CASE						:		Optional[int]		, _SCREAMING_SNAKE_CASE						:		int		, _SCREAMING_SNAKE_CASE						:		Tuple		, _SCREAMING_SNAKE_CASE						:		int		, _SCREAMING_SNAKE_CASE						:		Any		, )->	List[Any]:
			lowerCAmelCase__       :      int   					= self.num_choices
			lowerCAmelCase__       :      List[str]   					= FlaubertForMultipleChoice(config=_SCREAMING_SNAKE_CASE		)
			model.to(_SCREAMING_SNAKE_CASE		)
			model.eval()
			lowerCAmelCase__       :      int   					= input_ids.unsqueeze(1		).expand(-1		, self.num_choices		, -1		).contiguous()
			lowerCAmelCase__       :      Tuple   					= token_type_ids.unsqueeze(1		).expand(-1		, self.num_choices		, -1		).contiguous()
			lowerCAmelCase__       :      Optional[Any]   					= input_mask.unsqueeze(1		).expand(-1		, self.num_choices		, -1		).contiguous()
			lowerCAmelCase__       :      str   					= model(
			    _SCREAMING_SNAKE_CASE		, attention_mask=_SCREAMING_SNAKE_CASE		, token_type_ids=_SCREAMING_SNAKE_CASE		, labels=_SCREAMING_SNAKE_CASE		, )
			self.parent.assertEqual(result.logits.shape		, (self.batch_size, self.num_choices)		)




	def 							UpperCAmelCase__( self						:		Optional[Any]		)->	Any:
			lowerCAmelCase__       :      Dict   					= self.prepare_config_and_inputs()
			(
			    lowerCAmelCase__     
			)       :      str   					= config_and_inputs
			lowerCAmelCase__       :      Optional[Any]   					= {
			    '''input_ids''': input_ids,
			    '''token_type_ids''': token_type_ids,
			    '''lengths''': input_lengths,
			    '''attention_mask''': input_mask,
			}
			return config, inputs_dict





@require_torch
class  _a							(    _lowercase					,						_lowercase					,						unittest.TestCase):
	_a  :  int				   =							(
	    (
	        FlaubertModel,
	        FlaubertWithLMHeadModel,
	        FlaubertForQuestionAnswering,
	        FlaubertForQuestionAnsweringSimple,
	        FlaubertForSequenceClassification,
	        FlaubertForTokenClassification,
	        FlaubertForMultipleChoice,
	    )
	    if is_torch_available()
	    else ()
	)
	_a  :  Union[str, Any]				   =							(
	    {
	        '''feature-extraction''': FlaubertModel,
	        '''fill-mask''': FlaubertWithLMHeadModel,
	        '''question-answering''': FlaubertForQuestionAnsweringSimple,
	        '''text-classification''': FlaubertForSequenceClassification,
	        '''token-classification''': FlaubertForTokenClassification,
	        '''zero-shot''': FlaubertForSequenceClassification,
	    }
	    if is_torch_available()
	    else {}
	)




	def 							UpperCAmelCase__( self						:		Union[str, Any]		, _SCREAMING_SNAKE_CASE						:		str		, _SCREAMING_SNAKE_CASE						:		Union[str, Any]		, _SCREAMING_SNAKE_CASE						:		int		, _SCREAMING_SNAKE_CASE						:		List[Any]		, _SCREAMING_SNAKE_CASE						:		Any		)->	Optional[Any]:
			if (
			    pipeline_test_casse_name == "QAPipelineTests"
			    and tokenizer_name is not None
			    and not tokenizer_name.endswith('''Fast'''		)
			):
					# `QAPipelineTests` fails for a few models when the slower tokenizer are used.
					# (The slower tokenizers were never used for pipeline tests before the pipeline testing rework)
					# TODO: check (and possibly fix) the `QAPipelineTests` with slower tokenizer
					return True

			return False




	def 							UpperCAmelCase__( self						:		int		, _SCREAMING_SNAKE_CASE						:		Dict		, _SCREAMING_SNAKE_CASE						:		List[str]		, _SCREAMING_SNAKE_CASE						:		str=False		)->	List[str]:
			lowerCAmelCase__       :      Union[str, Any]   					= super()._prepare_for_class(_SCREAMING_SNAKE_CASE		, _SCREAMING_SNAKE_CASE		, return_labels=_SCREAMING_SNAKE_CASE		)

			if return_labels:
					if model_class.__name__ == "FlaubertForQuestionAnswering":
							lowerCAmelCase__       :      str   					= torch.zeros(
							    self.model_tester.batch_size		, dtype=torch.long		, device=_SCREAMING_SNAKE_CASE		)
							lowerCAmelCase__       :      str   					= torch.zeros(
							    self.model_tester.batch_size		, dtype=torch.long		, device=_SCREAMING_SNAKE_CASE		)

			return inputs_dict




	def 							UpperCAmelCase__( self						:		int		)->	List[str]:
			lowerCAmelCase__       :      Union[str, Any]   					= FlaubertModelTester(self		)
			lowerCAmelCase__       :      Tuple   					= ConfigTester(self		, config_class=_SCREAMING_SNAKE_CASE		, emb_dim=37		)




	def 							UpperCAmelCase__( self						:		Optional[Any]		)->	str:
			self.config_tester.run_common_tests()




	def 							UpperCAmelCase__( self						:		str		)->	Dict:
			lowerCAmelCase__       :      str   					= self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_flaubert_model(*_SCREAMING_SNAKE_CASE		)




	def 							UpperCAmelCase__( self						:		Optional[int]		)->	List[str]:
			lowerCAmelCase__       :      Optional[int]   					= self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_flaubert_lm_head(*_SCREAMING_SNAKE_CASE		)




	def 							UpperCAmelCase__( self						:		int		)->	Union[str, Any]:
			lowerCAmelCase__       :      Union[str, Any]   					= self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_flaubert_simple_qa(*_SCREAMING_SNAKE_CASE		)




	def 							UpperCAmelCase__( self						:		int		)->	str:
			lowerCAmelCase__       :      str   					= self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_flaubert_qa(*_SCREAMING_SNAKE_CASE		)




	def 							UpperCAmelCase__( self						:		str		)->	Tuple:
			lowerCAmelCase__       :      int   					= self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_flaubert_sequence_classif(*_SCREAMING_SNAKE_CASE		)




	def 							UpperCAmelCase__( self						:		Union[str, Any]		)->	Optional[int]:
			lowerCAmelCase__       :      Tuple   					= self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_flaubert_token_classif(*_SCREAMING_SNAKE_CASE		)




	def 							UpperCAmelCase__( self						:		Optional[Any]		)->	Union[str, Any]:
			lowerCAmelCase__       :      Dict   					= self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_flaubert_multiple_choice(*_SCREAMING_SNAKE_CASE		)




	@slow
	def 							UpperCAmelCase__( self						:		int		)->	Dict:
			for model_name in FLAUBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
					lowerCAmelCase__       :      List[str]   					= FlaubertModel.from_pretrained(_SCREAMING_SNAKE_CASE		)
					self.assertIsNotNone(_SCREAMING_SNAKE_CASE		)




	@slow
	@require_torch_gpu
	def 							UpperCAmelCase__( self						:		List[Any]		)->	Union[str, Any]:
			lowerCAmelCase__       :      Any   					= self.model_tester.prepare_config_and_inputs_for_common()
			for model_class in self.all_model_classes:
					# FlauBertForMultipleChoice behaves incorrectly in JIT environments.
					if model_class == FlaubertForMultipleChoice:
							return

					lowerCAmelCase__       :      Optional[int]   					= True
					lowerCAmelCase__       :      Optional[Any]   					= model_class(config=_SCREAMING_SNAKE_CASE		)

					lowerCAmelCase__       :      Any   					= self._prepare_for_class(_SCREAMING_SNAKE_CASE		, _SCREAMING_SNAKE_CASE		)
					lowerCAmelCase__       :      str   					= torch.jit.trace(
					    _SCREAMING_SNAKE_CASE		, (inputs_dict['''input_ids'''].to('''cpu'''		), inputs_dict['''attention_mask'''].to('''cpu'''		))		)

					with tempfile.TemporaryDirectory() as tmp:
							torch.jit.save(_SCREAMING_SNAKE_CASE		, os.path.join(_SCREAMING_SNAKE_CASE		, '''traced_model.pt'''		)		)
							lowerCAmelCase__       :      List[Any]   					= torch.jit.load(os.path.join(_SCREAMING_SNAKE_CASE		, '''traced_model.pt'''		)		, map_location=_SCREAMING_SNAKE_CASE		)
							loaded(inputs_dict['''input_ids'''].to(_SCREAMING_SNAKE_CASE		)		, inputs_dict['''attention_mask'''].to(_SCREAMING_SNAKE_CASE		)		)





@require_torch
class  _a							(    unittest.TestCase):




	@slow
	def 							UpperCAmelCase__( self						:		List[str]		)->	Optional[int]:
			lowerCAmelCase__       :      Dict   					= FlaubertModel.from_pretrained('''flaubert/flaubert_base_cased'''		)
			lowerCAmelCase__       :      Optional[Any]   					= torch.tensor([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]]		)
			with torch.no_grad():
					lowerCAmelCase__       :      Dict   					= model(_SCREAMING_SNAKE_CASE		)[0]
			lowerCAmelCase__       :      List[str]   					= torch.Size((1, 11, 768)		)
			self.assertEqual(output.shape		, _SCREAMING_SNAKE_CASE		)
			lowerCAmelCase__       :      str   					= torch.tensor(
			    [[[-2.6251, -1.4298, -0.0227], [-2.8510, -1.6387, 0.2258], [-2.8114, -1.1832, -0.3066]]]		)

			self.assertTrue(torch.allclose(output[:, :3, :3]		, _SCREAMING_SNAKE_CASE		, atol=1E-4		)		)








from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


lowerCamelCase						=		logging.get_logger(__name__)

lowerCamelCase						=		{
    '''facebook/xlm-roberta-xl''': '''https://huggingface.co/facebook/xlm-roberta-xl/resolve/main/config.json''',
    '''facebook/xlm-roberta-xxl''': '''https://huggingface.co/facebook/xlm-roberta-xxl/resolve/main/config.json''',
    # See all XLM-RoBERTa-XL models at https://huggingface.co/models?filter=xlm-roberta-xl
}





class  _a							(    _lowercase):
	_a  :  Optional[int]				   =							'''xlm-roberta-xl'''




	def __init__( self						:		Any		, _SCREAMING_SNAKE_CASE						:		str=25_0880		, _SCREAMING_SNAKE_CASE						:		Optional[Any]=2560		, _SCREAMING_SNAKE_CASE						:		int=36		, _SCREAMING_SNAKE_CASE						:		Optional[int]=32		, _SCREAMING_SNAKE_CASE						:		Any=1_0240		, _SCREAMING_SNAKE_CASE						:		List[str]="gelu"		, _SCREAMING_SNAKE_CASE						:		Optional[Any]=0.1		, _SCREAMING_SNAKE_CASE						:		Dict=0.1		, _SCREAMING_SNAKE_CASE						:		Optional[int]=514		, _SCREAMING_SNAKE_CASE						:		Optional[int]=1		, _SCREAMING_SNAKE_CASE						:		Tuple=0.02		, _SCREAMING_SNAKE_CASE						:		Dict=1E-05		, _SCREAMING_SNAKE_CASE						:		Tuple=1		, _SCREAMING_SNAKE_CASE						:		Optional[int]=0		, _SCREAMING_SNAKE_CASE						:		Tuple=2		, _SCREAMING_SNAKE_CASE						:		Union[str, Any]="absolute"		, _SCREAMING_SNAKE_CASE						:		Any=True		, _SCREAMING_SNAKE_CASE						:		Any=None		, **_SCREAMING_SNAKE_CASE						:		Tuple		, )->	str:
			super().__init__(pad_token_id=_SCREAMING_SNAKE_CASE		, bos_token_id=_SCREAMING_SNAKE_CASE		, eos_token_id=_SCREAMING_SNAKE_CASE		, **_SCREAMING_SNAKE_CASE		)
			lowerCAmelCase__       :      Any   					= vocab_size
			lowerCAmelCase__       :      List[Any]   					= hidden_size
			lowerCAmelCase__       :      int   					= num_hidden_layers
			lowerCAmelCase__       :      Dict   					= num_attention_heads
			lowerCAmelCase__       :      str   					= hidden_act
			lowerCAmelCase__       :      List[Any]   					= intermediate_size
			lowerCAmelCase__       :      Tuple   					= hidden_dropout_prob
			lowerCAmelCase__       :      str   					= attention_probs_dropout_prob
			lowerCAmelCase__       :      List[str]   					= max_position_embeddings
			lowerCAmelCase__       :      Any   					= type_vocab_size
			lowerCAmelCase__       :      Optional[Any]   					= initializer_range
			lowerCAmelCase__       :      Optional[int]   					= layer_norm_eps
			lowerCAmelCase__       :      Optional[int]   					= position_embedding_type
			lowerCAmelCase__       :      Any   					= use_cache
			lowerCAmelCase__       :      List[Any]   					= classifier_dropout





class  _a							(    _lowercase):




	@property
	def 							UpperCAmelCase__( self						:		Any		)->	Mapping[str, Mapping[int, str]]:
			if self.task == "multiple-choice":
					lowerCAmelCase__       :      int   					= {0: '''batch''', 1: '''choice''', 2: '''sequence'''}
			else:
					lowerCAmelCase__       :      List[Any]   					= {0: '''batch''', 1: '''sequence'''}
			return OrderedDict(
			    [
			        ('''input_ids''', dynamic_axis),
			        ('''attention_mask''', dynamic_axis),
			    ]		)




