





"""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  __UpperCamelCase       :






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






							def 					__a     (     self   )			->				Union[str, Any]:
								a   :	Union[str, Any]			=       ids_tensor([self.batch_size, self.seq_length]   ,      self.vocab_size   )

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

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

								a   :	Optional[Any]			=       None
								if self.use_mc_token_ids:
									a   :	Tuple			=       ids_tensor([self.batch_size, self.num_choices]   ,      self.seq_length   )

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

								a   :	int			=       self.get_config()

								a   :	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 					__a     (     self   )			->				Optional[Any]:
								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 					__a     (     self   ,      lowerCAmelCase__   ,      lowerCAmelCase__   ,      lowerCAmelCase__   ,      lowerCAmelCase__   ,      lowerCAmelCase__   ,      *lowerCAmelCase__   )			->				Dict:
								a   :	Union[str, Any]			=       CTRLModel(config=lowerCAmelCase__   )
								model.to(lowerCAmelCase__   )
								model.eval()

								model(lowerCAmelCase__   ,      token_type_ids=lowerCAmelCase__   ,      head_mask=lowerCAmelCase__   )
								model(lowerCAmelCase__   ,      token_type_ids=lowerCAmelCase__   )
								a   :	str			=       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 					__a     (     self   ,      lowerCAmelCase__   ,      lowerCAmelCase__   ,      lowerCAmelCase__   ,      lowerCAmelCase__   ,      lowerCAmelCase__   ,      *lowerCAmelCase__   )			->				Any:
								a   :	Any			=       CTRLLMHeadModel(lowerCAmelCase__   )
								model.to(lowerCAmelCase__   )
								model.eval()

								a   :	int			=       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 					__a     (     self   )			->				Dict:
								a   :	Union[str, Any]			=       self.prepare_config_and_inputs()

								(
								    (
								    a
								), (
								    a
								), (
								    a
								), (
								    a
								), (
								    a
								), (
								    a
								), (
								    a
								), (
								    a
								), (
								    a
								), 
								)   :	Optional[Any]			=       config_and_inputs

								a   :	Optional[Any]			=       {"input_ids": input_ids, "token_type_ids": token_type_ids, "head_mask": head_mask}

								return config, inputs_dict






							def 					__a     (     self   ,      lowerCAmelCase__   ,      lowerCAmelCase__   ,      lowerCAmelCase__   ,      lowerCAmelCase__   ,      *lowerCAmelCase__   )			->				Any:
								a   :	List[Any]			=       self.num_labels
								a   :	Any			=       CTRLForSequenceClassification(lowerCAmelCase__   )
								model.to(lowerCAmelCase__   )
								model.eval()
								a   :	Optional[Any]			=       ids_tensor([self.batch_size]   ,      self.type_sequence_label_size   )
								a   :	Any			=       model(lowerCAmelCase__   ,      token_type_ids=lowerCAmelCase__   ,      labels=lowerCAmelCase__   )
								self.parent.assertEqual(result.logits.shape   ,      (self.batch_size, self.num_labels)   )


@require_torch
class  __UpperCamelCase       (		a__	, a__	, a__	, unittest.TestCase		):
							lowerCamelCase     :      List[str]         =(CTRLModel, CTRLLMHeadModel, CTRLForSequenceClassification) if is_torch_available() else ()
							lowerCamelCase     :      List[str]         =(CTRLLMHeadModel,) if is_torch_available() else ()
							lowerCamelCase     :      Optional[Any]         =(
							    {
							        """feature-extraction""": CTRLModel,
							        """text-classification""": CTRLForSequenceClassification,
							        """text-generation""": CTRLLMHeadModel,
							        """zero-shot""": CTRLForSequenceClassification,
							    }
							    if is_torch_available()
							    else {}
							)
							lowerCamelCase     :      Optional[Any]         =True
							lowerCamelCase     :      Dict         =False
							lowerCamelCase     :      Optional[int]         =False






							def 					__a     (     self   ,      lowerCAmelCase__   ,      lowerCAmelCase__   ,      lowerCAmelCase__   ,      lowerCAmelCase__   ,      lowerCAmelCase__   )			->				List[Any]:
								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   )			->				Union[str, Any]:
								a   :	Any			=       CTRLModelTester(self   )
								a   :	Union[str, Any]			=       ConfigTester(self   ,      config_class=lowerCAmelCase__   ,      n_embd=37   )






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






							def 					__a     (     self   )			->				Optional[Any]:
								self.config_tester.run_common_tests()






							def 					__a     (     self   )			->				List[Any]:
								a   :	Any			=       self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_ctrl_model(*lowerCAmelCase__   )






							def 					__a     (     self   )			->				Any:
								a   :	Optional[Any]			=       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 					__a     (     self   )			->				Dict:
								pass






							@slow
							def 					__a     (     self   )			->				Dict:
								for model_name in CTRL_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
									a   :	Tuple			=       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 					__a     (     self   )			->				Optional[Any]:
								pass


@require_torch
class  __UpperCamelCase       (		unittest.TestCase		):






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






							@slow
							def 					__a     (     self   )			->				Dict:
								a   :	Union[str, Any]			=       CTRLLMHeadModel.from_pretrained("ctrl"   )
								model.to(lowerCAmelCase__   )
								a   :	str			=       torch.tensor(
								    [[1_1859, 0, 1611, 8]]   ,      dtype=torch.long   ,      device=lowerCAmelCase__   )  # Legal the president is
								a   :	Optional[int]			=       [
								    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

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









"""simple docstring"""




def    _SCREAMING_SNAKE_CASE	(			_lowercase		:					int = 200      )				->int:






	'''simple docstring'''






	a   :	Dict			=       [1, 2, 5, 10, 20, 50, 100, 200]
	a   :	Optional[Any]			=       [0] * (pence + 1)
	a   :	List[Any]			=       1  # base case: 1 way to make 0 pence

	for coin in coins:
		for i in range(_lowercase					, pence + 1					, 1      ):
			number_of_ways[i] += number_of_ways[i - coin]
	return number_of_ways[pence]


if __name__ == "__main__":
		assert solution(200) == 73682


