'''simple docstring'''

import os
from shutil import copyfile
from typing import List, Optional, Tuple

from tokenizers import processors

from ...tokenization_utils import AddedToken, BatchEncoding
from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import is_sentencepiece_available, logging


if is_sentencepiece_available():
       from .tokenization_nllb import NllbTokenizer
else:
       lowerCAmelCase_ : str						  =      None


lowerCAmelCase_ : List[str]						  =      logging.get_logger(__name__)


lowerCAmelCase_ : Union[str, Any]						  =      {"vocab_file": "sentencepiece.bpe.model", "tokenizer_file": "tokenizer.json"}

lowerCAmelCase_ : List[Any]						  =      {
    "vocab_file": {
        "facebook/nllb-200-distilled-600M": (
            "https://huggingface.co/facebook/nllb-200-distilled-600M/resolve/main/sentencepiece.bpe.model"
        ),
    },
    "tokenizer_file": {
        "facebook/nllb-200-distilled-600M": (
            "https://huggingface.co/facebook/nllb-200-distilled-600M/resolve/main/tokenizer.json"
        ),
    },
}

lowerCAmelCase_ : Optional[Any]						  =      {
    "facebook/nllb-large-en-ro": 1_024,
    "facebook/nllb-200-distilled-600M": 1_024,
}

# fmt: off
lowerCAmelCase_ : Optional[Any]						  =      ["ace_Arab", "ace_Latn", "acm_Arab", "acq_Arab", "aeb_Arab", "afr_Latn", "ajp_Arab", "aka_Latn", "amh_Ethi", "apc_Arab", "arb_Arab", "ars_Arab", "ary_Arab", "arz_Arab", "asm_Beng", "ast_Latn", "awa_Deva", "ayr_Latn", "azb_Arab", "azj_Latn", "bak_Cyrl", "bam_Latn", "ban_Latn", "bel_Cyrl", "bem_Latn", "ben_Beng", "bho_Deva", "bjn_Arab", "bjn_Latn", "bod_Tibt", "bos_Latn", "bug_Latn", "bul_Cyrl", "cat_Latn", "ceb_Latn", "ces_Latn", "cjk_Latn", "ckb_Arab", "crh_Latn", "cym_Latn", "dan_Latn", "deu_Latn", "dik_Latn", "dyu_Latn", "dzo_Tibt", "ell_Grek", "eng_Latn", "epo_Latn", "est_Latn", "eus_Latn", "ewe_Latn", "fao_Latn", "pes_Arab", "fij_Latn", "fin_Latn", "fon_Latn", "fra_Latn", "fur_Latn", "fuv_Latn", "gla_Latn", "gle_Latn", "glg_Latn", "grn_Latn", "guj_Gujr", "hat_Latn", "hau_Latn", "heb_Hebr", "hin_Deva", "hne_Deva", "hrv_Latn", "hun_Latn", "hye_Armn", "ibo_Latn", "ilo_Latn", "ind_Latn", "isl_Latn", "ita_Latn", "jav_Latn", "jpn_Jpan", "kab_Latn", "kac_Latn", "kam_Latn", "kan_Knda", "kas_Arab", "kas_Deva", "kat_Geor", "knc_Arab", "knc_Latn", "kaz_Cyrl", "kbp_Latn", "kea_Latn", "khm_Khmr", "kik_Latn", "kin_Latn", "kir_Cyrl", "kmb_Latn", "kon_Latn", "kor_Hang", "kmr_Latn", "lao_Laoo", "lvs_Latn", "lij_Latn", "lim_Latn", "lin_Latn", "lit_Latn", "lmo_Latn", "ltg_Latn", "ltz_Latn", "lua_Latn", "lug_Latn", "luo_Latn", "lus_Latn", "mag_Deva", "mai_Deva", "mal_Mlym", "mar_Deva", "min_Latn", "mkd_Cyrl", "plt_Latn", "mlt_Latn", "mni_Beng", "khk_Cyrl", "mos_Latn", "mri_Latn", "zsm_Latn", "mya_Mymr", "nld_Latn", "nno_Latn", "nob_Latn", "npi_Deva", "nso_Latn", "nus_Latn", "nya_Latn", "oci_Latn", "gaz_Latn", "ory_Orya", "pag_Latn", "pan_Guru", "pap_Latn", "pol_Latn", "por_Latn", "prs_Arab", "pbt_Arab", "quy_Latn", "ron_Latn", "run_Latn", "rus_Cyrl", "sag_Latn", "san_Deva", "sat_Beng", "scn_Latn", "shn_Mymr", "sin_Sinh", "slk_Latn", "slv_Latn", "smo_Latn", "sna_Latn", "snd_Arab", "som_Latn", "sot_Latn", "spa_Latn", "als_Latn", "srd_Latn", "srp_Cyrl", "ssw_Latn", "sun_Latn", "swe_Latn", "swh_Latn", "szl_Latn", "tam_Taml", "tat_Cyrl", "tel_Telu", "tgk_Cyrl", "tgl_Latn", "tha_Thai", "tir_Ethi", "taq_Latn", "taq_Tfng", "tpi_Latn", "tsn_Latn", "tso_Latn", "tuk_Latn", "tum_Latn", "tur_Latn", "twi_Latn", "tzm_Tfng", "uig_Arab", "ukr_Cyrl", "umb_Latn", "urd_Arab", "uzn_Latn", "vec_Latn", "vie_Latn", "war_Latn", "wol_Latn", "xho_Latn", "ydd_Hebr", "yor_Latn", "yue_Hant", "zho_Hans", "zho_Hant", "zul_Latn"]





class 							lowercase						(						__lowerCamelCase ):
   lowerCamelCase_    					=VOCAB_FILES_NAMES
   lowerCamelCase_    					=PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
   lowerCamelCase_    					=PRETRAINED_VOCAB_FILES_MAP
   lowerCamelCase_    					=['input_ids', 'attention_mask']
   lowerCamelCase_    					=NllbTokenizer

   lowerCamelCase_    					=[]
   lowerCamelCase_    					=[]


   def __init__(   self				:	Union[str, Any]   ,		__lowerCAmelCase				:	Dict=None   ,		__lowerCAmelCase				:	Optional[Any]=None   ,		__lowerCAmelCase				:	Dict="<s>"   ,		__lowerCAmelCase				:	List[Any]="</s>"   ,		__lowerCAmelCase				:	Optional[Any]="</s>"   ,		__lowerCAmelCase				:	Tuple="<s>"   ,		__lowerCAmelCase				:	List[str]="<unk>"   ,		__lowerCAmelCase				:	Union[str, Any]="<pad>"   ,		__lowerCAmelCase				:	Optional[int]="<mask>"   ,		__lowerCAmelCase				:	List[Any]=None   ,		__lowerCAmelCase				:	Any=None   ,		__lowerCAmelCase				:	Tuple=None   ,		__lowerCAmelCase				:	Dict=False   ,		**__lowerCAmelCase				:	Tuple   ,		)      ->					Dict:
         # Mask token behave like a normal word, i.e. include the space before it
         lowercase_     =      AddedToken(__lowerCAmelCase   ,		lstrip=__lowerCAmelCase   ,		rstrip=__lowerCAmelCase) if isinstance(__lowerCAmelCase   ,		__lowerCAmelCase) else mask_token
         lowercase_     =      legacy_behaviour
         super().__init__(
             vocab_file=__lowerCAmelCase   ,		tokenizer_file=__lowerCAmelCase   ,		bos_token=__lowerCAmelCase   ,		eos_token=__lowerCAmelCase   ,		sep_token=__lowerCAmelCase   ,		cls_token=__lowerCAmelCase   ,		unk_token=__lowerCAmelCase   ,		pad_token=__lowerCAmelCase   ,		mask_token=__lowerCAmelCase   ,		src_lang=__lowerCAmelCase   ,		tgt_lang=__lowerCAmelCase   ,		additional_special_tokens=__lowerCAmelCase   ,		legacy_behaviour=__lowerCAmelCase   ,		**__lowerCAmelCase   ,		)

         lowercase_     =      vocab_file
         lowercase_     =      False if not self.vocab_file else True

         lowercase_     =      FAIRSEQ_LANGUAGE_CODES.copy()

         if additional_special_tokens is not None:
               # Only add those special tokens if they are not already there.
               _additional_special_tokens.extend(
                   [t for t in additional_special_tokens if t not in _additional_special_tokens])

         self.add_special_tokens({"additional_special_tokens": _additional_special_tokens})
         lowercase_     =      {
             lang_code: self.convert_tokens_to_ids(__lowerCAmelCase) for lang_code in FAIRSEQ_LANGUAGE_CODES
         }

         lowercase_     =      src_lang if src_lang is not None else "eng_Latn"
         lowercase_     =      self.convert_tokens_to_ids(self._src_lang)
         lowercase_     =      tgt_lang
         self.set_src_lang_special_tokens(self._src_lang)


   @property
   def __UpperCAmelCase       (   self				:	Optional[Any])      ->					str:
         return self._src_lang


   @src_lang.setter
   def __UpperCAmelCase       (   self				:	List[str]   ,		__lowerCAmelCase				:	str)      ->					None:
         lowercase_     =      new_src_lang
         self.set_src_lang_special_tokens(self._src_lang)


   def __UpperCAmelCase       (   self				:	Tuple   ,		__lowerCAmelCase				:	List[int]   ,		__lowerCAmelCase				:	Optional[List[int]] = None)      ->					List[int]:
         if token_ids_a is None:
               return self.prefix_tokens + token_ids_a + self.suffix_tokens
         # We don't expect to process pairs, but leave the pair logic for API consistency
         return self.prefix_tokens + token_ids_a + token_ids_a + self.suffix_tokens


   def __UpperCAmelCase       (   self				:	Optional[int]   ,		__lowerCAmelCase				:	List[int]   ,		__lowerCAmelCase				:	Optional[List[int]] = None)      ->					List[int]:
         lowercase_     =      [self.sep_token_id]
         lowercase_     =      [self.cls_token_id]

         if token_ids_a is None:
               return len(cls + token_ids_a + sep) * [0]
         return len(cls + token_ids_a + sep + sep + token_ids_a + sep) * [0]


   def __UpperCAmelCase       (   self				:	str   ,		__lowerCAmelCase				:	Optional[Any]   ,		__lowerCAmelCase				:	str   ,		__lowerCAmelCase				:	Optional[str]   ,		__lowerCAmelCase				:	Optional[str]   ,		**__lowerCAmelCase				:	str)      ->					Optional[int]:
         if src_lang is None or tgt_lang is None:
               raise ValueError("Translation requires a `src_lang` and a `tgt_lang` for this model")
         lowercase_     =      src_lang
         lowercase_     =      self(__lowerCAmelCase   ,		add_special_tokens=__lowerCAmelCase   ,		return_tensors=__lowerCAmelCase   ,		**__lowerCAmelCase)
         lowercase_     =      self.convert_tokens_to_ids(__lowerCAmelCase)
         lowercase_     =      tgt_lang_id
         return inputs


   def __UpperCAmelCase       (   self				:	Optional[int]   ,		__lowerCAmelCase				:	List[str]   ,		__lowerCAmelCase				:	str = "eng_Latn"   ,		__lowerCAmelCase				:	Optional[List[str]] = None   ,		__lowerCAmelCase				:	str = "fra_Latn"   ,		**__lowerCAmelCase				:	Optional[int]   ,		)      ->					BatchEncoding:
         lowercase_     =      src_lang
         lowercase_     =      tgt_lang
         return super().prepare_seqaseq_batch(__lowerCAmelCase   ,		__lowerCAmelCase   ,		**__lowerCAmelCase)


   def __UpperCAmelCase       (   self				:	List[str])      ->					Optional[Any]:
         return self.set_src_lang_special_tokens(self.src_lang)


   def __UpperCAmelCase       (   self				:	Optional[Any])      ->					List[str]:
         return self.set_tgt_lang_special_tokens(self.tgt_lang)


   def __UpperCAmelCase       (   self				:	List[Any]   ,		__lowerCAmelCase				:	Union[str, Any])      ->					None:
         lowercase_     =      self.convert_tokens_to_ids(__lowerCAmelCase)

         if self.legacy_behaviour:
               lowercase_     =      []
               lowercase_     =      [self.eos_token_id, self.cur_lang_code]
         else:
               lowercase_     =      [self.cur_lang_code]
               lowercase_     =      [self.eos_token_id]

         lowercase_     =      self.convert_ids_to_tokens(self.prefix_tokens)
         lowercase_     =      self.convert_ids_to_tokens(self.suffix_tokens)

         lowercase_     =      processors.TemplateProcessing(
             single=prefix_tokens_str + ["$A"] + suffix_tokens_str   ,		pair=prefix_tokens_str + ["$A", "$B"] + suffix_tokens_str   ,		special_tokens=list(zip(prefix_tokens_str + suffix_tokens_str   ,		self.prefix_tokens + self.suffix_tokens))   ,		)


   def __UpperCAmelCase       (   self				:	Union[str, Any]   ,		__lowerCAmelCase				:	str)      ->					None:
         lowercase_     =      self.convert_tokens_to_ids(__lowerCAmelCase)
         if self.legacy_behaviour:
               lowercase_     =      []
               lowercase_     =      [self.eos_token_id, self.cur_lang_code]
         else:
               lowercase_     =      [self.cur_lang_code]
               lowercase_     =      [self.eos_token_id]

         lowercase_     =      self.convert_ids_to_tokens(self.prefix_tokens)
         lowercase_     =      self.convert_ids_to_tokens(self.suffix_tokens)

         lowercase_     =      processors.TemplateProcessing(
             single=prefix_tokens_str + ["$A"] + suffix_tokens_str   ,		pair=prefix_tokens_str + ["$A", "$B"] + suffix_tokens_str   ,		special_tokens=list(zip(prefix_tokens_str + suffix_tokens_str   ,		self.prefix_tokens + self.suffix_tokens))   ,		)


   def __UpperCAmelCase       (   self				:	Tuple   ,		__lowerCAmelCase				:	str   ,		__lowerCAmelCase				:	Optional[str] = None)      ->					Tuple[str]:
         if not self.can_save_slow_tokenizer:
               raise ValueError(
                   "Your fast tokenizer does not have the necessary information to save the vocabulary for a slow "
                   "tokenizer.")

         if not os.path.isdir(__lowerCAmelCase):
               logger.error(F'Vocabulary path ({save_directory}) should be a directory.')
               return
         lowercase_     =      os.path.join(
             __lowerCAmelCase   ,		(filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["vocab_file"])

         if os.path.abspath(self.vocab_file) != os.path.abspath(__lowerCAmelCase):
               copyfile(self.vocab_file   ,		__lowerCAmelCase)

         return (out_vocab_file,)







'''simple docstring'''

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 							lowercase						:


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


   def __UpperCAmelCase       (   self				:	Tuple)      ->					int:
         lowercase_     =      ids_tensor([self.batch_size, self.seq_length]   ,		self.vocab_size)

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

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

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

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

         lowercase_     =      self.get_config()

         lowercase_     =      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 __UpperCAmelCase       (   self				:	Union[str, Any])      ->					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 __UpperCAmelCase       (   self				:	Union[str, Any]   ,		__lowerCAmelCase				:	Optional[Any]   ,		__lowerCAmelCase				:	Union[str, Any]   ,		__lowerCAmelCase				:	Union[str, Any]   ,		__lowerCAmelCase				:	Tuple   ,		__lowerCAmelCase				:	Union[str, Any]   ,		*__lowerCAmelCase				:	Tuple)      ->					List[str]:
         lowercase_     =      CTRLModel(config=__lowerCAmelCase)
         model.to(__lowerCAmelCase)
         model.eval()

         model(__lowerCAmelCase   ,		token_type_ids=__lowerCAmelCase   ,		head_mask=__lowerCAmelCase)
         model(__lowerCAmelCase   ,		token_type_ids=__lowerCAmelCase)
         lowercase_     =      model(__lowerCAmelCase)
         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 __UpperCAmelCase       (   self				:	List[Any]   ,		__lowerCAmelCase				:	Optional[int]   ,		__lowerCAmelCase				:	Union[str, Any]   ,		__lowerCAmelCase				:	Dict   ,		__lowerCAmelCase				:	int   ,		__lowerCAmelCase				:	Dict   ,		*__lowerCAmelCase				:	int)      ->					int:
         lowercase_     =      CTRLLMHeadModel(__lowerCAmelCase)
         model.to(__lowerCAmelCase)
         model.eval()

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


   def __UpperCAmelCase       (   self				:	Dict)      ->					int:
         lowercase_     =      self.prepare_config_and_inputs()

         (
             (
             lowercase_
         ) ,							(
             lowercase_
         ) ,							(
             lowercase_
         ) ,							(
             lowercase_
         ) ,							(
             lowercase_
         ) ,							(
             lowercase_
         ) ,							(
             lowercase_
         ) ,							(
             lowercase_
         ) ,							(
             lowercase_
         ) ,							
         )     =      config_and_inputs

         lowercase_     =      {"input_ids": input_ids, "token_type_ids": token_type_ids, "head_mask": head_mask}

         return config, inputs_dict


   def __UpperCAmelCase       (   self				:	Any   ,		__lowerCAmelCase				:	Optional[int]   ,		__lowerCAmelCase				:	Optional[Any]   ,		__lowerCAmelCase				:	int   ,		__lowerCAmelCase				:	List[str]   ,		*__lowerCAmelCase				:	List[Any])      ->					int:
         lowercase_     =      self.num_labels
         lowercase_     =      CTRLForSequenceClassification(__lowerCAmelCase)
         model.to(__lowerCAmelCase)
         model.eval()
         lowercase_     =      ids_tensor([self.batch_size]   ,		self.type_sequence_label_size)
         lowercase_     =      model(__lowerCAmelCase   ,		token_type_ids=__lowerCAmelCase   ,		labels=__lowerCAmelCase)
         self.parent.assertEqual(result.logits.shape   ,		(self.batch_size, self.num_labels))





@require_torch
class 							lowercase						(						__lowerCamelCase ,				__lowerCamelCase ,				__lowerCamelCase ,				unittest.TestCase ):
   lowerCamelCase_    					=(CTRLModel, CTRLLMHeadModel, CTRLForSequenceClassification) if is_torch_available() else ()
   lowerCamelCase_    					=(CTRLLMHeadModel,) if is_torch_available() else ()
   lowerCamelCase_    					=(
       {
           'feature-extraction': CTRLModel,
           'text-classification': CTRLForSequenceClassification,
           'text-generation': CTRLLMHeadModel,
           'zero-shot': CTRLForSequenceClassification,
       }
       if is_torch_available()
       else {}
   )
   lowerCamelCase_    					=True
   lowerCamelCase_    					=False
   lowerCamelCase_    					=False


   def __UpperCAmelCase       (   self				:	Tuple   ,		__lowerCAmelCase				:	Dict   ,		__lowerCAmelCase				:	Dict   ,		__lowerCAmelCase				:	str   ,		__lowerCAmelCase				:	List[Any]   ,		__lowerCAmelCase				:	int)      ->					Optional[int]:
         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 __UpperCAmelCase       (   self				:	str)      ->					Tuple:
         lowercase_     =      CTRLModelTester(self)
         lowercase_     =      ConfigTester(self   ,		config_class=__lowerCAmelCase   ,		n_embd=37)


   def __UpperCAmelCase       (   self				:	Dict)      ->					Optional[Any]:
         super().tearDown()
         # clean-up as much as possible GPU memory occupied by PyTorch
         gc.collect()
         torch.cuda.empty_cache()


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


   def __UpperCAmelCase       (   self				:	Any)      ->					List[Any]:
         lowercase_     =      self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_ctrl_model(*__lowerCAmelCase)


   def __UpperCAmelCase       (   self				:	Tuple)      ->					Dict:
         lowercase_     =      self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_lm_head_model(*__lowerCAmelCase)


   @unittest.skip("Will be fixed soon by reducing the size of the model used for common tests.")
   def __UpperCAmelCase       (   self				:	Union[str, Any])      ->					Optional[Any]:
         pass


   @slow
   def __UpperCAmelCase       (   self				:	Dict)      ->					List[str]:
         for model_name in CTRL_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
               lowercase_     =      CTRLModel.from_pretrained(__lowerCAmelCase)
               self.assertIsNotNone(__lowerCAmelCase)


   @unittest.skip("The model doesn't support left padding")  # and it's not used enough to be worth fixing :)
   def __UpperCAmelCase       (   self				:	Optional[Any])      ->					Dict:
         pass





@require_torch
class 							lowercase						(						unittest.TestCase ):


   def __UpperCAmelCase       (   self				:	Optional[int])      ->					Any:
         super().tearDown()
         # clean-up as much as possible GPU memory occupied by PyTorch
         gc.collect()
         torch.cuda.empty_cache()


   @slow
   def __UpperCAmelCase       (   self				:	int)      ->					Any:
         lowercase_     =      CTRLLMHeadModel.from_pretrained("ctrl")
         model.to(__lowerCAmelCase)
         lowercase_     =      torch.tensor(
             [[1_1859, 0, 1611, 8]]   ,		dtype=torch.long   ,		device=__lowerCAmelCase)  # Legal the president is
         lowercase_     =      [
             1_1859,
             0,
             1611,
             8,
             5,
             150,
             2_6449,
             2,
             19,
             348,
             469,
             3,
             2595,
             48,
             2_0740,
             24_6533,
             24_6533,
             19,
             30,
             5,
         ]  # Legal the president is a good guy and I don't want to lose my job. \n \n I have a

         lowercase_     =      model.generate(__lowerCAmelCase   ,		do_sample=__lowerCAmelCase)
         self.assertListEqual(output_ids[0].tolist()   ,		__lowerCAmelCase)






