code: 
  
  
  
  
  
  
  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 					snake_case_							(       lowercase_      ):
  
  
  
  
  
  
  
     """simple docstring"""
  
  
  
     def __init__(    self:	Any   ,       snake_case__:	int   ,       )  ->		Any:
  
  
           """simple docstring"""
  
  
  
           _lowercase     =	parent
           _lowercase     =	13
           _lowercase     =	7
           _lowercase     =	True
           _lowercase     =	True
           _lowercase     =	True
           _lowercase     =	True
           _lowercase     =	True
           _lowercase     =	99
           _lowercase     =	32
           _lowercase     =	2
           _lowercase     =	4
           _lowercase     =	37
           _lowercase     =	'gelu'
           _lowercase     =	0.1
           _lowercase     =	0.1
           _lowercase     =	512
           _lowercase     =	16
           _lowercase     =	2
           _lowercase     =	0.02
           _lowercase     =	3
           _lowercase     =	4
           _lowercase     =	None
           _lowercase     =	self.vocab_size - 1
  
     def 			SCREAMING_SNAKE_CASE__				(    self:	List[str]	)  ->		Tuple:
  
  
           """simple docstring"""
  
  
  
           _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     =	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   ,       )
  
           _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 			SCREAMING_SNAKE_CASE__				(    self:	Optional[int]   ,       snake_case__:	List[Any]   ,       snake_case__:	Optional[Any]   ,       snake_case__:	List[str]   ,       snake_case__:	str   ,       snake_case__:	Optional[Any]   ,       *snake_case__:	int	)  ->		List[Any]:
  
  
           """simple docstring"""
  
  
  
           _lowercase     =	TFCTRLModel(config=snake_case__	)
           _lowercase     =	{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
           _lowercase     =	model(snake_case__	)
  
           _lowercase     =	[input_ids, None, input_mask]  # None is the input for 'past'
           _lowercase     =	model(snake_case__	)
  
           _lowercase     =	model(snake_case__	)
  
           self.parent.assertEqual(result.last_hidden_state.shape   ,       (self.batch_size, self.seq_length, self.hidden_size)	)
  
     def 			SCREAMING_SNAKE_CASE__				(    self:	Any   ,       snake_case__:	Optional[int]   ,       snake_case__:	int   ,       snake_case__:	Tuple   ,       snake_case__:	Optional[Any]   ,       snake_case__:	List[Any]   ,       *snake_case__:	str	)  ->		Union[str, Any]:
  
  
           """simple docstring"""
  
  
  
           _lowercase     =	TFCTRLLMHeadModel(config=snake_case__	)
           _lowercase     =	{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
           _lowercase     =	model(snake_case__	)
           self.parent.assertEqual(result.logits.shape   ,       (self.batch_size, self.seq_length, self.vocab_size)	)
  
     def 			SCREAMING_SNAKE_CASE__				(    self:	Optional[Any]   ,       snake_case__:	Dict   ,       snake_case__:	List[Any]   ,       snake_case__:	int   ,       snake_case__:	Tuple   ,       snake_case__:	Dict   ,       *snake_case__:	Optional[Any]	)  ->		Optional[int]:
  
  
           """simple docstring"""
  
  
  
           _lowercase     =	self.num_labels
           _lowercase     =	ids_tensor([self.batch_size]   ,       self.type_sequence_label_size	)
           _lowercase     =	{
               'input_ids': input_ids,
               'token_type_ids': token_type_ids,
               'labels': sequence_labels,
           }
           _lowercase     =	TFCTRLForSequenceClassification(snake_case__	)
           _lowercase     =	model(snake_case__	)
           self.parent.assertEqual(result.logits.shape   ,       (self.batch_size, self.num_labels)	)
  
     def 			SCREAMING_SNAKE_CASE__				(    self:	Any	)  ->		Optional[Any]:
  
  
           """simple docstring"""
  
  
  
           _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, 'attention_mask': input_mask}
           return config, inputs_dict
  
  
  
  
  
  
  @require_tf
  class 					snake_case_							(       lowercase_      ,			lowercase_      ,			unittest.TestCase      ):
  
  
  
  
  
  
  
     """simple docstring"""
  
  
  
     __lowerCAmelCase      =						(TFCTRLModel, TFCTRLLMHeadModel, TFCTRLForSequenceClassification) if is_tf_available() else ()
     __lowerCAmelCase      =						(TFCTRLLMHeadModel,) if is_tf_available() else ()
     __lowerCAmelCase      =						(
         {
             """feature-extraction""": TFCTRLModel,
             """text-classification""": TFCTRLForSequenceClassification,
             """text-generation""": TFCTRLLMHeadModel,
             """zero-shot""": TFCTRLForSequenceClassification,
         }
         if is_tf_available()
         else {}
     )
     __lowerCAmelCase      =						False
     __lowerCAmelCase      =						False
  
     def 			SCREAMING_SNAKE_CASE__				(    self:	List[str]   ,       snake_case__:	Dict   ,       snake_case__:	int   ,       snake_case__:	Optional[int]   ,       snake_case__:	Optional[int]   ,       snake_case__:	List[Any]	)  ->		Any:
  
  
           """simple docstring"""
  
  
  
           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 			SCREAMING_SNAKE_CASE__				(    self:	Tuple	)  ->		Dict:
  
  
           """simple docstring"""
  
  
  
           _lowercase     =	TFCTRLModelTester(self	)
           _lowercase     =	ConfigTester(self   ,       config_class=snake_case__   ,       n_embd=37	)
  
     def 			SCREAMING_SNAKE_CASE__				(    self:	Any	)  ->		int:
  
  
           """simple docstring"""
  
  
  
           self.config_tester.run_common_tests()
  
     def 			SCREAMING_SNAKE_CASE__				(    self:	Union[str, Any]	)  ->		str:
  
  
           """simple docstring"""
  
  
  
           _lowercase     =	self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_ctrl_model(*snake_case__	)
  
     def 			SCREAMING_SNAKE_CASE__				(    self:	Any	)  ->		List[str]:
  
  
           """simple docstring"""
  
  
  
           _lowercase     =	self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_ctrl_lm_head(*snake_case__	)
  
     def 			SCREAMING_SNAKE_CASE__				(    self:	str	)  ->		List[str]:
  
  
           """simple docstring"""
  
  
  
           _lowercase     =	self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_ctrl_for_sequence_classification(*snake_case__	)
  
     def 			SCREAMING_SNAKE_CASE__				(    self:	Dict	)  ->		Optional[int]:
  
  
           """simple docstring"""
  
  
  
           _lowercase ,    _lowercase     =	self.model_tester.prepare_config_and_inputs_for_common()
           _lowercase     =	[TFCTRLLMHeadModel]
           _lowercase     =	[TFCTRLForSequenceClassification]
  
           for model_class in self.all_model_classes:
                 _lowercase     =	model_class(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:
                       _lowercase     =	model.get_output_embeddings()
                       assert isinstance(snake_case__   ,       tf.keras.layers.Layer	)
                       _lowercase     =	model.get_bias()
                       assert isinstance(snake_case__   ,       snake_case__	)
                       for k, v in name.items():
                             assert isinstance(snake_case__   ,       tf.Variable	)
                 elif model_class in list_other_models_with_output_ebd:
                       _lowercase     =	model.get_output_embeddings()
                       assert isinstance(snake_case__   ,       tf.keras.layers.Layer	)
                       _lowercase     =	model.get_bias()
                       assert name is None
                 else:
                       _lowercase     =	model.get_output_embeddings()
                       assert x is None
                       _lowercase     =	model.get_bias()
                       assert name is None
  
     @slow
     def 			SCREAMING_SNAKE_CASE__				(    self:	List[Any]	)  ->		Tuple:
  
  
           """simple docstring"""
  
  
  
           for model_name in TF_CTRL_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                 _lowercase     =	TFCTRLModel.from_pretrained(snake_case__	)
                 self.assertIsNotNone(snake_case__	)
  
  
  
  
  
  
  @require_tf
  class 					snake_case_							(       unittest.TestCase      ):
  
  
  
  
  
  
  
     """simple docstring"""
  
  
  
     @slow
     def 			SCREAMING_SNAKE_CASE__				(    self:	List[Any]	)  ->		List[str]:
  
  
           """simple docstring"""
  
  
  
           _lowercase     =	TFCTRLLMHeadModel.from_pretrained('ctrl'	)
           _lowercase     =	tf.convert_to_tensor([[11_859, 0, 1_611, 8]]   ,       dtype=tf.intaa	)  # Legal the president is
           _lowercase     =	[
               11_859,
               0,
               1_611,
               8,
               5,
               150,
               26_449,
               2,
               19,
               348,
               469,
               3,
               2_595,
               48,
               20_740,
               246_533,
               246_533,
               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(snake_case__   ,       do_sample=snake_case__	)
           self.assertListEqual(output_ids[0].numpy().tolist()   ,       snake_case__	)
  
style_context: 
  
  
  
  
  
  
  import functools
  import operator
  
  from ...configuration_utils import PretrainedConfig
  from ...utils import logging
  
  
  lowerCamelCase										=  logging.get_logger(__name__)
  
  lowerCamelCase										=  {
      '''facebook/hubert-base-ls960''': '''https://huggingface.co/facebook/hubert-base-ls960/resolve/main/config.json''',
      # See all Hubert models at https://huggingface.co/models?filter=hubert
  }
  
  class 					snake_case_							(       lowercase_      ):
  
  
  
  
  
  
  
     """simple docstring"""
  
  
  
     __lowerCAmelCase      =						"""hubert"""
  
     def __init__(    self:	Any   ,       snake_case__:	str=32   ,       snake_case__:	int=768   ,       snake_case__:	Dict=12   ,       snake_case__:	Optional[int]=12   ,       snake_case__:	List[str]=3_072   ,       snake_case__:	Optional[Any]="gelu"   ,       snake_case__:	Optional[int]=0.1   ,       snake_case__:	List[str]=0.1   ,       snake_case__:	Optional[int]=0.1   ,       snake_case__:	List[str]=True   ,       snake_case__:	Union[str, Any]=0.0   ,       snake_case__:	Union[str, Any]=0.1   ,       snake_case__:	List[str]=0.1   ,       snake_case__:	List[Any]=0.02   ,       snake_case__:	Dict=1E-5   ,       snake_case__:	Any="group"   ,       snake_case__:	Union[str, Any]="gelu"   ,       snake_case__:	List[str]=(512, 512, 512, 512, 512, 512, 512)   ,       snake_case__:	Union[str, Any]=(5, 2, 2, 2, 2, 2, 2)   ,       snake_case__:	Any=(10, 3, 3, 3, 3, 2, 2)   ,       snake_case__:	int=False   ,       snake_case__:	Any=128   ,       snake_case__:	Dict=16   ,       snake_case__:	Optional[Any]=False   ,       snake_case__:	Tuple=True   ,       snake_case__:	int=0.05   ,       snake_case__:	List[Any]=10   ,       snake_case__:	Tuple=2   ,       snake_case__:	List[Any]=0.0   ,       snake_case__:	Optional[int]=10   ,       snake_case__:	Optional[int]=0   ,       snake_case__:	Union[str, Any]="sum"   ,       snake_case__:	Union[str, Any]=False   ,       snake_case__:	int=False   ,       snake_case__:	Any=256   ,       snake_case__:	Union[str, Any]=0   ,       snake_case__:	Optional[int]=1   ,       snake_case__:	List[str]=2   ,       **snake_case__:	Optional[int]   ,       )  ->		Any:
  
  
         """simple docstring"""
  
  
  
         super().__init__(**snake_case__   ,       pad_token_id=snake_case__   ,       bos_token_id=snake_case__   ,       eos_token_id=snake_case__	)
         _lowercase     =	hidden_size
         _lowercase     =	feat_extract_norm
         _lowercase     =	feat_extract_activation
         _lowercase     =	list(snake_case__	)
         _lowercase     =	list(snake_case__	)
         _lowercase     =	list(snake_case__	)
         _lowercase     =	conv_bias
         _lowercase     =	num_conv_pos_embeddings
         _lowercase     =	num_conv_pos_embedding_groups
         _lowercase     =	len(self.conv_dim	)
         _lowercase     =	num_hidden_layers
         _lowercase     =	intermediate_size
         _lowercase     =	hidden_act
         _lowercase     =	num_attention_heads
         _lowercase     =	hidden_dropout
         _lowercase     =	attention_dropout
         _lowercase     =	activation_dropout
         _lowercase     =	feat_proj_layer_norm
         _lowercase     =	feat_proj_dropout
         _lowercase     =	final_dropout
         _lowercase     =	layerdrop
         _lowercase     =	layer_norm_eps
         _lowercase     =	initializer_range
         _lowercase     =	vocab_size
         _lowercase     =	do_stable_layer_norm
         _lowercase     =	use_weighted_layer_sum
         _lowercase     =	classifier_proj_size
  
         if (
             (len(self.conv_stride	) != self.num_feat_extract_layers)
             or (len(self.conv_kernel	) != self.num_feat_extract_layers)
             or (len(self.conv_dim	) != self.num_feat_extract_layers)
         ):
             raise ValueError(
                 'Configuration for convolutional layers is incorrect. It is required that `len(config.conv_dim)` =='
                 ' `len(config.conv_stride)` == `len(config.conv_kernel)`, but is `len(config.conv_dim) ='
                 f''' {len(self.conv_dim	)}`, `len(config.conv_stride) = {len(self.conv_stride	)}`,'''
                 f''' `len(config.conv_kernel) = {len(self.conv_kernel	)}`.'''	)
  
         # fine-tuning config parameters for SpecAugment: https://arxiv.org/abs/1904.08779
         _lowercase     =	apply_spec_augment
         _lowercase     =	mask_time_prob
         _lowercase     =	mask_time_length
         _lowercase     =	mask_time_min_masks
         _lowercase     =	mask_feature_prob
         _lowercase     =	mask_feature_length
         _lowercase     =	mask_feature_min_masks
  
         # ctc loss
         _lowercase     =	ctc_loss_reduction
         _lowercase     =	ctc_zero_infinity
  
     @property
     def 			SCREAMING_SNAKE_CASE__				(    self:	int	)  ->		Optional[int]:
  
  
         """simple docstring"""
  
  
  
         return functools.reduce(operator.mul   ,       self.conv_stride   ,       1	)
  