





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


__A     =    logging.get_logger(__name__)


__A     =    {
    "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        _SCREAMING_SNAKE_CASE						(     __SCREAMING_SNAKE_CASE   ):







 '''simple docstring'''
 lowercase_		=      "codegen"
 lowercase_		=      {
     "max_position_embeddings": "n_positions",
     "hidden_size": "n_embd",
     "num_attention_heads": "n_head",
     "num_hidden_layers": "n_layer",
 }

 def __init__(self    :       Union[str, Any]	,			UpperCAmelCase_    :       Optional[Any]=50_400	,			UpperCAmelCase_    :       Optional[Any]=2_048	,			UpperCAmelCase_    :       str=2_048	,			UpperCAmelCase_    :       Union[str, Any]=4_096	,			UpperCAmelCase_    :       List[str]=28	,			UpperCAmelCase_    :       Union[str, Any]=16	,			UpperCAmelCase_    :       Dict=64	,			UpperCAmelCase_    :       Any=None	,			UpperCAmelCase_    :       Optional[int]="gelu_new"	,			UpperCAmelCase_    :       List[Any]=0.0	,			UpperCAmelCase_    :       Optional[int]=0.0	,			UpperCAmelCase_    :       Any=0.0	,			UpperCAmelCase_    :       Optional[Any]=1E-5	,			UpperCAmelCase_    :       Tuple=0.02	,			UpperCAmelCase_    :       List[str]=True	,			UpperCAmelCase_    :       Any=50_256	,			UpperCAmelCase_    :       Union[str, Any]=50_256	,			UpperCAmelCase_    :       Union[str, Any]=False	,			**UpperCAmelCase_    :       List[str]	,			)	->Optional[int]:



   '''simple docstring'''



   lowerCamelCase__:				Optional[Any]        =vocab_size
   lowerCamelCase__:				int        =n_ctx
   lowerCamelCase__:				str        =n_positions
   lowerCamelCase__:				str        =n_embd
   lowerCamelCase__:				Optional[int]        =n_layer
   lowerCamelCase__:				Dict        =n_head
   lowerCamelCase__:				Tuple        =n_inner
   lowerCamelCase__:				Optional[int]        =rotary_dim
   lowerCamelCase__:				Tuple        =activation_function
   lowerCamelCase__:				Optional[Any]        =resid_pdrop
   lowerCamelCase__:				int        =embd_pdrop
   lowerCamelCase__:				Tuple        =attn_pdrop
   lowerCamelCase__:				Union[str, Any]        =layer_norm_epsilon
   lowerCamelCase__:				List[Any]        =initializer_range
   lowerCamelCase__:				Any        =use_cache

   lowerCamelCase__:				Optional[Any]        =bos_token_id
   lowerCamelCase__:				int        =eos_token_id

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



class        _SCREAMING_SNAKE_CASE						(     __SCREAMING_SNAKE_CASE   ):







 '''simple docstring'''

 def __init__(self    :       List[Any]	,			UpperCAmelCase_    :       PretrainedConfig	,			UpperCAmelCase_    :       str = "default"	,			UpperCAmelCase_    :       List[PatchingSpec] = None	,			UpperCAmelCase_    :       bool = False	,			)	->Optional[int]:



   '''simple docstring'''



   super().__init__(UpperCAmelCase_	,			task=UpperCAmelCase_	,			patching_specs=UpperCAmelCase_	,			use_past=UpperCAmelCase_)
   if not getattr(self._config	,			"pad_token_id"	,			UpperCAmelCase_):
     # TODO: how to do that better?
     lowerCamelCase__:				Optional[Any]        =0

 @property
 def 							SCREAMING_SNAKE_CASE_ (self    :       Optional[int])	->Mapping[str, Mapping[int, str]]:



   '''simple docstring'''



   lowerCamelCase__:				Any        =OrderedDict({"input_ids": {0: "batch", 1: "sequence"}})
   if self.use_past:
     self.fill_with_past_key_values_(UpperCAmelCase_	,			direction="inputs")
     lowerCamelCase__:				Optional[Any]        ={0: "batch", 1: "past_sequence + sequence"}
   else:
     lowerCamelCase__:				Tuple        ={0: "batch", 1: "sequence"}

   return common_inputs

 @property
 def 							SCREAMING_SNAKE_CASE_ (self    :       Optional[Any])	->int:



   '''simple docstring'''



   return self._config.n_layer

 @property
 def 							SCREAMING_SNAKE_CASE_ (self    :       Optional[int])	->int:



   '''simple docstring'''



   return self._config.n_head

 def 							SCREAMING_SNAKE_CASE_ (self    :       Optional[Any]	,			UpperCAmelCase_    :       PreTrainedTokenizer	,			UpperCAmelCase_    :       int = -1	,			UpperCAmelCase_    :       int = -1	,			UpperCAmelCase_    :       bool = False	,			UpperCAmelCase_    :       Optional[TensorType] = None	,			)	->Mapping[str, Any]:



   '''simple docstring'''



   lowerCamelCase__:				Union[str, Any]        =super(UpperCAmelCase_	,			self).generate_dummy_inputs(
       UpperCAmelCase_	,			batch_size=UpperCAmelCase_	,			seq_length=UpperCAmelCase_	,			is_pair=UpperCAmelCase_	,			framework=UpperCAmelCase_)

   # We need to order the input in the way they appears in the forward()
   lowerCamelCase__:				List[str]        =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__:				Union[str, Any]        =common_inputs["input_ids"].shape
       # Not using the same length for past_key_values
       lowerCamelCase__:				List[Any]        =seqlen + 2
       lowerCamelCase__:				str        =(
           batch,
           self.num_attention_heads,
           past_key_values_length,
           self._config.hidden_size // self.num_attention_heads,
       )
       lowerCamelCase__:				Tuple        =[
           (torch.zeros(UpperCAmelCase_), torch.zeros(UpperCAmelCase_)) for _ in range(self.num_layers)
       ]

   lowerCamelCase__:				str        =common_inputs["attention_mask"]
   if self.use_past:
     lowerCamelCase__:				List[Any]        =ordered_inputs["attention_mask"].dtype
     lowerCamelCase__:				Union[str, Any]        =torch.cat(
         [ordered_inputs["attention_mask"], torch.ones(UpperCAmelCase_	,			UpperCAmelCase_	,			dtype=UpperCAmelCase_)]	,			dim=1)

   return ordered_inputs







 @property
 def 							SCREAMING_SNAKE_CASE_ (self    :       Union[str, Any])	->int:



   '''simple docstring'''



   return 13








from __future__ import annotations

from typing import Any



class        _SCREAMING_SNAKE_CASE						:







 '''simple docstring'''

 def __init__(self    :       Any	,			UpperCAmelCase_    :       int)	->None:



   '''simple docstring'''



   lowerCamelCase__:				int        =num_of_nodes
   lowerCamelCase__:				list[list[int]]        =[]
   lowerCamelCase__:				dict[int, int]        ={}

 def 							SCREAMING_SNAKE_CASE_ (self    :       Tuple	,			UpperCAmelCase_    :       int	,			UpperCAmelCase_    :       int	,			UpperCAmelCase_    :       int)	->None:



   '''simple docstring'''



   self.m_edges.append([u_node, v_node, weight])

 def 							SCREAMING_SNAKE_CASE_ (self    :       List[str]	,			UpperCAmelCase_    :       int)	->int:



   '''simple docstring'''



   if self.m_component[u_node] == u_node:
     return u_node
   return self.find_component(self.m_component[u_node])

 def 							SCREAMING_SNAKE_CASE_ (self    :       Union[str, Any]	,			UpperCAmelCase_    :       int)	->None:



   '''simple docstring'''



   if self.m_component[u_node] != u_node:
     for k in self.m_component:
       lowerCamelCase__:				Dict        =self.find_component(UpperCAmelCase_)

 def 							SCREAMING_SNAKE_CASE_ (self    :       Union[str, Any]	,			UpperCAmelCase_    :       list[int]	,			UpperCAmelCase_    :       int	,			UpperCAmelCase_    :       int)	->None:



   '''simple docstring'''



   if component_size[u_node] <= component_size[v_node]:
     lowerCamelCase__:				Optional[int]        =v_node
     component_size[v_node] += component_size[u_node]
     self.set_component(UpperCAmelCase_)

   elif component_size[u_node] >= component_size[v_node]:
     lowerCamelCase__:				Tuple        =self.find_component(UpperCAmelCase_)
     component_size[u_node] += component_size[v_node]
     self.set_component(UpperCAmelCase_)







 def 							SCREAMING_SNAKE_CASE_ (self    :       List[str])	->None:



   '''simple docstring'''



   lowerCamelCase__:				List[Any]        =[]
   lowerCamelCase__:				List[str]        =0

   lowerCamelCase__:				list[Any]        =[-1] * self.m_num_of_nodes

   # A list of components (initialized to all of the nodes)
   for node in range(self.m_num_of_nodes):
     self.m_component.update({node: node})
     component_size.append(1)

   lowerCamelCase__:				List[str]        =self.m_num_of_nodes

   while num_of_components > 1:
     for edge in self.m_edges:
       lowerCamelCase__  , lowerCamelCase__  , lowerCamelCase__:				Tuple        =edge

       lowerCamelCase__:				List[Any]        =self.m_component[u]
       lowerCamelCase__:				str        =self.m_component[v]

       if u_component != v_component:

         for component in (u_component, v_component):
           if (
               minimum_weight_edge[component] == -1
               or minimum_weight_edge[component][2] > w
           ):
             lowerCamelCase__:				Union[str, Any]        =[u, v, w]

     for edge in minimum_weight_edge:
       if isinstance(UpperCAmelCase_	,			UpperCAmelCase_):
         lowerCamelCase__  , lowerCamelCase__  , lowerCamelCase__:				Tuple        =edge

         lowerCamelCase__:				str        =self.m_component[u]
         lowerCamelCase__:				Any        =self.m_component[v]

         if u_component != v_component:
           mst_weight += w
           self.union(UpperCAmelCase_	,			UpperCAmelCase_	,			UpperCAmelCase_)
           print(F"""Added edge [{u} - {v}]\nAdded weight: {w}\n""")
           num_of_components -= 1

     lowerCamelCase__:				Tuple        =[-1] * self.m_num_of_nodes
   print(F"""The total weight of the minimal spanning tree is: {mst_weight}""")





def 					lowerCAmelCase_			(	)					->		None:







  """simple docstring"""







if __name__ == "__main__":
     import doctest

     doctest.testmod()

