




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


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     lowercase_	(					__lowercase							):



 '''simple docstring'''
 UpperCAmelCase   :					str				  =     '''codegen'''
 UpperCAmelCase   :					Optional[int]				  =     {
     '''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	:	Any=2_048   ,							_UpperCAmelCase	:	List[str]=2_048   ,							_UpperCAmelCase	:	Union[str, Any]=4_096   ,							_UpperCAmelCase	:	Tuple=28   ,							_UpperCAmelCase	:	Dict=16   ,							_UpperCAmelCase	:	List[str]=64   ,							_UpperCAmelCase	:	str=None   ,							_UpperCAmelCase	:	Tuple="gelu_new"   ,							_UpperCAmelCase	:	Tuple=0.0   ,							_UpperCAmelCase	:	Tuple=0.0   ,							_UpperCAmelCase	:	Dict=0.0   ,							_UpperCAmelCase	:	Optional[Any]=1E-5   ,							_UpperCAmelCase	:	int=0.02   ,							_UpperCAmelCase	:	List[Any]=True   ,							_UpperCAmelCase	:	int=50_256   ,							_UpperCAmelCase	:	int=50_256   ,							_UpperCAmelCase	:	Any=False   ,							**_UpperCAmelCase	:	Optional[int]   ,							):
       _A        =       vocab_size
       _A        =       n_ctx
       _A        =       n_positions
       _A        =       n_embd
       _A        =       n_layer
       _A        =       n_head
       _A        =       n_inner
       _A        =       rotary_dim
       _A        =       activation_function
       _A        =       resid_pdrop
       _A        =       embd_pdrop
       _A        =       attn_pdrop
       _A        =       layer_norm_epsilon
       _A        =       initializer_range
       _A        =       use_cache

       _A        =       bos_token_id
       _A        =       eos_token_id

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





class     lowercase_	(					__lowercase							):



 '''simple docstring'''

 def __init__(			self	:	int   ,							_UpperCAmelCase	:	PretrainedConfig   ,							_UpperCAmelCase	:	str = "default"   ,							_UpperCAmelCase	:	List[PatchingSpec] = None   ,							_UpperCAmelCase	:	bool = False   ,							):
       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?
             _A        =       0

 @property
 def       lowerCAmelCase_							(			self	:	Tuple		):
       _A        =       OrderedDict({'input_ids': {0: 'batch', 1: 'sequence'}}		)
       if self.use_past:
             self.fill_with_past_key_values_(_UpperCAmelCase   ,							direction='inputs'		)
             _A        =       {0: """batch""", 1: """past_sequence + sequence"""}
       else:
             _A        =       {0: """batch""", 1: """sequence"""}

       return common_inputs

 @property
 def       lowerCAmelCase_							(			self	:	Tuple		):
       return self._config.n_layer

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

 def       lowerCAmelCase_							(			self	:	Dict   ,							_UpperCAmelCase	:	PreTrainedTokenizer   ,							_UpperCAmelCase	:	int = -1   ,							_UpperCAmelCase	:	int = -1   ,							_UpperCAmelCase	:	bool = False   ,							_UpperCAmelCase	:	Optional[TensorType] = None   ,							):
       _A        =       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()
       _A        =       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

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

       _A        =       common_inputs["""attention_mask"""]
       if self.use_past:
             _A        =       ordered_inputs["""attention_mask"""].dtype
             _A        =       torch.cat(
                 [ordered_inputs['attention_mask'], torch.ones(_UpperCAmelCase   ,							_UpperCAmelCase   ,							dtype=_UpperCAmelCase		)]   ,							dim=1		)

       return ordered_inputs



 @property
 def       lowerCAmelCase_							(			self	:	Union[str, Any]		):
       return 13







"""simple docstring"""

import os

from huggingface_hub.constants import HUGGINGFACE_HUB_CACHE, hf_cache_home


a         =      HUGGINGFACE_HUB_CACHE


a         =      '''config.json'''
a         =      '''diffusion_pytorch_model.bin'''
a         =      '''diffusion_flax_model.msgpack'''
a         =      '''model.onnx'''
a         =      '''diffusion_pytorch_model.safetensors'''
a         =      '''weights.pb'''
a         =      '''https://huggingface.co'''
a         =      default_cache_path
a         =      '''diffusers_modules'''
a         =      os.getenv('''HF_MODULES_CACHE''', os.path.join(hf_cache_home, '''modules'''))
a         =      ['''fp16''', '''non-ema''']
a         =      '''.self_attn'''

