
'''simple docstring'''

import json
import os
from functools import lru_cache
from typing import List, Optional, Tuple

import regex as re

from ...tokenization_utils import AddedToken, PreTrainedTokenizer
from ...utils import logging


__UpperCAmelCase												=   logging.get_logger(__name__)


__UpperCAmelCase												=   {'vocab_file': 'vocab.json', 'merges_file': 'merges.txt'}

# See all MVP models at https://huggingface.co/models?filter=mvp
__UpperCAmelCase												=   {
    'vocab_file': {
        'RUCAIBox/mvp': 'https://huggingface.co/RUCAIBox/mvp/resolve/main/vocab.json',
    },
    'added_tokens.json': {
        'RUCAIBox/mvp': 'https://huggingface.co/RUCAIBox/mvp/resolve/main/added_tokens.json',
    },
    'merges_file': {
        'RUCAIBox/mvp': 'https://huggingface.co/RUCAIBox/mvp/resolve/main/merges.txt',
    },
}

__UpperCAmelCase												=   {
    'RUCAIBox/mvp': 1024,
}



@lru_cache()
def        SCREAMING_SNAKE_CASE_  (	)       ->	Tuple:
 SCREAMING_SNAKE_CASE  :  int								=		(
     list(range(ord('!'							)   ,     ord('~'							) + 1							)							) + list(range(ord('¡'							)   ,     ord('¬'							) + 1							)							) + list(range(ord('®'							)   ,     ord('ÿ'							) + 1							)							)
 )
 SCREAMING_SNAKE_CASE  :  Union[str, Any]								=		bs[:]
 SCREAMING_SNAKE_CASE  :  Any								=		0
 for b in range(2**8							):
  if b not in bs:
   bs.append(snake_case_							)
   cs.append(2**8 + n							)
   n += 1
 SCREAMING_SNAKE_CASE  :  str								=		[chr(snake_case_							) for n in cs]
 return dict(zip(snake_case_   ,     snake_case_							)							)



def        SCREAMING_SNAKE_CASE_  (	snake_case_				:	Any							)       ->	Optional[int]:
 SCREAMING_SNAKE_CASE  :  int								=		set()
 SCREAMING_SNAKE_CASE  :  Tuple								=		word[0]
 for char in word[1:]:
  pairs.add((prev_char, char)							)
  SCREAMING_SNAKE_CASE  :  Optional[Any]								=		char
 return pairs





class 		_a     (							SCREAMING_SNAKE_CASE  ):







   """simple docstring"""




   A		= VOCAB_FILES_NAMES
   A		= PRETRAINED_VOCAB_FILES_MAP
   A		= PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
   A		= ['input_ids', 'attention_mask']






   def __init__(       self    ,__SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE="replace"    ,__SCREAMING_SNAKE_CASE="<s>"    ,__SCREAMING_SNAKE_CASE="</s>"    ,__SCREAMING_SNAKE_CASE="</s>"    ,__SCREAMING_SNAKE_CASE="<s>"    ,__SCREAMING_SNAKE_CASE="<unk>"    ,__SCREAMING_SNAKE_CASE="<pad>"    ,__SCREAMING_SNAKE_CASE="<mask>"    ,__SCREAMING_SNAKE_CASE=False    ,**__SCREAMING_SNAKE_CASE    ,):
    SCREAMING_SNAKE_CASE  :  Tuple								=		AddedToken(__SCREAMING_SNAKE_CASE    ,lstrip=__SCREAMING_SNAKE_CASE    ,rstrip=__SCREAMING_SNAKE_CASE      ) if isinstance(__SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE      ) else bos_token
    SCREAMING_SNAKE_CASE  :  Optional[int]								=		AddedToken(__SCREAMING_SNAKE_CASE    ,lstrip=__SCREAMING_SNAKE_CASE    ,rstrip=__SCREAMING_SNAKE_CASE      ) if isinstance(__SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE      ) else eos_token
    SCREAMING_SNAKE_CASE  :  Dict								=		AddedToken(__SCREAMING_SNAKE_CASE    ,lstrip=__SCREAMING_SNAKE_CASE    ,rstrip=__SCREAMING_SNAKE_CASE      ) if isinstance(__SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE      ) else sep_token
    SCREAMING_SNAKE_CASE  :  str								=		AddedToken(__SCREAMING_SNAKE_CASE    ,lstrip=__SCREAMING_SNAKE_CASE    ,rstrip=__SCREAMING_SNAKE_CASE      ) if isinstance(__SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE      ) else cls_token
    SCREAMING_SNAKE_CASE  :  str								=		AddedToken(__SCREAMING_SNAKE_CASE    ,lstrip=__SCREAMING_SNAKE_CASE    ,rstrip=__SCREAMING_SNAKE_CASE      ) if isinstance(__SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE      ) else unk_token
    SCREAMING_SNAKE_CASE  :  List[str]								=		AddedToken(__SCREAMING_SNAKE_CASE    ,lstrip=__SCREAMING_SNAKE_CASE    ,rstrip=__SCREAMING_SNAKE_CASE      ) if isinstance(__SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE      ) else pad_token

    # Mask token behave like a normal word, i.e. include the space before it
    SCREAMING_SNAKE_CASE  :  List[Any]								=		AddedToken(__SCREAMING_SNAKE_CASE    ,lstrip=__SCREAMING_SNAKE_CASE    ,rstrip=__SCREAMING_SNAKE_CASE      ) if isinstance(__SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE      ) else mask_token

    super().__init__(
        errors=__SCREAMING_SNAKE_CASE    ,bos_token=__SCREAMING_SNAKE_CASE    ,eos_token=__SCREAMING_SNAKE_CASE    ,unk_token=__SCREAMING_SNAKE_CASE    ,sep_token=__SCREAMING_SNAKE_CASE    ,cls_token=__SCREAMING_SNAKE_CASE    ,pad_token=__SCREAMING_SNAKE_CASE    ,mask_token=__SCREAMING_SNAKE_CASE    ,add_prefix_space=__SCREAMING_SNAKE_CASE    ,**__SCREAMING_SNAKE_CASE    ,)
    with open(__SCREAMING_SNAKE_CASE    ,encoding='utf-8'      ) as vocab_handle:
     SCREAMING_SNAKE_CASE  :  str								=		json.load(__SCREAMING_SNAKE_CASE      )
    SCREAMING_SNAKE_CASE  :  int								=		{v: k for k, v in self.encoder.items()}
    SCREAMING_SNAKE_CASE  :  str								=		errors  # how to handle errors in decoding
    SCREAMING_SNAKE_CASE  :  str								=		bytes_to_unicode()
    SCREAMING_SNAKE_CASE  :  Optional[Any]								=		{v: k for k, v in self.byte_encoder.items()}
    with open(__SCREAMING_SNAKE_CASE    ,encoding='utf-8'      ) as merges_handle:
     SCREAMING_SNAKE_CASE  :  Optional[int]								=		merges_handle.read().split('\n'      )[1:-1]
    SCREAMING_SNAKE_CASE  :  Dict								=		[tuple(merge.split()      ) for merge in bpe_merges]
    SCREAMING_SNAKE_CASE  :  List[str]								=		dict(zip(__SCREAMING_SNAKE_CASE    ,range(len(__SCREAMING_SNAKE_CASE      )      )      )      )
    SCREAMING_SNAKE_CASE  :  Optional[int]								=		{}
    SCREAMING_SNAKE_CASE  :  Tuple								=		add_prefix_space

    # Should have added re.IGNORECASE so BPE merges can happen for capitalized versions of contractions
    SCREAMING_SNAKE_CASE  :  Union[str, Any]								=		re.compile(R'\'s|\'t|\'re|\'ve|\'m|\'ll|\'d| ?\p{L}+| ?\p{N}+| ?[^\s\p{L}\p{N}]+|\s+(?!\S)|\s+'      )






   @property
   def 					__a			(       self      ):
    return len(self.encoder      )






   def 					__a			(       self      ):
    return dict(self.encoder    ,**self.added_tokens_encoder      )






   def 					__a			(       self    ,__SCREAMING_SNAKE_CASE      ):
    if token in self.cache:
     return self.cache[token]
    SCREAMING_SNAKE_CASE  :  Optional[Any]								=		tuple(__SCREAMING_SNAKE_CASE      )
    SCREAMING_SNAKE_CASE  :  str								=		get_pairs(__SCREAMING_SNAKE_CASE      )

    if not pairs:
     return token

    while True:
     SCREAMING_SNAKE_CASE  :  Optional[Any]								=		min(__SCREAMING_SNAKE_CASE    ,key=lambda __SCREAMING_SNAKE_CASE      : self.bpe_ranks.get(__SCREAMING_SNAKE_CASE    ,float('inf'      )      )      )
     if bigram not in self.bpe_ranks:
      break
     SCREAMING_SNAKE_CASE				, SCREAMING_SNAKE_CASE  :  str								=		bigram
     SCREAMING_SNAKE_CASE  :  List[str]								=		[]
     SCREAMING_SNAKE_CASE  :  str								=		0
     while i < len(__SCREAMING_SNAKE_CASE      ):
      try:
       SCREAMING_SNAKE_CASE  :  Tuple								=		word.index(__SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE      )
      except ValueError:
       new_word.extend(word[i:]      )
       break
      else:
       new_word.extend(word[i:j]      )
       SCREAMING_SNAKE_CASE  :  Tuple								=		j

      if word[i] == first and i < len(__SCREAMING_SNAKE_CASE      ) - 1 and word[i + 1] == second:
       new_word.append(first + second      )
       i += 2
      else:
       new_word.append(word[i]      )
       i += 1
     SCREAMING_SNAKE_CASE  :  Dict								=		tuple(__SCREAMING_SNAKE_CASE      )
     SCREAMING_SNAKE_CASE  :  Dict								=		new_word
     if len(__SCREAMING_SNAKE_CASE      ) == 1:
      break
     else:
      SCREAMING_SNAKE_CASE  :  Optional[int]								=		get_pairs(__SCREAMING_SNAKE_CASE      )
    SCREAMING_SNAKE_CASE  :  List[str]								=		' '.join(__SCREAMING_SNAKE_CASE      )
    SCREAMING_SNAKE_CASE  :  Tuple								=		word
    return word






   def 					__a			(       self    ,__SCREAMING_SNAKE_CASE      ):
    SCREAMING_SNAKE_CASE  :  Tuple								=		[]
    for token in re.findall(self.pat    ,__SCREAMING_SNAKE_CASE      ):
     SCREAMING_SNAKE_CASE  :  Dict								=		''.join(
         self.byte_encoder[b] for b in token.encode('utf-8'      )      )  # Maps all our bytes to unicode strings, avoiding control tokens of the BPE (spaces in our case)
     bpe_tokens.extend(bpe_token for bpe_token in self.bpe(__SCREAMING_SNAKE_CASE      ).split(' '      )      )
    return bpe_tokens






   def 					__a			(       self    ,__SCREAMING_SNAKE_CASE      ):
    return self.encoder.get(__SCREAMING_SNAKE_CASE    ,self.encoder.get(self.unk_token      )      )






   def 					__a			(       self    ,__SCREAMING_SNAKE_CASE      ):
    return self.decoder.get(__SCREAMING_SNAKE_CASE      )






   def 					__a			(       self    ,__SCREAMING_SNAKE_CASE      ):
    SCREAMING_SNAKE_CASE  :  List[Any]								=		''.join(__SCREAMING_SNAKE_CASE      )
    SCREAMING_SNAKE_CASE  :  int								=		bytearray([self.byte_decoder[c] for c in text]      ).decode('utf-8'    ,errors=self.errors      )
    return text






   def 					__a			(       self    ,__SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE = None      ):
    if not os.path.isdir(__SCREAMING_SNAKE_CASE      ):
     logger.error(f"""Vocabulary path ({save_directory}) should be a directory"""      )
     return
    SCREAMING_SNAKE_CASE  :  Any								=		os.path.join(
        __SCREAMING_SNAKE_CASE    ,(filename_prefix + '-' if filename_prefix else '') + VOCAB_FILES_NAMES['vocab_file']      )
    SCREAMING_SNAKE_CASE  :  Union[str, Any]								=		os.path.join(
        __SCREAMING_SNAKE_CASE    ,(filename_prefix + '-' if filename_prefix else '') + VOCAB_FILES_NAMES['merges_file']      )

    with open(__SCREAMING_SNAKE_CASE    ,'w'    ,encoding='utf-8'      ) as f:
     f.write(json.dumps(self.encoder    ,indent=2    ,sort_keys=__SCREAMING_SNAKE_CASE    ,ensure_ascii=__SCREAMING_SNAKE_CASE      ) + '\n'      )

    SCREAMING_SNAKE_CASE  :  int								=		0
    with open(__SCREAMING_SNAKE_CASE    ,'w'    ,encoding='utf-8'      ) as writer:
     writer.write('#version: 0.2\n'      )
     for bpe_tokens, token_index in sorted(self.bpe_ranks.items()    ,key=lambda __SCREAMING_SNAKE_CASE      : kv[1]      ):
      if index != token_index:
       logger.warning(
           f"""Saving vocabulary to {merge_file}: BPE merge indices are not consecutive."""
           ' Please check that the tokenizer is not corrupted!'      )
       SCREAMING_SNAKE_CASE  :  Any								=		token_index
      writer.write(' '.join(__SCREAMING_SNAKE_CASE      ) + '\n'      )
      index += 1

    return vocab_file, merge_file






   def 					__a			(       self    ,__SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE = None      ):
    if token_ids_a is None:
     return [self.cls_token_id] + token_ids_a + [self.sep_token_id]
    SCREAMING_SNAKE_CASE  :  Optional[Any]								=		[self.cls_token_id]
    SCREAMING_SNAKE_CASE  :  Dict								=		[self.sep_token_id]
    return cls + token_ids_a + sep + sep + token_ids_a + sep






   def 					__a			(       self    ,__SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE = None    ,__SCREAMING_SNAKE_CASE = False      ):
    if already_has_special_tokens:
     return super().get_special_tokens_mask(
         token_ids_a=__SCREAMING_SNAKE_CASE    ,token_ids_a=__SCREAMING_SNAKE_CASE    ,already_has_special_tokens=__SCREAMING_SNAKE_CASE      )

    if token_ids_a is None:
     return [1] + ([0] * len(__SCREAMING_SNAKE_CASE      )) + [1]
    return [1] + ([0] * len(__SCREAMING_SNAKE_CASE      )) + [1, 1] + ([0] * len(__SCREAMING_SNAKE_CASE      )) + [1]






   def 					__a			(       self    ,__SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE = None      ):
    SCREAMING_SNAKE_CASE  :  int								=		[self.sep_token_id]
    SCREAMING_SNAKE_CASE  :  Tuple								=		[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 					__a			(       self    ,__SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE=False    ,**__SCREAMING_SNAKE_CASE      ):
    SCREAMING_SNAKE_CASE  :  Dict								=		kwargs.pop('add_prefix_space'    ,self.add_prefix_space      )
    if (is_split_into_words or add_prefix_space) and (len(__SCREAMING_SNAKE_CASE      ) > 0 and not text[0].isspace()):
     SCREAMING_SNAKE_CASE  :  Union[str, Any]								=		' ' + text
    return (text, kwargs)




'''simple docstring'''

from __future__ import annotations

import unittest

from transformers import CTRLConfig, 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, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
   import tensorflow as tf

   from transformers.models.ctrl.modeling_tf_ctrl import (
       TF_CTRL_PRETRAINED_MODEL_ARCHIVE_LIST,
       TFCTRLForSequenceClassification,
       TFCTRLLMHeadModel,
       TFCTRLModel,
   )


class 		_a     (							SCREAMING_SNAKE_CASE  ):







   """simple docstring"""




   def __init__(       self    ,__SCREAMING_SNAKE_CASE    ,):
    SCREAMING_SNAKE_CASE  :  Dict								=		parent
    SCREAMING_SNAKE_CASE  :  int								=		13
    SCREAMING_SNAKE_CASE  :  Union[str, Any]								=		7
    SCREAMING_SNAKE_CASE  :  List[Any]								=		True
    SCREAMING_SNAKE_CASE  :  Dict								=		True
    SCREAMING_SNAKE_CASE  :  Optional[int]								=		True
    SCREAMING_SNAKE_CASE  :  int								=		True
    SCREAMING_SNAKE_CASE  :  str								=		True
    SCREAMING_SNAKE_CASE  :  int								=		99
    SCREAMING_SNAKE_CASE  :  List[str]								=		32
    SCREAMING_SNAKE_CASE  :  List[str]								=		2
    SCREAMING_SNAKE_CASE  :  Optional[Any]								=		4
    SCREAMING_SNAKE_CASE  :  Tuple								=		37
    SCREAMING_SNAKE_CASE  :  str								=		'gelu'
    SCREAMING_SNAKE_CASE  :  Tuple								=		0.1
    SCREAMING_SNAKE_CASE  :  Any								=		0.1
    SCREAMING_SNAKE_CASE  :  List[str]								=		512
    SCREAMING_SNAKE_CASE  :  List[Any]								=		16
    SCREAMING_SNAKE_CASE  :  List[Any]								=		2
    SCREAMING_SNAKE_CASE  :  Any								=		0.02
    SCREAMING_SNAKE_CASE  :  List[str]								=		3
    SCREAMING_SNAKE_CASE  :  Any								=		4
    SCREAMING_SNAKE_CASE  :  List[Any]								=		None
    SCREAMING_SNAKE_CASE  :  Optional[int]								=		self.vocab_size - 1






   def 					__a			(       self      ):
    SCREAMING_SNAKE_CASE  :  Any								=		ids_tensor([self.batch_size, self.seq_length]    ,self.vocab_size      )

    SCREAMING_SNAKE_CASE  :  Dict								=		None
    if self.use_input_mask:
     SCREAMING_SNAKE_CASE  :  List[str]								=		random_attention_mask([self.batch_size, self.seq_length]      )

    SCREAMING_SNAKE_CASE  :  List[Any]								=		None
    if self.use_token_type_ids:
     SCREAMING_SNAKE_CASE  :  str								=		ids_tensor([self.batch_size, self.seq_length]    ,self.type_vocab_size      )

    SCREAMING_SNAKE_CASE  :  int								=		None
    if self.use_mc_token_ids:
     SCREAMING_SNAKE_CASE  :  Union[str, Any]								=		ids_tensor([self.batch_size, self.num_choices]    ,self.seq_length      )

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

    SCREAMING_SNAKE_CASE  :  Dict								=		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    ,)

    SCREAMING_SNAKE_CASE  :  Tuple								=		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 					__a			(       self    ,__SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE    ,*__SCREAMING_SNAKE_CASE      ):
    SCREAMING_SNAKE_CASE  :  int								=		TFCTRLModel(config=__SCREAMING_SNAKE_CASE      )
    SCREAMING_SNAKE_CASE  :  Union[str, Any]								=		{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
    SCREAMING_SNAKE_CASE  :  Union[str, Any]								=		model(__SCREAMING_SNAKE_CASE      )

    SCREAMING_SNAKE_CASE  :  Union[str, Any]								=		[input_ids, None, input_mask]  # None is the input for 'past'
    SCREAMING_SNAKE_CASE  :  Union[str, Any]								=		model(__SCREAMING_SNAKE_CASE      )

    SCREAMING_SNAKE_CASE  :  Tuple								=		model(__SCREAMING_SNAKE_CASE      )

    self.parent.assertEqual(result.last_hidden_state.shape    ,(self.batch_size, self.seq_length, self.hidden_size)      )






   def 					__a			(       self    ,__SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE    ,*__SCREAMING_SNAKE_CASE      ):
    SCREAMING_SNAKE_CASE  :  Optional[int]								=		TFCTRLLMHeadModel(config=__SCREAMING_SNAKE_CASE      )
    SCREAMING_SNAKE_CASE  :  Any								=		{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
    SCREAMING_SNAKE_CASE  :  Any								=		model(__SCREAMING_SNAKE_CASE      )
    self.parent.assertEqual(result.logits.shape    ,(self.batch_size, self.seq_length, self.vocab_size)      )






   def 					__a			(       self    ,__SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE    ,*__SCREAMING_SNAKE_CASE      ):
    SCREAMING_SNAKE_CASE  :  Tuple								=		self.num_labels
    SCREAMING_SNAKE_CASE  :  Any								=		ids_tensor([self.batch_size]    ,self.type_sequence_label_size      )
    SCREAMING_SNAKE_CASE  :  Dict								=		{
        'input_ids': input_ids,
        'token_type_ids': token_type_ids,
        'labels': sequence_labels,
    }
    SCREAMING_SNAKE_CASE  :  Union[str, Any]								=		TFCTRLForSequenceClassification(__SCREAMING_SNAKE_CASE      )
    SCREAMING_SNAKE_CASE  :  str								=		model(__SCREAMING_SNAKE_CASE      )
    self.parent.assertEqual(result.logits.shape    ,(self.batch_size, self.num_labels)      )






   def 					__a			(       self      ):
    SCREAMING_SNAKE_CASE  :  str								=		self.prepare_config_and_inputs()

    (
        (
        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
    )				, 
    )  :  List[Any]								=		config_and_inputs

    SCREAMING_SNAKE_CASE  :  int								=		{'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
    return config, inputs_dict



@require_tf
class 		_a     (							SCREAMING_SNAKE_CASE			,    SCREAMING_SNAKE_CASE			,    unittest.TestCase  ):







   """simple docstring"""




   A		= (TFCTRLModel, TFCTRLLMHeadModel, TFCTRLForSequenceClassification) if is_tf_available() else ()
   A		= (TFCTRLLMHeadModel,) if is_tf_available() else ()
   A		= (
       {
           'feature-extraction': TFCTRLModel,
           'text-classification': TFCTRLForSequenceClassification,
           'text-generation': TFCTRLLMHeadModel,
           'zero-shot': TFCTRLForSequenceClassification,
       }
       if is_tf_available()
       else {}
   )
   A		= False
   A		= False






   def 					__a			(       self    ,__SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE      ):
    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 					__a			(       self      ):
    SCREAMING_SNAKE_CASE  :  List[Any]								=		TFCTRLModelTester(self      )
    SCREAMING_SNAKE_CASE  :  Dict								=		ConfigTester(self    ,config_class=__SCREAMING_SNAKE_CASE    ,n_embd=37      )






   def 					__a			(       self      ):
    self.config_tester.run_common_tests()






   def 					__a			(       self      ):
    SCREAMING_SNAKE_CASE  :  Tuple								=		self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_ctrl_model(*__SCREAMING_SNAKE_CASE      )






   def 					__a			(       self      ):
    SCREAMING_SNAKE_CASE  :  str								=		self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_ctrl_lm_head(*__SCREAMING_SNAKE_CASE      )






   def 					__a			(       self      ):
    SCREAMING_SNAKE_CASE  :  Optional[Any]								=		self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_ctrl_for_sequence_classification(*__SCREAMING_SNAKE_CASE      )






   def 					__a			(       self      ):
    SCREAMING_SNAKE_CASE				, SCREAMING_SNAKE_CASE  :  Tuple								=		self.model_tester.prepare_config_and_inputs_for_common()
    SCREAMING_SNAKE_CASE  :  Any								=		[TFCTRLLMHeadModel]
    SCREAMING_SNAKE_CASE  :  str								=		[TFCTRLForSequenceClassification]

    for model_class in self.all_model_classes:
     SCREAMING_SNAKE_CASE  :  List[str]								=		model_class(__SCREAMING_SNAKE_CASE      )
     model.build()  # may be needed for the get_bias() call below
     assert isinstance(model.get_input_embeddings()    ,tf.keras.layers.Layer      )

     if model_class in list_lm_models:
      SCREAMING_SNAKE_CASE  :  Dict								=		model.get_output_embeddings()
      assert isinstance(__SCREAMING_SNAKE_CASE    ,tf.keras.layers.Layer      )
      SCREAMING_SNAKE_CASE  :  Any								=		model.get_bias()
      assert isinstance(__SCREAMING_SNAKE_CASE    ,__SCREAMING_SNAKE_CASE      )
      for k, v in name.items():
       assert isinstance(__SCREAMING_SNAKE_CASE    ,tf.Variable      )
     elif model_class in list_other_models_with_output_ebd:
      SCREAMING_SNAKE_CASE  :  Any								=		model.get_output_embeddings()
      assert isinstance(__SCREAMING_SNAKE_CASE    ,tf.keras.layers.Layer      )
      SCREAMING_SNAKE_CASE  :  str								=		model.get_bias()
      assert name is None
     else:
      SCREAMING_SNAKE_CASE  :  List[Any]								=		model.get_output_embeddings()
      assert x is None
      SCREAMING_SNAKE_CASE  :  int								=		model.get_bias()
      assert name is None






   @slow
   def 					__a			(       self      ):
    for model_name in TF_CTRL_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
     SCREAMING_SNAKE_CASE  :  List[str]								=		TFCTRLModel.from_pretrained(__SCREAMING_SNAKE_CASE      )
     self.assertIsNotNone(__SCREAMING_SNAKE_CASE      )



@require_tf
class 		_a     (							unittest.TestCase  ):







   """simple docstring"""




   @slow
   def 					__a			(       self      ):
    SCREAMING_SNAKE_CASE  :  Union[str, Any]								=		TFCTRLLMHeadModel.from_pretrained('ctrl'      )
    SCREAMING_SNAKE_CASE  :  Any								=		tf.convert_to_tensor([[11859, 0, 1611, 8]]    ,dtype=tf.intaa      )  # Legal the president is
    SCREAMING_SNAKE_CASE  :  Optional[Any]								=		[
        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

    SCREAMING_SNAKE_CASE  :  Union[str, Any]								=		model.generate(__SCREAMING_SNAKE_CASE    ,do_sample=__SCREAMING_SNAKE_CASE      )
    self.assertListEqual(output_ids[0].numpy().tolist()    ,__SCREAMING_SNAKE_CASE      )


