
import unittest

from parameterized import parameterized

from transformers import LlamaConfig, is_torch_available, set_seed
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 LlamaForCausalLM, LlamaForSequenceClassification, LlamaModel, LlamaTokenizer






class      UpperCamelCase    :



	def __init__(       self			,	UpperCAmelCase__			,	UpperCAmelCase__=13			,	UpperCAmelCase__=7			,	UpperCAmelCase__=True			,	UpperCAmelCase__=True			,	UpperCAmelCase__=False			,	UpperCAmelCase__=True			,	UpperCAmelCase__=99			,	UpperCAmelCase__=32			,	UpperCAmelCase__=5			,	UpperCAmelCase__=4			,	UpperCAmelCase__=37			,	UpperCAmelCase__="gelu"			,	UpperCAmelCase__=0.1			,	UpperCAmelCase__=0.1			,	UpperCAmelCase__=512			,	UpperCAmelCase__=16			,	UpperCAmelCase__=2			,	UpperCAmelCase__=0.02			,	UpperCAmelCase__=3			,	UpperCAmelCase__=4			,	UpperCAmelCase__=None			,	):
							A__							=       parent
							A__							=       batch_size
							A__							=       seq_length
							A__							=       is_training
							A__							=       use_input_mask
							A__							=       use_token_type_ids
							A__							=       use_labels
							A__							=       vocab_size
							A__							=       hidden_size
							A__							=       num_hidden_layers
							A__							=       num_attention_heads
							A__							=       intermediate_size
							A__							=       hidden_act
							A__							=       hidden_dropout_prob
							A__							=       attention_probs_dropout_prob
							A__							=       max_position_embeddings
							A__							=       type_vocab_size
							A__							=       type_sequence_label_size
							A__							=       initializer_range
							A__							=       num_labels
							A__							=       num_choices
							A__							=       scope



	def 			__A							(       self		):
							A__							=       ids_tensor([self.batch_size, self.seq_length]			,	self.vocab_size		)

							A__							=       None
							if self.use_input_mask:
													A__							=       random_attention_mask([self.batch_size, self.seq_length]		)

							A__							=       None
							if self.use_token_type_ids:
													A__							=       ids_tensor([self.batch_size, self.seq_length]			,	self.type_vocab_size		)

							A__							=       None
							A__							=       None
							A__							=       None
							if self.use_labels:
													A__							=       ids_tensor([self.batch_size]			,	self.type_sequence_label_size		)
													A__							=       ids_tensor([self.batch_size, self.seq_length]			,	self.num_labels		)
													A__							=       ids_tensor([self.batch_size]			,	self.num_choices		)

							A__							=       self.get_config()

							return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels



	def 			__A							(       self		):
							return LlamaConfig(
							    vocab_size=self.vocab_size			,	hidden_size=self.hidden_size			,	num_hidden_layers=self.num_hidden_layers			,	num_attention_heads=self.num_attention_heads			,	intermediate_size=self.intermediate_size			,	hidden_act=self.hidden_act			,	hidden_dropout_prob=self.hidden_dropout_prob			,	attention_probs_dropout_prob=self.attention_probs_dropout_prob			,	max_position_embeddings=self.max_position_embeddings			,	type_vocab_size=self.type_vocab_size			,	is_decoder=lowerCamelCase_			,	initializer_range=self.initializer_range			,	)



	def 			__A							(       self			,	UpperCAmelCase__			,	UpperCAmelCase__			,	UpperCAmelCase__			,	UpperCAmelCase__			,	UpperCAmelCase__			,	UpperCAmelCase__			,	UpperCAmelCase__		):
							A__							=       LlamaModel(config=lowerCamelCase_		)
							model.to(lowerCamelCase_		)
							model.eval()
							A__							=       model(lowerCamelCase_			,	attention_mask=lowerCamelCase_		)
							A__							=       model(lowerCamelCase_		)
							self.parent.assertEqual(result.last_hidden_state.shape			,	(self.batch_size, self.seq_length, self.hidden_size)		)



	def 			__A							(       self			,	UpperCAmelCase__			,	UpperCAmelCase__			,	UpperCAmelCase__			,	UpperCAmelCase__			,	UpperCAmelCase__			,	UpperCAmelCase__			,	UpperCAmelCase__			,	UpperCAmelCase__			,	UpperCAmelCase__			,	):
							A__							=       True
							A__							=       LlamaModel(lowerCamelCase_		)
							model.to(lowerCamelCase_		)
							model.eval()
							A__							=       model(
							    lowerCamelCase_			,	attention_mask=lowerCamelCase_			,	encoder_hidden_states=lowerCamelCase_			,	encoder_attention_mask=lowerCamelCase_			,	)
							A__							=       model(
							    lowerCamelCase_			,	attention_mask=lowerCamelCase_			,	encoder_hidden_states=lowerCamelCase_			,	)
							A__							=       model(lowerCamelCase_			,	attention_mask=lowerCamelCase_		)
							self.parent.assertEqual(result.last_hidden_state.shape			,	(self.batch_size, self.seq_length, self.hidden_size)		)



	def 			__A							(       self			,	UpperCAmelCase__			,	UpperCAmelCase__			,	UpperCAmelCase__			,	UpperCAmelCase__			,	UpperCAmelCase__			,	UpperCAmelCase__			,	UpperCAmelCase__			,	UpperCAmelCase__			,	UpperCAmelCase__			,	):
							A__							=       LlamaForCausalLM(config=lowerCamelCase_		)
							model.to(lowerCamelCase_		)
							model.eval()
							A__							=       model(lowerCamelCase_			,	attention_mask=lowerCamelCase_			,	labels=lowerCamelCase_		)
							self.parent.assertEqual(result.logits.shape			,	(self.batch_size, self.seq_length, self.vocab_size)		)



	def 			__A							(       self			,	UpperCAmelCase__			,	UpperCAmelCase__			,	UpperCAmelCase__			,	UpperCAmelCase__			,	UpperCAmelCase__			,	UpperCAmelCase__			,	UpperCAmelCase__			,	UpperCAmelCase__			,	UpperCAmelCase__			,	):
							A__							=       True
							A__							=       True
							A__							=       LlamaForCausalLM(config=lowerCamelCase_		)
							model.to(lowerCamelCase_		)
							model.eval()

							# first forward pass
							A__							=       model(
							    lowerCamelCase_			,	attention_mask=lowerCamelCase_			,	encoder_hidden_states=lowerCamelCase_			,	encoder_attention_mask=lowerCamelCase_			,	use_cache=lowerCamelCase_			,	)
							A__							=       outputs.past_key_values

							# create hypothetical multiple next token and extent to next_input_ids
							A__							=       ids_tensor((self.batch_size, 3)			,	config.vocab_size		)
							A__							=       ids_tensor((self.batch_size, 3)			,	vocab_size=2		)

							# append to next input_ids and
							A__							=       torch.cat([input_ids, next_tokens]			,	dim=-1		)
							A__							=       torch.cat([input_mask, next_mask]			,	dim=-1		)

							A__							=       model(
							    lowerCamelCase_			,	attention_mask=lowerCamelCase_			,	encoder_hidden_states=lowerCamelCase_			,	encoder_attention_mask=lowerCamelCase_			,	output_hidden_states=lowerCamelCase_			,	)["hidden_states"][0]
							A__							=       model(
							    lowerCamelCase_			,	attention_mask=lowerCamelCase_			,	encoder_hidden_states=lowerCamelCase_			,	encoder_attention_mask=lowerCamelCase_			,	past_key_values=lowerCamelCase_			,	output_hidden_states=lowerCamelCase_			,	)["hidden_states"][0]

							# select random slice
							A__							=       ids_tensor((1,)			,	output_from_past.shape[-1]		).item()
							A__							=       output_from_no_past[:, -3:, random_slice_idx].detach()
							A__							=       output_from_past[:, :, random_slice_idx].detach()

							self.parent.assertTrue(output_from_past_slice.shape[1] == next_tokens.shape[1]		)

							# test that outputs are equal for slice
							self.parent.assertTrue(torch.allclose(lowerCamelCase_			,	lowerCamelCase_			,	atol=1e-3		)		)



	def 			__A							(       self		):
							A__							=       self.prepare_config_and_inputs()
							(
							    (
							    A__    
							)						,       (
							    A__    
							)						,       (
							    A__    
							)						,       (
							    A__    
							)						,       (
							    A__    
							)						,       (
							    A__    
							)						,       (
							    A__    
							)						,           
							)							=       config_and_inputs
							A__							=       {"input_ids": input_ids, "attention_mask": input_mask}
							return config, inputs_dict






@require_torch
class      UpperCamelCase    (						_UpperCAmelCase       ,    _UpperCAmelCase       ,    _UpperCAmelCase       ,    unittest.TestCase     ):
	lowerCAmelCase	:   Union[str, Any]				=	(LlamaModel, LlamaForCausalLM, LlamaForSequenceClassification) if is_torch_available() else ()
	lowerCAmelCase	:   Any				=	(LlamaForCausalLM,) if is_torch_available() else ()
	lowerCAmelCase	:   Any				=	(
	    {
	        """feature-extraction""": LlamaModel,
	        """text-classification""": LlamaForSequenceClassification,
	        """text-generation""": LlamaForCausalLM,
	        """zero-shot""": LlamaForSequenceClassification,
	    }
	    if is_torch_available()
	    else {}
	)
	lowerCAmelCase	:   List[str]				=	False
	lowerCAmelCase	:   Any				=	False



	def 			__A							(       self		):
							A__							=       LlamaModelTester(self		)
							A__							=       ConfigTester(self			,	config_class=lowerCamelCase_			,	hidden_size=37		)



	def 			__A							(       self		):
							self.config_tester.run_common_tests()



	def 			__A							(       self		):
							A__							=       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*lowerCamelCase_		)



	def 			__A							(       self		):
							A__							=       self.model_tester.prepare_config_and_inputs()
							for type in ["absolute", "relative_key", "relative_key_query"]:
													A__							=       type
													self.model_tester.create_and_check_model(*lowerCamelCase_		)



	def 			__A							(       self		):
							A__						,       A__							=       self.model_tester.prepare_config_and_inputs_for_common()
							A__							=       3
							A__							=       input_dict["input_ids"]
							A__							=       input_ids.ne(1		).to(lowerCamelCase_		)
							A__							=       ids_tensor([self.model_tester.batch_size]			,	self.model_tester.type_sequence_label_size		)
							A__							=       LlamaForSequenceClassification(lowerCamelCase_		)
							model.to(lowerCamelCase_		)
							model.eval()
							A__							=       model(lowerCamelCase_			,	attention_mask=lowerCamelCase_			,	labels=lowerCamelCase_		)
							self.assertEqual(result.logits.shape			,	(self.model_tester.batch_size, self.model_tester.num_labels)		)



	def 			__A							(       self		):
							A__						,       A__							=       self.model_tester.prepare_config_and_inputs_for_common()
							A__							=       3
							A__							=       "single_label_classification"
							A__							=       input_dict["input_ids"]
							A__							=       input_ids.ne(1		).to(lowerCamelCase_		)
							A__							=       ids_tensor([self.model_tester.batch_size]			,	self.model_tester.type_sequence_label_size		)
							A__							=       LlamaForSequenceClassification(lowerCamelCase_		)
							model.to(lowerCamelCase_		)
							model.eval()
							A__							=       model(lowerCamelCase_			,	attention_mask=lowerCamelCase_			,	labels=lowerCamelCase_		)
							self.assertEqual(result.logits.shape			,	(self.model_tester.batch_size, self.model_tester.num_labels)		)



	def 			__A							(       self		):
							A__						,       A__							=       self.model_tester.prepare_config_and_inputs_for_common()
							A__							=       3
							A__							=       "multi_label_classification"
							A__							=       input_dict["input_ids"]
							A__							=       input_ids.ne(1		).to(lowerCamelCase_		)
							A__							=       ids_tensor(
							    [self.model_tester.batch_size, config.num_labels]			,	self.model_tester.type_sequence_label_size		).to(torch.float		)
							A__							=       LlamaForSequenceClassification(lowerCamelCase_		)
							model.to(lowerCamelCase_		)
							model.eval()
							A__							=       model(lowerCamelCase_			,	attention_mask=lowerCamelCase_			,	labels=lowerCamelCase_		)
							self.assertEqual(result.logits.shape			,	(self.model_tester.batch_size, self.model_tester.num_labels)		)



	@unittest.skip("LLaMA buffers include complex numbers, which breaks this test"		)
	def 			__A							(       self		):
							pass



	@parameterized.expand([("linear",), ("dynamic",)]		)
	def 			__A							(       self			,	UpperCAmelCase__		):
							A__						,       A__							=       self.model_tester.prepare_config_and_inputs_for_common()
							A__							=       ids_tensor([1, 10]			,	config.vocab_size		)
							A__							=       ids_tensor([1, int(config.max_position_embeddings * 1.5		)]			,	config.vocab_size		)

							set_seed(42		)  # Fixed seed at init time so the two models get the same random weights
							A__							=       LlamaModel(lowerCamelCase_		)
							original_model.to(lowerCamelCase_		)
							original_model.eval()
							A__							=       original_model(lowerCamelCase_		).last_hidden_state
							A__							=       original_model(lowerCamelCase_		).last_hidden_state

							set_seed(42		)  # Fixed seed at init time so the two models get the same random weights
							A__							=       {"type": scaling_type, "factor": 10.0}
							A__							=       LlamaModel(lowerCamelCase_		)
							scaled_model.to(lowerCamelCase_		)
							scaled_model.eval()
							A__							=       scaled_model(lowerCamelCase_		).last_hidden_state
							A__							=       scaled_model(lowerCamelCase_		).last_hidden_state

							# Dynamic scaling does not change the RoPE embeddings until it receives an input longer than the original
							# maximum sequence length, so the outputs for the short input should match.
							if scaling_type == "dynamic":
													self.assertTrue(torch.allclose(lowerCamelCase_			,	lowerCamelCase_			,	atol=1e-5		)		)
							else:
													self.assertFalse(torch.allclose(lowerCamelCase_			,	lowerCamelCase_			,	atol=1e-5		)		)

							# The output should be different for long inputs
							self.assertFalse(torch.allclose(lowerCamelCase_			,	lowerCamelCase_			,	atol=1e-5		)		)






@require_torch
class      UpperCamelCase    (						unittest.TestCase     ):



	@unittest.skip("Logits are not exactly the same, once we fix the instabalities somehow, will update!"		)
	@slow
	def 			__A							(       self		):
							A__							=       [1, 306, 4_658, 278, 6_593, 310, 2_834, 338]
							A__							=       LlamaForCausalLM.from_pretrained("meta-llama/Llama-2-7b-hf"			,	device_map="auto"		)
							A__							=       model(torch.tensor([input_ids]		)		)
							# Expected mean on dim = -1
							A__							=       torch.tensor([[-6.6_550, -4.1_227, -4.9_859, -3.2_406, 0.8_262, -3.0_033, 1.2_964, -3.3_699]]		)
							torch.testing.assert_close(out.mean(-1		)			,	lowerCamelCase_			,	atol=1e-2			,	rtol=1e-2		)
							# slicing logits[0, 0, 0:30]
							# fmt: off
							A__							=       torch.tensor([-12.8_281, -7.4_453, -0.4_639, -8.0_625, -7.2_500, -8.0_000, -6.4_883, -7.7_695, -7.8_438, -7.0_312, -6.2_188, -7.1_328, -1.8_496, 1.9_961, -8.6_250, -6.7_227, -12.8_281, -6.9_492, -7.0_742, -7.7_852, -7.5_820, -7.9_062, -6.9_375, -7.9_805, -8.3_438, -8.1_562, -8.0_469, -7.6_250, -7.7_422, -7.3_398,]		)
							# fmt: on
							torch.testing.assert_close(out[0, 0, :30]			,	lowerCamelCase_			,	atol=1e-5			,	rtol=1e-5		)



	@unittest.skip("Logits are not exactly the same, once we fix the instabalities somehow, will update!"		)
	@slow
	def 			__A							(       self		):
							A__							=       [1, 306, 4_658, 278, 6_593, 310, 2_834, 338]
							A__							=       LlamaForCausalLM.from_pretrained("meta-llama/Llama-2-13b-hf"			,	device_map="auto"		)
							A__							=       model(torch.tensor(lowerCamelCase_		)		)
							# Expected mean on dim = -1
							A__							=       torch.tensor([[-2.0_622, -1.2_794, -1.1_638, -0.9_788, -1.4_603, -1.0_238, -1.7_893, -1.4_411]]		)
							torch.testing.assert_close(out.mean(-1		)			,	lowerCamelCase_			,	atol=1e-2			,	rtol=1e-2		)
							# slicing logits[0, 0, 0:30]
							# fmt: off
							A__							=       torch.tensor([-8.1_406, -8.0_547, 2.7_461, -1.2_344, -0.1_448, -1.8_262, -1.0_020, -1.8_154, -1.6_895, -1.8_516, -2.3_574, -0.9_277, 3.7_598, 6.5_742, -1.2_998, -0.1_177, -8.1_406, -2.9_688, -2.9_199, -3.1_699, -3.5_254, -2.3_555, -2.7_988, -3.4_141, -2.8_262, -4.5_195, -3.3_379, -3.3_164, -2.7_832, -3.0_273]		)
							# fmt: on
							torch.testing.assert_close(out[0, 0, :30]			,	lowerCamelCase_			,	atol=1e-5			,	rtol=1e-5		)



	@unittest.skip("Logits are not exactly the same, once we fix the instabalities somehow, will update!"		)
	@slow
	def 			__A							(       self		):
							A__							=       [1, 306, 4_658, 278, 6_593, 310, 2_834, 338]
							A__							=       LlamaForCausalLM.from_pretrained("meta-llama/Llama-2-13b-chat-hf"			,	device_map="auto"		)
							A__							=       model(torch.tensor(lowerCamelCase_		)		)
							# Expected mean on dim = -1
							A__							=       torch.tensor([[-0.8_562, -1.8_520, -0.7_551, -0.4_162, -1.5_161, -1.2_038, -2.4_823, -2.3_254]]		)
							torch.testing.assert_close(out.mean(-1		)			,	lowerCamelCase_			,	atol=1e-2			,	rtol=1e-2		)
							# slicing logits[0, 0, 0:30]
							# fmt: off
							A__							=       torch.tensor([-2.2_227, 4.8_828, 0.9_023, -0.4_578, -0.7_871, -0.1_033, -0.6_221, -0.5_786, -0.7_803, -1.0_674, -1.2_920, -0.1_570, 0.8_008, 2.0_723, -0.9_497, 0.2_771, -2.2_227, -0.7_612, -1.4_346, -1.2_061, -1.6_426, -0.3_000, -0.7_139, -1.1_934, -1.8_691, -1.6_973, -1.5_947, -1.2_705, -0.3_523, -0.5_513]		)
							# fmt: on
							torch.testing.assert_close(out.mean(-1		)			,	lowerCamelCase_			,	atol=1e-2			,	rtol=1e-2		)



	@unittest.skip(
	    "Logits are not exactly the same, once we fix the instabalities somehow, will update! Also it is gonna be a `too_slow` test"		)
	@slow
	def 			__A							(       self		):
							A__							=       [1, 306, 4_658, 278, 6_593, 310, 2_834, 338]
							A__							=       LlamaForCausalLM.from_pretrained("meta-llama/Llama-2-70b-hf"			,	device_map="auto"		)
							A__							=       model(torch.tensor(lowerCamelCase_		)		)

							A__							=       torch.tensor(
							    [[-4.2_327, -3.3_360, -4.6_665, -4.7_631, -1.8_180, -3.4_170, -1.4_211, -3.1_810]]			,	dtype=torch.floataa		)
							torch.testing.assert_close(out.mean(-1		)			,	lowerCamelCase_			,	atol=1e-2			,	rtol=1e-2		)
							# fmt: off
							A__							=       torch.tensor([-9.4_922, -3.9_551, 1.7_998, -5.6_758, -5.1_055, -5.8_984, -4.8_320, -6.8_086, -6.5_391, -5.6_172, -5.5_820, -5.5_352, 1.7_881, 3.6_289, -6.5_117, -3.4_785, -9.5_000, -6.0_352, -6.8_125, -6.0_195, -6.6_836, -5.4_727, -6.2_812, -6.0_391, -7.3_398, -7.4_297, -7.4_844, -6.5_820, -5.8_789, -5.5_312]		)
							# fmt: on
							torch.testing.assert_close(out[0, 0, :30]			,	lowerCamelCase_			,	atol=1e-5			,	rtol=1e-5		)



	@unittest.skip("Model is curently gated"		)
	@slow
	def 			__A							(       self		):
							A__							=       "Simply put, the theory of relativity states that 1) the laws of physics are the same everywhere in the universe and 2) the passage of time and the length of objects can vary depending on the observer\'s frame of reference.\n\nThe first part of the theory, that the laws of physics are the same everywhere, is known as the \"princi"
							A__							=       "Simply put, the theory of relativity states that "
							A__							=       LlamaTokenizer.from_pretrained("meta-llama/Llama-2-13b-chat-hf"		)
							A__							=       tokenizer.encode(lowerCamelCase_			,	return_tensors="pt"		)
							A__							=       LlamaForCausalLM.from_pretrained(
							    "meta-llama/Llama-2-13b-chat-hf"			,	device_map="sequential"			,	use_safetensors=lowerCamelCase_		)

							# greedy generation outputs
							A__							=       model.generate(lowerCamelCase_			,	max_new_tokens=64			,	top_p=lowerCamelCase_			,	temperature=1			,	do_sample=lowerCamelCase_		)
							A__							=       tokenizer.decode(generated_ids[0]			,	skip_special_tokens=lowerCamelCase_		)
							self.assertEqual(lowerCamelCase_			,	lowerCamelCase_		)










import argparse
import struct
import unittest






class      UpperCamelCase    :



	def __init__(       self			,	UpperCAmelCase__		):
							A__							=       data

							# Initialize hash values
							A__							=       [
							    0x6A_09E_667,
							    0xBB_67A_E85,
							    0x3C_6EF_372,
							    0xA5_4FF_53A,
							    0x51_0E5_27F,
							    0x9B_056_88C,
							    0x1F_83D_9AB,
							    0x5B_E0C_D19,
							]

							# Initialize round constants
							A__							=       [
							    0x42_8A2_F98,
							    0x71_374_491,
							    0xB5_C0F_BCF,
							    0xE9_B5D_BA5,
							    0x39_56C_25B,
							    0x59_F11_1F1,
							    0x92_3F8_2A4,
							    0xAB_1C5_ED5,
							    0xD8_07A_A98,
							    0x12_835_B01,
							    0x24_318_5BE,
							    0x55_0C7_DC3,
							    0x72_BE5_D74,
							    0x80_DEB_1FE,
							    0x9B_DC0_6A7,
							    0xC1_9BF_174,
							    0xE4_9B6_9C1,
							    0xEF_BE4_786,
							    0x0F_C19_DC6,
							    0x24_0CA_1CC,
							    0x2D_E92_C6F,
							    0x4A_748_4AA,
							    0x5C_B0A_9DC,
							    0x76_F98_8DA,
							    0x98_3E5_152,
							    0xA8_31C_66D,
							    0xB0_032_7C8,
							    0xBF_597_FC7,
							    0xC6_E00_BF3,
							    0xD5_A79_147,
							    0x06_CA6_351,
							    0x14_292_967,
							    0x27_B70_A85,
							    0x2E_1B2_138,
							    0x4D_2C6_DFC,
							    0x53_380_D13,
							    0x65_0A7_354,
							    0x76_6A0_ABB,
							    0x81_C2C_92E,
							    0x92_722_C85,
							    0xA2_BFE_8A1,
							    0xA8_1A6_64B,
							    0xC2_4B8_B70,
							    0xC7_6C5_1A3,
							    0xD1_92E_819,
							    0xD6_990_624,
							    0xF4_0E3_585,
							    0x10_6AA_070,
							    0x19_A4C_116,
							    0x1E_376_C08,
							    0x27_487_74C,
							    0x34_B0B_CB5,
							    0x39_1C0_CB3,
							    0x4E_D8A_A4A,
							    0x5B_9CC_A4F,
							    0x68_2E6_FF3,
							    0x74_8F8_2EE,
							    0x78_A56_36F,
							    0x84_C87_814,
							    0x8C_C70_208,
							    0x90_BEF_FFA,
							    0xA4_506_CEB,
							    0xBE_F9A_3F7,
							    0xC6_717_8F2,
							]

							A__							=       self.preprocessing(self.data		)
							self.final_hash()



	@staticmethod
	def 			__A							(       UpperCAmelCase__		):
							A__							=       b"\x80" + (b"\x00" * (63 - (len(UpperCAmelCase__		) + 8) % 64))
							A__							=       struct.pack(">Q"			,	(len(UpperCAmelCase__		) * 8)		)
							return data + padding + big_endian_integer



	def 			__A							(       self		):
							# Convert into blocks of 64 bytes
							A__							=       [
							    self.preprocessed_data[x : x + 64]
							    for x in range(0			,	len(self.preprocessed_data		)			,	64		)
							]

							for block in self.blocks:
													# Convert the given block into a list of 4 byte integers
													A__							=       list(struct.unpack(">16L"			,	UpperCAmelCase__		)		)
													# add 48 0-ed integers
													words += [0] * 48

													A__						,       A__						,       A__						,       A__						,       A__						,       A__						,       A__						,       A__							=       self.hashes

													for index in range(0			,	64		):
																			if index > 15:
																									# modify the zero-ed indexes at the end of the array
																									A__							=       (
																									    self.ror(words[index - 15]			,	7		)
																									    ^ self.ror(words[index - 15]			,	18		)
																									    ^ (words[index - 15] >> 3)
																									)
																									A__							=       (
																									    self.ror(words[index - 2]			,	17		)
																									    ^ self.ror(words[index - 2]			,	19		)
																									    ^ (words[index - 2] >> 10)
																									)

																									A__							=       (
																									    words[index - 16] + sa + words[index - 7] + sa
																									) % 0x100_000_000

																			# Compression
																			A__							=       self.ror(UpperCAmelCase__			,	6		) ^ self.ror(UpperCAmelCase__			,	11		) ^ self.ror(UpperCAmelCase__			,	25		)
																			A__							=       (e & f) ^ ((~e & 0xFF_FFF_FFF) & g)
																			A__							=       (
																			    h + sa + ch + self.round_constants[index] + words[index]
																			) % 0x100_000_000
																			A__							=       self.ror(UpperCAmelCase__			,	2		) ^ self.ror(UpperCAmelCase__			,	13		) ^ self.ror(UpperCAmelCase__			,	22		)
																			A__							=       (a & b) ^ (a & c) ^ (b & c)
																			A__							=       (sa + maj) % 0x100_000_000

																			A__						,       A__						,       A__						,       A__						,       A__						,       A__						,       A__						,       A__							=       (
																			    g,
																			    f,
																			    e,
																			    ((d + tempa) % 0x100_000_000),
																			    c,
																			    b,
																			    a,
																			    ((tempa + tempa) % 0x100_000_000),
																			)

													A__							=       [a, b, c, d, e, f, g, h]

													# Modify final values
													A__							=       [
													    ((element + mutated_hash_values[index]) % 0x100_000_000)
													    for index, element in enumerate(self.hashes		)
													]

							A__							=       "".join([hex(UpperCAmelCase__		)[2:].zfill(8		) for value in self.hashes]		)



	def 			__A							(       self			,	UpperCAmelCase__			,	UpperCAmelCase__		):
							return 0xFF_FFF_FFF & (value << (32 - rotations)) | (value >> rotations)






class      UpperCamelCase    (						unittest.TestCase     ):



	def 			__A							(       self		):
							import hashlib

							A__							=       bytes("Test String"			,	"utf-8"		)
							self.assertEqual(SHAaaa(UpperCAmelCase__		).hash			,	hashlib.shaaaa(UpperCAmelCase__		).hexdigest()		)





def  UpperCamelCase						(       )->       None:





						"""simple docstring"""





						import doctest

						doctest.testmod()

						A__							=       argparse.ArgumentParser()
						parser.add_argument(
						    "-s"			,							"--string"			,							dest="input_string"			,							default="Hello World!! Welcome to Cryptography"			,							help="Hash the string"			,							)
						parser.add_argument(
						    "-f"			,							"--file"			,							dest="input_file"			,							help="Hash contents of a file"    )

						A__							=       parser.parse_args()

						A__							=       args.input_string

						# hash input should be a bytestring
						if args.input_file:
												with open(args.input_file			,							"rb"    ) as f:
																		A__							=       f.read()
						else:
												A__							=       bytes(_A			,							"utf-8"    )

						print(SHAaaa(_A    ).hash    )


if __name__ == "__main__":
						main()





