
"""simple docstring"""




import unittest

from transformers import FunnelConfig, FunnelTokenizer, is_torch_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
    import torch

    from transformers import (
        MODEL_FOR_PRETRAINING_MAPPING,
        FunnelBaseModel,
        FunnelForMaskedLM,
        FunnelForMultipleChoice,
        FunnelForPreTraining,
        FunnelForQuestionAnswering,
        FunnelForSequenceClassification,
        FunnelForTokenClassification,
        FunnelModel,
    )







class 	_lowercase    :


     '''simple docstring'''





     def __init__(   self			,      __UpperCamelCase			,      __UpperCamelCase=13			,      __UpperCamelCase=7			,      __UpperCamelCase=True			,      __UpperCamelCase=True			,      __UpperCamelCase=True			,      __UpperCamelCase=True			,      __UpperCamelCase=99			,      __UpperCamelCase=[1, 1, 2]			,      __UpperCamelCase=1			,      __UpperCamelCase=32			,      __UpperCamelCase=4			,      __UpperCamelCase=8			,      __UpperCamelCase=37			,      __UpperCamelCase="gelu_new"			,      __UpperCamelCase=0.1			,      __UpperCamelCase=0.1			,      __UpperCamelCase=0.0			,      __UpperCamelCase=5_12			,      __UpperCamelCase=3			,      __UpperCamelCase=0.02			,      __UpperCamelCase=3			,      __UpperCamelCase=4			,      __UpperCamelCase=None			,      __UpperCamelCase=False			,      )->       List[str]:
          UpperCAmelCase__				:			Optional[int]							=    parent
          UpperCAmelCase__				:			List[Any]							=    batch_size
          UpperCAmelCase__				:			Optional[int]							=    seq_length
          UpperCAmelCase__				:			Dict							=    is_training
          UpperCAmelCase__				:			Union[str, Any]							=    use_input_mask
          UpperCAmelCase__				:			Union[str, Any]							=    use_token_type_ids
          UpperCAmelCase__				:			List[Any]							=    use_labels
          UpperCAmelCase__				:			List[str]							=    vocab_size
          UpperCAmelCase__				:			Optional[int]							=    block_sizes
          UpperCAmelCase__				:			int							=    num_decoder_layers
          UpperCAmelCase__				:			List[str]							=    d_model
          UpperCAmelCase__				:			List[Any]							=    n_head
          UpperCAmelCase__				:			Any							=    d_head
          UpperCAmelCase__				:			Optional[int]							=    d_inner
          UpperCAmelCase__				:			Any							=    hidden_act
          UpperCAmelCase__				:			Optional[int]							=    hidden_dropout
          UpperCAmelCase__				:			Any							=    attention_dropout
          UpperCAmelCase__				:			str							=    activation_dropout
          UpperCAmelCase__				:			List[Any]							=    max_position_embeddings
          UpperCAmelCase__				:			Tuple							=    type_vocab_size
          UpperCAmelCase__				:			int							=    2
          UpperCAmelCase__				:			Tuple							=    num_labels
          UpperCAmelCase__				:			List[str]							=    num_choices
          UpperCAmelCase__				:			str							=    scope
          UpperCAmelCase__				:			Tuple							=    initializer_std

          # Used in the tests to check the size of the first attention layer
          UpperCAmelCase__				:			Union[str, Any]							=    n_head
          # Used in the tests to check the size of the first hidden state
          UpperCAmelCase__				:			Dict							=    self.d_model
          # Used in the tests to check the number of output hidden states/attentions
          UpperCAmelCase__				:			Optional[Any]							=    sum(self.block_sizes	) + (0 if base else self.num_decoder_layers)
          # FunnelModel adds two hidden layers: input embeddings and the sum of the upsampled encoder hidden state with
          # the last hidden state of the first block (which is the first hidden state of the decoder).
          if not base:
               UpperCAmelCase__				:			List[Any]							=    self.num_hidden_layers + 2



     def 			lowerCAmelCase__							(   self	)->       List[str]:
          UpperCAmelCase__				:			Any							=    ids_tensor([self.batch_size, self.seq_length]			,      self.vocab_size	)

          UpperCAmelCase__				:			List[str]							=    None
          if self.use_input_mask:
               UpperCAmelCase__				:			Union[str, Any]							=    ids_tensor([self.batch_size, self.seq_length]			,      vocab_size=2	)

          UpperCAmelCase__				:			int							=    None
          if self.use_token_type_ids:
               UpperCAmelCase__				:			Optional[int]							=    ids_tensor([self.batch_size, self.seq_length]			,      self.type_vocab_size	)

          UpperCAmelCase__				:			Union[str, Any]							=    None
          UpperCAmelCase__				:			int							=    None
          UpperCAmelCase__				:			Optional[int]							=    None
          if self.use_labels:
               UpperCAmelCase__				:			Any							=    ids_tensor([self.batch_size]			,      self.type_sequence_label_size	)
               UpperCAmelCase__				:			Optional[int]							=    ids_tensor([self.batch_size, self.seq_length]			,      self.num_labels	)
               UpperCAmelCase__				:			Optional[Any]							=    ids_tensor([self.batch_size]			,      self.num_choices	)
               UpperCAmelCase__				:			List[str]							=    ids_tensor([self.batch_size, self.seq_length]			,      1	)

          UpperCAmelCase__				:			List[Any]							=    self.get_config()

          return (
              config,
              input_ids,
              token_type_ids,
              input_mask,
              sequence_labels,
              token_labels,
              choice_labels,
              fake_token_labels,
          )



     def 			lowerCAmelCase__							(   self	)->       Any:
          return FunnelConfig(
              vocab_size=self.vocab_size			,      block_sizes=self.block_sizes			,      num_decoder_layers=self.num_decoder_layers			,      d_model=self.d_model			,      n_head=self.n_head			,      d_head=self.d_head			,      d_inner=self.d_inner			,      hidden_act=self.hidden_act			,      hidden_dropout=self.hidden_dropout			,      attention_dropout=self.attention_dropout			,      activation_dropout=self.activation_dropout			,      max_position_embeddings=self.max_position_embeddings			,      type_vocab_size=self.type_vocab_size			,      initializer_std=self.initializer_std			,      )



     def 			lowerCAmelCase__							(   self			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      )->       str:
          UpperCAmelCase__				:			int							=    FunnelModel(config=__UpperCamelCase	)
          model.to(__UpperCamelCase	)
          model.eval()
          UpperCAmelCase__				:			int							=    model(__UpperCamelCase			,      attention_mask=__UpperCamelCase			,      token_type_ids=__UpperCamelCase	)
          UpperCAmelCase__				:			str							=    model(__UpperCamelCase			,      token_type_ids=__UpperCamelCase	)
          UpperCAmelCase__				:			Optional[Any]							=    model(__UpperCamelCase	)
          self.parent.assertEqual(result.last_hidden_state.shape			,      (self.batch_size, self.seq_length, self.d_model)	)

          UpperCAmelCase__				:			List[str]							=    False
          UpperCAmelCase__				:			str							=    model(__UpperCamelCase	)
          self.parent.assertEqual(result.last_hidden_state.shape			,      (self.batch_size, self.seq_length, self.d_model)	)

          UpperCAmelCase__				:			str							=    False
          UpperCAmelCase__				:			Dict							=    model(__UpperCamelCase	)
          self.parent.assertEqual(result.last_hidden_state.shape			,      (self.batch_size, self.seq_length, self.d_model)	)



     def 			lowerCAmelCase__							(   self			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      )->       str:
          UpperCAmelCase__				:			int							=    FunnelBaseModel(config=__UpperCamelCase	)
          model.to(__UpperCamelCase	)
          model.eval()
          UpperCAmelCase__				:			int							=    model(__UpperCamelCase			,      attention_mask=__UpperCamelCase			,      token_type_ids=__UpperCamelCase	)
          UpperCAmelCase__				:			List[str]							=    model(__UpperCamelCase			,      token_type_ids=__UpperCamelCase	)
          UpperCAmelCase__				:			Optional[int]							=    model(__UpperCamelCase	)
          self.parent.assertEqual(result.last_hidden_state.shape			,      (self.batch_size, 2, self.d_model)	)

          UpperCAmelCase__				:			Optional[Any]							=    False
          UpperCAmelCase__				:			List[Any]							=    model(__UpperCamelCase	)
          self.parent.assertEqual(result.last_hidden_state.shape			,      (self.batch_size, 3, self.d_model)	)

          UpperCAmelCase__				:			Union[str, Any]							=    False
          UpperCAmelCase__				:			Any							=    model(__UpperCamelCase	)
          self.parent.assertEqual(result.last_hidden_state.shape			,      (self.batch_size, 2, self.d_model)	)



     def 			lowerCAmelCase__							(   self			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      )->       Any:
          UpperCAmelCase__				:			List[Any]							=    self.num_labels
          UpperCAmelCase__				:			Tuple							=    FunnelForPreTraining(config=__UpperCamelCase	)
          model.to(__UpperCamelCase	)
          model.eval()
          UpperCAmelCase__				:			Union[str, Any]							=    model(__UpperCamelCase			,      attention_mask=__UpperCamelCase			,      token_type_ids=__UpperCamelCase			,      labels=__UpperCamelCase	)
          self.parent.assertEqual(result.logits.shape			,      (self.batch_size, self.seq_length)	)



     def 			lowerCAmelCase__							(   self			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      )->       int:
          UpperCAmelCase__				:			Union[str, Any]							=    FunnelForMaskedLM(config=__UpperCamelCase	)
          model.to(__UpperCamelCase	)
          model.eval()
          UpperCAmelCase__				:			List[str]							=    model(__UpperCamelCase			,      attention_mask=__UpperCamelCase			,      token_type_ids=__UpperCamelCase			,      labels=__UpperCamelCase	)
          self.parent.assertEqual(result.logits.shape			,      (self.batch_size, self.seq_length, self.vocab_size)	)



     def 			lowerCAmelCase__							(   self			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      )->       int:
          UpperCAmelCase__				:			List[str]							=    self.num_labels
          UpperCAmelCase__				:			Optional[int]							=    FunnelForSequenceClassification(__UpperCamelCase	)
          model.to(__UpperCamelCase	)
          model.eval()
          UpperCAmelCase__				:			Any							=    model(__UpperCamelCase			,      attention_mask=__UpperCamelCase			,      token_type_ids=__UpperCamelCase			,      labels=__UpperCamelCase	)
          self.parent.assertEqual(result.logits.shape			,      (self.batch_size, self.num_labels)	)



     def 			lowerCAmelCase__							(   self			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      )->       str:
          UpperCAmelCase__				:			List[str]							=    self.num_choices
          UpperCAmelCase__				:			Any							=    FunnelForMultipleChoice(config=__UpperCamelCase	)
          model.to(__UpperCamelCase	)
          model.eval()
          UpperCAmelCase__				:			Union[str, Any]							=    input_ids.unsqueeze(1	).expand(-1			,      self.num_choices			,      -1	).contiguous()
          UpperCAmelCase__				:			str							=    token_type_ids.unsqueeze(1	).expand(-1			,      self.num_choices			,      -1	).contiguous()
          UpperCAmelCase__				:			List[Any]							=    input_mask.unsqueeze(1	).expand(-1			,      self.num_choices			,      -1	).contiguous()
          UpperCAmelCase__				:			List[str]							=    model(
              __UpperCamelCase			,      attention_mask=__UpperCamelCase			,      token_type_ids=__UpperCamelCase			,      labels=__UpperCamelCase			,      )
          self.parent.assertEqual(result.logits.shape			,      (self.batch_size, self.num_choices)	)



     def 			lowerCAmelCase__							(   self			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      )->       int:
          UpperCAmelCase__				:			Optional[int]							=    self.num_labels
          UpperCAmelCase__				:			int							=    FunnelForTokenClassification(config=__UpperCamelCase	)
          model.to(__UpperCamelCase	)
          model.eval()
          UpperCAmelCase__				:			Union[str, Any]							=    model(__UpperCamelCase			,      attention_mask=__UpperCamelCase			,      token_type_ids=__UpperCamelCase			,      labels=__UpperCamelCase	)
          self.parent.assertEqual(result.logits.shape			,      (self.batch_size, self.seq_length, self.num_labels)	)



     def 			lowerCAmelCase__							(   self			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      )->       List[Any]:
          UpperCAmelCase__				:			int							=    FunnelForQuestionAnswering(config=__UpperCamelCase	)
          model.to(__UpperCamelCase	)
          model.eval()
          UpperCAmelCase__				:			Any							=    model(
              __UpperCamelCase			,      attention_mask=__UpperCamelCase			,      token_type_ids=__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 			lowerCAmelCase__							(   self	)->       Optional[int]:
          UpperCAmelCase__				:			Any							=    self.prepare_config_and_inputs()
          (
              (
              UpperCAmelCase__
          )				,						(
              UpperCAmelCase__
          )				,						(
              UpperCAmelCase__
          )				,						(
              UpperCAmelCase__
          )				,						(
              UpperCAmelCase__
          )				,						(
              UpperCAmelCase__
          )				,						(
              UpperCAmelCase__
          )				,						(
              UpperCAmelCase__
          )				,						
          )				:			Optional[Any]							=    config_and_inputs
          UpperCAmelCase__				:			Tuple							=    {"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
          return config, inputs_dict







@require_torch
class 	_lowercase    (							lowerCAmelCase_						, lowerCAmelCase_						, unittest.TestCase					):


     '''simple docstring'''





     _A		    =				False
     _A		    =				False
     _A		    =				(
         (
             FunnelModel,
             FunnelForMaskedLM,
             FunnelForPreTraining,
             FunnelForQuestionAnswering,
             FunnelForTokenClassification,
         )
         if is_torch_available()
         else ()
     )
     _A		    =				(
         {
             'feature-extraction': (FunnelBaseModel, FunnelModel),
             'fill-mask': FunnelForMaskedLM,
             'question-answering': FunnelForQuestionAnswering,
             'text-classification': FunnelForSequenceClassification,
             'token-classification': FunnelForTokenClassification,
             'zero-shot': FunnelForSequenceClassification,
         }
         if is_torch_available()
         else {}
     )



     def 			lowerCAmelCase__							(   self			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase=False	)->       Dict:
          UpperCAmelCase__				:			int							=    super()._prepare_for_class(__UpperCamelCase			,      __UpperCamelCase			,      return_labels=__UpperCamelCase	)

          if return_labels:
               if model_class in get_values(__UpperCamelCase	):
                    UpperCAmelCase__				:			Optional[Any]							=    torch.zeros(
                        (self.model_tester.batch_size, self.model_tester.seq_length)			,      dtype=torch.long			,      device=__UpperCamelCase	)
          return inputs_dict



     def 			lowerCAmelCase__							(   self	)->       Any:
          UpperCAmelCase__				:			Any							=    FunnelModelTester(self	)
          UpperCAmelCase__				:			int							=    ConfigTester(self			,      config_class=__UpperCamelCase	)



     def 			lowerCAmelCase__							(   self	)->       List[str]:
          self.config_tester.run_common_tests()



     def 			lowerCAmelCase__							(   self	)->       int:
          UpperCAmelCase__				:			List[Any]							=    self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_model(*__UpperCamelCase	)



     def 			lowerCAmelCase__							(   self	)->       Optional[int]:
          UpperCAmelCase__				:			int							=    self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_pretraining(*__UpperCamelCase	)



     def 			lowerCAmelCase__							(   self	)->       List[Any]:
          UpperCAmelCase__				:			Tuple							=    self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_masked_lm(*__UpperCamelCase	)



     def 			lowerCAmelCase__							(   self	)->       str:
          UpperCAmelCase__				:			str							=    self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_token_classification(*__UpperCamelCase	)



     def 			lowerCAmelCase__							(   self	)->       List[Any]:
          UpperCAmelCase__				:			List[str]							=    self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_question_answering(*__UpperCamelCase	)



     def 			lowerCAmelCase__							(   self			,      __UpperCamelCase	)->       List[Any]:
          if hasattr(__UpperCamelCase			,      "weight"	) and module.weight is not None:
               module.weight.data.fill_(3	)
          if hasattr(__UpperCamelCase			,      "bias"	) and module.bias is not None:
               module.bias.data.fill_(3	)

          for param in ["r_w_bias", "r_r_bias", "r_kernel", "r_s_bias", "seg_embed"]:
               if hasattr(__UpperCamelCase			,      __UpperCamelCase	) and getattr(__UpperCamelCase			,      __UpperCamelCase	) is not None:
                    UpperCAmelCase__				:			Tuple							=    getattr(__UpperCamelCase			,      __UpperCamelCase	)
                    weight.data.fill_(3	)







@require_torch
class 	_lowercase    (							lowerCAmelCase_						, unittest.TestCase					):


     '''simple docstring'''





     _A		    =				False
     _A		    =				False
     _A		    =				(
         (FunnelBaseModel, FunnelForMultipleChoice, FunnelForSequenceClassification) if is_torch_available() else ()
     )



     def 			lowerCAmelCase__							(   self	)->       Any:
          UpperCAmelCase__				:			Any							=    FunnelModelTester(self			,      base=__UpperCamelCase	)
          UpperCAmelCase__				:			Any							=    ConfigTester(self			,      config_class=__UpperCamelCase	)



     def 			lowerCAmelCase__							(   self	)->       Optional[int]:
          self.config_tester.run_common_tests()



     def 			lowerCAmelCase__							(   self	)->       Union[str, Any]:
          UpperCAmelCase__				:			List[str]							=    self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_base_model(*__UpperCamelCase	)



     def 			lowerCAmelCase__							(   self	)->       int:
          UpperCAmelCase__				:			Optional[Any]							=    self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_sequence_classification(*__UpperCamelCase	)



     def 			lowerCAmelCase__							(   self	)->       Any:
          UpperCAmelCase__				:			Union[str, Any]							=    self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_multiple_choice(*__UpperCamelCase	)



     def 			lowerCAmelCase__							(   self	)->       List[str]:
          UpperCAmelCase__				,						UpperCAmelCase__				:			Union[str, Any]							=    self.model_tester.prepare_config_and_inputs_for_common()
          UpperCAmelCase__				:			Optional[Any]							=    True

          for model_class in self.all_model_classes:
               if model_class.__name__ == "FunnelBaseModel":
                    continue
               UpperCAmelCase__				:			Any							=    model_class(__UpperCamelCase	)
               model.to(__UpperCamelCase	)
               model.train()
               UpperCAmelCase__				:			List[str]							=    self._prepare_for_class(__UpperCamelCase			,      __UpperCamelCase			,      return_labels=__UpperCamelCase	)
               UpperCAmelCase__				:			Any							=    model(**__UpperCamelCase	).loss
               loss.backward()



     def 			lowerCAmelCase__							(   self			,      __UpperCamelCase	)->       int:
          if hasattr(__UpperCamelCase			,      "weight"	) and module.weight is not None:
               module.weight.data.fill_(3	)
          if hasattr(__UpperCamelCase			,      "bias"	) and module.bias is not None:
               module.bias.data.fill_(3	)

          for param in ["r_w_bias", "r_r_bias", "r_kernel", "r_s_bias", "seg_embed"]:
               if hasattr(__UpperCamelCase			,      __UpperCamelCase	) and getattr(__UpperCamelCase			,      __UpperCamelCase	) is not None:
                    UpperCAmelCase__				:			Optional[Any]							=    getattr(__UpperCamelCase			,      __UpperCamelCase	)
                    weight.data.fill_(3	)







@require_torch
@require_sentencepiece
@require_tokenizers
class 	_lowercase    (							unittest.TestCase					):


     '''simple docstring'''





     def 			lowerCAmelCase__							(   self	)->       Any:
          UpperCAmelCase__				:			Union[str, Any]							=    13
          UpperCAmelCase__				:			int							=    7
          UpperCAmelCase__				:			Optional[int]							=    torch.arange(0			,      batch_size * sequence_length	).long().reshape(__UpperCamelCase			,      __UpperCamelCase	)
          UpperCAmelCase__				:			Optional[int]							=    [0, 1, 2, 3, 4, 5, 6, 4, 1, 3, 5, 0, 1]
          UpperCAmelCase__				:			int							=    torch.tensor([[2] + [0] * a + [1] * (sequence_length - a - 1) for a in lengths]	)

          UpperCAmelCase__				:			Dict							=    FunnelModel.from_pretrained("sgugger/funnel-random-tiny"	)
          UpperCAmelCase__				:			int							=    model(__UpperCamelCase			,      token_type_ids=__UpperCamelCase	)[0].abs()

          UpperCAmelCase__				:			int							=    torch.tensor(2344.8352	)
          UpperCAmelCase__				:			Union[str, Any]							=    torch.tensor(0.8052	)
          self.assertTrue(torch.allclose(output.sum()			,      __UpperCamelCase			,      atol=1E-4	)	)
          self.assertTrue(torch.allclose(output.mean()			,      __UpperCamelCase			,      atol=1E-4	)	)

          UpperCAmelCase__				:			Any							=    torch.tensor([[1] * 7, [1] * 4 + [0] * 3] * 6 + [[0, 1, 1, 0, 0, 1, 1]]	)
          UpperCAmelCase__				:			Union[str, Any]							=    model(__UpperCamelCase			,      attention_mask=__UpperCamelCase			,      token_type_ids=__UpperCamelCase	)[0].abs()

          UpperCAmelCase__				:			Any							=    torch.tensor(2343.8425	)
          UpperCAmelCase__				:			Optional[Any]							=    torch.tensor(0.8049	)
          self.assertTrue(torch.allclose(output.sum()			,      __UpperCamelCase			,      atol=1E-4	)	)
          self.assertTrue(torch.allclose(output.mean()			,      __UpperCamelCase			,      atol=1E-4	)	)



     @slow
     def 			lowerCAmelCase__							(   self	)->       Optional[int]:
          UpperCAmelCase__				:			Any							=    FunnelTokenizer.from_pretrained("huggingface/funnel-small"	)
          UpperCAmelCase__				:			Union[str, Any]							=    FunnelModel.from_pretrained("huggingface/funnel-small"	)
          UpperCAmelCase__				:			Any							=    tokenizer("Hello! I am the Funnel Transformer model."			,      return_tensors="pt"	)
          UpperCAmelCase__				:			Optional[int]							=    model(**__UpperCamelCase	)[0]

          UpperCAmelCase__				:			Dict							=    torch.tensor(235.7246	)
          UpperCAmelCase__				:			Union[str, Any]							=    torch.tensor(0.0256	)
          self.assertTrue(torch.allclose(output.sum()			,      __UpperCamelCase			,      atol=1E-4	)	)
          self.assertTrue(torch.allclose(output.mean()			,      __UpperCamelCase			,      atol=1E-4	)	)





"""simple docstring"""




import argparse
import os


A__   :						Any 							=     {
    """pytorch""": {
        """1.13""": {
            """torch""": """1.13.1""",
            """torchvision""": """0.14.1""",
            """torchaudio""": """0.13.1""",
            """python""": 3.9,
            """cuda""": """cu116""",
            """install""": (
                """python3 -m pip install --no-cache-dir -U torch==1.13.1 torchvision==0.14.1 torchaudio==0.13.1"""
                """ --extra-index-url https://download.pytorch.org/whl/cu116"""
            ),
            """base_image""": """nvidia/cuda:11.6.2-cudnn8-devel-ubuntu20.04""",
        },
        """1.12""": {
            """torch""": """1.12.1""",
            """torchvision""": """0.13.1""",
            """torchaudio""": """0.12.1""",
            """python""": 3.9,
            """cuda""": """cu113""",
            """install""": (
                """python3 -m pip install --no-cache-dir -U torch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1"""
                """ --extra-index-url https://download.pytorch.org/whl/cu113"""
            ),
            """base_image""": """nvidia/cuda:11.2.2-cudnn8-devel-ubuntu20.04""",
        },
        """1.11""": {
            """torch""": """1.11.0""",
            """torchvision""": """0.12.0""",
            """torchaudio""": """0.11.0""",
            """python""": 3.9,
            """cuda""": """cu113""",
            """install""": (
                """python3 -m pip install --no-cache-dir -U torch==1.11.0 torchvision==0.12.0 torchaudio==0.11.0"""
                """ --extra-index-url https://download.pytorch.org/whl/cu113"""
            ),
            """base_image""": """nvidia/cuda:11.2.2-cudnn8-devel-ubuntu20.04""",
        },
        """1.10""": {
            """torch""": """1.10.2""",
            """torchvision""": """0.11.3""",
            """torchaudio""": """0.10.2""",
            """python""": 3.9,
            """cuda""": """cu113""",
            """install""": (
                """python3 -m pip install --no-cache-dir -U torch==1.10.2 torchvision==0.11.3 torchaudio==0.10.2"""
                """ --extra-index-url https://download.pytorch.org/whl/cu113"""
            ),
            """base_image""": """nvidia/cuda:11.2.2-cudnn8-devel-ubuntu20.04""",
        },
        # torchaudio < 0.10 has no CUDA-enabled binary distributions
        """1.9""": {
            """torch""": """1.9.1""",
            """torchvision""": """0.10.1""",
            """torchaudio""": """0.9.1""",
            """python""": 3.9,
            """cuda""": """cu111""",
            """install""": (
                """python3 -m pip install --no-cache-dir -U torch==1.9.1 torchvision==0.10.1 torchaudio==0.9.1"""
                """ --extra-index-url https://download.pytorch.org/whl/cu111"""
            ),
            """base_image""": """nvidia/cuda:11.2.2-cudnn8-devel-ubuntu20.04""",
        },
    },
    """tensorflow""": {
        """2.11""": {
            """tensorflow""": """2.11.1""",
            """install""": """python3 -m pip install --no-cache-dir -U tensorflow==2.11.1""",
            """base_image""": """nvidia/cuda:11.2.2-cudnn8-devel-ubuntu20.04""",
        },
        """2.10""": {
            """tensorflow""": """2.10.1""",
            """install""": """python3 -m pip install --no-cache-dir -U tensorflow==2.10.1""",
            """base_image""": """nvidia/cuda:11.2.2-cudnn8-devel-ubuntu20.04""",
        },
        """2.9""": {
            """tensorflow""": """2.9.3""",
            """install""": """python3 -m pip install --no-cache-dir -U tensorflow==2.9.3""",
            """base_image""": """nvidia/cuda:11.2.2-cudnn8-devel-ubuntu20.04""",
        },
        """2.8""": {
            """tensorflow""": """2.8.2""",
            """install""": """python3 -m pip install --no-cache-dir -U tensorflow==2.8.2""",
            """base_image""": """nvidia/cuda:11.2.2-cudnn8-devel-ubuntu20.04""",
        },
        """2.7""": {
            """tensorflow""": """2.7.3""",
            """install""": """python3 -m pip install --no-cache-dir -U tensorflow==2.7.3""",
            """base_image""": """nvidia/cuda:11.2.2-cudnn8-devel-ubuntu20.04""",
        },
        """2.6""": {
            """tensorflow""": """2.6.5""",
            """install""": """python3 -m pip install --no-cache-dir -U tensorflow==2.6.5""",
            """base_image""": """nvidia/cuda:11.2.2-cudnn8-devel-ubuntu20.04""",
        },
        """2.5""": {
            """tensorflow""": """2.5.3""",
            """install""": """python3 -m pip install --no-cache-dir -U tensorflow==2.5.3""",
            """base_image""": """nvidia/cuda:11.2.2-cudnn8-devel-ubuntu20.04""",
        },
    },
}


if __name__ == "__main__":
    A__   :						str 							=     argparse.ArgumentParser("""Choose the framework and version to install""")
    parser.add_argument(
        """--framework""", help="""The framework to install. Should be `torch` or `tensorflow`""", type=str, required=True
    )
    parser.add_argument("""--version""", help="""The version of the framework to install.""", type=str, required=True)
    A__   :						Any 							=     parser.parse_args()

    A__   :						List[Any] 							=     past_versions_testing[args.framework][args.version]

    os.system(f"""echo \"export INSTALL_CMD=\'{info["install"]}\'\" >> ~/.profile""")
    print(f"""echo \"export INSTALL_CMD=\'{info["install"]}\'\" >> ~/.profile""")

    A__   :						Any 							=     """"""
    if args.framework == "pytorch":
        A__   :						str 							=     info["""cuda"""]
    os.system(f"""echo \"export CUDA='{cuda}'\" >> ~/.profile""")
    print(f"""echo \"export CUDA='{cuda}'\" >> ~/.profile""")



