



'''simple docstring'''






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







	"""simple docstring"""






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







	def   A			(		self    :  int	)    ->	str:
								UpperCAmelCase				: Any											=	ids_tensor([self.batch_size, self.seq_length]	,    self.vocab_size	)

								UpperCAmelCase				: List[Any]											=	None
								if self.use_input_mask:
															UpperCAmelCase				: Optional[Any]											=	random_attention_mask([self.batch_size, self.seq_length]	)

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

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

								UpperCAmelCase				: Tuple											=	self.get_config()

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







	def   A			(		self    :  List[Any]	)    ->	Optional[int]:
								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=__snake_case	,    initializer_range=self.initializer_range	,    )







	def   A			(		self    :  int	,    __snake_case    :  List[str]	,    __snake_case    :  List[str]	,    __snake_case    :  Dict	,    __snake_case    :  List[str]	,    __snake_case    :  Dict	,    __snake_case    :  Dict	,    __snake_case    :  int	)    ->	Tuple:
								UpperCAmelCase				: str											=	LlamaModel(config=__snake_case	)
								model.to(__snake_case	)
								model.eval()
								UpperCAmelCase				: List[Any]											=	model(__snake_case	,    attention_mask=__snake_case	)
								UpperCAmelCase				: Dict											=	model(__snake_case	)
								self.parent.assertEqual(result.last_hidden_state.shape	,    (self.batch_size, self.seq_length, self.hidden_size)	)







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







	def   A			(		self    :  Any	,    __snake_case    :  List[Any]	,    __snake_case    :  int	,    __snake_case    :  str	,    __snake_case    :  Any	,    __snake_case    :  str	,    __snake_case    :  List[Any]	,    __snake_case    :  List[str]	,    __snake_case    :  Dict	,    __snake_case    :  Tuple	,    )    ->	int:
								UpperCAmelCase				: Any											=	LlamaForCausalLM(config=__snake_case	)
								model.to(__snake_case	)
								model.eval()
								UpperCAmelCase				: Any											=	model(__snake_case	,    attention_mask=__snake_case	,    labels=__snake_case	)
								self.parent.assertEqual(result.logits.shape	,    (self.batch_size, self.seq_length, self.vocab_size)	)







	def   A			(		self    :  List[str]	,    __snake_case    :  str	,    __snake_case    :  Optional[int]	,    __snake_case    :  Tuple	,    __snake_case    :  Tuple	,    __snake_case    :  Union[str, Any]	,    __snake_case    :  List[str]	,    __snake_case    :  str	,    __snake_case    :  Optional[Any]	,    __snake_case    :  List[Any]	,    )    ->	List[str]:
								UpperCAmelCase				: Union[str, Any]											=	True
								UpperCAmelCase				: Tuple											=	True
								UpperCAmelCase				: Any											=	LlamaForCausalLM(config=__snake_case	)
								model.to(__snake_case	)
								model.eval()

								# first forward pass
								UpperCAmelCase				: Union[str, Any]											=	model(
								    __snake_case	,    attention_mask=__snake_case	,    encoder_hidden_states=__snake_case	,    encoder_attention_mask=__snake_case	,    use_cache=__snake_case	,    )
								UpperCAmelCase				: List[Any]											=	outputs.past_key_values

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

								# append to next input_ids and
								UpperCAmelCase				: Dict											=	torch.cat([input_ids, next_tokens]	,    dim=-1	)
								UpperCAmelCase				: Optional[int]											=	torch.cat([input_mask, next_mask]	,    dim=-1	)

								UpperCAmelCase				: List[str]											=	model(
								    __snake_case	,    attention_mask=__snake_case	,    encoder_hidden_states=__snake_case	,    encoder_attention_mask=__snake_case	,    output_hidden_states=__snake_case	,    )['''hidden_states'''][0]
								UpperCAmelCase				: List[str]											=	model(
								    __snake_case	,    attention_mask=__snake_case	,    encoder_hidden_states=__snake_case	,    encoder_attention_mask=__snake_case	,    past_key_values=__snake_case	,    output_hidden_states=__snake_case	,    )['''hidden_states'''][0]

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







	def   A			(		self    :  List[str]	)    ->	Any:
								UpperCAmelCase				: List[str]											=	self.prepare_config_and_inputs()
								(
								    (
								    UpperCAmelCase
								)							,	(
								    UpperCAmelCase
								)							,	(
								    UpperCAmelCase
								)							,	(
								    UpperCAmelCase
								)							,	(
								    UpperCAmelCase
								)							,	(
								    UpperCAmelCase
								)							,	(
								    UpperCAmelCase
								)							,	
								)				: List[str]											=	config_and_inputs
								UpperCAmelCase				: Any											=	{'''input_ids''': input_ids, '''attention_mask''': input_mask}
								return config, inputs_dict

@require_torch
class        SCREAMING_SNAKE_CASE(							A__							,	A__							,	A__							,	unittest.TestCase    ):







	"""simple docstring"""






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







	def   A			(		self    :  int	)    ->	int:
								UpperCAmelCase				: str											=	LlamaModelTester(self	)
								UpperCAmelCase				: Optional[Any]											=	ConfigTester(self	,    config_class=__snake_case	,    hidden_size=37	)







	def   A			(		self    :  str	)    ->	List[str]:
								self.config_tester.run_common_tests()







	def   A			(		self    :  Optional[Any]	)    ->	Tuple:
								UpperCAmelCase				: List[Any]											=	self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_model(*__snake_case	)







	def   A			(		self    :  List[Any]	)    ->	List[Any]:
								UpperCAmelCase				: List[str]											=	self.model_tester.prepare_config_and_inputs()
								for type in ["absolute", "relative_key", "relative_key_query"]:
															UpperCAmelCase				: List[Any]											=	type
															self.model_tester.create_and_check_model(*__snake_case	)







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







	def   A			(		self    :  int	)    ->	List[str]:
								UpperCAmelCase							,	UpperCAmelCase				: Any											=	self.model_tester.prepare_config_and_inputs_for_common()
								UpperCAmelCase				: Tuple											=	3
								UpperCAmelCase				: Tuple											=	'''single_label_classification'''
								UpperCAmelCase				: int											=	input_dict['''input_ids''']
								UpperCAmelCase				: List[str]											=	input_ids.ne(1	).to(__snake_case	)
								UpperCAmelCase				: List[Any]											=	ids_tensor([self.model_tester.batch_size]	,    self.model_tester.type_sequence_label_size	)
								UpperCAmelCase				: List[str]											=	LlamaForSequenceClassification(__snake_case	)
								model.to(__snake_case	)
								model.eval()
								UpperCAmelCase				: List[str]											=	model(__snake_case	,    attention_mask=__snake_case	,    labels=__snake_case	)
								self.assertEqual(result.logits.shape	,    (self.model_tester.batch_size, self.model_tester.num_labels)	)







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







	@parameterized.expand([('''linear''',), ('''dynamic''',)]	)
	def   A			(		self    :  Dict	,    __snake_case    :  Any	)    ->	int:
								UpperCAmelCase							,	UpperCAmelCase				: Tuple											=	self.model_tester.prepare_config_and_inputs_for_common()
								UpperCAmelCase				: str											=	ids_tensor([1, 10]	,    config.vocab_size	)
								UpperCAmelCase				: Dict											=	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
								UpperCAmelCase				: Dict											=	LlamaModel(__snake_case	)
								original_model.to(__snake_case	)
								original_model.eval()
								UpperCAmelCase				: Optional[int]											=	original_model(__snake_case	).last_hidden_state
								UpperCAmelCase				: List[str]											=	original_model(__snake_case	).last_hidden_state

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

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

@require_torch
class        SCREAMING_SNAKE_CASE(							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]	)    ->	Any:
								UpperCAmelCase				: Optional[Any]											=	[1, 306, 4658, 278, 6593, 310, 2834, 338]
								UpperCAmelCase				: List[str]											=	LlamaForCausalLM.from_pretrained('''meta-llama/Llama-2-7b-hf'''	,    device_map='''auto'''	)
								UpperCAmelCase				: List[str]											=	model(torch.tensor([input_ids]	)	)
								# Expected mean on dim = -1
								UpperCAmelCase				: str											=	torch.tensor([[-6.65_50, -4.12_27, -4.98_59, -3.24_06, 0.82_62, -3.00_33, 1.29_64, -3.36_99]]	)
								torch.testing.assert_close(out.mean(-1	)	,    __snake_case	,    atol=1E-2	,    rtol=1E-2	)
								# slicing logits[0, 0, 0:30]
								# fmt: off
								UpperCAmelCase				: Dict											=	torch.tensor([-12.82_81, -7.44_53, -0.46_39, -8.06_25, -7.25_00, -8.00_00, -6.48_83, -7.76_95, -7.84_38, -7.03_12, -6.21_88, -7.13_28, -1.84_96, 1.99_61, -8.62_50, -6.72_27, -12.82_81, -6.94_92, -7.07_42, -7.78_52, -7.58_20, -7.90_62, -6.93_75, -7.98_05, -8.34_38, -8.15_62, -8.04_69, -7.62_50, -7.74_22, -7.33_98,]	)
								# fmt: on
								torch.testing.assert_close(out[0, 0, :30]	,    __snake_case	,    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    :  List[str]	)    ->	List[str]:
								UpperCAmelCase				: str											=	[1, 306, 4658, 278, 6593, 310, 2834, 338]
								UpperCAmelCase				: Union[str, Any]											=	LlamaForCausalLM.from_pretrained('''meta-llama/Llama-2-13b-hf'''	,    device_map='''auto'''	)
								UpperCAmelCase				: Optional[int]											=	model(torch.tensor(__snake_case	)	)
								# Expected mean on dim = -1
								UpperCAmelCase				: List[Any]											=	torch.tensor([[-2.06_22, -1.27_94, -1.16_38, -0.97_88, -1.46_03, -1.02_38, -1.78_93, -1.44_11]]	)
								torch.testing.assert_close(out.mean(-1	)	,    __snake_case	,    atol=1E-2	,    rtol=1E-2	)
								# slicing logits[0, 0, 0:30]
								# fmt: off
								UpperCAmelCase				: List[Any]											=	torch.tensor([-8.14_06, -8.05_47, 2.74_61, -1.23_44, -0.14_48, -1.82_62, -1.00_20, -1.81_54, -1.68_95, -1.85_16, -2.35_74, -0.92_77, 3.75_98, 6.57_42, -1.29_98, -0.11_77, -8.14_06, -2.96_88, -2.91_99, -3.16_99, -3.52_54, -2.35_55, -2.79_88, -3.41_41, -2.82_62, -4.51_95, -3.33_79, -3.31_64, -2.78_32, -3.02_73]	)
								# fmt: on
								torch.testing.assert_close(out[0, 0, :30]	,    __snake_case	,    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    :  Union[str, Any]	)    ->	Optional[Any]:
								UpperCAmelCase				: str											=	[1, 306, 4658, 278, 6593, 310, 2834, 338]
								UpperCAmelCase				: Optional[int]											=	LlamaForCausalLM.from_pretrained('''meta-llama/Llama-2-13b-chat-hf'''	,    device_map='''auto'''	)
								UpperCAmelCase				: str											=	model(torch.tensor(__snake_case	)	)
								# Expected mean on dim = -1
								UpperCAmelCase				: Optional[Any]											=	torch.tensor([[-0.85_62, -1.85_20, -0.75_51, -0.41_62, -1.51_61, -1.20_38, -2.48_23, -2.32_54]]	)
								torch.testing.assert_close(out.mean(-1	)	,    __snake_case	,    atol=1E-2	,    rtol=1E-2	)
								# slicing logits[0, 0, 0:30]
								# fmt: off
								UpperCAmelCase				: Dict											=	torch.tensor([-2.22_27, 4.88_28, 0.90_23, -0.45_78, -0.78_71, -0.10_33, -0.62_21, -0.57_86, -0.78_03, -1.06_74, -1.29_20, -0.15_70, 0.80_08, 2.07_23, -0.94_97, 0.27_71, -2.22_27, -0.76_12, -1.43_46, -1.20_61, -1.64_26, -0.30_00, -0.71_39, -1.19_34, -1.86_91, -1.69_73, -1.59_47, -1.27_05, -0.35_23, -0.55_13]	)
								# fmt: on
								torch.testing.assert_close(out.mean(-1	)	,    __snake_case	,    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    :  Dict	)    ->	Any:
								UpperCAmelCase				: Union[str, Any]											=	[1, 306, 4658, 278, 6593, 310, 2834, 338]
								UpperCAmelCase				: Union[str, Any]											=	LlamaForCausalLM.from_pretrained('''meta-llama/Llama-2-70b-hf'''	,    device_map='''auto'''	)
								UpperCAmelCase				: Optional[int]											=	model(torch.tensor(__snake_case	)	)

								UpperCAmelCase				: Union[str, Any]											=	torch.tensor(
								    [[-4.23_27, -3.33_60, -4.66_65, -4.76_31, -1.81_80, -3.41_70, -1.42_11, -3.18_10]]	,    dtype=torch.floataa	)
								torch.testing.assert_close(out.mean(-1	)	,    __snake_case	,    atol=1E-2	,    rtol=1E-2	)
								# fmt: off
								UpperCAmelCase				: List[str]											=	torch.tensor([-9.49_22, -3.95_51, 1.79_98, -5.67_58, -5.10_55, -5.89_84, -4.83_20, -6.80_86, -6.53_91, -5.61_72, -5.58_20, -5.53_52, 1.78_81, 3.62_89, -6.51_17, -3.47_85, -9.50_00, -6.03_52, -6.81_25, -6.01_95, -6.68_36, -5.47_27, -6.28_12, -6.03_91, -7.33_98, -7.42_97, -7.48_44, -6.58_20, -5.87_89, -5.53_12]	)
								# fmt: on
								torch.testing.assert_close(out[0, 0, :30]	,    __snake_case	,    atol=1E-5	,    rtol=1E-5	)







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

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










'''simple docstring'''






import math

import tensorflow as tf
from packaging import version


def 				snake_case_  (      _lowerCAmelCase						:		List[str]						)   ->     Dict:
							UpperCAmelCase				: Tuple											=	tf.convert_to_tensor(_lowerCAmelCase						)
							UpperCAmelCase				: Dict											=	0.5 * (1.0 + tf.math.erf(x / tf.cast(tf.sqrt(2.0						)     ,   x.dtype						)						))

							return x * cdf


def 				snake_case_  (      _lowerCAmelCase						:		int						)   ->     List[Any]:
							UpperCAmelCase				: str											=	tf.convert_to_tensor(_lowerCAmelCase						)
							UpperCAmelCase				: Union[str, Any]											=	tf.cast(math.pi     ,   x.dtype						)
							UpperCAmelCase				: Tuple											=	tf.cast(0.0_4_4_7_1_5     ,   x.dtype						)
							UpperCAmelCase				: List[Any]											=	0.5 * (1.0 + tf.tanh(tf.sqrt(2.0 / pi						) * (x + coeff * tf.pow(_lowerCAmelCase     ,   3						))						))

							return x * cdf


def 				snake_case_  (      _lowerCAmelCase						:		Optional[Any]						)   ->     Any:
							UpperCAmelCase				: List[Any]											=	tf.convert_to_tensor(_lowerCAmelCase						)

							return x * tf.tanh(tf.math.softplus(_lowerCAmelCase						)						)


def 				snake_case_  (      _lowerCAmelCase						:		str						)   ->     Tuple:
							UpperCAmelCase				: Union[str, Any]											=	tf.convert_to_tensor(_lowerCAmelCase						)
							UpperCAmelCase				: Union[str, Any]											=	tf.cast(0.0_4_4_7_1_5     ,   x.dtype						)
							UpperCAmelCase				: Tuple											=	tf.cast(0.7_9_7_8_8_4_5_6_0_8     ,   x.dtype						)

							return 0.5 * x * (1.0 + tf.tanh(x * coeffa * (1.0 + coeffa * x * x)						))


def 				snake_case_  (      _lowerCAmelCase						:		Optional[Any]						)   ->     Optional[int]:
							UpperCAmelCase				: str											=	tf.convert_to_tensor(_lowerCAmelCase						)
							UpperCAmelCase				: Optional[int]											=	tf.cast(1.7_0_2     ,   x.dtype						)
							return x * tf.math.sigmoid(coeff * x						)


def 				snake_case_  (      _lowerCAmelCase						:		Any						)   ->     Any:
							return tf.clip_by_value(_gelu(_lowerCAmelCase						)     ,   -10     ,   10						)


def 				snake_case_  (      _lowerCAmelCase						:		Dict     ,   _lowerCAmelCase						:		Optional[Any]=-1						)   ->     Union[str, Any]:
							UpperCAmelCase							,	UpperCAmelCase				: Optional[Any]											=	tf.split(_lowerCAmelCase     ,   2     ,   axis=_lowerCAmelCase						)
							return a * tf.math.sigmoid(_lowerCAmelCase						)


if version.parse(tf.version.VERSION) >= version.parse("2.4"):


						def 				snake_case_  (      _lowerCAmelCase						:		Tuple						)   ->     Any:
													return tf.keras.activations.gelu(_lowerCAmelCase     ,   approximate=_lowerCAmelCase						)

						UpperCamelCase__:     List[Any]										=    tf.keras.activations.gelu




						UpperCamelCase__:     List[Any]										=    approximate_gelu_wrap
else:
						UpperCamelCase__:     List[str]										=    _gelu
						UpperCamelCase__:     Tuple										=    _gelu_new


UpperCamelCase__:     List[Any]										=    {
    "gelu": gelu,
    "gelu_10": gelu_aa,
    "gelu_fast": gelu_fast,
    "gelu_new": gelu_new,
    "glu": glu,
    "mish": mish,
    "quick_gelu": quick_gelu,
    "relu": tf.keras.activations.relu,
    "sigmoid": tf.keras.activations.sigmoid,
    "silu": tf.keras.activations.swish,
    "swish": tf.keras.activations.swish,
    "tanh": tf.keras.activations.tanh,
}




def 				snake_case_  (      _lowerCAmelCase						:		Dict						)   ->     List[Any]:
							if activation_string in ACTaFN:
														return ACTaFN[activation_string]
							else:
														raise KeyError(f"""function {activation_string} not found in ACT2FN mapping {list(ACTaFN.keys()						)}"""						)





