"""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 							snake_case			(					_lowerCamelCase							):




					"""simple docstring"""

					def __init__(							self  :      str       ,lowerCamelCase__  :      List[str]       ,):
									UpperCAmelCase__			 =				parent
									UpperCAmelCase__			 =				13
									UpperCAmelCase__			 =				7
									UpperCAmelCase__			 =				True
									UpperCAmelCase__			 =				True
									UpperCAmelCase__			 =				True
									UpperCAmelCase__			 =				True
									UpperCAmelCase__			 =				True
									UpperCAmelCase__			 =				99
									UpperCAmelCase__			 =				32
									UpperCAmelCase__			 =				2
									UpperCAmelCase__			 =				4
									UpperCAmelCase__			 =				37
									UpperCAmelCase__			 =				"""gelu"""
									UpperCAmelCase__			 =				0.1
									UpperCAmelCase__			 =				0.1
									UpperCAmelCase__			 =				512
									UpperCAmelCase__			 =				16
									UpperCAmelCase__			 =				2
									UpperCAmelCase__			 =				0.0_2
									UpperCAmelCase__			 =				3
									UpperCAmelCase__			 =				4
									UpperCAmelCase__			 =				None
									UpperCAmelCase__			 =				self.vocab_size - 1







					def 						__lowerCAmelCase		(							self  :      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__			 =				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       ,)

									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 						__lowerCAmelCase		(							self  :      str       ,lowerCamelCase__  :      Dict       ,lowerCamelCase__  :      Tuple       ,lowerCamelCase__  :      Any       ,lowerCamelCase__  :      Optional[int]       ,lowerCamelCase__  :      int       ,*lowerCamelCase__  :      Optional[Any]     ):
									UpperCAmelCase__			 =				TFCTRLModel(config=a_     )
									UpperCAmelCase__			 =				{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
									UpperCAmelCase__			 =				model(a_     )

									UpperCAmelCase__			 =				[input_ids, None, input_mask]  # None is the input for 'past'
									UpperCAmelCase__			 =				model(a_     )

									UpperCAmelCase__			 =				model(a_     )

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







					def 						__lowerCAmelCase		(							self  :      str       ,lowerCamelCase__  :      List[str]       ,lowerCamelCase__  :      List[str]       ,lowerCamelCase__  :      Optional[Any]       ,lowerCamelCase__  :      str       ,lowerCamelCase__  :      int       ,*lowerCamelCase__  :      List[Any]     ):
									UpperCAmelCase__			 =				TFCTRLLMHeadModel(config=a_     )
									UpperCAmelCase__			 =				{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
									UpperCAmelCase__			 =				model(a_     )
									self.parent.assertEqual(result.logits.shape       ,(self.batch_size, self.seq_length, self.vocab_size)     )







					def 						__lowerCAmelCase		(							self  :      str       ,lowerCamelCase__  :      List[Any]       ,lowerCamelCase__  :      Any       ,lowerCamelCase__  :      Any       ,lowerCamelCase__  :      List[str]       ,lowerCamelCase__  :      Optional[Any]       ,*lowerCamelCase__  :      Optional[Any]     ):
									UpperCAmelCase__			 =				self.num_labels
									UpperCAmelCase__			 =				ids_tensor([self.batch_size]       ,self.type_sequence_label_size     )
									UpperCAmelCase__			 =				{
									    """input_ids""": input_ids,
									    """token_type_ids""": token_type_ids,
									    """labels""": sequence_labels,
									}
									UpperCAmelCase__			 =				TFCTRLForSequenceClassification(a_     )
									UpperCAmelCase__			 =				model(a_     )
									self.parent.assertEqual(result.logits.shape       ,(self.batch_size, self.num_labels)     )







					def 						__lowerCAmelCase		(							self  :      List[str]     ):
									UpperCAmelCase__			 =				self.prepare_config_and_inputs()

									(
									    UpperCAmelCase__
									)			 =				config_and_inputs

									UpperCAmelCase__			 =				{"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
									return config, inputs_dict






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




					"""simple docstring"""

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







					def 						__lowerCAmelCase		(							self  :      Any       ,lowerCamelCase__  :      Optional[Any]       ,lowerCamelCase__  :      Optional[Any]       ,lowerCamelCase__  :      Optional[int]       ,lowerCamelCase__  :      Dict       ,lowerCamelCase__  :      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 						__lowerCAmelCase		(							self  :      int     ):
									UpperCAmelCase__			 =				TFCTRLModelTester(self     )
									UpperCAmelCase__			 =				ConfigTester(self       ,config_class=a_       ,n_embd=37     )







					def 						__lowerCAmelCase		(							self  :      str     ):
									self.config_tester.run_common_tests()







					def 						__lowerCAmelCase		(							self  :      Dict     ):
									UpperCAmelCase__			 =				self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_ctrl_model(*a_     )







					def 						__lowerCAmelCase		(							self  :      Optional[int]     ):
									UpperCAmelCase__			 =				self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_ctrl_lm_head(*a_     )







					def 						__lowerCAmelCase		(							self  :      int     ):
									UpperCAmelCase__			 =				self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_ctrl_for_sequence_classification(*a_     )







					def 						__lowerCAmelCase		(							self  :      int     ):
									UpperCAmelCase__			 =				self.model_tester.prepare_config_and_inputs_for_common()
									UpperCAmelCase__			 =				[TFCTRLLMHeadModel]
									UpperCAmelCase__			 =				[TFCTRLForSequenceClassification]

									for model_class in self.all_model_classes:
													UpperCAmelCase__			 =				model_class(a_     )
													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:
																	UpperCAmelCase__			 =				model.get_output_embeddings()
																	assert isinstance(a_       ,tf.keras.layers.Layer     )
																	UpperCAmelCase__			 =				model.get_bias()
																	assert isinstance(a_       ,a_     )
																	for k, v in name.items():
																					assert isinstance(a_       ,tf.Variable     )
													elif model_class in list_other_models_with_output_ebd:
																	UpperCAmelCase__			 =				model.get_output_embeddings()
																	assert isinstance(a_       ,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







					@slow
					def 						__lowerCAmelCase		(							self  :      Dict     ):
									for model_name in TF_CTRL_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
													UpperCAmelCase__			 =				TFCTRLModel.from_pretrained(a_     )
													self.assertIsNotNone(a_     )






@require_tf
class 							snake_case			(					unittest.TestCase							):




					"""simple docstring"""

					@slow
					def 						__lowerCAmelCase		(							self  :      List[str]     ):
									UpperCAmelCase__			 =				TFCTRLLMHeadModel.from_pretrained('ctrl'     )
									UpperCAmelCase__			 =				tf.convert_to_tensor([[11_859, 0, 1_611, 8]]       ,dtype=tf.intaa     )  # Legal the president is
									UpperCAmelCase__			 =				[
									    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

									UpperCAmelCase__			 =				model.generate(a_       ,do_sample=a_     )
									self.assertListEqual(output_ids[0].numpy().tolist()       ,a_     )








'''simple docstring'''






def        snake_case_   (	lowerCAmelCase_			,  lowerCAmelCase_						)->						float:





       '''simple docstring'''


       return a + b


if __name__ == "__main__":
   A_				:					Tuple							=      5
   A_				:					Tuple							=      6
   print(f"""The sum of {a} + {b} is {add(a, b)}""")



