






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 				__UpperCAmelCase		(_UpperCAmelCase   ):







			def __init__(     self:  List[Any]				,     UpperCAmelCase_:  List[Any]				,     UpperCAmelCase_:  List[str]=13				,     UpperCAmelCase_:  Any=7				,     UpperCAmelCase_:  int=True				,     UpperCAmelCase_:  Dict=True				,     UpperCAmelCase_:  Any=True				,     UpperCAmelCase_:  List[str]=True				,     UpperCAmelCase_:  Optional[int]=True				,     UpperCAmelCase_:  List[Any]=False				,     UpperCAmelCase_:  int=False				,     UpperCAmelCase_:  int=False				,     UpperCAmelCase_:  Union[str, Any]=2				,     UpperCAmelCase_:  Dict=99				,     UpperCAmelCase_:  List[str]=0				,     UpperCAmelCase_:  str=32				,     UpperCAmelCase_:  Dict=5				,     UpperCAmelCase_:  Optional[Any]=4				,     UpperCAmelCase_:  Any=0.1				,     UpperCAmelCase_:  int=0.1				,     UpperCAmelCase_:  List[str]=512				,     UpperCAmelCase_:  str=12				,     UpperCAmelCase_:  List[Any]=2				,     UpperCAmelCase_:  List[Any]=0.02				,     UpperCAmelCase_:  str=3				,     UpperCAmelCase_:  Tuple=4				,     UpperCAmelCase_:  Any="last"				,     UpperCAmelCase_:  Optional[Any]=None				,     UpperCAmelCase_:  Tuple=None				,     ) ->    Tuple:







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE     				=  parent
									_SCREAMING_SNAKE_CASE     				=  batch_size
									_SCREAMING_SNAKE_CASE     				=  seq_length
									_SCREAMING_SNAKE_CASE     				=  is_training
									_SCREAMING_SNAKE_CASE     				=  use_input_lengths
									_SCREAMING_SNAKE_CASE     				=  use_token_type_ids
									_SCREAMING_SNAKE_CASE     				=  use_labels
									_SCREAMING_SNAKE_CASE     				=  gelu_activation
									_SCREAMING_SNAKE_CASE     				=  sinusoidal_embeddings
									_SCREAMING_SNAKE_CASE     				=  causal
									_SCREAMING_SNAKE_CASE     				=  asm
									_SCREAMING_SNAKE_CASE     				=  n_langs
									_SCREAMING_SNAKE_CASE     				=  vocab_size
									_SCREAMING_SNAKE_CASE     				=  n_special
									_SCREAMING_SNAKE_CASE     				=  hidden_size
									_SCREAMING_SNAKE_CASE     				=  num_hidden_layers
									_SCREAMING_SNAKE_CASE     				=  num_attention_heads
									_SCREAMING_SNAKE_CASE     				=  hidden_dropout_prob
									_SCREAMING_SNAKE_CASE     				=  attention_probs_dropout_prob
									_SCREAMING_SNAKE_CASE     				=  max_position_embeddings
									_SCREAMING_SNAKE_CASE     				=  type_vocab_size
									_SCREAMING_SNAKE_CASE     				=  type_sequence_label_size
									_SCREAMING_SNAKE_CASE     				=  initializer_range
									_SCREAMING_SNAKE_CASE     				=  num_labels
									_SCREAMING_SNAKE_CASE     				=  num_choices
									_SCREAMING_SNAKE_CASE     				=  summary_type
									_SCREAMING_SNAKE_CASE     				=  use_proj
									_SCREAMING_SNAKE_CASE     				=  scope







			def 							UpperCamelCase				(     self:  Tuple					) ->    Any:







									'''simple docstring'''




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

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

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

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

									_SCREAMING_SNAKE_CASE     				=  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]					) ->    Tuple:







									'''simple docstring'''




									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:  str				,     UpperCAmelCase_:  Optional[Any]				,     UpperCAmelCase_:  Optional[Any]				,     UpperCAmelCase_:  List[str]				,     UpperCAmelCase_:  Union[str, Any]				,     UpperCAmelCase_:  Tuple				,     UpperCAmelCase_:  int				,     UpperCAmelCase_:  List[Any]				,     UpperCAmelCase_:  List[Any]				,     UpperCAmelCase_:  List[Any]				,     ) ->    List[str]:







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE     				=  FlaubertModel(config=UpperCAmelCase_					)
									model.to(UpperCAmelCase_					)
									model.eval()
									_SCREAMING_SNAKE_CASE     				=  model(UpperCAmelCase_				,     lengths=UpperCAmelCase_				,     langs=UpperCAmelCase_					)
									_SCREAMING_SNAKE_CASE     				=  model(UpperCAmelCase_				,     langs=UpperCAmelCase_					)
									_SCREAMING_SNAKE_CASE     				=  model(UpperCAmelCase_					)
									self.parent.assertEqual(result.last_hidden_state.shape				,     (self.batch_size, self.seq_length, self.hidden_size)					)







			def 							UpperCamelCase				(     self:  Optional[int]				,     UpperCAmelCase_:  Any				,     UpperCAmelCase_:  List[Any]				,     UpperCAmelCase_:  Tuple				,     UpperCAmelCase_:  Optional[int]				,     UpperCAmelCase_:  Optional[Any]				,     UpperCAmelCase_:  List[Any]				,     UpperCAmelCase_:  int				,     UpperCAmelCase_:  Tuple				,     UpperCAmelCase_:  int				,     ) ->    Optional[int]:







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE     				=  FlaubertWithLMHeadModel(UpperCAmelCase_					)
									model.to(UpperCAmelCase_					)
									model.eval()

									_SCREAMING_SNAKE_CASE     				=  model(UpperCAmelCase_				,     token_type_ids=UpperCAmelCase_				,     labels=UpperCAmelCase_					)
									self.parent.assertEqual(result.loss.shape				,     ()					)
									self.parent.assertEqual(result.logits.shape				,     (self.batch_size, self.seq_length, self.vocab_size)					)







			def 							UpperCamelCase				(     self:  Union[str, Any]				,     UpperCAmelCase_:  str				,     UpperCAmelCase_:  Union[str, Any]				,     UpperCAmelCase_:  str				,     UpperCAmelCase_:  Union[str, Any]				,     UpperCAmelCase_:  Optional[Any]				,     UpperCAmelCase_:  int				,     UpperCAmelCase_:  Optional[Any]				,     UpperCAmelCase_:  List[str]				,     UpperCAmelCase_:  Optional[Any]				,     ) ->    Any:







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE     				=  FlaubertForQuestionAnsweringSimple(UpperCAmelCase_					)
									model.to(UpperCAmelCase_					)
									model.eval()

									_SCREAMING_SNAKE_CASE     				=  model(UpperCAmelCase_					)

									_SCREAMING_SNAKE_CASE     				=  model(UpperCAmelCase_				,     start_positions=UpperCAmelCase_				,     end_positions=UpperCAmelCase_					)
									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:  Optional[Any]				,     UpperCAmelCase_:  Tuple				,     UpperCAmelCase_:  List[Any]				,     UpperCAmelCase_:  List[Any]				,     UpperCAmelCase_:  int				,     UpperCAmelCase_:  List[Any]				,     UpperCAmelCase_:  Tuple				,     UpperCAmelCase_:  List[str]				,     UpperCAmelCase_:  Any				,     UpperCAmelCase_:  Optional[int]				,     ) ->    int:







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE     				=  FlaubertForQuestionAnswering(UpperCAmelCase_					)
									model.to(UpperCAmelCase_					)
									model.eval()

									_SCREAMING_SNAKE_CASE     				=  model(UpperCAmelCase_					)

									_SCREAMING_SNAKE_CASE     				=  model(
									    UpperCAmelCase_				,     start_positions=UpperCAmelCase_				,     end_positions=UpperCAmelCase_				,     cls_index=UpperCAmelCase_				,     is_impossible=UpperCAmelCase_				,     p_mask=UpperCAmelCase_				,     )

									_SCREAMING_SNAKE_CASE     				=  model(
									    UpperCAmelCase_				,     start_positions=UpperCAmelCase_				,     end_positions=UpperCAmelCase_				,     cls_index=UpperCAmelCase_				,     is_impossible=UpperCAmelCase_				,     )

									((_SCREAMING_SNAKE_CASE					)				,										)     				=  result_with_labels.to_tuple()

									_SCREAMING_SNAKE_CASE     				=  model(UpperCAmelCase_				,     start_positions=UpperCAmelCase_				,     end_positions=UpperCAmelCase_					)

									((_SCREAMING_SNAKE_CASE					)				,										)     				=  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:  int				,     UpperCAmelCase_:  Union[str, Any]				,     UpperCAmelCase_:  List[Any]				,     UpperCAmelCase_:  Tuple				,     UpperCAmelCase_:  int				,     UpperCAmelCase_:  Union[str, Any]				,     UpperCAmelCase_:  Optional[Any]				,     UpperCAmelCase_:  int				,     UpperCAmelCase_:  List[str]				,     UpperCAmelCase_:  Optional[Any]				,     ) ->    Dict:







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE     				=  FlaubertForSequenceClassification(UpperCAmelCase_					)
									model.to(UpperCAmelCase_					)
									model.eval()

									_SCREAMING_SNAKE_CASE     				=  model(UpperCAmelCase_					)
									_SCREAMING_SNAKE_CASE     				=  model(UpperCAmelCase_				,     labels=UpperCAmelCase_					)

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







			def 							UpperCamelCase				(     self:  Any				,     UpperCAmelCase_:  List[Any]				,     UpperCAmelCase_:  Dict				,     UpperCAmelCase_:  Optional[Any]				,     UpperCAmelCase_:  Dict				,     UpperCAmelCase_:  Optional[int]				,     UpperCAmelCase_:  str				,     UpperCAmelCase_:  str				,     UpperCAmelCase_:  int				,     UpperCAmelCase_:  Any				,     ) ->    Optional[int]:







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE     				=  self.num_labels
									_SCREAMING_SNAKE_CASE     				=  FlaubertForTokenClassification(UpperCAmelCase_					)
									model.to(UpperCAmelCase_					)
									model.eval()

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







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







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE     				=  self.num_choices
									_SCREAMING_SNAKE_CASE     				=  FlaubertForMultipleChoice(config=UpperCAmelCase_					)
									model.to(UpperCAmelCase_					)
									model.eval()
									_SCREAMING_SNAKE_CASE     				=  input_ids.unsqueeze(1					).expand(-1				,     self.num_choices				,     -1					).contiguous()
									_SCREAMING_SNAKE_CASE     				=  token_type_ids.unsqueeze(1					).expand(-1				,     self.num_choices				,     -1					).contiguous()
									_SCREAMING_SNAKE_CASE     				=  input_mask.unsqueeze(1					).expand(-1				,     self.num_choices				,     -1					).contiguous()
									_SCREAMING_SNAKE_CASE     				=  model(
									    UpperCAmelCase_				,     attention_mask=UpperCAmelCase_				,     token_type_ids=UpperCAmelCase_				,     labels=UpperCAmelCase_				,     )
									self.parent.assertEqual(result.logits.shape				,     (self.batch_size, self.num_choices)					)







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







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE     				=  self.prepare_config_and_inputs()
									(
									    (
									    _SCREAMING_SNAKE_CASE					
									)				,					(
									    _SCREAMING_SNAKE_CASE					
									)				,					(
									    _SCREAMING_SNAKE_CASE					
									)				,					(
									    _SCREAMING_SNAKE_CASE					
									)				,					(
									    _SCREAMING_SNAKE_CASE					
									)				,					(
									    _SCREAMING_SNAKE_CASE					
									)				,					(
									    _SCREAMING_SNAKE_CASE					
									)				,					(
									    _SCREAMING_SNAKE_CASE					
									)				,					(
									    _SCREAMING_SNAKE_CASE					
									)				,										
									)     				=  config_and_inputs
									_SCREAMING_SNAKE_CASE     				=  {
									    """input_ids""": input_ids,
									    """token_type_ids""": token_type_ids,
									    """lengths""": input_lengths,
									    """attention_mask""": input_mask,
									}
									return config, inputs_dict



@require_torch
class 				__UpperCAmelCase		(_UpperCAmelCase	,_UpperCAmelCase	,unittest.TestCase   ):
			__snake_case    :				Union[str, Any]									=							(
			    (
			        FlaubertModel,
			        FlaubertWithLMHeadModel,
			        FlaubertForQuestionAnswering,
			        FlaubertForQuestionAnsweringSimple,
			        FlaubertForSequenceClassification,
			        FlaubertForTokenClassification,
			        FlaubertForMultipleChoice,
			    )
			    if is_torch_available()
			    else ()
			)
			__snake_case    :				int									=							(
			    {
			        "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:  Tuple				,     UpperCAmelCase_:  List[str]				,     UpperCAmelCase_:  Union[str, Any]				,     UpperCAmelCase_:  List[str]				,     UpperCAmelCase_:  Optional[Any]				,     UpperCAmelCase_:  Union[str, Any]					) ->    Union[str, Any]:







									'''simple docstring'''




									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:  Any				,     UpperCAmelCase_:  str				,     UpperCAmelCase_:  Optional[Any]				,     UpperCAmelCase_:  List[str]=False					) ->    Optional[Any]:







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE     				=  super()._prepare_for_class(UpperCAmelCase_				,     UpperCAmelCase_				,     return_labels=UpperCAmelCase_					)

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

									return inputs_dict







			def 							UpperCamelCase				(     self:  str					) ->    Dict:







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE     				=  FlaubertModelTester(self					)
									_SCREAMING_SNAKE_CASE     				=  ConfigTester(self				,     config_class=UpperCAmelCase_				,     emb_dim=37					)







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







									'''simple docstring'''




									self.config_tester.run_common_tests()







			def 							UpperCamelCase				(     self:  Dict					) ->    int:







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE     				=  self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_flaubert_model(*UpperCAmelCase_					)







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







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE     				=  self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_flaubert_lm_head(*UpperCAmelCase_					)







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







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE     				=  self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_flaubert_simple_qa(*UpperCAmelCase_					)







			def 							UpperCamelCase				(     self:  Tuple					) ->    Tuple:







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE     				=  self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_flaubert_qa(*UpperCAmelCase_					)







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







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE     				=  self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_flaubert_sequence_classif(*UpperCAmelCase_					)







			def 							UpperCamelCase				(     self:  Optional[int]					) ->    Any:







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE     				=  self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_flaubert_token_classif(*UpperCAmelCase_					)







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







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE     				=  self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_flaubert_multiple_choice(*UpperCAmelCase_					)







			@slow
			def 							UpperCamelCase				(     self:  List[str]					) ->    int:







									'''simple docstring'''




									for model_name in FLAUBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
															_SCREAMING_SNAKE_CASE     				=  FlaubertModel.from_pretrained(UpperCAmelCase_					)
															self.assertIsNotNone(UpperCAmelCase_					)







			@slow
			@require_torch_gpu
			def 							UpperCamelCase				(     self:  List[Any]					) ->    Optional[int]:







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE				,					_SCREAMING_SNAKE_CASE     				=  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

															_SCREAMING_SNAKE_CASE     				=  True
															_SCREAMING_SNAKE_CASE     				=  model_class(config=UpperCAmelCase_					)

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

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



@require_torch
class 				__UpperCAmelCase		(unittest.TestCase   ):







			@slow
			def 							UpperCamelCase				(     self:  Optional[Any]					) ->    Dict:







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE     				=  FlaubertModel.from_pretrained("""flaubert/flaubert_base_cased"""					)
									_SCREAMING_SNAKE_CASE     				=  torch.tensor([[0, 345, 232, 328, 740, 140, 1_695, 69, 6_078, 1_588, 2]]					)
									with torch.no_grad():
															_SCREAMING_SNAKE_CASE     				=  model(UpperCAmelCase_					)[0]
									_SCREAMING_SNAKE_CASE     				=  torch.Size((1, 11, 768)					)
									self.assertEqual(output.shape				,     UpperCAmelCase_					)
									_SCREAMING_SNAKE_CASE     				=  torch.tensor(
									    [[[-2.62_51, -1.42_98, -0.02_27], [-2.85_10, -1.63_87, 0.22_58], [-2.81_14, -1.18_32, -0.30_66]]]					)

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









from typing import TYPE_CHECKING

from ....utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


UpperCamelCase			    =     {'''configuration_mmbt''': ['''MMBTConfig''']}

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		UpperCamelCase			    =     ['''MMBTForClassification''', '''MMBTModel''', '''ModalEmbeddings''']


if TYPE_CHECKING:
		from .configuration_mmbt import MMBTConfig

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_mmbt import MMBTForClassification, MMBTModel, ModalEmbeddings

else:
		import sys

		UpperCamelCase			    =     _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)

