





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





     """simple docstring"""



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





        '''simple docstring'''




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



     def     SCREAMING_SNAKE_CASE		(				self							:Optional[Any]	):





        '''simple docstring'''




        A_       :					Optional[int]        =      ids_tensor([self.batch_size, self.seq_length]      ,   self.vocab_size	)

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

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

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

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

        A_       :					Tuple        =      self.get_config()

        A_       :					int        =      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	):





        '''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							:Dict      ,   snake_case							:Optional[Any]      ,   snake_case							:str      ,   snake_case							:List[str]      ,   snake_case							:Any      ,   snake_case							:Tuple      ,   *snake_case							:Tuple	):





        '''simple docstring'''




        A_       :					Dict        =      CTRLModel(config=snake_case	)
        model.to(snake_case	)
        model.eval()

        model(snake_case      ,   token_type_ids=snake_case      ,   head_mask=snake_case	)
        model(snake_case      ,   token_type_ids=snake_case	)
        A_       :					List[str]        =      model(snake_case	)
        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[str]      ,   snake_case							:Tuple      ,   snake_case							:int      ,   snake_case							:Any      ,   snake_case							:int      ,   snake_case							:Any      ,   *snake_case							:Optional[int]	):





        '''simple docstring'''




        A_       :					List[Any]        =      CTRLLMHeadModel(snake_case	)
        model.to(snake_case	)
        model.eval()

        A_       :					Any        =      model(snake_case      ,   token_type_ids=snake_case      ,   labels=snake_case	)
        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							:Union[str, Any]	):





        '''simple docstring'''




        A_       :					Optional[Any]        =      self.prepare_config_and_inputs()

        (
            (
            A_
        )   ,    (
            A_
        )   ,    (
            A_
        )   ,    (
            A_
        )   ,    (
            A_
        )   ,    (
            A_
        )   ,    (
            A_
        )   ,    (
            A_
        )   ,    (
            A_
        )   ,    
        )       :					List[Any]        =      config_and_inputs

        A_       :					Optional[int]        =      {"input_ids": input_ids, "token_type_ids": token_type_ids, "head_mask": head_mask}

        return config, inputs_dict





     def     SCREAMING_SNAKE_CASE		(				self							:Union[str, Any]      ,   snake_case							:Dict      ,   snake_case							:Dict      ,   snake_case							:Dict      ,   snake_case							:int      ,   *snake_case							:Optional[Any]	):





        '''simple docstring'''




        A_       :					str        =      self.num_labels
        A_       :					str        =      CTRLForSequenceClassification(snake_case	)
        model.to(snake_case	)
        model.eval()
        A_       :					List[Any]        =      ids_tensor([self.batch_size]      ,   self.type_sequence_label_size	)
        A_       :					str        =      model(snake_case      ,   token_type_ids=snake_case      ,   labels=snake_case	)
        self.parent.assertEqual(result.logits.shape      ,   (self.batch_size, self.num_labels)	)




@require_torch
class        __magic_name__	(				lowerCamelCase__     ,					lowerCamelCase__     ,					lowerCamelCase__     ,					unittest.TestCase				):





     """simple docstring"""



     __UpperCamelCase            =  (CTRLModel, CTRLLMHeadModel, CTRLForSequenceClassification) if is_torch_available() else ()
     __UpperCamelCase            =  (CTRLLMHeadModel,) if is_torch_available() else ()
     __UpperCamelCase            =  (
         {
             '''feature-extraction''': CTRLModel,
             '''text-classification''': CTRLForSequenceClassification,
             '''text-generation''': CTRLLMHeadModel,
             '''zero-shot''': CTRLForSequenceClassification,
         }
         if is_torch_available()
         else {}
     )
     __UpperCamelCase            =  True
     __UpperCamelCase            =  False
     __UpperCamelCase            =  False



     def     SCREAMING_SNAKE_CASE		(				self							:int      ,   snake_case							:List[str]      ,   snake_case							:Optional[int]      ,   snake_case							:Optional[int]      ,   snake_case							:Tuple      ,   snake_case							:int	):





        '''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							:int	):





        '''simple docstring'''




        A_       :					Optional[int]        =      CTRLModelTester(self	)
        A_       :					Optional[int]        =      ConfigTester(self      ,   config_class=snake_case      ,   n_embd=37	)



     def     SCREAMING_SNAKE_CASE		(				self							:Union[str, 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							:int	):





        '''simple docstring'''




        self.config_tester.run_common_tests()



     def     SCREAMING_SNAKE_CASE		(				self							:str	):





        '''simple docstring'''




        A_       :					List[Any]        =      self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_ctrl_model(*snake_case	)



     def     SCREAMING_SNAKE_CASE		(				self							:Tuple	):





        '''simple docstring'''




        A_       :					Any        =      self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_lm_head_model(*snake_case	)



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





        '''simple docstring'''




        pass



     @slow
     def     SCREAMING_SNAKE_CASE		(				self							:Tuple	):





        '''simple docstring'''




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





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





        '''simple docstring'''




        pass




@require_torch
class        __magic_name__	(				unittest.TestCase				):





     """simple docstring"""



     def     SCREAMING_SNAKE_CASE		(				self							:Union[str, 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							:Optional[int]	):





        '''simple docstring'''




        A_       :					int        =      CTRLLMHeadModel.from_pretrained("ctrl"	)
        model.to(snake_case	)
        A_       :					List[Any]        =      torch.tensor(
            [[11_859, 0, 1_611, 8]]      ,   dtype=torch.long      ,   device=snake_case	)  # Legal the president is
        A_       :					Tuple        =      [
            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

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







from __future__ import annotations

def   __snake_case    (       _lowerCAmelCase			:			list[int]					,					_lowerCAmelCase			:			int						)			->    list[list[int]]:
   A_       :					list[list[int]]        =      []
   A_       :					list[int]        =      []
   A_       :					Dict        =      0
   A_       :					str        =      sum(_lowerCAmelCase						)
   create_state_space_tree(_lowerCAmelCase					,					_lowerCAmelCase					,					_lowerCAmelCase					,					_lowerCAmelCase					,					_lowerCAmelCase					,					_lowerCAmelCase						)
   return result

def   __snake_case    (       _lowerCAmelCase			:			list[int]					,					_lowerCAmelCase			:			int					,					_lowerCAmelCase			:			int					,					_lowerCAmelCase			:			list[int]					,					_lowerCAmelCase			:			list[list[int]]					,					_lowerCAmelCase			:			int					,					)			->    None:
   if sum(_lowerCAmelCase						) > max_sum or (remaining_nums_sum + sum(_lowerCAmelCase						)) < max_sum:
      return
   if sum(_lowerCAmelCase						) == max_sum:
      result.append(_lowerCAmelCase						)
      return
   for index in range(_lowerCAmelCase					,					len(_lowerCAmelCase						)						):
      create_state_space_tree(
          _lowerCAmelCase					,					_lowerCAmelCase					,					index + 1					,					[*path, nums[index]]					,					_lowerCAmelCase					,					remaining_nums_sum - nums[index]					,					)
_lowerCAmelCase				:   List[Any]						       =						[3, 34, 4, 12, 5, 2]
_lowerCAmelCase				:   Dict						       =						9
_lowerCAmelCase				:   Dict						       =						generate_sum_of_subsets_soln(nums, max_sum)





print(*result)
