

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




			"""simple docstring"""







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



			def        _SCREAMING_SNAKE_CASE			( self  :     Union[str, Any]):
									SCREAMING_SNAKE_CASE_: int  		=       ids_tensor([self.batch_size, self.seq_length]   ,						self.vocab_size)
									SCREAMING_SNAKE_CASE_: List[str]  		=       random_attention_mask([self.batch_size, self.seq_length])

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

									SCREAMING_SNAKE_CASE_: Union[str, Any]  		=       None
									if self.use_token_type_ids:
															SCREAMING_SNAKE_CASE_: int  		=       ids_tensor([self.batch_size, self.seq_length]   ,						self.n_langs)

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

									SCREAMING_SNAKE_CASE_: str  		=       self.get_config()

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



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



			def        _SCREAMING_SNAKE_CASE			( self  :     Dict   ,						lowerCAmelCase__  :     str   ,						lowerCAmelCase__  :     Any   ,						lowerCAmelCase__  :     List[Any]   ,						lowerCAmelCase__  :     Tuple   ,						lowerCAmelCase__  :     Any   ,						lowerCAmelCase__  :     Union[str, Any]   ,						lowerCAmelCase__  :     int   ,						lowerCAmelCase__  :     Dict   ,						lowerCAmelCase__  :     List[str]   ,						):
									SCREAMING_SNAKE_CASE_: str  		=       FlaubertWithLMHeadModel(lowerCAmelCase__)
									model.to(lowerCAmelCase__)
									model.eval()

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



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

									SCREAMING_SNAKE_CASE_: int  		=       model(lowerCAmelCase__)

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

									SCREAMING_SNAKE_CASE_: Dict  		=       model(lowerCAmelCase__)

									SCREAMING_SNAKE_CASE_: Optional[Any]  		=       model(
									    lowerCAmelCase__   ,						start_positions=lowerCAmelCase__   ,						end_positions=lowerCAmelCase__   ,						cls_index=lowerCAmelCase__   ,						is_impossible=lowerCAmelCase__   ,						p_mask=lowerCAmelCase__   ,						)

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

									((SCREAMING_SNAKE_CASE_)		,    ): Union[str, Any]  		=       result_with_labels.to_tuple()

									SCREAMING_SNAKE_CASE_: str  		=       model(lowerCAmelCase__   ,						start_positions=lowerCAmelCase__   ,						end_positions=lowerCAmelCase__)

									((SCREAMING_SNAKE_CASE_)		,    ): Optional[int]  		=       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        _SCREAMING_SNAKE_CASE			( self  :     str   ,						lowerCAmelCase__  :     List[Any]   ,						lowerCAmelCase__  :     Tuple   ,						lowerCAmelCase__  :     Union[str, Any]   ,						lowerCAmelCase__  :     Any   ,						lowerCAmelCase__  :     Tuple   ,						lowerCAmelCase__  :     int   ,						lowerCAmelCase__  :     List[Any]   ,						lowerCAmelCase__  :     List[str]   ,						lowerCAmelCase__  :     Any   ,						):
									SCREAMING_SNAKE_CASE_: Any  		=       FlaubertForSequenceClassification(lowerCAmelCase__)
									model.to(lowerCAmelCase__)
									model.eval()

									SCREAMING_SNAKE_CASE_: List[Any]  		=       model(lowerCAmelCase__)
									SCREAMING_SNAKE_CASE_: str  		=       model(lowerCAmelCase__   ,						labels=lowerCAmelCase__)

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



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

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



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




			def        _SCREAMING_SNAKE_CASE			( self  :     Dict):
									SCREAMING_SNAKE_CASE_: Union[str, Any]  		=       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_
									)		,    
									): Union[str, Any]  		=       config_and_inputs
									SCREAMING_SNAKE_CASE_: 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   __lowercase				( UpperCAmelCase_		,       UpperCAmelCase_		,       unittest.TestCase	):




			"""simple docstring"""







			_UpperCAmelCase   :							Dict										=     (
			    (
			        FlaubertModel,
			        FlaubertWithLMHeadModel,
			        FlaubertForQuestionAnswering,
			        FlaubertForQuestionAnsweringSimple,
			        FlaubertForSequenceClassification,
			        FlaubertForTokenClassification,
			        FlaubertForMultipleChoice,
			    )
			    if is_torch_available()
			    else ()
			)
			_UpperCAmelCase   :							List[str]										=     (
			    {
			        '''feature-extraction''': FlaubertModel,
			        '''fill-mask''': FlaubertWithLMHeadModel,
			        '''question-answering''': FlaubertForQuestionAnsweringSimple,
			        '''text-classification''': FlaubertForSequenceClassification,
			        '''token-classification''': FlaubertForTokenClassification,
			        '''zero-shot''': FlaubertForSequenceClassification,
			    }
			    if is_torch_available()
			    else {}
			)



			def        _SCREAMING_SNAKE_CASE			( self  :     str   ,						lowerCAmelCase__  :     Tuple   ,						lowerCAmelCase__  :     Union[str, Any]   ,						lowerCAmelCase__  :     Any   ,						lowerCAmelCase__  :     str   ,						lowerCAmelCase__  :     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        _SCREAMING_SNAKE_CASE			( self  :     Optional[int]   ,						lowerCAmelCase__  :     Union[str, Any]   ,						lowerCAmelCase__  :     Optional[Any]   ,						lowerCAmelCase__  :     List[Any]=False):
									SCREAMING_SNAKE_CASE_: str  		=       super()._prepare_for_class(lowerCAmelCase__   ,						lowerCAmelCase__   ,						return_labels=lowerCAmelCase__)

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

									return inputs_dict



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



			def        _SCREAMING_SNAKE_CASE			( self  :     Optional[int]):
									self.config_tester.run_common_tests()



			def        _SCREAMING_SNAKE_CASE			( self  :     List[str]):
									SCREAMING_SNAKE_CASE_: Dict  		=       self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_flaubert_model(*lowerCAmelCase__)



			def        _SCREAMING_SNAKE_CASE			( self  :     Union[str, Any]):
									SCREAMING_SNAKE_CASE_: str  		=       self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_flaubert_lm_head(*lowerCAmelCase__)



			def        _SCREAMING_SNAKE_CASE			( self  :     Optional[int]):
									SCREAMING_SNAKE_CASE_: int  		=       self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_flaubert_simple_qa(*lowerCAmelCase__)



			def        _SCREAMING_SNAKE_CASE			( self  :     str):
									SCREAMING_SNAKE_CASE_: Optional[Any]  		=       self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_flaubert_qa(*lowerCAmelCase__)



			def        _SCREAMING_SNAKE_CASE			( self  :     Dict):
									SCREAMING_SNAKE_CASE_: Dict  		=       self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_flaubert_sequence_classif(*lowerCAmelCase__)



			def        _SCREAMING_SNAKE_CASE			( self  :     Union[str, Any]):
									SCREAMING_SNAKE_CASE_: str  		=       self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_flaubert_token_classif(*lowerCAmelCase__)



			def        _SCREAMING_SNAKE_CASE			( self  :     Any):
									SCREAMING_SNAKE_CASE_: Any  		=       self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_flaubert_multiple_choice(*lowerCAmelCase__)



			@slow
			def        _SCREAMING_SNAKE_CASE			( self  :     Optional[int]):
									for model_name in FLAUBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
															SCREAMING_SNAKE_CASE_: Any  		=       FlaubertModel.from_pretrained(lowerCAmelCase__)
															self.assertIsNotNone(lowerCAmelCase__)




			@slow
			@require_torch_gpu
			def        _SCREAMING_SNAKE_CASE			( self  :     str):
									SCREAMING_SNAKE_CASE_		,    SCREAMING_SNAKE_CASE_: Union[str, 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

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

															SCREAMING_SNAKE_CASE_: Optional[int]  		=       self._prepare_for_class(lowerCAmelCase__   ,						lowerCAmelCase__)
															SCREAMING_SNAKE_CASE_: int  		=       torch.jit.trace(
															    lowerCAmelCase__   ,						(inputs_dict["input_ids"].to("cpu"), inputs_dict["attention_mask"].to("cpu")))

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







@require_torch
class   __lowercase				( unittest.TestCase	):




			"""simple docstring"""







			@slow
			def        _SCREAMING_SNAKE_CASE			( self  :     int):
									SCREAMING_SNAKE_CASE_: Union[str, Any]  		=       FlaubertModel.from_pretrained("flaubert/flaubert_base_cased")
									SCREAMING_SNAKE_CASE_: List[Any]  		=       torch.tensor([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]])
									with torch.no_grad():
															SCREAMING_SNAKE_CASE_: int  		=       model(lowerCAmelCase__)[0]
									SCREAMING_SNAKE_CASE_: List[Any]  		=       torch.Size((1, 11, 768))
									self.assertEqual(output.shape   ,						lowerCAmelCase__)
									SCREAMING_SNAKE_CASE_: int  		=       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]   ,						lowerCAmelCase__   ,						atol=1E-4))









from collections.abc import Callable



class   __lowercase				:




			"""simple docstring"""







			def __init__( self  :     Tuple   ,						lowerCAmelCase__  :     Callable | None = None):
									# Stores actual heap items.
									SCREAMING_SNAKE_CASE_: list  		=       []
									# Stores indexes of each item for supporting updates and deletion.
									SCREAMING_SNAKE_CASE_: dict  		=       {}
									# Stores current size of heap.
									SCREAMING_SNAKE_CASE_: Optional[Any]  		=       0
									# Stores function used to evaluate the score of an item on which basis ordering
									# will be done.
									SCREAMING_SNAKE_CASE_: Any  		=       key or (lambda lowerCAmelCase__: x)



			def        _SCREAMING_SNAKE_CASE			( self  :     Dict   ,						lowerCAmelCase__  :     int):
									return int((i - 1) / 2) if i > 0 else None



			def        _SCREAMING_SNAKE_CASE			( self  :     Optional[Any]   ,						lowerCAmelCase__  :     int):
									SCREAMING_SNAKE_CASE_: Union[str, Any]  		=       int(2 * i + 1)
									return left if 0 < left < self.size else None



			def        _SCREAMING_SNAKE_CASE			( self  :     Union[str, Any]   ,						lowerCAmelCase__  :     int):
									SCREAMING_SNAKE_CASE_: Union[str, Any]  		=       int(2 * i + 2)
									return right if 0 < right < self.size else None



			def        _SCREAMING_SNAKE_CASE			( self  :     str   ,						lowerCAmelCase__  :     int   ,						lowerCAmelCase__  :     int):
									SCREAMING_SNAKE_CASE_		,    SCREAMING_SNAKE_CASE_: str  		=       (
									    self.pos_map[self.arr[j][0]],
									    self.pos_map[self.arr[i][0]],
									)
									# Then swap the items in the list.
									SCREAMING_SNAKE_CASE_		,    SCREAMING_SNAKE_CASE_: List[str]  		=       self.arr[j], self.arr[i]



			def        _SCREAMING_SNAKE_CASE			( self  :     str   ,						lowerCAmelCase__  :     int   ,						lowerCAmelCase__  :     int):
									return self.arr[i][1] < self.arr[j][1]



			def        _SCREAMING_SNAKE_CASE			( self  :     str   ,						lowerCAmelCase__  :     int):
									SCREAMING_SNAKE_CASE_: Any  		=       self._left(lowerCAmelCase__)
									SCREAMING_SNAKE_CASE_: List[Any]  		=       self._right(lowerCAmelCase__)
									SCREAMING_SNAKE_CASE_: List[Any]  		=       i

									if left is not None and not self._cmp(lowerCAmelCase__   ,						lowerCAmelCase__):
															SCREAMING_SNAKE_CASE_: Optional[int]  		=       left
									if right is not None and not self._cmp(lowerCAmelCase__   ,						lowerCAmelCase__):
															SCREAMING_SNAKE_CASE_: Tuple  		=       right

									return valid_parent



			def        _SCREAMING_SNAKE_CASE			( self  :     Optional[int]   ,						lowerCAmelCase__  :     int):
									SCREAMING_SNAKE_CASE_: List[Any]  		=       self._parent(lowerCAmelCase__)
									while parent is not None and not self._cmp(lowerCAmelCase__   ,						lowerCAmelCase__):
															self._swap(lowerCAmelCase__   ,						lowerCAmelCase__)
															SCREAMING_SNAKE_CASE_		,    SCREAMING_SNAKE_CASE_: List[str]  		=       parent, self._parent(lowerCAmelCase__)



			def        _SCREAMING_SNAKE_CASE			( self  :     Optional[Any]   ,						lowerCAmelCase__  :     int):
									SCREAMING_SNAKE_CASE_: Optional[int]  		=       self._get_valid_parent(lowerCAmelCase__)
									while valid_parent != index:
															self._swap(lowerCAmelCase__   ,						lowerCAmelCase__)
															SCREAMING_SNAKE_CASE_		,    SCREAMING_SNAKE_CASE_: Dict  		=       valid_parent, self._get_valid_parent(lowerCAmelCase__)



			def        _SCREAMING_SNAKE_CASE			( self  :     Optional[int]   ,						lowerCAmelCase__  :     int   ,						lowerCAmelCase__  :     int):
									if item not in self.pos_map:
															return
									SCREAMING_SNAKE_CASE_: Any  		=       self.pos_map[item]
									SCREAMING_SNAKE_CASE_: int  		=       [item, self.key(lowerCAmelCase__)]
									# Make sure heap is right in both up and down direction.
									# Ideally only one of them will make any change.
									self._heapify_up(lowerCAmelCase__)
									self._heapify_down(lowerCAmelCase__)



			def        _SCREAMING_SNAKE_CASE			( self  :     List[str]   ,						lowerCAmelCase__  :     int):
									if item not in self.pos_map:
															return
									SCREAMING_SNAKE_CASE_: Optional[Any]  		=       self.pos_map[item]
									del self.pos_map[item]
									SCREAMING_SNAKE_CASE_: List[str]  		=       self.arr[self.size - 1]
									SCREAMING_SNAKE_CASE_: Tuple  		=       index
									self.size -= 1
									# Make sure heap is right in both up and down direction. Ideally only one
									# of them will make any change- so no performance loss in calling both.
									if self.size > index:
															self._heapify_up(lowerCAmelCase__)
															self._heapify_down(lowerCAmelCase__)



			def        _SCREAMING_SNAKE_CASE			( self  :     Optional[Any]   ,						lowerCAmelCase__  :     int   ,						lowerCAmelCase__  :     int):
									SCREAMING_SNAKE_CASE_: Optional[int]  		=       len(self.arr)
									if arr_len == self.size:
															self.arr.append([item, self.key(lowerCAmelCase__)])
									else:
															SCREAMING_SNAKE_CASE_: str  		=       [item, self.key(lowerCAmelCase__)]
									SCREAMING_SNAKE_CASE_: List[Any]  		=       self.size
									self.size += 1
									self._heapify_up(self.size - 1)



			def        _SCREAMING_SNAKE_CASE			( self  :     List[Any]):
									return self.arr[0] if self.size else None




			def        _SCREAMING_SNAKE_CASE			( self  :     Dict):
									SCREAMING_SNAKE_CASE_: Dict  		=       self.get_top()
									if top_item_tuple:
															self.delete_item(top_item_tuple[0])
									return top_item_tuple







def 			A_      (    ):
						pass


if __name__ == "__main__":
						import doctest

						doctest.testmod()






