


import unittest

from transformers import AutoTokenizer, FalconConfig, is_torch_available
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 (
				    FalconForCausalLM,
				    FalconForQuestionAnswering,
				    FalconForSequenceClassification,
				    FalconForTokenClassification,
				    FalconModel,
				)







class 	__lowercase    :





							"""simple docstring"""







							def __init__(      self			,						lowerCAmelCase__			,						lowerCAmelCase__=3			,						lowerCAmelCase__=7			,						lowerCAmelCase__=True			,						lowerCAmelCase__=True			,						lowerCAmelCase__=False			,						lowerCAmelCase__=True			,						lowerCAmelCase__=9_9			,						lowerCAmelCase__=3_2			,						lowerCAmelCase__=5			,						lowerCAmelCase__=4			,						lowerCAmelCase__=3_7			,						lowerCAmelCase__="gelu"			,						lowerCAmelCase__=0.1			,						lowerCAmelCase__=0.1			,						lowerCAmelCase__=5_1_2			,						lowerCAmelCase__=1_6			,						lowerCAmelCase__=2			,						lowerCAmelCase__=0.02			,						lowerCAmelCase__=3			,						lowerCAmelCase__=4			,						lowerCAmelCase__=None			,						):





										"""simple docstring"""




										SCREAMING_SNAKE_CASE_		:     Tuple					=					parent
										SCREAMING_SNAKE_CASE_		:     int					=					batch_size
										SCREAMING_SNAKE_CASE_		:     Tuple					=					seq_length
										SCREAMING_SNAKE_CASE_		:     int					=					is_training
										SCREAMING_SNAKE_CASE_		:     Any					=					use_input_mask
										SCREAMING_SNAKE_CASE_		:     int					=					use_token_type_ids
										SCREAMING_SNAKE_CASE_		:     Any					=					use_labels
										SCREAMING_SNAKE_CASE_		:     List[str]					=					vocab_size
										SCREAMING_SNAKE_CASE_		:     int					=					hidden_size
										SCREAMING_SNAKE_CASE_		:     List[str]					=					num_hidden_layers
										SCREAMING_SNAKE_CASE_		:     List[Any]					=					num_attention_heads
										SCREAMING_SNAKE_CASE_		:     Tuple					=					intermediate_size
										SCREAMING_SNAKE_CASE_		:     Any					=					hidden_act
										SCREAMING_SNAKE_CASE_		:     List[str]					=					hidden_dropout_prob
										SCREAMING_SNAKE_CASE_		:     Union[str, Any]					=					attention_probs_dropout_prob
										SCREAMING_SNAKE_CASE_		:     List[str]					=					max_position_embeddings
										SCREAMING_SNAKE_CASE_		:     Optional[Any]					=					type_vocab_size
										SCREAMING_SNAKE_CASE_		:     Union[str, Any]					=					type_sequence_label_size
										SCREAMING_SNAKE_CASE_		:     int					=					initializer_range
										SCREAMING_SNAKE_CASE_		:     str					=					num_labels
										SCREAMING_SNAKE_CASE_		:     Union[str, Any]					=					num_choices
										SCREAMING_SNAKE_CASE_		:     Tuple					=					scope






							def 					UpperCamelCase__     (      self       ):





										"""simple docstring"""




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

										SCREAMING_SNAKE_CASE_		:     Union[str, Any]					=					None
										if self.use_input_mask:
													SCREAMING_SNAKE_CASE_		:     Any					=					random_attention_mask([self.batch_size, self.seq_length]       )

										SCREAMING_SNAKE_CASE_		:     List[Any]					=					None

										SCREAMING_SNAKE_CASE_		:     str					=					None
										SCREAMING_SNAKE_CASE_		:     Optional[Any]					=					None
										SCREAMING_SNAKE_CASE_		:     int					=					None
										if self.use_labels:
													SCREAMING_SNAKE_CASE_		:     int					=					ids_tensor([self.batch_size]			,						self.type_sequence_label_size       )
													SCREAMING_SNAKE_CASE_		:     Optional[Any]					=					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 					UpperCamelCase__     (      self       ):





										"""simple docstring"""




										return FalconConfig(
										    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			,						pad_token_id=1			,						new_decoder_architecture=lowerCAmelCase__			,						)






							def 					UpperCamelCase__     (      self			,						lowerCAmelCase__			,						lowerCAmelCase__			,						lowerCAmelCase__			,						lowerCAmelCase__			,						lowerCAmelCase__			,						lowerCAmelCase__			,						lowerCAmelCase__       ):





										"""simple docstring"""




										SCREAMING_SNAKE_CASE_		:     Dict					=					FalconModel(config=lowerCAmelCase__       )
										model.to(lowerCAmelCase__       )
										model.eval()
										SCREAMING_SNAKE_CASE_		:     Any					=					model(lowerCAmelCase__			,						attention_mask=lowerCAmelCase__       )
										SCREAMING_SNAKE_CASE_		:     List[Any]					=					model(lowerCAmelCase__       )
										self.parent.assertEqual(result.last_hidden_state.shape			,						(self.batch_size, self.seq_length, self.hidden_size)       )






							def 					UpperCamelCase__     (      self			,						lowerCAmelCase__			,						lowerCAmelCase__			,						lowerCAmelCase__			,						lowerCAmelCase__			,						lowerCAmelCase__			,						lowerCAmelCase__			,						lowerCAmelCase__			,						lowerCAmelCase__			,						lowerCAmelCase__			,						):





										"""simple docstring"""




										SCREAMING_SNAKE_CASE_		:     int					=					True
										SCREAMING_SNAKE_CASE_		:     int					=					FalconModel(lowerCAmelCase__       )
										model.to(lowerCAmelCase__       )
										model.eval()
										SCREAMING_SNAKE_CASE_		:     Tuple					=					model(
										    lowerCAmelCase__			,						attention_mask=lowerCAmelCase__			,						encoder_hidden_states=lowerCAmelCase__			,						encoder_attention_mask=lowerCAmelCase__			,						)
										SCREAMING_SNAKE_CASE_		:     Dict					=					model(
										    lowerCAmelCase__			,						attention_mask=lowerCAmelCase__			,						encoder_hidden_states=lowerCAmelCase__			,						)
										SCREAMING_SNAKE_CASE_		:     Union[str, Any]					=					model(lowerCAmelCase__			,						attention_mask=lowerCAmelCase__       )
										self.parent.assertEqual(result.last_hidden_state.shape			,						(self.batch_size, self.seq_length, self.hidden_size)       )






							def 					UpperCamelCase__     (      self			,						lowerCAmelCase__			,						lowerCAmelCase__			,						lowerCAmelCase__			,						lowerCAmelCase__			,						lowerCAmelCase__			,						lowerCAmelCase__			,						lowerCAmelCase__			,						lowerCAmelCase__			,						lowerCAmelCase__			,						):





										"""simple docstring"""




										SCREAMING_SNAKE_CASE_		:     Any					=					FalconForCausalLM(config=lowerCAmelCase__       )
										model.to(lowerCAmelCase__       )
										model.eval()
										SCREAMING_SNAKE_CASE_		:     Dict					=					model(lowerCAmelCase__			,						attention_mask=lowerCAmelCase__			,						labels=lowerCAmelCase__       )
										self.parent.assertEqual(result.logits.shape			,						(self.batch_size, self.seq_length, self.vocab_size)       )






							def 					UpperCamelCase__     (      self			,						lowerCAmelCase__			,						lowerCAmelCase__			,						lowerCAmelCase__			,						lowerCAmelCase__			,						lowerCAmelCase__			,						lowerCAmelCase__			,						lowerCAmelCase__			,						lowerCAmelCase__			,						lowerCAmelCase__			,						):





										"""simple docstring"""




										SCREAMING_SNAKE_CASE_		:     int					=					True
										SCREAMING_SNAKE_CASE_		:     Optional[Any]					=					True
										SCREAMING_SNAKE_CASE_		:     Union[str, Any]					=					FalconForCausalLM(config=lowerCAmelCase__       )
										model.to(lowerCAmelCase__       )
										model.eval()

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

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

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

										SCREAMING_SNAKE_CASE_		:     List[str]					=					model(
										    lowerCAmelCase__			,						attention_mask=lowerCAmelCase__			,						encoder_hidden_states=lowerCAmelCase__			,						encoder_attention_mask=lowerCAmelCase__			,						output_hidden_states=lowerCAmelCase__			,						)['hidden_states'][0]
										SCREAMING_SNAKE_CASE_		:     Any					=					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
										SCREAMING_SNAKE_CASE_		:     List[Any]					=					ids_tensor((1,)			,						output_from_past.shape[-1]       ).item()
										SCREAMING_SNAKE_CASE_		:     str					=					output_from_no_past[:, -3:, random_slice_idx].detach()
										SCREAMING_SNAKE_CASE_		:     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(lowerCAmelCase__			,						lowerCAmelCase__			,						atol=1E-3       )       )






							def 					UpperCamelCase__     (      self       ):





										"""simple docstring"""




										SCREAMING_SNAKE_CASE_		:     Any					=					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_
										)		,      
										)		:     Any					=					config_and_inputs
										SCREAMING_SNAKE_CASE_		:     str					=					{'input_ids': input_ids, 'attention_mask': input_mask}
										return config, inputs_dict







@require_torch
class 	__lowercase    (__SCREAMING_SNAKE_CASE	,       __SCREAMING_SNAKE_CASE	,       __SCREAMING_SNAKE_CASE	,       unittest.TestCase  ):





							"""simple docstring"""







							_UpperCAmelCase      =						(
							    (
							        FalconModel,
							        FalconForCausalLM,
							        FalconForSequenceClassification,
							        FalconForTokenClassification,
							        FalconForQuestionAnswering,
							    )
							    if is_torch_available()
							    else ()
							)
							_UpperCAmelCase      =						(FalconForCausalLM,) if is_torch_available() else ()
							_UpperCAmelCase      =						(
							    {
							        """feature-extraction""": FalconModel,
							        """text-classification""": FalconForSequenceClassification,
							        """text-generation""": FalconForCausalLM,
							        """question-answering""": FalconForQuestionAnswering,
							        """token-classification""": FalconForTokenClassification,
							        """zero-shot""": FalconForSequenceClassification,
							    }
							    if is_torch_available()
							    else {}
							)
							_UpperCAmelCase      =						False
							_UpperCAmelCase      =						False






							def 					UpperCamelCase__     (      self       ):





										"""simple docstring"""




										SCREAMING_SNAKE_CASE_		:     Dict					=					FalconModelTester(self       )
										SCREAMING_SNAKE_CASE_		:     Any					=					ConfigTester(self			,						config_class=lowerCAmelCase__			,						hidden_size=3_7       )






							def 					UpperCamelCase__     (      self       ):





										"""simple docstring"""




										self.config_tester.run_common_tests()






							def 					UpperCamelCase__     (      self       ):





										"""simple docstring"""




										SCREAMING_SNAKE_CASE_		:     Dict					=					self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_model(*lowerCAmelCase__       )






							def 					UpperCamelCase__     (      self       ):





										"""simple docstring"""




										SCREAMING_SNAKE_CASE_		,      *SCREAMING_SNAKE_CASE_		:     Union[str, Any]					=					self.model_tester.prepare_config_and_inputs()
										for alibi in [True, False]:
													SCREAMING_SNAKE_CASE_		:     Dict					=					alibi
													self.model_tester.create_and_check_model(lowerCAmelCase__			,						*lowerCAmelCase__       )






							def 					UpperCamelCase__     (      self       ):





										"""simple docstring"""




										SCREAMING_SNAKE_CASE_		,      SCREAMING_SNAKE_CASE_		:     Tuple					=					self.model_tester.prepare_config_and_inputs_for_common()
										SCREAMING_SNAKE_CASE_		:     int					=					3
										SCREAMING_SNAKE_CASE_		:     str					=					input_dict['input_ids']
										SCREAMING_SNAKE_CASE_		:     Optional[Any]					=					input_ids.ne(1       ).to(lowerCAmelCase__       )
										SCREAMING_SNAKE_CASE_		:     Any					=					ids_tensor([self.model_tester.batch_size]			,						self.model_tester.type_sequence_label_size       )
										SCREAMING_SNAKE_CASE_		:     int					=					FalconForSequenceClassification(lowerCAmelCase__       )
										model.to(lowerCAmelCase__       )
										model.eval()
										SCREAMING_SNAKE_CASE_		:     Optional[Any]					=					model(lowerCAmelCase__			,						attention_mask=lowerCAmelCase__			,						labels=lowerCAmelCase__       )
										self.assertEqual(result.logits.shape			,						(self.model_tester.batch_size, self.model_tester.num_labels)       )






							def 					UpperCamelCase__     (      self       ):





										"""simple docstring"""




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






							def 					UpperCamelCase__     (      self       ):





										"""simple docstring"""




										SCREAMING_SNAKE_CASE_		,      SCREAMING_SNAKE_CASE_		:     List[Any]					=					self.model_tester.prepare_config_and_inputs_for_common()
										SCREAMING_SNAKE_CASE_		:     Dict					=					input_dict['input_ids']
										SCREAMING_SNAKE_CASE_		:     Dict					=					FalconForCausalLM(lowerCAmelCase__       )
										model.to(lowerCAmelCase__       )
										model.eval()
										SCREAMING_SNAKE_CASE_		:     str					=					model(lowerCAmelCase__			,						use_cache=lowerCAmelCase__       )
										SCREAMING_SNAKE_CASE_		:     Any					=					input_ids.shape[0]
										SCREAMING_SNAKE_CASE_		:     Optional[int]					=					model._convert_to_rw_cache(result.past_key_values       )
										SCREAMING_SNAKE_CASE_		:     Optional[int]					=					model._convert_cache_to_standard_format(lowerCAmelCase__			,						lowerCAmelCase__       )
										for layer in range(len(lowerCAmelCase__       )       ):
													for tensor_idx in range(2       ):
																self.assertTrue(rw_cache[layer][tensor_idx].ndim == 3       )
																self.assertTrue(result.past_key_values[layer][tensor_idx].ndim == 4       )
																self.assertTrue(
																    torch.all(result.past_key_values[layer][tensor_idx] == standard_cache[layer][tensor_idx]       )       )






							def 					UpperCamelCase__     (      self       ):





										"""simple docstring"""




										SCREAMING_SNAKE_CASE_		,      SCREAMING_SNAKE_CASE_		:     Union[str, Any]					=					self.model_tester.prepare_config_and_inputs_for_common()
										SCREAMING_SNAKE_CASE_		:     List[Any]					=					3
										SCREAMING_SNAKE_CASE_		:     Dict					=					'multi_label_classification'
										SCREAMING_SNAKE_CASE_		:     Dict					=					input_dict['input_ids']
										SCREAMING_SNAKE_CASE_		:     Tuple					=					input_ids.ne(1       ).to(lowerCAmelCase__       )
										SCREAMING_SNAKE_CASE_		:     Optional[Any]					=					ids_tensor(
										    [self.model_tester.batch_size, config.num_labels]			,						self.model_tester.type_sequence_label_size       ).to(torch.float       )
										SCREAMING_SNAKE_CASE_		:     Tuple					=					FalconForSequenceClassification(lowerCAmelCase__       )
										model.to(lowerCAmelCase__       )
										model.eval()
										SCREAMING_SNAKE_CASE_		:     Union[str, Any]					=					model(lowerCAmelCase__			,						attention_mask=lowerCAmelCase__			,						labels=lowerCAmelCase__       )
										self.assertEqual(result.logits.shape			,						(self.model_tester.batch_size, self.model_tester.num_labels)       )






							def 					UpperCamelCase__     (      self       ):





										"""simple docstring"""




										for model_class in self.all_generative_model_classes:
													SCREAMING_SNAKE_CASE_		,      SCREAMING_SNAKE_CASE_		:     List[str]					=					self.model_tester.prepare_config_and_inputs_for_common()

													# If it doesn't support cache, pass the test
													if not hasattr(lowerCAmelCase__			,						'use_cache'       ):
																return

													SCREAMING_SNAKE_CASE_		:     Dict					=					model_class(lowerCAmelCase__       ).to(lowerCAmelCase__       )
													if "use_cache" not in inputs:
																SCREAMING_SNAKE_CASE_		:     Union[str, Any]					=					True
													SCREAMING_SNAKE_CASE_		:     Any					=					model(**lowerCAmelCase__       )

													# If "past_key_values" is not returned, pass the test (e.g. RWKV uses a different cache name and format)
													if "past_key_values" not in outputs:
																return

													SCREAMING_SNAKE_CASE_		:     Optional[Any]					=					(
													    getattr(lowerCAmelCase__			,						'decoder_layers'			,						lowerCAmelCase__       )
													    or getattr(lowerCAmelCase__			,						'num_decoder_layers'			,						lowerCAmelCase__       )
													    or config.num_hidden_layers
													)
													SCREAMING_SNAKE_CASE_		:     List[str]					=					getattr(lowerCAmelCase__			,						'num_kv_heads'			,						config.num_attention_heads       )
													SCREAMING_SNAKE_CASE_		:     str					=					getattr(lowerCAmelCase__			,						'd_model'			,						config.hidden_size       )
													SCREAMING_SNAKE_CASE_		:     List[str]					=					embed_dim // num_attention_heads

													SCREAMING_SNAKE_CASE_		:     List[Any]					=					outputs['past_key_values']
													self.assertEqual(len(lowerCAmelCase__       )			,						lowerCAmelCase__       )

													SCREAMING_SNAKE_CASE_		,      SCREAMING_SNAKE_CASE_		:     Optional[Any]					=					inputs['input_ids'].shape
													for i in range(lowerCAmelCase__       ):
																if config.new_decoder_architecture:
																			SCREAMING_SNAKE_CASE_		:     Any					=					config.num_attention_heads
																elif config.multi_query:
																			SCREAMING_SNAKE_CASE_		:     Any					=					1
																self.assertEqual(len(past_kv[0]       )			,						2       )  # K V for the decoder = 2
																self.assertEqual(
																    past_kv[i][0].shape			,						(batch_size, num_attention_heads, seq_length, per_head_embed_dim)       )
																self.assertEqual(
																    past_kv[i][1].shape			,						(batch_size, num_attention_heads, seq_length, per_head_embed_dim)       )







@require_torch
class 	__lowercase    (unittest.TestCase  ):





							"""simple docstring"""







							@slow
							def 					UpperCamelCase__     (      self       ):





										"""simple docstring"""




										SCREAMING_SNAKE_CASE_		:     Union[str, Any]					=					AutoTokenizer.from_pretrained('Rocketknight1/falcon-rw-1b'       )
										SCREAMING_SNAKE_CASE_		:     Optional[Any]					=					FalconForCausalLM.from_pretrained('Rocketknight1/falcon-rw-1b'       )
										model.eval()
										model.to(lowerCAmelCase__       )
										SCREAMING_SNAKE_CASE_		:     Dict					=					tokenizer('My favorite food is'			,						return_tensors='pt'       ).to(lowerCAmelCase__       )

										SCREAMING_SNAKE_CASE_		:     List[str]					=					(
										    'My favorite food is pizza. I love it so much that I have a pizza party every year for my birthday.'
										)

										SCREAMING_SNAKE_CASE_		:     Dict					=					model.generate(**lowerCAmelCase__			,						do_sample=lowerCAmelCase__			,						max_new_tokens=1_9       )
										SCREAMING_SNAKE_CASE_		:     List[Any]					=					tokenizer.batch_decode(lowerCAmelCase__       )[0]

										self.assertEqual(lowerCAmelCase__			,						lowerCAmelCase__       )






							@slow
							def 					UpperCamelCase__     (      self       ):





										"""simple docstring"""




										for repo in ["Rocketknight1/tiny-random-falcon-7b", "Rocketknight1/tiny-random-falcon-40b"]:
													SCREAMING_SNAKE_CASE_		:     int					=					AutoTokenizer.from_pretrained(lowerCAmelCase__       )
													SCREAMING_SNAKE_CASE_		:     Tuple					=					FalconForCausalLM.from_pretrained(lowerCAmelCase__       )
													model.eval()
													model.to(lowerCAmelCase__       )
													SCREAMING_SNAKE_CASE_		:     int					=					tokenizer('My favorite food is'			,						return_tensors='pt'       ).to(lowerCAmelCase__       )

													# We just test that these run without errors - the models are randomly initialized
													# and so the actual text outputs will be garbage
													model.generate(**lowerCAmelCase__			,						do_sample=lowerCAmelCase__			,						max_new_tokens=4       )
													model.generate(**lowerCAmelCase__			,						do_sample=lowerCAmelCase__			,						max_new_tokens=4       )
													model.generate(**lowerCAmelCase__			,						num_beams=2			,						max_new_tokens=4       )






							@slow
							def 					UpperCamelCase__     (      self       ):





										"""simple docstring"""




										with torch.no_grad():
													for repo in [
													    "Rocketknight1/falcon-rw-1b",
													    "Rocketknight1/tiny-random-falcon-7b",
													    "Rocketknight1/tiny-random-falcon-40b",
													]:
																SCREAMING_SNAKE_CASE_		:     List[str]					=					AutoTokenizer.from_pretrained(lowerCAmelCase__       )
																SCREAMING_SNAKE_CASE_		:     int					=					FalconForCausalLM.from_pretrained(lowerCAmelCase__       )
																model.eval()
																model.to(device=lowerCAmelCase__       )
																SCREAMING_SNAKE_CASE_		:     Tuple					=					tokenizer('My favorite food is'			,						return_tensors='pt'       ).to(lowerCAmelCase__       )

																# Test results are the same with and without cache
																SCREAMING_SNAKE_CASE_		:     Optional[Any]					=					model.generate(**lowerCAmelCase__			,						do_sample=lowerCAmelCase__			,						max_new_tokens=2_0			,						use_cache=lowerCAmelCase__       )
																SCREAMING_SNAKE_CASE_		:     Any					=					model.generate(**lowerCAmelCase__			,						do_sample=lowerCAmelCase__			,						max_new_tokens=2_0			,						use_cache=lowerCAmelCase__       )
																self.assertTrue((outputs_cache - outputs_no_cache).sum().item() == 0       )













"""simple docstring"""



import os


def 	SCREAMING_SNAKE_CASE__       (  )->		Optional[Any]:






     '''simple docstring'''



     with open(os.path.dirname(snake_case				) + "/p022_names.txt"				) as file:
          UpperCAmelCase__						:    Tuple							=							str(file.readlines()[0]				)
          UpperCAmelCase__						:    str							=							names.replace("\""			,					""				).split(","				)

     names.sort()

     UpperCAmelCase__						:    Optional[int]							=							0
     UpperCAmelCase__						:    List[str]							=							0

     for i, name in enumerate(snake_case				):
          for letter in name:
               name_score += ord(snake_case				) - 64

          total_score += (i + 1) * name_score
          UpperCAmelCase__						:    Optional[int]							=							0
     return total_score


if __name__ == "__main__":
 print(solution())


