





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    _a     :






							"""simple docstring"""

							def __init__(      self				:     Any							,	a				:     List[Any]							,	a				:     Any=13							,	a				:     Dict=7							,	a				:     int=True							,	a				:     List[str]=True							,	a				:     Union[str, Any]=False							,	a				:     Union[str, Any]=True							,	a				:     List[Any]=99							,	a				:     Dict=32							,	a				:     List[Any]=5							,	a				:     int=4							,	a				:     Tuple=37							,	a				:     Any="gelu"							,	a				:     Dict=0.1							,	a				:     Tuple=0.1							,	a				:     Union[str, Any]=5_12							,	a				:     List[str]=16							,	a				:     Any=2							,	a				:     List[str]=0.02							,	a				:     Any=3							,	a				:     int=4							,	a				:     List[str]=None							,	)	->Dict:
													SCREAMING_SNAKE_CASE__     :				List[str]   =					parent
													SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					batch_size
													SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					seq_length
													SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					is_training
													SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					use_input_mask
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					use_token_type_ids
													SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					use_labels
													SCREAMING_SNAKE_CASE__     :				Tuple   =					vocab_size
													SCREAMING_SNAKE_CASE__     :				Any   =					hidden_size
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					num_hidden_layers
													SCREAMING_SNAKE_CASE__     :				Any   =					num_attention_heads
													SCREAMING_SNAKE_CASE__     :				Tuple   =					intermediate_size
													SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					hidden_act
													SCREAMING_SNAKE_CASE__     :				Tuple   =					hidden_dropout_prob
													SCREAMING_SNAKE_CASE__     :				List[Any]   =					attention_probs_dropout_prob
													SCREAMING_SNAKE_CASE__     :				List[Any]   =					max_position_embeddings
													SCREAMING_SNAKE_CASE__     :				str   =					type_vocab_size
													SCREAMING_SNAKE_CASE__     :				str   =					type_sequence_label_size
													SCREAMING_SNAKE_CASE__     :				str   =					initializer_range
													SCREAMING_SNAKE_CASE__     :				Dict   =					num_labels
													SCREAMING_SNAKE_CASE__     :				Tuple   =					num_choices
													SCREAMING_SNAKE_CASE__     :				List[Any]   =					scope

							def      A_  (      self				:     List[Any]    )	->Any:
													SCREAMING_SNAKE_CASE__     :				List[Any]   =					ids_tensor([self.batch_size, self.seq_length]							,	self.vocab_size    )

													SCREAMING_SNAKE_CASE__     :				int   =					None
													if self.use_input_mask:
																			SCREAMING_SNAKE_CASE__     :				Tuple   =					random_attention_mask([self.batch_size, self.seq_length]    )

													SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					None
													if self.use_token_type_ids:
																			SCREAMING_SNAKE_CASE__     :				List[str]   =					ids_tensor([self.batch_size, self.seq_length]							,	self.type_vocab_size    )

													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					None
													SCREAMING_SNAKE_CASE__     :				Tuple   =					None
													SCREAMING_SNAKE_CASE__     :				str   =					None
													if self.use_labels:
																			SCREAMING_SNAKE_CASE__     :				Any   =					ids_tensor([self.batch_size]							,	self.type_sequence_label_size    )
																			SCREAMING_SNAKE_CASE__     :				int   =					ids_tensor([self.batch_size, self.seq_length]							,	self.num_labels    )
																			SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					ids_tensor([self.batch_size]							,	self.num_choices    )

													SCREAMING_SNAKE_CASE__     :				List[str]   =					self.get_config()

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

							def      A_  (      self				:     Union[str, Any]    )	->Any:
													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=a							,	initializer_range=self.initializer_range							,	)

							def      A_  (      self				:     List[Any]							,	a				:     str							,	a				:     int							,	a				:     List[str]							,	a				:     Optional[Any]							,	a				:     str							,	a				:     List[str]							,	a				:     Optional[Any]    )	->Optional[int]:
													SCREAMING_SNAKE_CASE__     :				List[Any]   =					LlamaModel(config=a    )
													model.to(a    )
													model.eval()
													SCREAMING_SNAKE_CASE__     :				Dict   =					model(a							,	attention_mask=a    )
													SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					model(a    )
													self.parent.assertEqual(result.last_hidden_state.shape							,	(self.batch_size, self.seq_length, self.hidden_size)    )

							def      A_  (      self				:     Optional[Any]							,	a				:     List[Any]							,	a				:     List[str]							,	a				:     Union[str, Any]							,	a				:     Optional[int]							,	a				:     int							,	a				:     Dict							,	a				:     Union[str, Any]							,	a				:     str							,	a				:     Optional[Any]							,	)	->List[str]:
													SCREAMING_SNAKE_CASE__     :				Any   =					True
													SCREAMING_SNAKE_CASE__     :				Any   =					LlamaModel(a    )
													model.to(a    )
													model.eval()
													SCREAMING_SNAKE_CASE__     :				Tuple   =					model(
													    a							,	attention_mask=a							,	encoder_hidden_states=a							,	encoder_attention_mask=a							,	)
													SCREAMING_SNAKE_CASE__     :				int   =					model(
													    a							,	attention_mask=a							,	encoder_hidden_states=a							,	)
													SCREAMING_SNAKE_CASE__     :				int   =					model(a							,	attention_mask=a    )
													self.parent.assertEqual(result.last_hidden_state.shape							,	(self.batch_size, self.seq_length, self.hidden_size)    )

							def      A_  (      self				:     List[Any]							,	a				:     Union[str, Any]							,	a				:     Union[str, Any]							,	a				:     Optional[Any]							,	a				:     List[Any]							,	a				:     Tuple							,	a				:     List[Any]							,	a				:     Any							,	a				:     Optional[Any]							,	a				:     Optional[int]							,	)	->Optional[Any]:
													SCREAMING_SNAKE_CASE__     :				int   =					LlamaForCausalLM(config=a    )
													model.to(a    )
													model.eval()
													SCREAMING_SNAKE_CASE__     :				str   =					model(a							,	attention_mask=a							,	labels=a    )
													self.parent.assertEqual(result.logits.shape							,	(self.batch_size, self.seq_length, self.vocab_size)    )

							def      A_  (      self				:     str							,	a				:     str							,	a				:     List[Any]							,	a				:     Tuple							,	a				:     Optional[int]							,	a				:     Dict							,	a				:     Optional[int]							,	a				:     Dict							,	a				:     Optional[int]							,	a				:     Dict							,	)	->List[Any]:
													SCREAMING_SNAKE_CASE__     :				List[Any]   =					True
													SCREAMING_SNAKE_CASE__     :				List[Any]   =					True
													SCREAMING_SNAKE_CASE__     :				List[str]   =					LlamaForCausalLM(config=a    )
													model.to(a    )
													model.eval()

													# first forward pass
													SCREAMING_SNAKE_CASE__     :				int   =					model(
													    a							,	attention_mask=a							,	encoder_hidden_states=a							,	encoder_attention_mask=a							,	use_cache=a							,	)
													SCREAMING_SNAKE_CASE__     :				List[str]   =					outputs.past_key_values

													# create hypothetical multiple next token and extent to next_input_ids
													SCREAMING_SNAKE_CASE__     :				List[str]   =					ids_tensor((self.batch_size, 3)							,	config.vocab_size    )
													SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					ids_tensor((self.batch_size, 3)							,	vocab_size=2    )

													# append to next input_ids and
													SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					torch.cat([input_ids, next_tokens]							,	dim=-1    )
													SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					torch.cat([input_mask, next_mask]							,	dim=-1    )

													SCREAMING_SNAKE_CASE__     :				Any   =					model(
													    a							,	attention_mask=a							,	encoder_hidden_states=a							,	encoder_attention_mask=a							,	output_hidden_states=a							,	)["hidden_states"][0]
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					model(
													    a							,	attention_mask=a							,	encoder_hidden_states=a							,	encoder_attention_mask=a							,	past_key_values=a							,	output_hidden_states=a							,	)["hidden_states"][0]

													# select random slice
													SCREAMING_SNAKE_CASE__     :				List[Any]   =					ids_tensor((1,)							,	output_from_past.shape[-1]    ).item()
													SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					output_from_no_past[:, -3:, random_slice_idx].detach()
													SCREAMING_SNAKE_CASE__     :				Any   =					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(a							,	a							,	atol=1E-3    )    )






							def      A_  (      self				:     List[str]    )	->Tuple:
													SCREAMING_SNAKE_CASE__     :				int   =					self.prepare_config_and_inputs()
													(
													    (
													    SCREAMING_SNAKE_CASE__
													),							(
													    SCREAMING_SNAKE_CASE__
													),							(
													    SCREAMING_SNAKE_CASE__
													),							(
													    SCREAMING_SNAKE_CASE__
													),							(
													    SCREAMING_SNAKE_CASE__
													),							(
													    SCREAMING_SNAKE_CASE__
													),							(
													    SCREAMING_SNAKE_CASE__
													),							
													)     :				Tuple   =					config_and_inputs
													SCREAMING_SNAKE_CASE__     :				Tuple   =					{"input_ids": input_ids, "attention_mask": input_mask}
													return config, inputs_dict







@require_torch
class    _a     (				lowercase__					,							lowercase__					,							lowercase__					,							unittest.TestCase							):






							"""simple docstring"""

							snake_case_							 =						(LlamaModel, LlamaForCausalLM, LlamaForSequenceClassification) if is_torch_available() else ()
							snake_case_							 =						(LlamaForCausalLM,) if is_torch_available() else ()
							snake_case_							 =						(
							    {
							        "feature-extraction": LlamaModel,
							        "text-classification": LlamaForSequenceClassification,
							        "text-generation": LlamaForCausalLM,
							        "zero-shot": LlamaForSequenceClassification,
							    }
							    if is_torch_available()
							    else {}
							)
							snake_case_							 =						False
							snake_case_							 =						False

							def      A_  (      self				:     Union[str, Any]    )	->Tuple:
													SCREAMING_SNAKE_CASE__     :				int   =					LlamaModelTester(self    )
													SCREAMING_SNAKE_CASE__     :				str   =					ConfigTester(self							,	config_class=a							,	hidden_size=37    )

							def      A_  (      self				:     Union[str, Any]    )	->List[str]:
													self.config_tester.run_common_tests()

							def      A_  (      self				:     Union[str, Any]    )	->Optional[Any]:
													SCREAMING_SNAKE_CASE__     :				str   =					self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_model(*a    )

							def      A_  (      self				:     List[Any]    )	->List[Any]:
													SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					self.model_tester.prepare_config_and_inputs()
													for type in ["absolute", "relative_key", "relative_key_query"]:
																			SCREAMING_SNAKE_CASE__     :				Optional[int]   =					type
																			self.model_tester.create_and_check_model(*a    )

							def      A_  (      self				:     List[str]    )	->Tuple:
													SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__     :				str   =					self.model_tester.prepare_config_and_inputs_for_common()
													SCREAMING_SNAKE_CASE__     :				Tuple   =					3
													SCREAMING_SNAKE_CASE__     :				List[str]   =					input_dict["input_ids"]
													SCREAMING_SNAKE_CASE__     :				int   =					input_ids.ne(1    ).to(a    )
													SCREAMING_SNAKE_CASE__     :				Dict   =					ids_tensor([self.model_tester.batch_size]							,	self.model_tester.type_sequence_label_size    )
													SCREAMING_SNAKE_CASE__     :				List[Any]   =					LlamaForSequenceClassification(a    )
													model.to(a    )
													model.eval()
													SCREAMING_SNAKE_CASE__     :				Tuple   =					model(a							,	attention_mask=a							,	labels=a    )
													self.assertEqual(result.logits.shape							,	(self.model_tester.batch_size, self.model_tester.num_labels)    )

							def      A_  (      self				:     str    )	->int:
													SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__     :				Tuple   =					self.model_tester.prepare_config_and_inputs_for_common()
													SCREAMING_SNAKE_CASE__     :				Dict   =					3
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					"single_label_classification"
													SCREAMING_SNAKE_CASE__     :				List[Any]   =					input_dict["input_ids"]
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					input_ids.ne(1    ).to(a    )
													SCREAMING_SNAKE_CASE__     :				Dict   =					ids_tensor([self.model_tester.batch_size]							,	self.model_tester.type_sequence_label_size    )
													SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					LlamaForSequenceClassification(a    )
													model.to(a    )
													model.eval()
													SCREAMING_SNAKE_CASE__     :				List[Any]   =					model(a							,	attention_mask=a							,	labels=a    )
													self.assertEqual(result.logits.shape							,	(self.model_tester.batch_size, self.model_tester.num_labels)    )

							def      A_  (      self				:     Tuple    )	->Optional[Any]:
													SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__     :				str   =					self.model_tester.prepare_config_and_inputs_for_common()
													SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					3
													SCREAMING_SNAKE_CASE__     :				Dict   =					"multi_label_classification"
													SCREAMING_SNAKE_CASE__     :				List[str]   =					input_dict["input_ids"]
													SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					input_ids.ne(1    ).to(a    )
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					ids_tensor(
													    [self.model_tester.batch_size, config.num_labels]							,	self.model_tester.type_sequence_label_size    ).to(torch.float    )
													SCREAMING_SNAKE_CASE__     :				Tuple   =					LlamaForSequenceClassification(a    )
													model.to(a    )
													model.eval()
													SCREAMING_SNAKE_CASE__     :				List[str]   =					model(a							,	attention_mask=a							,	labels=a    )
													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				:     Union[str, Any]    )	->Dict:
													pass






							@parameterized.expand([("linear",), ("dynamic",)]    )
							def      A_  (      self				:     str							,	a				:     Optional[int]    )	->Optional[int]:
													SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__     :				Any   =					self.model_tester.prepare_config_and_inputs_for_common()
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					ids_tensor([1, 10]							,	config.vocab_size    )
													SCREAMING_SNAKE_CASE__     :				List[str]   =					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
													SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					LlamaModel(a    )
													original_model.to(a    )
													original_model.eval()
													SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					original_model(a    ).last_hidden_state
													SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					original_model(a    ).last_hidden_state

													set_seed(42    )  # Fixed seed at init time so the two models get the same random weights
													SCREAMING_SNAKE_CASE__     :				str   =					{"type": scaling_type, "factor": 10.0}
													SCREAMING_SNAKE_CASE__     :				int   =					LlamaModel(a    )
													scaled_model.to(a    )
													scaled_model.eval()
													SCREAMING_SNAKE_CASE__     :				Tuple   =					scaled_model(a    ).last_hidden_state
													SCREAMING_SNAKE_CASE__     :				Any   =					scaled_model(a    ).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(a							,	a							,	atol=1E-5    )    )
													else:
																			self.assertFalse(torch.allclose(a							,	a							,	atol=1E-5    )    )

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







@require_torch
class    _a     (				unittest.TestCase							):






							"""simple docstring"""

							@unittest.skip("Logits are not exactly the same, once we fix the instabalities somehow, will update!"    )
							@slow
							def      A_  (      self				:     List[Any]    )	->Union[str, Any]:
													SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					[1, 3_06, 46_58, 2_78, 65_93, 3_10, 28_34, 3_38]
													SCREAMING_SNAKE_CASE__     :				List[Any]   =					LlamaForCausalLM.from_pretrained("meta-llama/Llama-2-7b-hf"							,	device_map="auto"    )
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					model(torch.tensor([input_ids]    )    )
													# Expected mean on dim = -1
													SCREAMING_SNAKE_CASE__     :				str   =					torch.tensor([[-6.6550, -4.1227, -4.9859, -3.2406, 0.8262, -3.0033, 1.2964, -3.3699]]    )
													torch.testing.assert_close(out.mean(-1    )							,	a							,	atol=1E-2							,	rtol=1E-2    )
													# slicing logits[0, 0, 0:30]
													# fmt: off
													SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					torch.tensor([-12.8281, -7.4453, -0.4639, -8.0625, -7.2500, -8.0000, -6.4883, -7.7695, -7.8438, -7.0312, -6.2188, -7.1328, -1.8496, 1.9961, -8.6250, -6.7227, -12.8281, -6.9492, -7.0742, -7.7852, -7.5820, -7.9062, -6.9375, -7.9805, -8.3438, -8.1562, -8.0469, -7.6250, -7.7422, -7.3398,]    )
													# fmt: on
													torch.testing.assert_close(out[0, 0, :30]							,	a							,	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				:     Optional[int]    )	->Any:
													SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					[1, 3_06, 46_58, 2_78, 65_93, 3_10, 28_34, 3_38]
													SCREAMING_SNAKE_CASE__     :				int   =					LlamaForCausalLM.from_pretrained("meta-llama/Llama-2-13b-hf"							,	device_map="auto"    )
													SCREAMING_SNAKE_CASE__     :				List[Any]   =					model(torch.tensor(a    )    )
													# Expected mean on dim = -1
													SCREAMING_SNAKE_CASE__     :				Any   =					torch.tensor([[-2.0622, -1.2794, -1.1638, -0.9788, -1.4603, -1.0238, -1.7893, -1.4411]]    )
													torch.testing.assert_close(out.mean(-1    )							,	a							,	atol=1E-2							,	rtol=1E-2    )
													# slicing logits[0, 0, 0:30]
													# fmt: off
													SCREAMING_SNAKE_CASE__     :				List[Any]   =					torch.tensor([-8.1406, -8.0547, 2.7461, -1.2344, -0.1448, -1.8262, -1.0020, -1.8154, -1.6895, -1.8516, -2.3574, -0.9277, 3.7598, 6.5742, -1.2998, -0.1177, -8.1406, -2.9688, -2.9199, -3.1699, -3.5254, -2.3555, -2.7988, -3.4141, -2.8262, -4.5195, -3.3379, -3.3164, -2.7832, -3.0273]    )
													# fmt: on
													torch.testing.assert_close(out[0, 0, :30]							,	a							,	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				:     str    )	->Any:
													SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					[1, 3_06, 46_58, 2_78, 65_93, 3_10, 28_34, 3_38]
													SCREAMING_SNAKE_CASE__     :				List[str]   =					LlamaForCausalLM.from_pretrained("meta-llama/Llama-2-13b-chat-hf"							,	device_map="auto"    )
													SCREAMING_SNAKE_CASE__     :				List[str]   =					model(torch.tensor(a    )    )
													# Expected mean on dim = -1
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					torch.tensor([[-0.8562, -1.8520, -0.7551, -0.4162, -1.5161, -1.2038, -2.4823, -2.3254]]    )
													torch.testing.assert_close(out.mean(-1    )							,	a							,	atol=1E-2							,	rtol=1E-2    )
													# slicing logits[0, 0, 0:30]
													# fmt: off
													SCREAMING_SNAKE_CASE__     :				Any   =					torch.tensor([-2.2227, 4.8828, 0.9023, -0.4578, -0.7871, -0.1033, -0.6221, -0.5786, -0.7803, -1.0674, -1.2920, -0.1570, 0.8008, 2.0723, -0.9497, 0.2771, -2.2227, -0.7612, -1.4346, -1.2061, -1.6426, -0.3000, -0.7139, -1.1934, -1.8691, -1.6973, -1.5947, -1.2705, -0.3523, -0.5513]    )
													# fmt: on
													torch.testing.assert_close(out.mean(-1    )							,	a							,	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				:     Tuple    )	->Any:
													SCREAMING_SNAKE_CASE__     :				Any   =					[1, 3_06, 46_58, 2_78, 65_93, 3_10, 28_34, 3_38]
													SCREAMING_SNAKE_CASE__     :				str   =					LlamaForCausalLM.from_pretrained("meta-llama/Llama-2-70b-hf"							,	device_map="auto"    )
													SCREAMING_SNAKE_CASE__     :				Tuple   =					model(torch.tensor(a    )    )

													SCREAMING_SNAKE_CASE__     :				List[Any]   =					torch.tensor(
													    [[-4.2327, -3.3360, -4.6665, -4.7631, -1.8180, -3.4170, -1.4211, -3.1810]]							,	dtype=torch.floataa    )
													torch.testing.assert_close(out.mean(-1    )							,	a							,	atol=1E-2							,	rtol=1E-2    )
													# fmt: off
													SCREAMING_SNAKE_CASE__     :				Dict   =					torch.tensor([-9.4922, -3.9551, 1.7998, -5.6758, -5.1055, -5.8984, -4.8320, -6.8086, -6.5391, -5.6172, -5.5820, -5.5352, 1.7881, 3.6289, -6.5117, -3.4785, -9.5000, -6.0352, -6.8125, -6.0195, -6.6836, -5.4727, -6.2812, -6.0391, -7.3398, -7.4297, -7.4844, -6.5820, -5.8789, -5.5312]    )
													# fmt: on
													torch.testing.assert_close(out[0, 0, :30]							,	a							,	atol=1E-5							,	rtol=1E-5    )






							@unittest.skip("Model is curently gated"    )
							@slow
							def      A_  (      self				:     List[str]    )	->int:
													SCREAMING_SNAKE_CASE__     :				int   =					"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"
													SCREAMING_SNAKE_CASE__     :				Tuple   =					"Simply put, the theory of relativity states that "
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					LlamaTokenizer.from_pretrained("meta-llama/Llama-2-13b-chat-hf"    )
													SCREAMING_SNAKE_CASE__     :				List[Any]   =					tokenizer.encode(a							,	return_tensors="pt"    )
													SCREAMING_SNAKE_CASE__     :				List[Any]   =					LlamaForCausalLM.from_pretrained(
													    "meta-llama/Llama-2-13b-chat-hf"							,	device_map="sequential"							,	use_safetensors=a    )

													# greedy generation outputs
													SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					model.generate(a							,	max_new_tokens=64							,	top_p=a							,	temperature=1							,	do_sample=a    )
													SCREAMING_SNAKE_CASE__     :				List[Any]   =					tokenizer.decode(generated_ids[0]							,	skip_special_tokens=a    )
													self.assertEqual(a							,	a    )






def       UpperCAmelCase							(     _lowerCamelCase      :  int			,   _lowerCamelCase      :  bool = False     ):





						'''simple docstring'''


						if n == 2:
												return True
						if not n % 2 or n < 2:
												return False
						if n > 5 and n % 10 not in (1, 3, 7, 9):  # can quickly check last digit
												return False
						if n > 3_317_044_064_679_887_385_961_981 and not allow_probable:
												raise ValueError(
												    "Warning: upper bound of deterministic test is exceeded. "
												    "Pass allow_probable=True to allow probabilistic test. "
												    "A return value of True indicates a probable prime."     )
						# array bounds provided by analysis
						SCREAMING_SNAKE_CASE__     :				List[str]   =					[
						    2_047,
						    1_373_653,
						    25_326_001,
						    3_215_031_751,
						    2_152_302_898_747,
						    3_474_749_660_383,
						    341_550_071_728_321,
						    1,
						    3_825_123_056_546_413_051,
						    1,
						    1,
						    318_665_857_834_031_151_167_461,
						    3_317_044_064_679_887_385_961_981,
						]

						SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41]
						for idx, _p in enumerate(_lowerCamelCase			,   1     ):
												if n < _p:
																		# then we have our last prime to check
																		SCREAMING_SNAKE_CASE__     :				Dict   =					primes[:idx]
																		break
						SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__     :				Dict   =					n - 1, 0
						# break up n -1 into a power of 2 (s) and
						# remaining odd component
						# essentially, solve for d * 2 ** s == n - 1
						while d % 2 == 0:
												d //= 2
												s += 1
						for prime in plist:
												SCREAMING_SNAKE_CASE__     :				str   =					False
												for r in range(_lowerCamelCase     ):
																		SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					pow(_lowerCamelCase			,   d * 2**r			,   _lowerCamelCase     )
																		# see article for analysis explanation for m
																		if (r == 0 and m == 1) or ((m + 1) % n == 0):
																								SCREAMING_SNAKE_CASE__     :				str   =					True
																								# this loop will not determine compositeness
																								break
												if pr:
																		continue
												# if pr is False, then the above loop never evaluated to true,
												# and the n MUST be composite
												return False
						return True







def       UpperCAmelCase							(     ):





						'''simple docstring'''


						assert not miller_rabin(561     )
						assert miller_rabin(563     )
						# 2047

						assert not miller_rabin(838_201     )
						assert miller_rabin(838_207     )
						# 1_373_653

						assert not miller_rabin(17_316_001     )
						assert miller_rabin(17_316_017     )
						# 25_326_001

						assert not miller_rabin(3_078_386_641     )
						assert miller_rabin(3_078_386_653     )
						# 3_215_031_751

						assert not miller_rabin(1_713_045_574_801     )
						assert miller_rabin(1_713_045_574_819     )
						# 2_152_302_898_747

						assert not miller_rabin(2_779_799_728_307     )
						assert miller_rabin(2_779_799_728_327     )
						# 3_474_749_660_383

						assert not miller_rabin(113_850_023_909_441     )
						assert miller_rabin(113_850_023_909_527     )
						# 341_550_071_728_321

						assert not miller_rabin(1_275_041_018_848_804_351     )
						assert miller_rabin(1_275_041_018_848_804_391     )
						# 3_825_123_056_546_413_051

						assert not miller_rabin(79_666_464_458_507_787_791_867     )
						assert miller_rabin(79_666_464_458_507_787_791_951     )
						# 318_665_857_834_031_151_167_461

						assert not miller_rabin(552_840_677_446_647_897_660_333     )
						assert miller_rabin(552_840_677_446_647_897_660_359     )
						# 3_317_044_064_679_887_385_961_981
						# upper limit for probabilistic test


if __name__ == "__main__":
				test_miller_rabin()