


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 			SCREAMING_SNAKE_CASE__  (    lowercase__      ):
      def __init__(	self    :	Optional[int]					,							SCREAMING_SNAKE_CASE__    :	Dict					,							SCREAMING_SNAKE_CASE__    :	List[str]=1_3					,							SCREAMING_SNAKE_CASE__    :	List[str]=7					,							SCREAMING_SNAKE_CASE__    :	Optional[int]=True					,							SCREAMING_SNAKE_CASE__    :	List[str]=True					,							SCREAMING_SNAKE_CASE__    :	List[Any]=True					,							SCREAMING_SNAKE_CASE__    :	Dict=True					,							SCREAMING_SNAKE_CASE__    :	Any=True					,							SCREAMING_SNAKE_CASE__    :	str=False					,							SCREAMING_SNAKE_CASE__    :	Optional[Any]=False					,							SCREAMING_SNAKE_CASE__    :	Optional[Any]=False					,							SCREAMING_SNAKE_CASE__    :	Dict=2					,							SCREAMING_SNAKE_CASE__    :	Optional[int]=9_9					,							SCREAMING_SNAKE_CASE__    :	str=0					,							SCREAMING_SNAKE_CASE__    :	Optional[int]=3_2					,							SCREAMING_SNAKE_CASE__    :	Union[str, Any]=5					,							SCREAMING_SNAKE_CASE__    :	Dict=4					,							SCREAMING_SNAKE_CASE__    :	str=0.1					,							SCREAMING_SNAKE_CASE__    :	Optional[int]=0.1					,							SCREAMING_SNAKE_CASE__    :	Dict=5_1_2					,							SCREAMING_SNAKE_CASE__    :	Tuple=1_2					,							SCREAMING_SNAKE_CASE__    :	Tuple=2					,							SCREAMING_SNAKE_CASE__    :	Tuple=0.02					,							SCREAMING_SNAKE_CASE__    :	Union[str, Any]=3					,							SCREAMING_SNAKE_CASE__    :	List[str]=4					,							SCREAMING_SNAKE_CASE__    :	Any="last"					,							SCREAMING_SNAKE_CASE__    :	Tuple=None					,							SCREAMING_SNAKE_CASE__    :	Dict=None					,							)		->      int:
             a_ :		List[Any]							=  parent
             a_ :		Optional[Any]							=  batch_size
             a_ :		str							=  seq_length
             a_ :		str							=  is_training
             a_ :		List[str]							=  use_input_lengths
             a_ :		Optional[Any]							=  use_token_type_ids
             a_ :		Optional[Any]							=  use_labels
             a_ :		int							=  gelu_activation
             a_ :		Optional[int]							=  sinusoidal_embeddings
             a_ :		Optional[Any]							=  causal
             a_ :		List[Any]							=  asm
             a_ :		Tuple							=  n_langs
             a_ :		str							=  vocab_size
             a_ :		str							=  n_special
             a_ :		int							=  hidden_size
             a_ :		int							=  num_hidden_layers
             a_ :		int							=  num_attention_heads
             a_ :		List[str]							=  hidden_dropout_prob
             a_ :		int							=  attention_probs_dropout_prob
             a_ :		Tuple							=  max_position_embeddings
             a_ :		Union[str, Any]							=  type_vocab_size
             a_ :		List[Any]							=  type_sequence_label_size
             a_ :		Tuple							=  initializer_range
             a_ :		Optional[int]							=  num_labels
             a_ :		Union[str, Any]							=  num_choices
             a_ :		Dict							=  summary_type
             a_ :		Optional[Any]							=  use_proj
             a_ :		Any							=  scope
      def 	SCREAMING_SNAKE_CASE							(	self    :	Any					)		->      List[Any]:
             a_ :		Optional[int]							=  ids_tensor([self.batch_size, self.seq_length]					,							self.vocab_size					)
             a_ :		List[str]							=  random_attention_mask([self.batch_size, self.seq_length]					)

             a_ :		Union[str, Any]							=  None
             if self.use_input_lengths:
                    a_ :		Tuple							=  (
                        ids_tensor([self.batch_size]					,							vocab_size=2					) + self.seq_length - 2
                    )  # small variation of seq_length

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

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

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

             a_ :		Dict							=  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 	SCREAMING_SNAKE_CASE							(	self    :	Union[str, Any]					,							SCREAMING_SNAKE_CASE__    :	int					,							SCREAMING_SNAKE_CASE__    :	Optional[int]					,							SCREAMING_SNAKE_CASE__    :	Tuple					,							SCREAMING_SNAKE_CASE__    :	List[str]					,							SCREAMING_SNAKE_CASE__    :	str					,							SCREAMING_SNAKE_CASE__    :	Tuple					,							SCREAMING_SNAKE_CASE__    :	int					,							SCREAMING_SNAKE_CASE__    :	int					,							SCREAMING_SNAKE_CASE__    :	Optional[int]					,							)		->      int:
             a_ :		Union[str, Any]							=  FlaubertForQuestionAnsweringSimple(SCREAMING_SNAKE_CASE__					)
             model.to(SCREAMING_SNAKE_CASE__					)
             model.eval()

             a_ :		Optional[int]							=  model(SCREAMING_SNAKE_CASE__					)

             a_ :		Optional[Any]							=  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 	SCREAMING_SNAKE_CASE							(	self    :	str					,							SCREAMING_SNAKE_CASE__    :	Tuple					,							SCREAMING_SNAKE_CASE__    :	Tuple					,							SCREAMING_SNAKE_CASE__    :	List[Any]					,							SCREAMING_SNAKE_CASE__    :	Tuple					,							SCREAMING_SNAKE_CASE__    :	Optional[Any]					,							SCREAMING_SNAKE_CASE__    :	Union[str, Any]					,							SCREAMING_SNAKE_CASE__    :	Any					,							SCREAMING_SNAKE_CASE__    :	Union[str, Any]					,							SCREAMING_SNAKE_CASE__    :	List[str]					,							)		->      Dict:
             a_ :		List[str]							=  FlaubertForQuestionAnswering(SCREAMING_SNAKE_CASE__					)
             model.to(SCREAMING_SNAKE_CASE__					)
             model.eval()

             a_ :		int							=  model(SCREAMING_SNAKE_CASE__					)

             a_ :		Tuple							=  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__					,							)

             a_ :		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__					,							)

             (a_		) :		List[Any]							=  result_with_labels.to_tuple()

             a_ :		List[str]							=  model(SCREAMING_SNAKE_CASE__					,							start_positions=SCREAMING_SNAKE_CASE__					,							end_positions=SCREAMING_SNAKE_CASE__					)

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

             a_ :		str							=  model(SCREAMING_SNAKE_CASE__					)
             a_ :		List[str]							=  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 	SCREAMING_SNAKE_CASE							(	self    :	List[str]					,							SCREAMING_SNAKE_CASE__    :	Dict					,							SCREAMING_SNAKE_CASE__    :	Optional[int]					,							SCREAMING_SNAKE_CASE__    :	List[str]					,							SCREAMING_SNAKE_CASE__    :	Optional[Any]					,							SCREAMING_SNAKE_CASE__    :	Optional[Any]					,							SCREAMING_SNAKE_CASE__    :	Union[str, Any]					,							SCREAMING_SNAKE_CASE__    :	Any					,							SCREAMING_SNAKE_CASE__    :	Any					,							SCREAMING_SNAKE_CASE__    :	Optional[int]					,							)		->      str:
             a_ :		Tuple							=  self.num_labels
             a_ :		Optional[Any]							=  FlaubertForTokenClassification(SCREAMING_SNAKE_CASE__					)
             model.to(SCREAMING_SNAKE_CASE__					)
             model.eval()

             a_ :		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 	SCREAMING_SNAKE_CASE							(	self    :	Optional[Any]					,							SCREAMING_SNAKE_CASE__    :	Union[str, Any]					,							SCREAMING_SNAKE_CASE__    :	Optional[int]					,							SCREAMING_SNAKE_CASE__    :	str					,							SCREAMING_SNAKE_CASE__    :	List[str]					,							SCREAMING_SNAKE_CASE__    :	Optional[Any]					,							SCREAMING_SNAKE_CASE__    :	Tuple					,							SCREAMING_SNAKE_CASE__    :	List[Any]					,							SCREAMING_SNAKE_CASE__    :	Optional[int]					,							SCREAMING_SNAKE_CASE__    :	str					,							)		->      Union[str, Any]:
             a_ :		Tuple							=  self.num_choices
             a_ :		List[Any]							=  FlaubertForMultipleChoice(config=SCREAMING_SNAKE_CASE__					)
             model.to(SCREAMING_SNAKE_CASE__					)
             model.eval()
             a_ :		Optional[Any]							=  input_ids.unsqueeze(1					).expand(-1					,							self.num_choices					,							-1					).contiguous()
             a_ :		Dict							=  token_type_ids.unsqueeze(1					).expand(-1					,							self.num_choices					,							-1					).contiguous()
             a_ :		Optional[int]							=  input_mask.unsqueeze(1					).expand(-1					,							self.num_choices					,							-1					).contiguous()
             a_ :		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 	SCREAMING_SNAKE_CASE							(	self    :	Tuple					)		->      Union[str, Any]:
             a_ :		Any							=  self.prepare_config_and_inputs()
             (
                 a_		
             ) :		Dict							=  config_and_inputs
             a_ :		Tuple							=  {
                 'input_ids': input_ids,
                 'token_type_ids': token_type_ids,
                 'lengths': input_lengths,
                 'attention_mask': input_mask,
             }
             return config, inputs_dict
@require_torch
class 			SCREAMING_SNAKE_CASE__  (    lowercase__						,   lowercase__						,   unittest.TestCase      ):
      snake_case__    :					Optional[Any]					       =						(
          (
              FlaubertModel,
              FlaubertWithLMHeadModel,
              FlaubertForQuestionAnswering,
              FlaubertForQuestionAnsweringSimple,
              FlaubertForSequenceClassification,
              FlaubertForTokenClassification,
              FlaubertForMultipleChoice,
          )
          if is_torch_available()
          else ()
      )
      snake_case__    :					Tuple					       =						(
          {
              '''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    :	Optional[Any]					,							SCREAMING_SNAKE_CASE__    :	List[str]					,							SCREAMING_SNAKE_CASE__    :	List[Any]					,							SCREAMING_SNAKE_CASE__    :	Any					,							SCREAMING_SNAKE_CASE__    :	List[Any]					,							SCREAMING_SNAKE_CASE__    :	Dict					)		->      List[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    :	Union[str, Any]					,							SCREAMING_SNAKE_CASE__    :	int					,							SCREAMING_SNAKE_CASE__    :	List[str]					,							SCREAMING_SNAKE_CASE__    :	Union[str, Any]=False					)		->      str:
             a_ :		List[Any]							=  super()._prepare_for_class(SCREAMING_SNAKE_CASE__					,							SCREAMING_SNAKE_CASE__					,							return_labels=SCREAMING_SNAKE_CASE__					)

             if return_labels:
                    if model_class.__name__ == "FlaubertForQuestionAnswering":
                           a_ :		Tuple							=  torch.zeros(
                               self.model_tester.batch_size					,							dtype=torch.long					,							device=SCREAMING_SNAKE_CASE__					)
                           a_ :		List[Any]							=  torch.zeros(
                               self.model_tester.batch_size					,							dtype=torch.long					,							device=SCREAMING_SNAKE_CASE__					)

             return inputs_dict
      def 	SCREAMING_SNAKE_CASE							(	self    :	Optional[int]					)		->      str:
             a_ :		List[str]							=  FlaubertModelTester(self					)
             a_ :		str							=  ConfigTester(self					,							config_class=SCREAMING_SNAKE_CASE__					,							emb_dim=3_7					)
      def 	SCREAMING_SNAKE_CASE							(	self    :	List[Any]					)		->      Dict:
             self.config_tester.run_common_tests()
      def 	SCREAMING_SNAKE_CASE							(	self    :	int					)		->      int:
             a_ :		List[str]							=  self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_flaubert_model(*SCREAMING_SNAKE_CASE__					)
      def 	SCREAMING_SNAKE_CASE							(	self    :	List[str]					)		->      str:
             a_ :		Union[str, Any]							=  self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_flaubert_lm_head(*SCREAMING_SNAKE_CASE__					)
      def 	SCREAMING_SNAKE_CASE							(	self    :	str					)		->      str:
             a_ :		Tuple							=  self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_flaubert_simple_qa(*SCREAMING_SNAKE_CASE__					)
      def 	SCREAMING_SNAKE_CASE							(	self    :	str					)		->      Any:
             a_ :		str							=  self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_flaubert_qa(*SCREAMING_SNAKE_CASE__					)
      def 	SCREAMING_SNAKE_CASE							(	self    :	List[Any]					)		->      Dict:
             a_ :		Tuple							=  self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_flaubert_sequence_classif(*SCREAMING_SNAKE_CASE__					)
      def 	SCREAMING_SNAKE_CASE							(	self    :	Tuple					)		->      int:
             a_ :		Optional[Any]							=  self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_flaubert_token_classif(*SCREAMING_SNAKE_CASE__					)
      def 	SCREAMING_SNAKE_CASE							(	self    :	Optional[int]					)		->      List[Any]:
             a_ :		int							=  self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_flaubert_multiple_choice(*SCREAMING_SNAKE_CASE__					)
      @slow
      def 	SCREAMING_SNAKE_CASE							(	self    :	List[str]					)		->      Optional[Any]:
             for model_name in FLAUBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                    a_ :		Tuple							=  FlaubertModel.from_pretrained(SCREAMING_SNAKE_CASE__					)
                    self.assertIsNotNone(SCREAMING_SNAKE_CASE__					)

      @slow
      @require_torch_gpu
      def 	SCREAMING_SNAKE_CASE							(	self    :	Optional[Any]					)		->      Tuple:
             a_ :		Optional[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

                    a_ :		Optional[Any]							=  True
                    a_ :		List[str]							=  model_class(config=SCREAMING_SNAKE_CASE__					)

                    a_ :		str							=  self._prepare_for_class(SCREAMING_SNAKE_CASE__					,							SCREAMING_SNAKE_CASE__					)
                    a_ :		List[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'					)					)
                           a_ :		int							=  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 			SCREAMING_SNAKE_CASE__  (    unittest.TestCase      ):
      @slow
      def 	SCREAMING_SNAKE_CASE							(	self    :	int					)		->      int:
             a_ :		List[Any]							=  FlaubertModel.from_pretrained('flaubert/flaubert_base_cased'					)
             a_ :		List[str]							=  torch.tensor([[0, 3_4_5, 2_3_2, 3_2_8, 7_4_0, 1_4_0, 1_6_9_5, 6_9, 6_0_7_8, 1_5_8_8, 2]]					)
             with torch.no_grad():
                    a_ :		int							=  model(SCREAMING_SNAKE_CASE__					)[0]
             a_ :		List[Any]							=  torch.Size((1, 1_1, 7_6_8)					)
             self.assertEqual(output.shape					,							SCREAMING_SNAKE_CASE__					)
             a_ :		Union[str, Any]							=  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					)					)






def 	SCREAMING_SNAKE_CASE_						(      __A			:      int    )     ->		int:

       """simple docstring"""

       if not isinstance(__A  ,   __A    ):
              raise ValueError('Input must be an integer'    )
       if input_num <= 0:
              raise ValueError('Input must be positive'    )
       return sum(
           divisor for divisor in range(1  ,   input_num // 2 + 1    ) if input_num % divisor == 0    )


if __name__ == "__main__":
   import doctest

   doctest.testmod()


