




'''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    __lowercase						:







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







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

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

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

     __a			=					None
     if self.use_mc_token_ids:
       __a			=					ids_tensor([self.batch_size, self.num_choices]      ,							self.seq_length      )

     __a			=					None
     __a			=					None
     __a			=					None
     if self.use_labels:
       __a			=					ids_tensor([self.batch_size]      ,							self.type_sequence_label_size      )
       __a			=					ids_tensor([self.batch_size, self.seq_length]      ,							self.num_labels      )
       __a			=					ids_tensor([self.batch_size]      ,							self.num_choices      )

     __a			=					self.get_config()

     __a			=					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 		UpperCamelCase__			(	self      )				->    Tuple:
     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 		UpperCamelCase__			(	self      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      ,							*UpperCamelCase      )				->    List[Any]:
     __a			=					CTRLModel(config=UpperCamelCase      )
     model.to(UpperCamelCase      )
     model.eval()

     model(UpperCamelCase      ,							token_type_ids=UpperCamelCase      ,							head_mask=UpperCamelCase      )
     model(UpperCamelCase      ,							token_type_ids=UpperCamelCase      )
     __a			=					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 		UpperCamelCase__			(	self      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      ,							*UpperCamelCase      )				->    Optional[int]:
     __a			=					CTRLLMHeadModel(UpperCamelCase      )
     model.to(UpperCamelCase      )
     model.eval()

     __a			=					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 		UpperCamelCase__			(	self      )				->    Tuple:
     __a			=					self.prepare_config_and_inputs()

     (
         (
         __a       
     )	,       (
         __a       
     )	,       (
         __a       
     )	,       (
         __a       
     )	,       (
         __a       
     )	,       (
         __a       
     )	,       (
         __a       
     )	,       (
         __a       
     )	,       (
         __a       
     )	,              
     )			=					config_and_inputs

     __a			=					{'input_ids': input_ids, 'token_type_ids': token_type_ids, 'head_mask': head_mask}

     return config, inputs_dict







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





@require_torch
class    __lowercase						(  __magic_name__       ,							__magic_name__       ,							__magic_name__       ,							unittest.TestCase ):
   _a							=      (CTRLModel, CTRLLMHeadModel, CTRLForSequenceClassification) if is_torch_available() else ()
   _a							=      (CTRLLMHeadModel,) if is_torch_available() else ()
   _a							=      (
       {
           """feature-extraction""": CTRLModel,
           """text-classification""": CTRLForSequenceClassification,
           """text-generation""": CTRLLMHeadModel,
           """zero-shot""": CTRLForSequenceClassification,
       }
       if is_torch_available()
       else {}
   )
   _a							=      True
   _a							=      False
   _a							=      False







   def 		UpperCamelCase__			(	self      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      ,							UpperCamelCase      )				->    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 		UpperCamelCase__			(	self      )				->    Any:
     __a			=					CTRLModelTester(self      )
     __a			=					ConfigTester(self      ,							config_class=UpperCamelCase      ,							n_embd=37      )







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







   def 		UpperCamelCase__			(	self      )				->    int:
     self.config_tester.run_common_tests()







   def 		UpperCamelCase__			(	self      )				->    Tuple:
     __a			=					self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_ctrl_model(*UpperCamelCase      )







   def 		UpperCamelCase__			(	self      )				->    int:
     __a			=					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 		UpperCamelCase__			(	self      )				->    Tuple:
     pass







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





@require_torch
class    __lowercase						(  unittest.TestCase ):







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







   @slow
   def 		UpperCamelCase__			(	self      )				->    Dict:
     __a			=					CTRLLMHeadModel.from_pretrained('ctrl'      )
     model.to(UpperCamelCase      )
     __a			=					torch.tensor(
         [[1_1859, 0, 1611, 8]]      ,							dtype=torch.long      ,							device=UpperCamelCase      )  # Legal the president is
     __a			=					[
         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			=					model.generate(UpperCamelCase      ,							do_sample=UpperCamelCase      )
     self.assertListEqual(output_ids[0].tolist()      ,							UpperCamelCase      )









'''simple docstring'''


def 						SCREAMING_SNAKE_CASE       (      a_	:							int = 10**12			):
  __a			=					1
  __a			=					0

  __a			=					1
  __a			=					1

  while numerator <= 2 * min_total - 1:
    prev_numerator += 2 * numerator
    numerator += 2 * prev_numerator

    prev_denominator += 2 * denominator
    denominator += 2 * prev_denominator

  return (denominator + 1) // 2


if __name__ == "__main__":
  print(f"""{solution() = }""")



