
'''simple docstring'''






from collections import OrderedDict
from typing import Any, List, Mapping, Optional

from ... import PreTrainedTokenizer, TensorType, is_torch_available
from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfigWithPast, PatchingSpec
from ...utils import logging


UpperCAmelCase_							: Optional[Any] =							logging.get_logger(__name__)


UpperCAmelCase_							: Union[str, Any] =							{
    'Salesforce/codegen-350M-nl': 'https://huggingface.co/Salesforce/codegen-350M-nl/resolve/main/config.json',
    'Salesforce/codegen-350M-multi': 'https://huggingface.co/Salesforce/codegen-350M-multi/resolve/main/config.json',
    'Salesforce/codegen-350M-mono': 'https://huggingface.co/Salesforce/codegen-350M-mono/resolve/main/config.json',
    'Salesforce/codegen-2B-nl': 'https://huggingface.co/Salesforce/codegen-2B-nl/resolve/main/config.json',
    'Salesforce/codegen-2B-multi': 'https://huggingface.co/Salesforce/codegen-2B-multi/resolve/main/config.json',
    'Salesforce/codegen-2B-mono': 'https://huggingface.co/Salesforce/codegen-2B-mono/resolve/main/config.json',
    'Salesforce/codegen-6B-nl': 'https://huggingface.co/Salesforce/codegen-6B-nl/resolve/main/config.json',
    'Salesforce/codegen-6B-multi': 'https://huggingface.co/Salesforce/codegen-6B-multi/resolve/main/config.json',
    'Salesforce/codegen-6B-mono': 'https://huggingface.co/Salesforce/codegen-6B-mono/resolve/main/config.json',
    'Salesforce/codegen-16B-nl': 'https://huggingface.co/Salesforce/codegen-16B-nl/resolve/main/config.json',
    'Salesforce/codegen-16B-multi': 'https://huggingface.co/Salesforce/codegen-16B-multi/resolve/main/config.json',
    'Salesforce/codegen-16B-mono': 'https://huggingface.co/Salesforce/codegen-16B-mono/resolve/main/config.json',
}

class 			UpperCAmelCase__    (							A			):
    lowerCAmelCase_					     =		'codegen'
    lowerCAmelCase_					     =		{
        'max_position_embeddings': 'n_positions',
        'hidden_size': 'n_embd',
        'num_attention_heads': 'n_head',
        'num_hidden_layers': 'n_layer',
    }



    def __init__(						self   :							Dict,__A   :							Optional[int]=5_0_4_0_0,__A   :							Optional[int]=2_0_4_8,__A   :							Optional[Any]=2_0_4_8,__A   :							Optional[int]=4_0_9_6,__A   :							List[Any]=2_8,__A   :							Optional[Any]=1_6,__A   :							int=6_4,__A   :							str=None,__A   :							Dict="gelu_new",__A   :							Tuple=0.0,__A   :							List[Any]=0.0,__A   :							Dict=0.0,__A   :							List[Any]=1e-5,__A   :							List[str]=0.02,__A   :							Tuple=True,__A   :							List[str]=5_0_2_5_6,__A   :							Optional[int]=5_0_2_5_6,__A   :							int=False,**__A   :							List[Any],):
          _lowerCamelCase					: Optional[int]		    = vocab_size
          _lowerCamelCase					: str		    = n_ctx
          _lowerCamelCase					: Optional[int]		    = n_positions
          _lowerCamelCase					: Any		    = n_embd
          _lowerCamelCase					: Dict		    = n_layer
          _lowerCamelCase					: Tuple		    = n_head
          _lowerCamelCase					: str		    = n_inner
          _lowerCamelCase					: List[str]		    = rotary_dim
          _lowerCamelCase					: str		    = activation_function
          _lowerCamelCase					: Any		    = resid_pdrop
          _lowerCamelCase					: List[Any]		    = embd_pdrop
          _lowerCamelCase					: Optional[Any]		    = attn_pdrop
          _lowerCamelCase					: Optional[int]		    = layer_norm_epsilon
          _lowerCamelCase					: Union[str, Any]		    = initializer_range
          _lowerCamelCase					: Dict		    = use_cache

          _lowerCamelCase					: str		    = bos_token_id
          _lowerCamelCase					: Union[str, Any]		    = eos_token_id

          super().__init__(
              bos_token_id=__A,eos_token_id=__A,tie_word_embeddings=__A,**__A  )


class 			UpperCAmelCase__    (							A			):



    def __init__(						self   :							Any,__A   :							PretrainedConfig,__A   :							str = "default",__A   :							List[PatchingSpec] = None,__A   :							bool = False,):
          super().__init__(__A,task=__A,patching_specs=__A,use_past=__A  )
          if not getattr(self._config,"pad_token_id",__A  ):
                # TODO: how to do that better?
                _lowerCamelCase					: Optional[Any]		    = 0



    @property
    def 	lowerCamelCase_	(						self   :							str  ):
          _lowerCamelCase					: List[Any]		    = OrderedDict({"input_ids": {0: "batch", 1: "sequence"}}  )
          if self.use_past:
                self.fill_with_past_key_values_(__A,direction="inputs"  )
                _lowerCamelCase					: List[Any]		    = {0: "batch", 1: "past_sequence + sequence"}
          else:
                _lowerCamelCase					: Optional[int]		    = {0: "batch", 1: "sequence"}

          return common_inputs



    @property
    def 	lowerCamelCase_	(						self   :							int  ):
          return self._config.n_layer



    @property
    def 	lowerCamelCase_	(						self   :							Union[str, Any]  ):
          return self._config.n_head



    def 	lowerCamelCase_	(						self   :							Any,__A   :							PreTrainedTokenizer,__A   :							int = -1,__A   :							int = -1,__A   :							bool = False,__A   :							Optional[TensorType] = None,):
          _lowerCamelCase					: Any		    = super(__A,self  ).generate_dummy_inputs(
              __A,batch_size=__A,seq_length=__A,is_pair=__A,framework=__A  )

          # We need to order the input in the way they appears in the forward()
          _lowerCamelCase					: Tuple		    = OrderedDict({"input_ids": common_inputs["input_ids"]}  )

          # Need to add the past_keys
          if self.use_past:
                if not is_torch_available():
                      raise ValueError("Cannot generate dummy past_keys inputs without PyTorch installed."  )
                else:
                      import torch

                      _lowerCamelCase    ,		_lowerCamelCase					: Any		    = common_inputs["input_ids"].shape
                      # Not using the same length for past_key_values
                      _lowerCamelCase					: List[Any]		    = seqlen + 2
                      _lowerCamelCase					: Dict		    = (
                          batch,
                          self.num_attention_heads,
                          past_key_values_length,
                          self._config.hidden_size // self.num_attention_heads,
                      )
                      _lowerCamelCase					: Dict		    = [
                          (torch.zeros(__A  ), torch.zeros(__A  )) for _ in range(self.num_layers  )
                      ]

          _lowerCamelCase					: Dict		    = common_inputs["attention_mask"]
          if self.use_past:
                _lowerCamelCase					: Optional[int]		    = ordered_inputs["attention_mask"].dtype
                _lowerCamelCase					: str		    = torch.cat(
                    [ordered_inputs["attention_mask"], torch.ones(__A,__A,dtype=__A  )],dim=1  )

          return ordered_inputs



    @property
    def 	lowerCamelCase_	(						self   :							Tuple  ):
          return 1_3






from collections import defaultdict


class        __magic_name__	:





     """simple docstring"""



     def __init__(				self							:int      ,   snake_case							:Dict      ,   snake_case							:Optional[Any]	):





        '''simple docstring'''




        A_       :					Optional[int]        =      total  # total no of tasks (N)

        # DP table will have a dimension of (2^M)*N
        # initially all values are set to -1
        A_       :					str        =      [
            [-1 for i in range(total + 1	)] for j in range(2 ** len(snake_case	)	)
        ]

        A_       :					Optional[int]        =      defaultdict(snake_case	)  # stores the list of persons for each task

        # final_mask is used to check if all persons are included by setting all bits
        # to 1
        A_       :					Dict        =      (1 << len(snake_case	)) - 1



     def     SCREAMING_SNAKE_CASE		(				self							:Union[str, Any]      ,   snake_case							:Union[str, Any]      ,   snake_case							:str	):





        '''simple docstring'''




        if mask == self.final_mask:
           return 1

        # if not everyone gets the task and no more tasks are available, return 0
        if task_no > self.total_tasks:
           return 0

        # if case already considered
        if self.dp[mask][task_no] != -1:
           return self.dp[mask][task_no]

        # Number of ways when we don't this task in the arrangement
        A_       :					Tuple        =      self.count_ways_until(snake_case      ,   task_no + 1	)

        # now assign the tasks one by one to all possible persons and recursively
        # assign for the remaining tasks.
        if task_no in self.task:
           for p in self.task[task_no]:
              # if p is already given a task
              if mask & (1 << p):
                 continue

              # assign this task to p and change the mask value. And recursively
              # assign tasks with the new mask value.
              total_ways_util += self.count_ways_until(mask | (1 << p)      ,   task_no + 1	)

        # save the value.
        A_       :					Any        =      total_ways_util

        return self.dp[mask][task_no]





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





        '''simple docstring'''




        for i in range(len(snake_case	)	):
           for j in task_performed[i]:
              self.task[j].append(snake_case	)

        # call the function to fill the DP table, final answer is stored in dp[0][1]
        return self.count_ways_until(0      ,   1	)


if __name__ == "__main__":
 _lowerCAmelCase				:   Dict						       =						5  # total no of tasks (the value of N)

 # the list of tasks that can be done by M persons.
 _lowerCAmelCase				:   str						       =						[[1, 3, 4], [1, 2, 5], [3, 4]]
 print(
     AssignmentUsingBitmask(task_performed, total_tasks).count_no_of_ways(
         task_performed
     )
 )
