




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



				def __init__(      self      :		List[Any]		,	_UpperCAmelCase      :		Optional[int]		,	_UpperCAmelCase      :		Dict=14		,	_UpperCAmelCase      :		List[Any]=7		,	_UpperCAmelCase      :		Optional[Any]=True		,	_UpperCAmelCase      :		List[Any]=True		,	_UpperCAmelCase      :		Optional[Any]=True		,	_UpperCAmelCase      :		Optional[int]=True		,	_UpperCAmelCase      :		Any=True		,	_UpperCAmelCase      :		Union[str, Any]=99		,	_UpperCAmelCase      :		List[str]=32		,	_UpperCAmelCase      :		str=5		,	_UpperCAmelCase      :		Dict=4		,	_UpperCAmelCase      :		Dict=37		,	_UpperCAmelCase      :		Optional[int]="gelu"		,	_UpperCAmelCase      :		Optional[Any]=0.1		,	_UpperCAmelCase      :		int=0.1		,	_UpperCAmelCase      :		Optional[int]=512		,	_UpperCAmelCase      :		Optional[Any]=16		,	_UpperCAmelCase      :		Optional[int]=2		,	_UpperCAmelCase      :		Any=0.02		,	_UpperCAmelCase      :		Union[str, Any]=3		,	_UpperCAmelCase      :		Tuple=4		,	_UpperCAmelCase      :		Optional[int]=None		,	)  ->    Optional[Any]:





								'''simple docstring'''




								_lowerCAmelCase    :    Tuple										=      parent
								_lowerCAmelCase    :    Any										=      batch_size
								_lowerCAmelCase    :    Optional[Any]										=      seq_length
								_lowerCAmelCase    :    Dict										=      is_training
								_lowerCAmelCase    :    Union[str, Any]										=      use_token_type_ids
								_lowerCAmelCase    :    Any										=      use_input_mask
								_lowerCAmelCase    :    Optional[Any]										=      use_labels
								_lowerCAmelCase    :    Optional[Any]										=      use_mc_token_ids
								_lowerCAmelCase    :    List[Any]										=      vocab_size
								_lowerCAmelCase    :    Union[str, Any]										=      hidden_size
								_lowerCAmelCase    :    List[Any]										=      num_hidden_layers
								_lowerCAmelCase    :    List[Any]										=      num_attention_heads
								_lowerCAmelCase    :    List[Any]										=      intermediate_size
								_lowerCAmelCase    :    Any										=      hidden_act
								_lowerCAmelCase    :    Dict										=      hidden_dropout_prob
								_lowerCAmelCase    :    List[str]										=      attention_probs_dropout_prob
								_lowerCAmelCase    :    Any										=      max_position_embeddings
								_lowerCAmelCase    :    Tuple										=      type_vocab_size
								_lowerCAmelCase    :    List[Any]										=      type_sequence_label_size
								_lowerCAmelCase    :    str										=      initializer_range
								_lowerCAmelCase    :    str										=      num_labels
								_lowerCAmelCase    :    Union[str, Any]										=      num_choices
								_lowerCAmelCase    :    Dict										=      scope
								_lowerCAmelCase    :    str										=      self.vocab_size - 1



				def       SCREAMING_SNAKE_CASE       (      self      :		Any      )  ->    str:





								'''simple docstring'''




								_lowerCAmelCase    :    Dict										=      ids_tensor([self.batch_size, self.seq_length]		,	self.vocab_size      )

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

								_lowerCAmelCase    :    str										=      None
								if self.use_token_type_ids:
												_lowerCAmelCase    :    Optional[int]										=      ids_tensor([self.batch_size, self.seq_length]		,	self.type_vocab_size      )

								_lowerCAmelCase    :    List[Any]										=      None
								if self.use_mc_token_ids:
												_lowerCAmelCase    :    Optional[int]										=      ids_tensor([self.batch_size, self.num_choices]		,	self.seq_length      )

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

								_lowerCAmelCase    :    Dict										=      self.get_config()

								_lowerCAmelCase    :    List[Any]										=      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      :		Any      )  ->    Tuple:





								'''simple docstring'''




								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       SCREAMING_SNAKE_CASE       (      self      :		Optional[Any]		,	_UpperCAmelCase      :		Any		,	_UpperCAmelCase      :		Union[str, Any]		,	_UpperCAmelCase      :		int		,	_UpperCAmelCase      :		List[Any]		,	_UpperCAmelCase      :		int		,	*_UpperCAmelCase      :		List[Any]      )  ->    Dict:





								'''simple docstring'''




								_lowerCAmelCase    :    Optional[int]										=      CTRLModel(config=_UpperCAmelCase      )
								model.to(_UpperCAmelCase      )
								model.eval()

								model(_UpperCAmelCase		,	token_type_ids=_UpperCAmelCase		,	head_mask=_UpperCAmelCase      )
								model(_UpperCAmelCase		,	token_type_ids=_UpperCAmelCase      )
								_lowerCAmelCase    :    Union[str, Any]										=      model(_UpperCAmelCase      )
								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       SCREAMING_SNAKE_CASE       (      self      :		List[Any]		,	_UpperCAmelCase      :		Union[str, Any]		,	_UpperCAmelCase      :		Dict		,	_UpperCAmelCase      :		Optional[int]		,	_UpperCAmelCase      :		Optional[int]		,	_UpperCAmelCase      :		Dict		,	*_UpperCAmelCase      :		Union[str, Any]      )  ->    Dict:





								'''simple docstring'''




								_lowerCAmelCase    :    List[Any]										=      CTRLLMHeadModel(_UpperCAmelCase      )
								model.to(_UpperCAmelCase      )
								model.eval()

								_lowerCAmelCase    :    List[Any]										=      model(_UpperCAmelCase		,	token_type_ids=_UpperCAmelCase		,	labels=_UpperCAmelCase      )
								self.parent.assertEqual(result.loss.shape		,	()      )
								self.parent.assertEqual(result.logits.shape		,	(self.batch_size, self.seq_length, self.vocab_size)      )



				def       SCREAMING_SNAKE_CASE       (      self      :		Optional[int]      )  ->    str:





								'''simple docstring'''




								_lowerCAmelCase    :    List[str]										=      self.prepare_config_and_inputs()

								(
								    (
								    _lowerCAmelCase
								)					,    (
								    _lowerCAmelCase
								)					,    (
								    _lowerCAmelCase
								)					,    (
								    _lowerCAmelCase
								)					,    (
								    _lowerCAmelCase
								)					,    (
								    _lowerCAmelCase
								)					,    (
								    _lowerCAmelCase
								)					,    (
								    _lowerCAmelCase
								)					,    (
								    _lowerCAmelCase
								)					,    
								)    :    Dict										=      config_and_inputs

								_lowerCAmelCase    :    Any										=      {"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """head_mask""": head_mask}

								return config, inputs_dict



				def       SCREAMING_SNAKE_CASE       (      self      :		List[Any]		,	_UpperCAmelCase      :		Optional[int]		,	_UpperCAmelCase      :		Any		,	_UpperCAmelCase      :		Union[str, Any]		,	_UpperCAmelCase      :		Dict		,	*_UpperCAmelCase      :		Any      )  ->    Union[str, Any]:





								'''simple docstring'''




								_lowerCAmelCase    :    List[Any]										=      self.num_labels
								_lowerCAmelCase    :    Dict										=      CTRLForSequenceClassification(_UpperCAmelCase      )
								model.to(_UpperCAmelCase      )
								model.eval()
								_lowerCAmelCase    :    int										=      ids_tensor([self.batch_size]		,	self.type_sequence_label_size      )
								_lowerCAmelCase    :    List[Any]										=      model(_UpperCAmelCase		,	token_type_ids=_UpperCAmelCase		,	labels=_UpperCAmelCase      )
								self.parent.assertEqual(result.logits.shape		,	(self.batch_size, self.num_labels)      )






@require_torch
class        __snake_case  (_a						,	_a						,	_a						,	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       SCREAMING_SNAKE_CASE       (      self      :		Dict		,	_UpperCAmelCase      :		int		,	_UpperCAmelCase      :		Union[str, Any]		,	_UpperCAmelCase      :		Optional[int]		,	_UpperCAmelCase      :		str		,	_UpperCAmelCase      :		Dict      )  ->    List[str]:





								'''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      :		Union[str, Any]      )  ->    str:





								'''simple docstring'''




								_lowerCAmelCase    :    Union[str, Any]										=      CTRLModelTester(self      )
								_lowerCAmelCase    :    Union[str, Any]										=      ConfigTester(self		,	config_class=_UpperCAmelCase		,	n_embd=37      )



				def       SCREAMING_SNAKE_CASE       (      self      :		Union[str, Any]      )  ->    List[Any]:





								'''simple docstring'''




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



				def       SCREAMING_SNAKE_CASE       (      self      :		Optional[Any]      )  ->    List[Any]:





								'''simple docstring'''




								self.config_tester.run_common_tests()



				def       SCREAMING_SNAKE_CASE       (      self      :		str      )  ->    int:





								'''simple docstring'''




								_lowerCAmelCase    :    Dict										=      self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_ctrl_model(*_UpperCAmelCase      )



				def       SCREAMING_SNAKE_CASE       (      self      :		Dict      )  ->    int:





								'''simple docstring'''




								_lowerCAmelCase    :    int										=      self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_lm_head_model(*_UpperCAmelCase      )



				@unittest.skip("""Will be fixed soon by reducing the size of the model used for common tests."""      )
				def       SCREAMING_SNAKE_CASE       (      self      :		Tuple      )  ->    int:





								'''simple docstring'''




								pass



				@slow
				def       SCREAMING_SNAKE_CASE       (      self      :		Any      )  ->    List[str]:





								'''simple docstring'''




								for model_name in CTRL_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
												_lowerCAmelCase    :    str										=      CTRLModel.from_pretrained(_UpperCAmelCase      )
												self.assertIsNotNone(_UpperCAmelCase      )



				@unittest.skip("""The model doesn't support left padding"""      )  # and it's not used enough to be worth fixing :)
				def       SCREAMING_SNAKE_CASE       (      self      :		Tuple      )  ->    str:





								'''simple docstring'''




								pass






@require_torch
class        __snake_case  (unittest.TestCase		):



				def       SCREAMING_SNAKE_CASE       (      self      :		Optional[int]      )  ->    Any:





								'''simple docstring'''




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



				@slow
				def       SCREAMING_SNAKE_CASE       (      self      :		List[Any]      )  ->    Optional[Any]:





								'''simple docstring'''




								_lowerCAmelCase    :    Optional[int]										=      CTRLLMHeadModel.from_pretrained("""ctrl"""      )
								model.to(_UpperCAmelCase      )
								_lowerCAmelCase    :    Optional[int]										=      torch.tensor(
								    [[1_1859, 0, 1611, 8]]		,	dtype=torch.long		,	device=_UpperCAmelCase      )  # Legal the president is
								_lowerCAmelCase    :    str										=      [
								    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

								_lowerCAmelCase    :    Optional[int]										=      model.generate(_UpperCAmelCase		,	do_sample=_UpperCAmelCase      )
								self.assertListEqual(output_ids[0].tolist()		,	_UpperCAmelCase      )







def 							_UpperCAmelCase  (UpperCamelCase_ : str       ):
				'''simple docstring'''
				_lowerCAmelCase    :    List[str]										=      [int(UpperCamelCase_       ) for i in ip_va_address.split("""."""       ) if i.isdigit()]
				return len(UpperCamelCase_       ) == 4 and all(0 <= int(UpperCamelCase_       ) <= 254 for octet in octets       )


if __name__ == "__main__":
	_lowerCamelCase      :  List[str]      						=						input().strip()
	_lowerCamelCase      :  int      						=						"valid" if is_ip_va_address_valid(ip) else "invalid"
	print(F'''{ip} is a {valid_or_invalid} IP v4 address.''')

