'''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 					__magic_name__		:







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







			def 			SCREAMING_SNAKE_CASE_  (			self       :						str					):
										lowercase_      :    Optional[int]       		= ids_tensor([self.batch_size, self.seq_length]       ,    self.vocab_size					)

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

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

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

										lowercase_      :    Any       		= self.get_config()

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







			def 			SCREAMING_SNAKE_CASE_  (			self       :						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=lowercase_       ,    initializer_range=self.initializer_range       ,    )







			def 			SCREAMING_SNAKE_CASE_  (			self       :						Any       ,    lowercase_       :						Tuple       ,    lowercase_       :						Any       ,    lowercase_       :						Dict       ,    lowercase_       :						Tuple       ,    lowercase_       :						Tuple       ,    lowercase_       :						str       ,    lowercase_       :						Union[str, Any]					):
										lowercase_      :    Optional[Any]       		= LlamaModel(config=lowercase_					)
										model.to(lowercase_					)
										model.eval()
										lowercase_      :    Tuple       		= model(lowercase_       ,    attention_mask=lowercase_					)
										lowercase_      :    int       		= model(lowercase_					)
										self.parent.assertEqual(result.last_hidden_state.shape       ,    (self.batch_size, self.seq_length, self.hidden_size)					)







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







			def 			SCREAMING_SNAKE_CASE_  (			self       :						List[Any]       ,    lowercase_       :						Tuple       ,    lowercase_       :						Optional[Any]       ,    lowercase_       :						List[str]       ,    lowercase_       :						Optional[int]       ,    lowercase_       :						Dict       ,    lowercase_       :						Optional[Any]       ,    lowercase_       :						List[Any]       ,    lowercase_       :						str       ,    lowercase_       :						Optional[int]       ,    ):
										lowercase_      :    Dict       		= LlamaForCausalLM(config=lowercase_					)
										model.to(lowercase_					)
										model.eval()
										lowercase_      :    Tuple       		= model(lowercase_       ,    attention_mask=lowercase_       ,    labels=lowercase_					)
										self.parent.assertEqual(result.logits.shape       ,    (self.batch_size, self.seq_length, self.vocab_size)					)







			def 			SCREAMING_SNAKE_CASE_  (			self       :						Any       ,    lowercase_       :						Union[str, Any]       ,    lowercase_       :						List[Any]       ,    lowercase_       :						List[Any]       ,    lowercase_       :						Union[str, Any]       ,    lowercase_       :						Optional[int]       ,    lowercase_       :						int       ,    lowercase_       :						int       ,    lowercase_       :						str       ,    lowercase_       :						Optional[Any]       ,    ):
										lowercase_      :    str       		= True
										lowercase_      :    List[str]       		= True
										lowercase_      :    Union[str, Any]       		= LlamaForCausalLM(config=lowercase_					)
										model.to(lowercase_					)
										model.eval()

										# first forward pass
										lowercase_      :    Optional[int]       		= model(
										    lowercase_       ,    attention_mask=lowercase_       ,    encoder_hidden_states=lowercase_       ,    encoder_attention_mask=lowercase_       ,    use_cache=lowercase_       ,    )
										lowercase_      :    Optional[Any]       		= outputs.past_key_values

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

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

										lowercase_      :    Union[str, Any]       		= model(
										    lowercase_       ,    attention_mask=lowercase_       ,    encoder_hidden_states=lowercase_       ,    encoder_attention_mask=lowercase_       ,    output_hidden_states=lowercase_       ,    )["""hidden_states"""][0]
										lowercase_      :    List[Any]       		= model(
										    lowercase_       ,    attention_mask=lowercase_       ,    encoder_hidden_states=lowercase_       ,    encoder_attention_mask=lowercase_       ,    past_key_values=lowercase_       ,    output_hidden_states=lowercase_       ,    )["""hidden_states"""][0]

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







			def 			SCREAMING_SNAKE_CASE_  (			self       :						str					):
										lowercase_      :    Tuple       		= self.prepare_config_and_inputs()
										(
										    (
										    lowercase_
										)		,		(
										    lowercase_
										)		,		(
										    lowercase_
										)		,		(
										    lowercase_
										)		,		(
										    lowercase_
										)		,		(
										    lowercase_
										)		,		(
										    lowercase_
										)		,		
										)      :    str       		= config_and_inputs
										lowercase_      :    Optional[int]       		= {"""input_ids""": input_ids, """attention_mask""": input_mask}
										return config, inputs_dict





@require_torch
class 					__magic_name__		(					_UpperCAmelCase,  _UpperCAmelCase,  _UpperCAmelCase,  unittest.TestCase):
			UpperCamelCase__       = (LlamaModel, LlamaForCausalLM, LlamaForSequenceClassification) if is_torch_available() else ()
			UpperCamelCase__       = (LlamaForCausalLM,) if is_torch_available() else ()
			UpperCamelCase__       = (
			    {
			        '''feature-extraction''': LlamaModel,
			        '''text-classification''': LlamaForSequenceClassification,
			        '''text-generation''': LlamaForCausalLM,
			        '''zero-shot''': LlamaForSequenceClassification,
			    }
			    if is_torch_available()
			    else {}
			)
			UpperCamelCase__       = False
			UpperCamelCase__       = False







			def 			SCREAMING_SNAKE_CASE_  (			self       :						Dict					):
										lowercase_      :    str       		= LlamaModelTester(self					)
										lowercase_      :    Dict       		= ConfigTester(self       ,    config_class=lowercase_       ,    hidden_size=37					)







			def 			SCREAMING_SNAKE_CASE_  (			self       :						Union[str, Any]					):
										self.config_tester.run_common_tests()







			def 			SCREAMING_SNAKE_CASE_  (			self       :						Optional[Any]					):
										lowercase_      :    List[Any]       		= self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_model(*lowercase_					)







			def 			SCREAMING_SNAKE_CASE_  (			self       :						Optional[Any]					):
										lowercase_      :    int       		= self.model_tester.prepare_config_and_inputs()
										for type in ["absolute", "relative_key", "relative_key_query"]:
																	lowercase_      :    List[Any]       		= type
																	self.model_tester.create_and_check_model(*lowercase_					)







			def 			SCREAMING_SNAKE_CASE_  (			self       :						Union[str, Any]					):
										lowercase_		,		lowercase_      :    Any       		= self.model_tester.prepare_config_and_inputs_for_common()
										lowercase_      :    Union[str, Any]       		= 3
										lowercase_      :    List[str]       		= input_dict["""input_ids"""]
										lowercase_      :    Any       		= input_ids.ne(1					).to(lowercase_					)
										lowercase_      :    List[str]       		= ids_tensor([self.model_tester.batch_size]       ,    self.model_tester.type_sequence_label_size					)
										lowercase_      :    List[Any]       		= LlamaForSequenceClassification(lowercase_					)
										model.to(lowercase_					)
										model.eval()
										lowercase_      :    Any       		= model(lowercase_       ,    attention_mask=lowercase_       ,    labels=lowercase_					)
										self.assertEqual(result.logits.shape       ,    (self.model_tester.batch_size, self.model_tester.num_labels)					)







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







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







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

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

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





@require_torch
class 					__magic_name__		(					unittest.TestCase):







			@unittest.skip("""Logits are not exactly the same, once we fix the instabalities somehow, will update!"""					)
			@slow
			def 			SCREAMING_SNAKE_CASE_  (			self       :						List[str]					):
										lowercase_      :    Optional[Any]       		= [1, 306, 4658, 278, 6593, 310, 2834, 338]
										lowercase_      :    str       		= LlamaForCausalLM.from_pretrained("""meta-llama/Llama-2-7b-hf"""       ,    device_map="""auto"""					)
										lowercase_      :    Optional[Any]       		= model(torch.tensor([input_ids]					)					)
										# Expected mean on dim = -1
										lowercase_      :    List[Any]       		= 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					)       ,    lowercase_       ,    atol=1E-2       ,    rtol=1E-2					)
										# slicing logits[0, 0, 0:30]
										# fmt: off
										lowercase_      :    Tuple       		= 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]       ,    lowercase_       ,    atol=1E-5       ,    rtol=1E-5					)







			@unittest.skip("""Logits are not exactly the same, once we fix the instabalities somehow, will update!"""					)
			@slow
			def 			SCREAMING_SNAKE_CASE_  (			self       :						int					):
										lowercase_      :    List[str]       		= [1, 306, 4658, 278, 6593, 310, 2834, 338]
										lowercase_      :    Any       		= LlamaForCausalLM.from_pretrained("""meta-llama/Llama-2-13b-hf"""       ,    device_map="""auto"""					)
										lowercase_      :    int       		= model(torch.tensor(lowercase_					)					)
										# Expected mean on dim = -1
										lowercase_      :    Tuple       		= 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					)       ,    lowercase_       ,    atol=1E-2       ,    rtol=1E-2					)
										# slicing logits[0, 0, 0:30]
										# fmt: off
										lowercase_      :    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]       ,    lowercase_       ,    atol=1E-5       ,    rtol=1E-5					)







			@unittest.skip("""Logits are not exactly the same, once we fix the instabalities somehow, will update!"""					)
			@slow
			def 			SCREAMING_SNAKE_CASE_  (			self       :						Dict					):
										lowercase_      :    Union[str, Any]       		= [1, 306, 4658, 278, 6593, 310, 2834, 338]
										lowercase_      :    Any       		= LlamaForCausalLM.from_pretrained("""meta-llama/Llama-2-13b-chat-hf"""       ,    device_map="""auto"""					)
										lowercase_      :    Union[str, Any]       		= model(torch.tensor(lowercase_					)					)
										# Expected mean on dim = -1
										lowercase_      :    Tuple       		= 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					)       ,    lowercase_       ,    atol=1E-2       ,    rtol=1E-2					)
										# slicing logits[0, 0, 0:30]
										# fmt: off
										lowercase_      :    Tuple       		= 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					)       ,    lowercase_       ,    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 			SCREAMING_SNAKE_CASE_  (			self       :						int					):
										lowercase_      :    Optional[int]       		= [1, 306, 4658, 278, 6593, 310, 2834, 338]
										lowercase_      :    str       		= LlamaForCausalLM.from_pretrained("""meta-llama/Llama-2-70b-hf"""       ,    device_map="""auto"""					)
										lowercase_      :    List[str]       		= model(torch.tensor(lowercase_					)					)

										lowercase_      :    int       		= 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					)       ,    lowercase_       ,    atol=1E-2       ,    rtol=1E-2					)
										# fmt: off
										lowercase_      :    Tuple       		= 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]       ,    lowercase_       ,    atol=1E-5       ,    rtol=1E-5					)







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

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






'''simple docstring'''




from typing import TYPE_CHECKING

# rely on isort to merge the imports
from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


_lowercase		:				List[Any]	       =		{"configuration_focalnet": ["FOCALNET_PRETRAINED_CONFIG_ARCHIVE_MAP", "FocalNetConfig"]}


try:
						if not is_torch_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						_lowercase		:				int	       =		[
						    "FOCALNET_PRETRAINED_MODEL_ARCHIVE_LIST",
						    "FocalNetForImageClassification",
						    "FocalNetForMaskedImageModeling",
						    "FocalNetBackbone",
						    "FocalNetModel",
						    "FocalNetPreTrainedModel",
						]

if TYPE_CHECKING:
						from .configuration_focalnet import FOCALNET_PRETRAINED_CONFIG_ARCHIVE_MAP, FocalNetConfig

						try:
												if not is_torch_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_focalnet import (
												    FOCALNET_PRETRAINED_MODEL_ARCHIVE_LIST,
												    FocalNetBackbone,
												    FocalNetForImageClassification,
												    FocalNetForMaskedImageModeling,
												    FocalNetModel,
												    FocalNetPreTrainedModel,
												)

else:
						import sys

						_lowercase		:				Union[str, Any]	       =		_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)





