






import shutil
import tempfile
import unittest

from transformers import ClapFeatureExtractor, ClapProcessor, RobertaTokenizer, RobertaTokenizerFast
from transformers.testing_utils import require_sentencepiece, require_torchaudio

from .test_feature_extraction_clap import floats_list
@require_torchaudio
@require_sentencepiece
class 		SCREAMING_SNAKE_CASE__	(  unittest.TestCase     ):

  '''simple docstring'''







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


         """simple docstring"""
         _UpperCAmelCase							=    """laion/clap-htsat-unfused"""
         _UpperCAmelCase							=    tempfile.mkdtemp()


  def  lowerCamelCase       (      self		:			List[str]       ,				**lowerCamelCase		:			List[str]							)						->	List[Any]:


         """simple docstring"""
         return RobertaTokenizer.from_pretrained(self.checkpoint       ,				**lowerCamelCase							)


  def  lowerCamelCase       (      self		:			List[Any]       ,				**lowerCamelCase		:			Any							)						->	Any:


         """simple docstring"""
         return ClapFeatureExtractor.from_pretrained(self.checkpoint       ,				**lowerCamelCase							)


  def  lowerCamelCase       (      self		:			Optional[int]							)						->	str:


         """simple docstring"""
         shutil.rmtree(self.tmpdirname							)


  def  lowerCamelCase       (      self		:			Any							)						->	int:


         """simple docstring"""
         _UpperCAmelCase							=    self.get_tokenizer()
         _UpperCAmelCase							=    self.get_feature_extractor()

         _UpperCAmelCase							=    ClapProcessor(tokenizer=lowerCamelCase       ,				feature_extractor=lowerCamelCase							)

         processor.save_pretrained(self.tmpdirname							)
         _UpperCAmelCase							=    ClapProcessor.from_pretrained(self.tmpdirname							)

         self.assertEqual(processor.tokenizer.get_vocab()       ,				tokenizer.get_vocab()							)
         self.assertIsInstance(processor.tokenizer       ,				lowerCamelCase							)

         self.assertEqual(processor.feature_extractor.to_json_string()       ,				feature_extractor.to_json_string()							)
         self.assertIsInstance(processor.feature_extractor       ,				lowerCamelCase							)


  def  lowerCamelCase       (      self		:			str							)						->	Optional[int]:


         """simple docstring"""
         _UpperCAmelCase							=    ClapProcessor(tokenizer=self.get_tokenizer()       ,				feature_extractor=self.get_feature_extractor()							)
         processor.save_pretrained(self.tmpdirname							)

         _UpperCAmelCase							=    self.get_tokenizer(bos_token="""(BOS)"""       ,				eos_token="""(EOS)"""							)
         _UpperCAmelCase							=    self.get_feature_extractor(do_normalize=lowerCamelCase       ,				padding_value=1.0							)

         _UpperCAmelCase							=    ClapProcessor.from_pretrained(
             self.tmpdirname       ,				bos_token="""(BOS)"""       ,				eos_token="""(EOS)"""       ,				do_normalize=lowerCamelCase       ,				padding_value=1.0							)

         self.assertEqual(processor.tokenizer.get_vocab()       ,				tokenizer_add_kwargs.get_vocab()							)
         self.assertIsInstance(processor.tokenizer       ,				lowerCamelCase							)

         self.assertEqual(processor.feature_extractor.to_json_string()       ,				feature_extractor_add_kwargs.to_json_string()							)
         self.assertIsInstance(processor.feature_extractor       ,				lowerCamelCase							)


  def  lowerCamelCase       (      self		:			Tuple							)						->	List[Any]:


         """simple docstring"""
         _UpperCAmelCase							=    self.get_feature_extractor()
         _UpperCAmelCase							=    self.get_tokenizer()

         _UpperCAmelCase							=    ClapProcessor(tokenizer=lowerCamelCase       ,				feature_extractor=lowerCamelCase							)

         _UpperCAmelCase							=    floats_list((3, 1000)							)

         _UpperCAmelCase							=    feature_extractor(lowerCamelCase       ,				return_tensors="""np"""							)
         _UpperCAmelCase							=    processor(audios=lowerCamelCase       ,				return_tensors="""np"""							)

         for key in input_feat_extract.keys():
                self.assertAlmostEqual(input_feat_extract[key].sum()       ,				input_processor[key].sum()       ,				delta=1E-2							)


  def  lowerCamelCase       (      self		:			List[Any]							)						->	List[Any]:


         """simple docstring"""
         _UpperCAmelCase							=    self.get_feature_extractor()
         _UpperCAmelCase							=    self.get_tokenizer()

         _UpperCAmelCase							=    ClapProcessor(tokenizer=lowerCamelCase       ,				feature_extractor=lowerCamelCase							)

         _UpperCAmelCase							=    """This is a test string"""

         _UpperCAmelCase							=    processor(text=lowerCamelCase							)

         _UpperCAmelCase							=    tokenizer(lowerCamelCase							)

         for key in encoded_tok.keys():
                self.assertListEqual(encoded_tok[key]       ,				encoded_processor[key]							)


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


         """simple docstring"""
         _UpperCAmelCase							=    self.get_feature_extractor()
         _UpperCAmelCase							=    self.get_tokenizer()

         _UpperCAmelCase							=    ClapProcessor(tokenizer=lowerCamelCase       ,				feature_extractor=lowerCamelCase							)

         _UpperCAmelCase							=    [[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]

         _UpperCAmelCase							=    processor.batch_decode(lowerCamelCase							)
         _UpperCAmelCase							=    tokenizer.batch_decode(lowerCamelCase							)

         self.assertListEqual(lowerCamelCase       ,				lowerCamelCase							)





  def  lowerCamelCase       (      self		:			Optional[Any]							)						->	List[Any]:


         """simple docstring"""
         _UpperCAmelCase							=    self.get_feature_extractor()
         _UpperCAmelCase							=    self.get_tokenizer()

         _UpperCAmelCase							=    ClapProcessor(tokenizer=lowerCamelCase       ,				feature_extractor=lowerCamelCase							)

         self.assertListEqual(
             processor.model_input_names[2:]       ,				feature_extractor.model_input_names       ,				msg="""`processor` and `feature_extractor` model input names do not match"""       ,				)




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			(  SCREAMING_SNAKE_CASE					):



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



	def 		UpperCamelCase				(    self				:     List[Any])->				str:
						__lowerCAmelCase						 =ids_tensor([self.batch_size, self.seq_length]					,						self.vocab_size)
						__lowerCAmelCase						 =random_attention_mask([self.batch_size, self.seq_length])

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

						__lowerCAmelCase						 =None
						if self.use_token_type_ids:
											__lowerCAmelCase						 =ids_tensor([self.batch_size, self.seq_length]					,						self.n_langs)

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

						__lowerCAmelCase						 =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				:     Union[str, Any])->				Union[str, Any]:
						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				:     Any					,						snake_case_				:     Optional[Any]					,						snake_case_				:     Dict					,						snake_case_				:     Any					,						snake_case_				:     Optional[int]					,						snake_case_				:     Tuple					,						snake_case_				:     Optional[Any]					,						snake_case_				:     Optional[int]					,						snake_case_				:     Optional[int]					,						snake_case_				:     int					,						)->				Tuple:
						__lowerCAmelCase						 =FlaubertModel(config=snake_case_)
						model.to(snake_case_)
						model.eval()
						__lowerCAmelCase						 =model(snake_case_					,						lengths=snake_case_					,						langs=snake_case_)
						__lowerCAmelCase						 =model(snake_case_					,						langs=snake_case_)
						__lowerCAmelCase						 =model(snake_case_)
						self.parent.assertEqual(result.last_hidden_state.shape					,						(self.batch_size, self.seq_length, self.hidden_size))



	def 		UpperCamelCase				(    self				:     Optional[int]					,						snake_case_				:     Tuple					,						snake_case_				:     Dict					,						snake_case_				:     List[Any]					,						snake_case_				:     int					,						snake_case_				:     List[str]					,						snake_case_				:     Any					,						snake_case_				:     Optional[int]					,						snake_case_				:     List[str]					,						snake_case_				:     str					,						)->				str:
						__lowerCAmelCase						 =FlaubertWithLMHeadModel(snake_case_)
						model.to(snake_case_)
						model.eval()

						__lowerCAmelCase						 =model(snake_case_					,						token_type_ids=snake_case_					,						labels=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[Any]					,						snake_case_				:     Dict					,						snake_case_				:     Union[str, Any]					,						snake_case_				:     Optional[int]					,						snake_case_				:     Union[str, Any]					,						snake_case_				:     Union[str, Any]					,						snake_case_				:     List[str]					,						snake_case_				:     Dict					,						snake_case_				:     Dict					,						snake_case_				:     Any					,						)->				Tuple:
						__lowerCAmelCase						 =FlaubertForQuestionAnsweringSimple(snake_case_)
						model.to(snake_case_)
						model.eval()

						__lowerCAmelCase						 =model(snake_case_)

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

						__lowerCAmelCase						 =model(snake_case_)

						__lowerCAmelCase						 =model(
						    snake_case_					,						start_positions=snake_case_					,						end_positions=snake_case_					,						cls_index=snake_case_					,						is_impossible=snake_case_					,						p_mask=snake_case_					,						)

						__lowerCAmelCase						 =model(
						    snake_case_					,						start_positions=snake_case_					,						end_positions=snake_case_					,						cls_index=snake_case_					,						is_impossible=snake_case_					,						)

						((__lowerCAmelCase) ,						)						 =result_with_labels.to_tuple()

						__lowerCAmelCase						 =model(snake_case_					,						start_positions=snake_case_					,						end_positions=snake_case_)

						((__lowerCAmelCase) ,						)						 =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				:     List[Any]					,						snake_case_				:     Any					,						snake_case_				:     int					,						snake_case_				:     Union[str, Any]					,						snake_case_				:     Dict					,						snake_case_				:     int					,						snake_case_				:     Tuple					,						snake_case_				:     int					,						snake_case_				:     str					,						snake_case_				:     Dict					,						)->				Tuple:
						__lowerCAmelCase						 =FlaubertForSequenceClassification(snake_case_)
						model.to(snake_case_)
						model.eval()

						__lowerCAmelCase						 =model(snake_case_)
						__lowerCAmelCase						 =model(snake_case_					,						labels=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				:     Tuple					,						snake_case_				:     Union[str, Any]					,						snake_case_				:     Dict					,						snake_case_				:     List[str]					,						snake_case_				:     str					,						snake_case_				:     List[Any]					,						snake_case_				:     Dict					,						snake_case_				:     List[str]					,						snake_case_				:     Any					,						snake_case_				:     Tuple					,						)->				Any:
						__lowerCAmelCase						 =self.num_labels
						__lowerCAmelCase						 =FlaubertForTokenClassification(snake_case_)
						model.to(snake_case_)
						model.eval()

						__lowerCAmelCase						 =model(snake_case_					,						attention_mask=snake_case_					,						labels=snake_case_)
						self.parent.assertEqual(result.logits.shape					,						(self.batch_size, self.seq_length, self.num_labels))



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



	def 		UpperCamelCase				(    self				:     int)->				Dict:
						__lowerCAmelCase						 =self.prepare_config_and_inputs()
						(
						    (
						    __lowerCAmelCase
						) ,						(
						    __lowerCAmelCase
						) ,						(
						    __lowerCAmelCase
						) ,						(
						    __lowerCAmelCase
						) ,						(
						    __lowerCAmelCase
						) ,						(
						    __lowerCAmelCase
						) ,						(
						    __lowerCAmelCase
						) ,						(
						    __lowerCAmelCase
						) ,						(
						    __lowerCAmelCase
						) ,						
						)						 =config_and_inputs
						__lowerCAmelCase						 ={
						    """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			(  SCREAMING_SNAKE_CASE						,     SCREAMING_SNAKE_CASE						,     unittest.TestCase					):
	SCREAMING_SNAKE_CASE  	=							(
	    (
	        FlaubertModel,
	        FlaubertWithLMHeadModel,
	        FlaubertForQuestionAnswering,
	        FlaubertForQuestionAnsweringSimple,
	        FlaubertForSequenceClassification,
	        FlaubertForTokenClassification,
	        FlaubertForMultipleChoice,
	    )
	    if is_torch_available()
	    else ()
	)
	SCREAMING_SNAKE_CASE  	=							(
	    {
	        "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				:     List[str]					,						snake_case_				:     Any					,						snake_case_				:     Dict					,						snake_case_				:     Any					,						snake_case_				:     Dict					,						snake_case_				:     Dict)->				str:
						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					,						snake_case_				:     List[str]					,						snake_case_				:     Any					,						snake_case_				:     int=False)->				Optional[Any]:
						__lowerCAmelCase						 =super()._prepare_for_class(snake_case_					,						snake_case_					,						return_labels=snake_case_)

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

						return inputs_dict



	def 		UpperCamelCase				(    self				:     Dict)->				Optional[Any]:
						__lowerCAmelCase						 =FlaubertModelTester(self)
						__lowerCAmelCase						 =ConfigTester(self					,						config_class=snake_case_					,						emb_dim=37)



	def 		UpperCamelCase				(    self				:     int)->				Dict:
						self.config_tester.run_common_tests()



	def 		UpperCamelCase				(    self				:     Any)->				Tuple:
						__lowerCAmelCase						 =self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_flaubert_model(*snake_case_)



	def 		UpperCamelCase				(    self				:     Union[str, Any])->				List[str]:
						__lowerCAmelCase						 =self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_flaubert_lm_head(*snake_case_)



	def 		UpperCamelCase				(    self				:     Any)->				Any:
						__lowerCAmelCase						 =self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_flaubert_simple_qa(*snake_case_)



	def 		UpperCamelCase				(    self				:     Optional[int])->				List[str]:
						__lowerCAmelCase						 =self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_flaubert_qa(*snake_case_)



	def 		UpperCamelCase				(    self				:     List[Any])->				Optional[Any]:
						__lowerCAmelCase						 =self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_flaubert_sequence_classif(*snake_case_)



	def 		UpperCamelCase				(    self				:     Tuple)->				Union[str, Any]:
						__lowerCAmelCase						 =self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_flaubert_token_classif(*snake_case_)



	def 		UpperCamelCase				(    self				:     List[Any])->				Any:
						__lowerCAmelCase						 =self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_flaubert_multiple_choice(*snake_case_)



	@slow
	def 		UpperCamelCase				(    self				:     List[str])->				Tuple:
						for model_name in FLAUBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
											__lowerCAmelCase						 =FlaubertModel.from_pretrained(snake_case_)
											self.assertIsNotNone(snake_case_)



	@slow
	@require_torch_gpu
	def 		UpperCamelCase				(    self				:     Dict)->				str:
						__lowerCAmelCase ,						__lowerCAmelCase						 =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						 =True
											__lowerCAmelCase						 =model_class(config=snake_case_)

											__lowerCAmelCase						 =self._prepare_for_class(snake_case_					,						snake_case_)
											__lowerCAmelCase						 =torch.jit.trace(
											    snake_case_					,						(inputs_dict["""input_ids"""].to("""cpu"""), inputs_dict["""attention_mask"""].to("""cpu""")))

											with tempfile.TemporaryDirectory() as tmp:
																torch.jit.save(snake_case_					,						os.path.join(snake_case_					,						"""traced_model.pt"""))
																__lowerCAmelCase						 =torch.jit.load(os.path.join(snake_case_					,						"""traced_model.pt""")					,						map_location=snake_case_)
																loaded(inputs_dict["""input_ids"""].to(snake_case_)					,						inputs_dict["""attention_mask"""].to(snake_case_))






@require_torch
class     __a			(  unittest.TestCase					):



	@slow
	def 		UpperCamelCase				(    self				:     Tuple)->				str:
						__lowerCAmelCase						 =FlaubertModel.from_pretrained("""flaubert/flaubert_base_cased""")
						__lowerCAmelCase						 =torch.tensor([[0, 3_45, 2_32, 3_28, 7_40, 1_40, 16_95, 69, 60_78, 15_88, 2]])
						with torch.no_grad():
											__lowerCAmelCase						 =model(snake_case_)[0]
						__lowerCAmelCase						 =torch.Size((1, 11, 7_68))
						self.assertEqual(output.shape					,						snake_case_)
						__lowerCAmelCase						 =torch.tensor(
						    [[[-2.6_2_5_1, -1.4_2_9_8, -0.0_2_2_7], [-2.8_5_1_0, -1.6_3_8_7, 0.2_2_5_8], [-2.8_1_1_4, -1.1_8_3_2, -0.3_0_6_6]]])

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




