
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 					_lowerCamelCase			(   UpperCamelCase_			):





     """simple docstring"""







     def __init__(				self    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE=1_3    ,    __SCREAMING_SNAKE_CASE=7    ,    __SCREAMING_SNAKE_CASE=True    ,    __SCREAMING_SNAKE_CASE=True    ,    __SCREAMING_SNAKE_CASE=True    ,    __SCREAMING_SNAKE_CASE=True    ,    __SCREAMING_SNAKE_CASE=True    ,    __SCREAMING_SNAKE_CASE=False    ,    __SCREAMING_SNAKE_CASE=False    ,    __SCREAMING_SNAKE_CASE=False    ,    __SCREAMING_SNAKE_CASE=2    ,    __SCREAMING_SNAKE_CASE=9_9    ,    __SCREAMING_SNAKE_CASE=0    ,    __SCREAMING_SNAKE_CASE=3_2    ,    __SCREAMING_SNAKE_CASE=5    ,    __SCREAMING_SNAKE_CASE=4    ,    __SCREAMING_SNAKE_CASE=0.1    ,    __SCREAMING_SNAKE_CASE=0.1    ,    __SCREAMING_SNAKE_CASE=5_1_2    ,    __SCREAMING_SNAKE_CASE=1_2    ,    __SCREAMING_SNAKE_CASE=2    ,    __SCREAMING_SNAKE_CASE=0.02    ,    __SCREAMING_SNAKE_CASE=3    ,    __SCREAMING_SNAKE_CASE=4    ,    __SCREAMING_SNAKE_CASE="last"    ,    __SCREAMING_SNAKE_CASE=None    ,    __SCREAMING_SNAKE_CASE=None    ,    )	-> List[Any]:




           """simple docstring"""







           UpperCamelCase__     : Dict											=					parent
           UpperCamelCase__     : Dict											=					batch_size
           UpperCamelCase__     : Tuple											=					seq_length
           UpperCamelCase__     : str											=					is_training
           UpperCamelCase__     : List[str]											=					use_input_lengths
           UpperCamelCase__     : List[Any]											=					use_token_type_ids
           UpperCamelCase__     : Dict											=					use_labels
           UpperCamelCase__     : Any											=					gelu_activation
           UpperCamelCase__     : Optional[Any]											=					sinusoidal_embeddings
           UpperCamelCase__     : List[str]											=					causal
           UpperCamelCase__     : List[Any]											=					asm
           UpperCamelCase__     : Optional[Any]											=					n_langs
           UpperCamelCase__     : Tuple											=					vocab_size
           UpperCamelCase__     : List[str]											=					n_special
           UpperCamelCase__     : int											=					hidden_size
           UpperCamelCase__     : List[str]											=					num_hidden_layers
           UpperCamelCase__     : List[str]											=					num_attention_heads
           UpperCamelCase__     : Optional[int]											=					hidden_dropout_prob
           UpperCamelCase__     : Dict											=					attention_probs_dropout_prob
           UpperCamelCase__     : List[str]											=					max_position_embeddings
           UpperCamelCase__     : Optional[Any]											=					type_vocab_size
           UpperCamelCase__     : str											=					type_sequence_label_size
           UpperCamelCase__     : int											=					initializer_range
           UpperCamelCase__     : List[str]											=					num_labels
           UpperCamelCase__     : Tuple											=					num_choices
           UpperCamelCase__     : Union[str, Any]											=					summary_type
           UpperCamelCase__     : Union[str, Any]											=					use_proj
           UpperCamelCase__     : Dict											=					scope






     def  __SCREAMING_SNAKE_CASE      (				self	)	-> str:




           """simple docstring"""







           UpperCamelCase__     : Union[str, Any]											=					ids_tensor([self.batch_size, self.seq_length]    ,    self.vocab_size	)
           UpperCamelCase__     : str											=					random_attention_mask([self.batch_size, self.seq_length]	)

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

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

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

           UpperCamelCase__     : 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	)	-> Optional[int]:




           """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  __SCREAMING_SNAKE_CASE      (				self    ,    __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]:




           """simple docstring"""







           UpperCamelCase__     : int											=					FlaubertModel(config=__SCREAMING_SNAKE_CASE	)
           model.to(__SCREAMING_SNAKE_CASE	)
           model.eval()
           UpperCamelCase__     : Any											=					model(__SCREAMING_SNAKE_CASE    ,    lengths=__SCREAMING_SNAKE_CASE    ,    langs=__SCREAMING_SNAKE_CASE	)
           UpperCamelCase__     : List[Any]											=					model(__SCREAMING_SNAKE_CASE    ,    langs=__SCREAMING_SNAKE_CASE	)
           UpperCamelCase__     : Union[str, Any]											=					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    ,    __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    ,    )	-> Optional[int]:




           """simple docstring"""







           UpperCamelCase__     : Optional[int]											=					FlaubertWithLMHeadModel(__SCREAMING_SNAKE_CASE	)
           model.to(__SCREAMING_SNAKE_CASE	)
           model.eval()

           UpperCamelCase__     : List[str]											=					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    ,    __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    ,    )	-> Any:




           """simple docstring"""







           UpperCamelCase__     : int											=					FlaubertForQuestionAnsweringSimple(__SCREAMING_SNAKE_CASE	)
           model.to(__SCREAMING_SNAKE_CASE	)
           model.eval()

           UpperCamelCase__     : Optional[Any]											=					model(__SCREAMING_SNAKE_CASE	)

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




           """simple docstring"""







           UpperCamelCase__     : int											=					FlaubertForQuestionAnswering(__SCREAMING_SNAKE_CASE	)
           model.to(__SCREAMING_SNAKE_CASE	)
           model.eval()

           UpperCamelCase__     : int											=					model(__SCREAMING_SNAKE_CASE	)

           UpperCamelCase__     : int											=					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    ,    )

           UpperCamelCase__     : str											=					model(
               __SCREAMING_SNAKE_CASE    ,    start_positions=__SCREAMING_SNAKE_CASE    ,    end_positions=__SCREAMING_SNAKE_CASE    ,    cls_index=__SCREAMING_SNAKE_CASE    ,    is_impossible=__SCREAMING_SNAKE_CASE    ,    )

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

           UpperCamelCase__     : List[Any]											=					model(__SCREAMING_SNAKE_CASE    ,    start_positions=__SCREAMING_SNAKE_CASE    ,    end_positions=__SCREAMING_SNAKE_CASE	)

           ((UpperCamelCase__)					,)     : Dict											=					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    ,    __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    ,    )	-> Tuple:




           """simple docstring"""







           UpperCamelCase__     : List[str]											=					FlaubertForSequenceClassification(__SCREAMING_SNAKE_CASE	)
           model.to(__SCREAMING_SNAKE_CASE	)
           model.eval()

           UpperCamelCase__     : Optional[int]											=					model(__SCREAMING_SNAKE_CASE	)
           UpperCamelCase__     : int											=					model(__SCREAMING_SNAKE_CASE    ,    labels=__SCREAMING_SNAKE_CASE	)

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






     def  __SCREAMING_SNAKE_CASE      (				self    ,    __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    ,    )	-> Optional[Any]:




           """simple docstring"""







           UpperCamelCase__     : List[Any]											=					self.num_labels
           UpperCamelCase__     : Any											=					FlaubertForTokenClassification(__SCREAMING_SNAKE_CASE	)
           model.to(__SCREAMING_SNAKE_CASE	)
           model.eval()

           UpperCamelCase__     : List[str]											=					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    ,    __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    ,    )	-> Tuple:




           """simple docstring"""







           UpperCamelCase__     : Union[str, Any]											=					self.num_choices
           UpperCamelCase__     : str											=					FlaubertForMultipleChoice(config=__SCREAMING_SNAKE_CASE	)
           model.to(__SCREAMING_SNAKE_CASE	)
           model.eval()
           UpperCamelCase__     : int											=					input_ids.unsqueeze(1	).expand(-1    ,    self.num_choices    ,    -1	).contiguous()
           UpperCamelCase__     : Dict											=					token_type_ids.unsqueeze(1	).expand(-1    ,    self.num_choices    ,    -1	).contiguous()
           UpperCamelCase__     : int											=					input_mask.unsqueeze(1	).expand(-1    ,    self.num_choices    ,    -1	).contiguous()
           UpperCamelCase__     : List[Any]											=					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	)	-> Any:




           """simple docstring"""







           UpperCamelCase__     : Any											=					self.prepare_config_and_inputs()
           (
               (
               UpperCamelCase__
           )					,(
               UpperCamelCase__
           )					,(
               UpperCamelCase__
           )					,(
               UpperCamelCase__
           )					,(
               UpperCamelCase__
           )					,(
               UpperCamelCase__
           )					,(
               UpperCamelCase__
           )					,(
               UpperCamelCase__
           )					,(
               UpperCamelCase__
           )					,
           )     : int											=					config_and_inputs
           UpperCamelCase__     : Optional[Any]											=					{
               '''input_ids''': input_ids,
               '''token_type_ids''': token_type_ids,
               '''lengths''': input_lengths,
               '''attention_mask''': input_mask,
           }
           return config, inputs_dict




@require_torch
class 					_lowerCamelCase			(   UpperCamelCase_						,				UpperCamelCase_						,				unittest.TestCase			):





     """simple docstring"""







     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  __SCREAMING_SNAKE_CASE      (				self    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE	)	-> Dict:




           """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  __SCREAMING_SNAKE_CASE      (				self    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE=False	)	-> Dict:




           """simple docstring"""







           UpperCamelCase__     : Optional[int]											=					super()._prepare_for_class(__SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE    ,    return_labels=__SCREAMING_SNAKE_CASE	)

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

           return inputs_dict






     def  __SCREAMING_SNAKE_CASE      (				self	)	-> Tuple:




           """simple docstring"""







           UpperCamelCase__     : Dict											=					FlaubertModelTester(self	)
           UpperCamelCase__     : Tuple											=					ConfigTester(self    ,    config_class=__SCREAMING_SNAKE_CASE    ,    emb_dim=3_7	)






     def  __SCREAMING_SNAKE_CASE      (				self	)	-> List[str]:




           """simple docstring"""







           self.config_tester.run_common_tests()






     def  __SCREAMING_SNAKE_CASE      (				self	)	-> str:




           """simple docstring"""







           UpperCamelCase__     : List[Any]											=					self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_flaubert_model(*__SCREAMING_SNAKE_CASE	)






     def  __SCREAMING_SNAKE_CASE      (				self	)	-> Tuple:




           """simple docstring"""







           UpperCamelCase__     : Dict											=					self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_flaubert_lm_head(*__SCREAMING_SNAKE_CASE	)






     def  __SCREAMING_SNAKE_CASE      (				self	)	-> int:




           """simple docstring"""







           UpperCamelCase__     : int											=					self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_flaubert_simple_qa(*__SCREAMING_SNAKE_CASE	)






     def  __SCREAMING_SNAKE_CASE      (				self	)	-> List[str]:




           """simple docstring"""







           UpperCamelCase__     : Dict											=					self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_flaubert_qa(*__SCREAMING_SNAKE_CASE	)






     def  __SCREAMING_SNAKE_CASE      (				self	)	-> Optional[Any]:




           """simple docstring"""







           UpperCamelCase__     : Union[str, Any]											=					self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_flaubert_sequence_classif(*__SCREAMING_SNAKE_CASE	)






     def  __SCREAMING_SNAKE_CASE      (				self	)	-> int:




           """simple docstring"""







           UpperCamelCase__     : Tuple											=					self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_flaubert_token_classif(*__SCREAMING_SNAKE_CASE	)






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




           """simple docstring"""







           UpperCamelCase__     : Optional[Any]											=					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	)	-> Union[str, Any]:




           """simple docstring"""







           for model_name in FLAUBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                 UpperCamelCase__     : int											=					FlaubertModel.from_pretrained(__SCREAMING_SNAKE_CASE	)
                 self.assertIsNotNone(__SCREAMING_SNAKE_CASE	)






     @slow
     @require_torch_gpu
     def  __SCREAMING_SNAKE_CASE      (				self	)	-> Union[str, Any]:




           """simple docstring"""







           UpperCamelCase__					,UpperCamelCase__     : Tuple											=					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

                 UpperCamelCase__     : Optional[int]											=					True
                 UpperCamelCase__     : Dict											=					model_class(config=__SCREAMING_SNAKE_CASE	)

                 UpperCamelCase__     : int											=					self._prepare_for_class(__SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE	)
                 UpperCamelCase__     : Tuple											=					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'''	)	)
                       UpperCamelCase__     : str											=					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 					_lowerCamelCase			(   unittest.TestCase			):





     """simple docstring"""







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




           """simple docstring"""







           UpperCamelCase__     : Union[str, Any]											=					FlaubertModel.from_pretrained('''flaubert/flaubert_base_cased'''	)
           UpperCamelCase__     : 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():
                 UpperCamelCase__     : Optional[int]											=					model(__SCREAMING_SNAKE_CASE	)[0]
           UpperCamelCase__     : int											=					torch.Size((1, 1_1, 7_6_8)	)
           self.assertEqual(output.shape    ,    __SCREAMING_SNAKE_CASE	)
           UpperCamelCase__     : Optional[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	)	)




import logging
import os
from logging import (
    CRITICAL,  # NOQA
    DEBUG,  # NOQA
    ERROR,  # NOQA
    FATAL,  # NOQA
    INFO,  # NOQA
    NOTSET,  # NOQA
    WARN,  # NOQA
    WARNING,  # NOQA
)
from typing import Optional

from tqdm import auto as tqdm_lib


lowerCamelCase  ={
    "debug": logging.DEBUG,
    "info": logging.INFO,
    "warning": logging.WARNING,
    "error": logging.ERROR,
    "critical": logging.CRITICAL,
}

lowerCamelCase  =logging.WARNING


def 				SCREAMING_SNAKE_CASE_   (      ):
      UpperCamelCase__     : int											=					os.getenv('''DATASETS_VERBOSITY'''			,		UpperCamelCase__		)
      if env_level_str:
            if env_level_str in log_levels:
                  return log_levels[env_level_str]
            else:
                  logging.getLogger().warning(
                      f'''Unknown option DATASETS_VERBOSITY={env_level_str}, '''
                      f'''has to be one of: { ", ".join(log_levels.keys()		) }'''		)
      return _default_log_level


def 				SCREAMING_SNAKE_CASE_   (      ):
      return __name__.split('''.'''		)[0]


def 				SCREAMING_SNAKE_CASE_   (      ):
      return logging.getLogger(_get_library_name()		)


def 				SCREAMING_SNAKE_CASE_   (      ):
      # Apply our default configuration to the library root logger.
      UpperCamelCase__     : List[Any]											=					_get_library_root_logger()
      library_root_logger.setLevel(_get_default_logging_level()		)


def 				SCREAMING_SNAKE_CASE_   (      ):
      UpperCamelCase__     : List[Any]											=					_get_library_root_logger()
      library_root_logger.setLevel(logging.NOTSET		)


def 				SCREAMING_SNAKE_CASE_   (      UpperCamelCase__ = None		):
      if name is None:
            UpperCamelCase__     : Union[str, Any]											=					_get_library_name()
      return logging.getLogger(UpperCamelCase__		)


def 				SCREAMING_SNAKE_CASE_   (      ):
      return _get_library_root_logger().getEffectiveLevel()


def 				SCREAMING_SNAKE_CASE_   (      UpperCamelCase__		):
      _get_library_root_logger().setLevel(UpperCamelCase__		)


def 				SCREAMING_SNAKE_CASE_   (      ):
      return set_verbosity(UpperCamelCase__		)


def 				SCREAMING_SNAKE_CASE_   (      ):
      return set_verbosity(UpperCamelCase__		)


def 				SCREAMING_SNAKE_CASE_   (      ):
      return set_verbosity(UpperCamelCase__		)


def 				SCREAMING_SNAKE_CASE_   (      ):
      return set_verbosity(UpperCamelCase__		)


def 				SCREAMING_SNAKE_CASE_   (      ):
      UpperCamelCase__     : str											=					False


def 				SCREAMING_SNAKE_CASE_   (      ):
      UpperCamelCase__     : List[Any]											=					True


# Configure the library root logger at the module level (singleton-like)
_configure_library_root_logger()




class 					_lowerCamelCase			:





     """simple docstring"""







     def __init__(				self    ,    *__SCREAMING_SNAKE_CASE    ,    **__SCREAMING_SNAKE_CASE	)	-> int:  # pylint: disable=unused-argument




           """simple docstring"""







           UpperCamelCase__     : Dict											=					args[0] if args else None






     def __iter__(				self	)	-> Dict:




           """simple docstring"""







           return iter(self._iterator	)






     def __getattr__(				self    ,    __SCREAMING_SNAKE_CASE	)	-> Tuple:




           """simple docstring"""







           def empty_fn(*__SCREAMING_SNAKE_CASE    ,    **__SCREAMING_SNAKE_CASE	):  # pylint: disable=unused-argument
                 return

           return empty_fn






     def __enter__(				self	)	-> Optional[int]:




           """simple docstring"""







           return self






     def __exit__(				self    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE	)	-> Dict:




           """simple docstring"""







           return
lowerCamelCase  =True




class 					_lowerCamelCase			:





     """simple docstring"""







     def __call__(				self    ,    *__SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE=False    ,    **__SCREAMING_SNAKE_CASE	)	-> int:




           """simple docstring"""







           if _tqdm_active and not disable:
                 return tqdm_lib.tqdm(*__SCREAMING_SNAKE_CASE    ,    **__SCREAMING_SNAKE_CASE	)
           else:
                 return EmptyTqdm(*__SCREAMING_SNAKE_CASE    ,    **__SCREAMING_SNAKE_CASE	)






     def  __SCREAMING_SNAKE_CASE      (				self    ,    *__SCREAMING_SNAKE_CASE    ,    **__SCREAMING_SNAKE_CASE	)	-> Tuple:




           """simple docstring"""







           UpperCamelCase__     : Any											=					None
           if _tqdm_active:
                 return tqdm_lib.tqdm.set_lock(*__SCREAMING_SNAKE_CASE    ,    **__SCREAMING_SNAKE_CASE	)






     def  __SCREAMING_SNAKE_CASE      (				self	)	-> Tuple:




           """simple docstring"""







           if _tqdm_active:
                 return tqdm_lib.tqdm.get_lock()
lowerCamelCase  =_tqdm_cls()


def 				SCREAMING_SNAKE_CASE_   (      ):
      global _tqdm_active
      return bool(_tqdm_active		)


def 				SCREAMING_SNAKE_CASE_   (      ):
      global _tqdm_active
      UpperCamelCase__     : Dict											=					True


def 				SCREAMING_SNAKE_CASE_   (      ):
      global _tqdm_active
      UpperCamelCase__     : Union[str, Any]											=					False


