




from __future__ import annotations

import random
import unittest

from transformers import TransfoXLConfig, is_tf_available
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
 import tensorflow as tf

 from transformers import (
     TF_TRANSFO_XL_PRETRAINED_MODEL_ARCHIVE_LIST,
     TFTransfoXLForSequenceClassification,
     TFTransfoXLLMHeadModel,
     TFTransfoXLModel,
 )

class  _lowerCamelCase						:

      """simple docstring"""

      def __init__(     self					: Optional[int] ,       snake_case					: Any ,       ):
          __UpperCamelCase  		=						parent
          __UpperCamelCase  		=						13
          __UpperCamelCase  		=						7
          __UpperCamelCase  		=						30
          __UpperCamelCase  		=						self.seq_length + self.mem_len
          __UpperCamelCase  		=						15
          __UpperCamelCase  		=						True
          __UpperCamelCase  		=						True
          __UpperCamelCase  		=						99
          __UpperCamelCase  		=						[10, 50, 80]
          __UpperCamelCase  		=						32
          __UpperCamelCase  		=						32
          __UpperCamelCase  		=						4
          __UpperCamelCase  		=						8
          __UpperCamelCase  		=						128
          __UpperCamelCase  		=						2
          __UpperCamelCase  		=						2
          __UpperCamelCase  		=						None
          __UpperCamelCase  		=						1
          __UpperCamelCase  		=						0
          __UpperCamelCase  		=						3
          __UpperCamelCase  		=						self.vocab_size - 1
          __UpperCamelCase  		=						0.01







      def       snake_case	(     self					: Union[str, Any]				):
          __UpperCamelCase  		=						ids_tensor([self.batch_size, self.seq_length] ,       self.vocab_size				)
          __UpperCamelCase  		=						ids_tensor([self.batch_size, self.seq_length] ,       self.vocab_size				)

          __UpperCamelCase  		=						None
          if self.use_labels:
              __UpperCamelCase  		=						ids_tensor([self.batch_size, self.seq_length] ,       self.vocab_size				)

          __UpperCamelCase  		=						TransfoXLConfig(
              vocab_size=self.vocab_size ,       mem_len=self.mem_len ,       clamp_len=self.clamp_len ,       cutoffs=self.cutoffs ,       d_model=self.hidden_size ,       d_embed=self.d_embed ,       n_head=self.num_attention_heads ,       d_head=self.d_head ,       d_inner=self.d_inner ,       div_val=self.div_val ,       n_layer=self.num_hidden_layers ,       eos_token_id=self.eos_token_id ,       pad_token_id=self.vocab_size - 1 ,       init_range=self.init_range ,       num_labels=self.num_labels ,       )

          return (config, input_ids_a, input_ids_a, lm_labels)







      def       snake_case	(     self					: List[Any]				):
          random.seed(self.seed				)
          tf.random.set_seed(self.seed				)







      def       snake_case	(     self					: List[Any] ,       snake_case					: List[str] ,       snake_case					: int ,       snake_case					: Tuple ,       snake_case					: Any				):
          __UpperCamelCase  		=						TFTransfoXLModel(lowercase_				)

          __UpperCamelCase  		=						model(lowercase_				).to_tuple()

          __UpperCamelCase  		=						{"input_ids": input_ids_a, "mems": mems_a}

          __UpperCamelCase  		=						model(lowercase_				).to_tuple()

          self.parent.assertEqual(hidden_states_a.shape ,       (self.batch_size, self.seq_length, self.hidden_size)				)
          self.parent.assertEqual(hidden_states_a.shape ,       (self.batch_size, self.seq_length, self.hidden_size)				)
          self.parent.assertListEqual(
              [mem.shape for mem in mems_a] ,       [(self.mem_len, self.batch_size, self.hidden_size)] * self.num_hidden_layers ,       )
          self.parent.assertListEqual(
              [mem.shape for mem in mems_a] ,       [(self.mem_len, self.batch_size, self.hidden_size)] * self.num_hidden_layers ,       )







      def       snake_case	(     self					: Optional[int] ,       snake_case					: Optional[int] ,       snake_case					: Optional[int] ,       snake_case					: Optional[int] ,       snake_case					: Dict				):
          __UpperCamelCase  		=						TFTransfoXLLMHeadModel(lowercase_				)

          __UpperCamelCase  		=						model(lowercase_				).to_tuple()

          __UpperCamelCase  		=						{"input_ids": input_ids_a, "labels": lm_labels}
          __UpperCamelCase  		=						model(lowercase_				).to_tuple()

          __UpperCamelCase  		=						model([input_ids_a, mems_a]				).to_tuple()

          __UpperCamelCase  		=						{"input_ids": input_ids_a, "mems": mems_a, "labels": lm_labels}

          __UpperCamelCase  		=						model(lowercase_				).to_tuple()

          self.parent.assertEqual(lm_logits_a.shape ,       (self.batch_size, self.seq_length, self.vocab_size)				)
          self.parent.assertListEqual(
              [mem.shape for mem in mems_a] ,       [(self.mem_len, self.batch_size, self.hidden_size)] * self.num_hidden_layers ,       )

          self.parent.assertEqual(lm_logits_a.shape ,       (self.batch_size, self.seq_length, self.vocab_size)				)
          self.parent.assertListEqual(
              [mem.shape for mem in mems_a] ,       [(self.mem_len, self.batch_size, self.hidden_size)] * self.num_hidden_layers ,       )







      def       snake_case	(     self					: List[str] ,       snake_case					: Optional[int] ,       snake_case					: Union[str, Any] ,       snake_case					: Optional[int] ,       snake_case					: str				):
          __UpperCamelCase  		=						TFTransfoXLForSequenceClassification(lowercase_				)
          __UpperCamelCase  		=						model(lowercase_				)
          self.parent.assertEqual(result.logits.shape ,       (self.batch_size, self.num_labels)				)







      def       snake_case	(     self					: List[Any]				):
          __UpperCamelCase  		=						self.prepare_config_and_inputs()
          (__UpperCamelCase)  		=						config_and_inputs
          __UpperCamelCase  		=						{"input_ids": input_ids_a}
          return config, inputs_dict







@require_tf
class  _lowerCamelCase						(			snake_case__							,			snake_case__							,			unittest.TestCase   ):

      """simple docstring"""

      lowerCAmelCase__			: Any    =					(
          (TFTransfoXLModel, TFTransfoXLLMHeadModel, TFTransfoXLForSequenceClassification) if is_tf_available() else ()
      )
      lowerCAmelCase__			: Tuple    =					() if is_tf_available() else ()
      lowerCAmelCase__			: Dict    =					(
          {
              "feature-extraction": TFTransfoXLModel,
              "text-classification": TFTransfoXLForSequenceClassification,
              "text-generation": TFTransfoXLLMHeadModel,
              "zero-shot": TFTransfoXLForSequenceClassification,
          }
          if is_tf_available()
          else {}
      )
      # TODO: add this test when TFTransfoXLLMHead has a linear output layer implemented
      lowerCAmelCase__			: int    =					False
      lowerCAmelCase__			: List[str]    =					False
      lowerCAmelCase__			: int    =					False
      lowerCAmelCase__			: Optional[Any]    =					False







      def       snake_case	(     self					: List[str] ,       snake_case					: Optional[Any] ,       snake_case					: List[Any] ,       snake_case					: Dict ,       snake_case					: List[str] ,       snake_case					: Optional[Any]				):
          if pipeline_test_casse_name == "TextGenerationPipelineTests":
              # Get `ValueError: AttributeError: 'NoneType' object has no attribute 'new_ones'` or `AssertionError`.
              # `TransfoXLConfig` was never used in pipeline tests: cannot create a simple
              # tokenizer.
              return True

          return False







      def       snake_case	(     self					: List[str]				):
          __UpperCamelCase  		=						TFTransfoXLModelTester(self				)
          __UpperCamelCase  		=						ConfigTester(self ,       config_class=lowercase_ ,       d_embed=37				)







      def       snake_case	(     self					: List[Any]				):
          self.config_tester.run_common_tests()







      def       snake_case	(     self					: List[str]				):
          self.model_tester.set_seed()
          __UpperCamelCase  		=						self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_transfo_xl_model(*lowercase_				)







      def       snake_case	(     self					: List[Any]				):
          self.model_tester.set_seed()
          __UpperCamelCase  		=						self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_transfo_xl_lm_head(*lowercase_				)







      def       snake_case	(     self					: Tuple				):
          __UpperCamelCase  		=						self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_transfo_xl_for_sequence_classification(*lowercase_				)







      def       snake_case	(     self					: str				):
          __UpperCamelCase  		=						self.model_tester.prepare_config_and_inputs_for_common()
          __UpperCamelCase  		=						[TFTransfoXLForSequenceClassification]

          for model_class in self.all_model_classes:
              __UpperCamelCase  		=						model_class(lowercase_				)
              assert isinstance(model.get_input_embeddings() ,       tf.keras.layers.Layer				)
              if model_class in list_other_models_with_output_ebd:
                  __UpperCamelCase  		=						model.get_output_embeddings()
                  assert isinstance(lowercase_ ,       tf.keras.layers.Layer				)
                  __UpperCamelCase  		=						model.get_bias()
                  assert name is None
              else:
                  __UpperCamelCase  		=						model.get_output_embeddings()
                  assert x is None
                  __UpperCamelCase  		=						model.get_bias()
                  assert name is None







      def       snake_case	(     self					: Any				):
          # TODO JP: Make TransfoXL XLA compliant
          pass







      @slow
      def       snake_case	(     self					: int				):
          for model_name in TF_TRANSFO_XL_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
              __UpperCamelCase  		=						TFTransfoXLModel.from_pretrained(lowercase_				)
              self.assertIsNotNone(lowercase_				)







      @unittest.skip(reason='''This model doesn\'t play well with fit() due to not returning a single loss.'''				)
      def       snake_case	(     self					: Union[str, Any]				):
          pass







@require_tf
class  _lowerCamelCase						(			unittest.TestCase   ):

      """simple docstring"""

      @unittest.skip('''Skip test until #12651 is resolved.'''				)
      @slow
      def       snake_case	(     self					: str				):
          __UpperCamelCase  		=						TFTransfoXLLMHeadModel.from_pretrained('''transfo-xl-wt103'''				)
          # fmt: off
          __UpperCamelCase  		=						tf.convert_to_tensor([[33,1297,2,1,1009,4,1109,11739,4762,358,5,25,245,22,1706,17,20098,5,3215,21,37,1110,3,13,1041,4,24,603,490,2,71477,20098,104447,2,20961,1,2604,4,1,329,3,6224,831,16002,2,8,603,78967,29546,23,803,20,25,416,5,8,232,4,277,6,1855,4601,3,29546,54,8,3609,5,57211,49,4,1,277,18,8,1755,15691,3,341,25,416,693,42573,71,17,401,94,31,17919,2,29546,7873,18,1,435,23,11011,755,5,5167,3,7983,98,84,2,29546,3267,8,3609,4,1,4865,1075,2,6087,71,6,346,8,5854,3,29546,824,1400,1868,2,19,160,2,311,8,5496,2,20920,17,25,15097,3,24,24,0]] ,       dtype=tf.intaa				)  # noqa: E231
          # fmt: on
          #  In 1991 , the remains of Russian Tsar Nicholas II and his family
          #  ( except for Alexei and Maria ) are discovered .
          #  The voice of Nicholas's young son , Tsarevich Alexei Nikolaevich , narrates the
          #  remainder of the story . 1883 Western Siberia ,
          #  a young Grigori Rasputin is asked by his father and a group of men to perform magic .
          #  Rasputin has a vision and denounces one of the men as a horse thief . Although his
          #  father initially slaps him for making such an accusation , Rasputin watches as the
          #  man is chased outside and beaten . Twenty years later , Rasputin sees a vision of
          #  the Virgin Mary , prompting him to become a priest . Rasputin quickly becomes famous ,
          #  with people , even a bishop , begging for his blessing . <eod> </s> <eos>

          # fmt: off
          __UpperCamelCase  		=						[33,1297,2,1,1009,4,1109,11739,4762,358,5,25,245,22,1706,17,20098,5,3215,21,37,1110,3,13,1041,4,24,603,490,2,71477,20098,104447,2,20961,1,2604,4,1,329,3,6224,831,16002,2,8,603,78967,29546,23,803,20,25,416,5,8,232,4,277,6,1855,4601,3,29546,54,8,3609,5,57211,49,4,1,277,18,8,1755,15691,3,341,25,416,693,42573,71,17,401,94,31,17919,2,29546,7873,18,1,435,23,11011,755,5,5167,3,7983,98,84,2,29546,3267,8,3609,4,1,4865,1075,2,6087,71,6,346,8,5854,3,29546,824,1400,1868,2,19,160,2,311,8,5496,2,20920,17,25,15097,3,24,24,0,33,1,1857,2,1,1009,4,1109,11739,4762,358,5,25,245,28,1110,3,13,1041,4,24,603,490,2,71477,20098,104447,2,20961,1,2604,4,1,329,3,0]  # noqa: E231
          # fmt: on
          #  In 1991, the remains of Russian Tsar Nicholas II and his family (
          #  except for Alexei and Maria ) are discovered. The voice of young son,
          #  Tsarevich Alexei Nikolaevich, narrates the remainder of the story.
          #  1883 Western Siberia, a young Grigori Rasputin is asked by his father
          #  and a group of men to perform magic. Rasputin has a vision and
          #  denounces one of the men as a horse thief. Although his father initially
          #  slaps him for making such an accusation, Rasputin watches as the man
          #  is chased outside and beaten. Twenty years later, Rasputin sees a vision
          #  of the Virgin Mary, prompting him to become a priest.
          #  Rasputin quickly becomes famous, with people, even a bishop, begging for
          #  his blessing. <unk> <unk> <eos> In the 1990s, the remains of Russian Tsar
          # Nicholas II and his family were discovered. The voice of <unk> young son,
          # Tsarevich Alexei Nikolaevich, narrates the remainder of the story.<eos>

          __UpperCamelCase  		=						model.generate(lowercase_ ,       max_length=200 ,       do_sample=lowercase_				)
          self.assertListEqual(output_ids[0].numpy().tolist() ,       lowercase_				)












import gc
import unittest

from transformers import CTRLConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...generation.test_utils import GenerationTesterMixin
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 (
     CTRL_PRETRAINED_MODEL_ARCHIVE_LIST,
     CTRLForSequenceClassification,
     CTRLLMHeadModel,
     CTRLModel,
 )

class  _lowerCamelCase						:

      """simple docstring"""

      def __init__(     self					: str ,       snake_case					: Any ,       snake_case					: str=14 ,       snake_case					: Dict=7 ,       snake_case					: Any=True ,       snake_case					: Any=True ,       snake_case					: str=True ,       snake_case					: List[str]=True ,       snake_case					: int=True ,       snake_case					: List[Any]=99 ,       snake_case					: Optional[int]=32 ,       snake_case					: str=5 ,       snake_case					: int=4 ,       snake_case					: str=37 ,       snake_case					: Union[str, Any]="gelu" ,       snake_case					: List[str]=0.1 ,       snake_case					: Optional[int]=0.1 ,       snake_case					: Tuple=512 ,       snake_case					: int=16 ,       snake_case					: Any=2 ,       snake_case					: List[str]=0.02 ,       snake_case					: List[Any]=3 ,       snake_case					: str=4 ,       snake_case					: Tuple=None ,       ):
          __UpperCamelCase  		=						parent
          __UpperCamelCase  		=						batch_size
          __UpperCamelCase  		=						seq_length
          __UpperCamelCase  		=						is_training
          __UpperCamelCase  		=						use_token_type_ids
          __UpperCamelCase  		=						use_input_mask
          __UpperCamelCase  		=						use_labels
          __UpperCamelCase  		=						use_mc_token_ids
          __UpperCamelCase  		=						vocab_size
          __UpperCamelCase  		=						hidden_size
          __UpperCamelCase  		=						num_hidden_layers
          __UpperCamelCase  		=						num_attention_heads
          __UpperCamelCase  		=						intermediate_size
          __UpperCamelCase  		=						hidden_act
          __UpperCamelCase  		=						hidden_dropout_prob
          __UpperCamelCase  		=						attention_probs_dropout_prob
          __UpperCamelCase  		=						max_position_embeddings
          __UpperCamelCase  		=						type_vocab_size
          __UpperCamelCase  		=						type_sequence_label_size
          __UpperCamelCase  		=						initializer_range
          __UpperCamelCase  		=						num_labels
          __UpperCamelCase  		=						num_choices
          __UpperCamelCase  		=						scope
          __UpperCamelCase  		=						self.vocab_size - 1







      def       snake_case	(     self					: Optional[Any]				):
          __UpperCamelCase  		=						ids_tensor([self.batch_size, self.seq_length] ,       self.vocab_size				)

          __UpperCamelCase  		=						None
          if self.use_input_mask:
              __UpperCamelCase  		=						random_attention_mask([self.batch_size, self.seq_length]				)

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

          __UpperCamelCase  		=						None
          if self.use_mc_token_ids:
              __UpperCamelCase  		=						ids_tensor([self.batch_size, self.num_choices] ,       self.seq_length				)

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

          __UpperCamelCase  		=						self.get_config()

          __UpperCamelCase  		=						ids_tensor([self.num_hidden_layers, self.num_attention_heads] ,       2				)

          return (
              config,
              input_ids,
              input_mask,
              head_mask,
              token_type_ids,
              mc_token_ids,
              sequence_labels,
              token_labels,
              choice_labels,
          )







      def       snake_case	(     self					: Optional[int]				):
          return CTRLConfig(
              vocab_size=self.vocab_size ,       n_embd=self.hidden_size ,       n_layer=self.num_hidden_layers ,       n_head=self.num_attention_heads ,       n_positions=self.max_position_embeddings ,       pad_token_id=self.pad_token_id ,       )







      def       snake_case	(     self					: Any ,       snake_case					: Optional[int] ,       snake_case					: Any ,       snake_case					: Union[str, Any] ,       snake_case					: Dict ,       snake_case					: List[Any] ,       *snake_case					: Union[str, Any]				):
          __UpperCamelCase  		=						CTRLModel(config=snake_case				)
          model.to(snake_case				)
          model.eval()

          model(snake_case ,       token_type_ids=snake_case ,       head_mask=snake_case				)
          model(snake_case ,       token_type_ids=snake_case				)
          __UpperCamelCase  		=						model(snake_case				)
          self.parent.assertEqual(result.last_hidden_state.shape ,       (self.batch_size, self.seq_length, self.hidden_size)				)
          self.parent.assertEqual(len(result.past_key_values				) ,       config.n_layer				)







      def       snake_case	(     self					: Any ,       snake_case					: Tuple ,       snake_case					: Tuple ,       snake_case					: Union[str, Any] ,       snake_case					: Dict ,       snake_case					: List[str] ,       *snake_case					: Union[str, Any]				):
          __UpperCamelCase  		=						CTRLLMHeadModel(snake_case				)
          model.to(snake_case				)
          model.eval()

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







      def       snake_case	(     self					: Any				):
          __UpperCamelCase  		=						self.prepare_config_and_inputs()

          (
              (
              __UpperCamelCase
          )		,      (
              __UpperCamelCase
          )		,      (
              __UpperCamelCase
          )		,      (
              __UpperCamelCase
          )		,      (
              __UpperCamelCase
          )		,      (
              __UpperCamelCase
          )		,      (
              __UpperCamelCase
          )		,      (
              __UpperCamelCase
          )		,      (
              __UpperCamelCase
          )		,      
          )  		=						config_and_inputs

          __UpperCamelCase  		=						{'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''head_mask''': head_mask}

          return config, inputs_dict







      def       snake_case	(     self					: List[Any] ,       snake_case					: int ,       snake_case					: Dict ,       snake_case					: Optional[Any] ,       snake_case					: Any ,       *snake_case					: str				):
          __UpperCamelCase  		=						self.num_labels
          __UpperCamelCase  		=						CTRLForSequenceClassification(snake_case				)
          model.to(snake_case				)
          model.eval()
          __UpperCamelCase  		=						ids_tensor([self.batch_size] ,       self.type_sequence_label_size				)
          __UpperCamelCase  		=						model(snake_case ,       token_type_ids=snake_case ,       labels=snake_case				)
          self.parent.assertEqual(result.logits.shape ,       (self.batch_size, self.num_labels)				)







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

      """simple docstring"""

      lowerCAmelCase__			: int    =					(CTRLModel, CTRLLMHeadModel, CTRLForSequenceClassification) if is_torch_available() else ()
      lowerCAmelCase__			: List[str]    =					(CTRLLMHeadModel,) if is_torch_available() else ()
      lowerCAmelCase__			: str    =					(
          {
              "feature-extraction": CTRLModel,
              "text-classification": CTRLForSequenceClassification,
              "text-generation": CTRLLMHeadModel,
              "zero-shot": CTRLForSequenceClassification,
          }
          if is_torch_available()
          else {}
      )
      lowerCAmelCase__			: Dict    =					True
      lowerCAmelCase__			: List[Any]    =					False
      lowerCAmelCase__			: str    =					False







      def       snake_case	(     self					: str ,       snake_case					: Optional[int] ,       snake_case					: List[str] ,       snake_case					: Tuple ,       snake_case					: Dict ,       snake_case					: List[str]				):
          if pipeline_test_casse_name == "ZeroShotClassificationPipelineTests":
              # Get `tokenizer does not have a padding token` error for both fast/slow tokenizers.
              # `CTRLConfig` was never used in pipeline tests, either because of a missing checkpoint or because a tiny
              # config could not be created.
              return True

          return False







      def       snake_case	(     self					: Optional[int]				):
          __UpperCamelCase  		=						CTRLModelTester(self				)
          __UpperCamelCase  		=						ConfigTester(self ,       config_class=snake_case ,       n_embd=37				)







      def       snake_case	(     self					: Union[str, Any]				):
          super().tearDown()
          # clean-up as much as possible GPU memory occupied by PyTorch
          gc.collect()
          torch.cuda.empty_cache()







      def       snake_case	(     self					: Dict				):
          self.config_tester.run_common_tests()







      def       snake_case	(     self					: Optional[int]				):
          __UpperCamelCase  		=						self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_ctrl_model(*snake_case				)







      def       snake_case	(     self					: Tuple				):
          __UpperCamelCase  		=						self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_lm_head_model(*snake_case				)







      @unittest.skip('''Will be fixed soon by reducing the size of the model used for common tests.'''				)
      def       snake_case	(     self					: List[Any]				):
          pass







      @slow
      def       snake_case	(     self					: Optional[Any]				):
          for model_name in CTRL_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
              __UpperCamelCase  		=						CTRLModel.from_pretrained(snake_case				)
              self.assertIsNotNone(snake_case				)







      @unittest.skip('''The model doesn\'t support left padding'''				)  # and it's not used enough to be worth fixing :)
      def       snake_case	(     self					: List[Any]				):
          pass







@require_torch
class  _lowerCamelCase						(			unittest.TestCase   ):

      """simple docstring"""

      def       snake_case	(     self					: int				):
          super().tearDown()
          # clean-up as much as possible GPU memory occupied by PyTorch
          gc.collect()
          torch.cuda.empty_cache()







      @slow
      def       snake_case	(     self					: Optional[int]				):
          __UpperCamelCase  		=						CTRLLMHeadModel.from_pretrained('''ctrl'''				)
          model.to(snake_case				)
          __UpperCamelCase  		=						torch.tensor(
              [[11859, 0, 1611, 8]] ,       dtype=torch.long ,       device=snake_case				)  # Legal the president is
          __UpperCamelCase  		=						[
              11859,
              0,
              1611,
              8,
              5,
              150,
              26449,
              2,
              19,
              348,
              469,
              3,
              2595,
              48,
              20740,
              246533,
              246533,
              19,
              30,
              5,
          ]  # Legal the president is a good guy and I don't want to lose my job. \n \n I have a

          __UpperCamelCase  		=						model.generate(snake_case ,       do_sample=snake_case				)
          self.assertListEqual(output_ids[0].tolist() ,       snake_case				)






