




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_				(       _UpperCamelCase   ):



	"""simple docstring"""


	__magic_name__   :       List[str]      	=		'codegen'
	__magic_name__   :       List[Any]      	=		{
	    'max_position_embeddings': 'n_positions',
	    'hidden_size': 'n_embd',
	    'num_attention_heads': 'n_head',
	    'num_hidden_layers': 'n_layer',
	}






	def __init__(					self		:						List[str]					,     lowerCAmelCase		:						str=50400					,     lowerCAmelCase		:						Optional[int]=2048					,     lowerCAmelCase		:						Optional[int]=2048					,     lowerCAmelCase		:						str=4096					,     lowerCAmelCase		:						List[str]=28					,     lowerCAmelCase		:						Union[str, Any]=16					,     lowerCAmelCase		:						Optional[int]=64					,     lowerCAmelCase		:						List[Any]=None					,     lowerCAmelCase		:						int="gelu_new"					,     lowerCAmelCase		:						List[str]=0.0					,     lowerCAmelCase		:						Optional[int]=0.0					,     lowerCAmelCase		:						List[Any]=0.0					,     lowerCAmelCase		:						int=1E-5					,     lowerCAmelCase		:						Optional[int]=0.02					,     lowerCAmelCase		:						Any=True					,     lowerCAmelCase		:						Optional[Any]=50256					,     lowerCAmelCase		:						Dict=50256					,     lowerCAmelCase		:						List[str]=False					,     **lowerCAmelCase		:						List[str]					,     )	->       Tuple:







						"""simple docstring"""







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

						__UpperCamelCase					:	List[Any]             =      bos_token_id
						__UpperCamelCase					:	Optional[Any]             =      eos_token_id

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






class    SCREAMING_SNAKE_CASE_				(       _UpperCamelCase   ):



	"""simple docstring"""


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







						"""simple docstring"""







						super().__init__(lowerCAmelCase					,     task=lowerCAmelCase					,     patching_specs=lowerCAmelCase					,     use_past=lowerCAmelCase	)
						if not getattr(self._config					,     """pad_token_id"""					,     lowerCAmelCase	):
											# TODO: how to do that better?
											__UpperCamelCase					:	Dict             =      0






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







						"""simple docstring"""







						__UpperCamelCase					:	Union[str, Any]             =      OrderedDict({"""input_ids""": {0: """batch""", 1: """sequence"""}}	)
						if self.use_past:
											self.fill_with_past_key_values_(lowerCAmelCase					,     direction="""inputs"""	)
											__UpperCamelCase					:	List[str]             =      {0: """batch""", 1: """past_sequence + sequence"""}
						else:
											__UpperCamelCase					:	Union[str, Any]             =      {0: """batch""", 1: """sequence"""}

						return common_inputs






	@property
	def 					lowerCamelCase__     (					self		:						str	)	->       int:







						"""simple docstring"""







						return self._config.n_layer






	@property
	def 					lowerCamelCase__     (					self		:						List[Any]	)	->       int:







						"""simple docstring"""







						return self._config.n_head






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







						"""simple docstring"""







						__UpperCamelCase					:	List[str]             =      super(lowerCAmelCase					,     self	).generate_dummy_inputs(
						    lowerCAmelCase					,     batch_size=lowerCAmelCase					,     seq_length=lowerCAmelCase					,     is_pair=lowerCAmelCase					,     framework=lowerCAmelCase	)

						# We need to order the input in the way they appears in the forward()
						__UpperCamelCase					:	List[Any]             =      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

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

						__UpperCamelCase					:	Tuple             =      common_inputs["""attention_mask"""]
						if self.use_past:
											__UpperCamelCase					:	Dict             =      ordered_inputs["""attention_mask"""].dtype
											__UpperCamelCase					:	str             =      torch.cat(
											    [ordered_inputs["""attention_mask"""], torch.ones(lowerCAmelCase					,     lowerCAmelCase					,     dtype=lowerCAmelCase	)]					,     dim=1	)

						return ordered_inputs






	@property
	def 					lowerCamelCase__     (					self		:						Any	)	->       int:







						"""simple docstring"""







						return 13












import argparse
import hashlib  # hashlib is only used inside the Test class
import struct


class    SCREAMING_SNAKE_CASE_				:



	"""simple docstring"""


	def __init__(					self		:						Tuple					,     lowerCAmelCase		:						Tuple	)	->       Dict:







						"""simple docstring"""







						__UpperCamelCase					:	Any             =      data
						__UpperCamelCase					:	List[str]             =      [0x6_7_4_5_2_3_0_1, 0xe_f_c_d_a_b_8_9, 0x9_8_b_a_d_c_f_e, 0x1_0_3_2_5_4_7_6, 0xc_3_d_2_e_1_f_0]






	@staticmethod
	def 					lowerCamelCase__     (					lowerCAmelCase		:						str					,     lowerCAmelCase		:						Union[str, Any]	)	->       str:







						"""simple docstring"""







						return ((n << b) | (n >> (32 - b))) & 0xf_f_f_f_f_f_f_f






	def 					lowerCamelCase__     (					self		:						Optional[int]	)	->       Dict:







						"""simple docstring"""







						__UpperCamelCase					:	int             =      b"""\x80""" + b"""\x00""" * (63 - (len(self.data	) + 8) % 64)
						__UpperCamelCase					:	int             =      self.data + padding + struct.pack(""">Q"""					,     8 * len(self.data	)	)
						return padded_data






	def 					lowerCamelCase__     (					self		:						str	)	->       str:







						"""simple docstring"""







						return [
						    self.padded_data[i : i + 64] for i in range(0					,     len(self.padded_data	)					,     64	)
						]






	def 					lowerCamelCase__     (					self		:						Union[str, Any]					,     lowerCAmelCase		:						Tuple	)	->       List[Any]:







						"""simple docstring"""







						__UpperCamelCase					:	Tuple             =      list(struct.unpack(""">16L"""					,     lowerCAmelCase	)	) + [0] * 64
						for i in range(16					,     80	):
											__UpperCamelCase					:	Dict             =      self.rotate((w[i - 3] ^ w[i - 8] ^ w[i - 14] ^ w[i - 16])					,     1	)
						return w






	def 					lowerCamelCase__     (					self		:						Union[str, Any]	)	->       Dict:







						"""simple docstring"""







						__UpperCamelCase					:	Dict             =      self.padding()
						__UpperCamelCase					:	int             =      self.split_blocks()
						for block in self.blocks:
											__UpperCamelCase					:	Union[str, Any]             =      self.expand_block(lowerCAmelCase	)
											__UpperCamelCase      ,			__UpperCamelCase      ,			__UpperCamelCase      ,			__UpperCamelCase      ,			__UpperCamelCase					:	str             =      self.h
											for i in range(0					,     80	):
																if 0 <= i < 20:
																					__UpperCamelCase					:	List[Any]             =      (b & c) | ((~b) & d)
																					__UpperCamelCase					:	str             =      0x5_a_8_2_7_9_9_9
																elif 20 <= i < 40:
																					__UpperCamelCase					:	Tuple             =      b ^ c ^ d
																					__UpperCamelCase					:	List[Any]             =      0x6_e_d_9_e_b_a_1
																elif 40 <= i < 60:
																					__UpperCamelCase					:	Tuple             =      (b & c) | (b & d) | (c & d)
																					__UpperCamelCase					:	List[str]             =      0x8_f_1_b_b_c_d_c
																elif 60 <= i < 80:
																					__UpperCamelCase					:	Optional[int]             =      b ^ c ^ d
																					__UpperCamelCase					:	Tuple             =      0xc_a_6_2_c_1_d_6
																__UpperCamelCase      ,			__UpperCamelCase      ,			__UpperCamelCase      ,			__UpperCamelCase      ,			__UpperCamelCase					:	Tuple             =      (
																    self.rotate(lowerCAmelCase					,     5	) + f + e + k + expanded_block[i] & 0xf_f_f_f_f_f_f_f,
																    a,
																    self.rotate(lowerCAmelCase					,     30	),
																    c,
																    d,
																)
											__UpperCamelCase					:	List[Any]             =      (
											    self.h[0] + a & 0xf_f_f_f_f_f_f_f,
											    self.h[1] + b & 0xf_f_f_f_f_f_f_f,
											    self.h[2] + c & 0xf_f_f_f_f_f_f_f,
											    self.h[3] + d & 0xf_f_f_f_f_f_f_f,
											    self.h[4] + e & 0xf_f_f_f_f_f_f_f,
											)
						return ("{:08x}" * 5).format(*self.h	)






def 				A__ ()     ->						int:
					__UpperCamelCase					:	Optional[int]             =      b"""Test String"""
					assert SHAaHash(snake_case				).final_hash() == hashlib.shaa(snake_case				).hexdigest()  # noqa: S324





def 				A__ ()     ->						Tuple:
					__UpperCamelCase					:	Optional[Any]             =      argparse.ArgumentParser(description="""Process some strings or files"""				)
					parser.add_argument(
					    """--string"""		,	dest="""input_string"""		,	default="""Hello World!! Welcome to Cryptography"""		,	help="""Hash the string"""		,	)
					parser.add_argument("""--file"""		,	dest="""input_file"""		,	help="""Hash contents of a file"""				)
					__UpperCamelCase					:	List[Any]             =      parser.parse_args()
					__UpperCamelCase					:	List[str]             =      args.input_string
					# In any case hash input should be a bytestring
					if args.input_file:
										with open(args.input_file		,	"""rb"""				) as f:
															__UpperCamelCase					:	Tuple             =      f.read()
					else:
										__UpperCamelCase					:	Any             =      bytes(snake_case		,	"""utf-8"""				)
					print(SHAaHash(snake_case				).final_hash()				)


if __name__ == "__main__":
	main()
	import doctest

	doctest.testmod()






