


"""simple docstring"""






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

		"""simple docstring"""





		def __init__( self					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__=3					,				SCREAMING_SNAKE_CASE__=7					,				SCREAMING_SNAKE_CASE__=True					,				SCREAMING_SNAKE_CASE__=True					,				SCREAMING_SNAKE_CASE__=False					,				SCREAMING_SNAKE_CASE__=True					,				SCREAMING_SNAKE_CASE__=99					,				SCREAMING_SNAKE_CASE__=32					,				SCREAMING_SNAKE_CASE__=5					,				SCREAMING_SNAKE_CASE__=4					,				SCREAMING_SNAKE_CASE__=37					,				SCREAMING_SNAKE_CASE__="gelu"					,				SCREAMING_SNAKE_CASE__=0.1					,				SCREAMING_SNAKE_CASE__=0.1					,				SCREAMING_SNAKE_CASE__=5_12					,				SCREAMING_SNAKE_CASE__=16					,				SCREAMING_SNAKE_CASE__=2					,				SCREAMING_SNAKE_CASE__=0.0_2					,				SCREAMING_SNAKE_CASE__=3					,				SCREAMING_SNAKE_CASE__=4					,				SCREAMING_SNAKE_CASE__=None					,				)      ->	Union[str, Any]:

					"""simple docstring"""



					_UpperCamelCase					:Union[str, Any]					     =	parent
					_UpperCamelCase					:Dict					     =	batch_size
					_UpperCamelCase					:Optional[int]					     =	seq_length
					_UpperCamelCase					:Dict					     =	is_training
					_UpperCamelCase					:Optional[int]					     =	use_input_mask
					_UpperCamelCase					:int					     =	use_token_type_ids
					_UpperCamelCase					:List[Any]					     =	use_labels
					_UpperCamelCase					:Optional[Any]					     =	vocab_size
					_UpperCamelCase					:int					     =	hidden_size
					_UpperCamelCase					:int					     =	num_hidden_layers
					_UpperCamelCase					:int					     =	num_attention_heads
					_UpperCamelCase					:List[str]					     =	intermediate_size
					_UpperCamelCase					:Optional[int]					     =	hidden_act
					_UpperCamelCase					:List[Any]					     =	hidden_dropout_prob
					_UpperCamelCase					:Union[str, Any]					     =	attention_probs_dropout_prob
					_UpperCamelCase					:Optional[int]					     =	max_position_embeddings
					_UpperCamelCase					:Union[str, Any]					     =	type_vocab_size
					_UpperCamelCase					:Dict					     =	type_sequence_label_size
					_UpperCamelCase					:int					     =	initializer_range
					_UpperCamelCase					:Optional[Any]					     =	num_labels
					_UpperCamelCase					:Optional[int]					     =	num_choices
					_UpperCamelCase					:List[Any]					     =	scope
		def   _UpperCamelCase( self   )      ->	Dict:

					"""simple docstring"""



					_UpperCamelCase					:Any					     =	ids_tensor([self.batch_size, self.seq_length]					,				self.vocab_size   )

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

					_UpperCamelCase					:List[str]					     =	None

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

					_UpperCamelCase					:str					     =	self.get_config()

					return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels
		def   _UpperCamelCase( self   )      ->	Dict:

					"""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=SCREAMING_SNAKE_CASE__					,				initializer_range=self.initializer_range					,				pad_token_id=1					,				new_decoder_architecture=SCREAMING_SNAKE_CASE__					,				)
		def   _UpperCamelCase( self					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__   )      ->	str:

					"""simple docstring"""



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

					"""simple docstring"""



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

					"""simple docstring"""



					_UpperCamelCase					:Optional[int]					     =	FalconForCausalLM(config=SCREAMING_SNAKE_CASE__   )
					model.to(SCREAMING_SNAKE_CASE__   )
					model.eval()
					_UpperCamelCase					:int					     =	model(SCREAMING_SNAKE_CASE__					,				attention_mask=SCREAMING_SNAKE_CASE__					,				labels=SCREAMING_SNAKE_CASE__   )
					self.parent.assertEqual(result.logits.shape					,				(self.batch_size, self.seq_length, self.vocab_size)   )
		def   _UpperCamelCase( self					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__					,				)      ->	List[Any]:

					"""simple docstring"""



					_UpperCamelCase					:List[Any]					     =	True
					_UpperCamelCase					:Any					     =	True
					_UpperCamelCase					:List[str]					     =	FalconForCausalLM(config=SCREAMING_SNAKE_CASE__   )
					model.to(SCREAMING_SNAKE_CASE__   )
					model.eval()

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

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

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

					_UpperCamelCase					:int					     =	model(
					    SCREAMING_SNAKE_CASE__					,				attention_mask=SCREAMING_SNAKE_CASE__					,				encoder_hidden_states=SCREAMING_SNAKE_CASE__					,				encoder_attention_mask=SCREAMING_SNAKE_CASE__					,				output_hidden_states=SCREAMING_SNAKE_CASE__					,				)['''hidden_states'''][0]
					_UpperCamelCase					:str					     =	model(
					    SCREAMING_SNAKE_CASE__					,				attention_mask=SCREAMING_SNAKE_CASE__					,				encoder_hidden_states=SCREAMING_SNAKE_CASE__					,				encoder_attention_mask=SCREAMING_SNAKE_CASE__					,				past_key_values=SCREAMING_SNAKE_CASE__					,				output_hidden_states=SCREAMING_SNAKE_CASE__					,				)['''hidden_states'''][0]

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





		def   _UpperCamelCase( self   )      ->	List[Any]:

					"""simple docstring"""



					_UpperCamelCase					:Optional[Any]					     =	self.prepare_config_and_inputs()
					(
					    (
					    _UpperCamelCase
					)     ,      (
					    _UpperCamelCase
					)     ,      (
					    _UpperCamelCase
					)     ,      (
					    _UpperCamelCase
					)     ,      (
					    _UpperCamelCase
					)     ,      (
					    _UpperCamelCase
					)     ,      (
					    _UpperCamelCase
					)     ,      
					)					:Tuple					     =	config_and_inputs
					_UpperCamelCase					:Optional[int]					     =	{'''input_ids''': input_ids, '''attention_mask''': input_mask}
					return config, inputs_dict






@require_torch
class      A(  lowerCamelCase__				,							lowerCamelCase__				,							lowerCamelCase__				,							unittest.TestCase		):

		"""simple docstring"""





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

					"""simple docstring"""



					_UpperCamelCase					:Optional[Any]					     =	FalconModelTester(self   )
					_UpperCamelCase					:Dict					     =	ConfigTester(self					,				config_class=SCREAMING_SNAKE_CASE__					,				hidden_size=37   )
		def   _UpperCamelCase( self   )      ->	Tuple:

					"""simple docstring"""



					self.config_tester.run_common_tests()
		def   _UpperCamelCase( self   )      ->	Dict:

					"""simple docstring"""



					_UpperCamelCase					:Tuple					     =	self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_model(*SCREAMING_SNAKE_CASE__   )
		def   _UpperCamelCase( self   )      ->	int:

					"""simple docstring"""



					_UpperCamelCase     ,      *_UpperCamelCase					:List[Any]					     =	self.model_tester.prepare_config_and_inputs()
					for alibi in [True, False]:
								_UpperCamelCase					:int					     =	alibi
								self.model_tester.create_and_check_model(SCREAMING_SNAKE_CASE__					,				*SCREAMING_SNAKE_CASE__   )
		def   _UpperCamelCase( self   )      ->	Union[str, Any]:

					"""simple docstring"""



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

					"""simple docstring"""



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

					"""simple docstring"""



					_UpperCamelCase     ,      _UpperCamelCase					:Tuple					     =	self.model_tester.prepare_config_and_inputs_for_common()
					_UpperCamelCase					:int					     =	input_dict['''input_ids''']
					_UpperCamelCase					:List[str]					     =	FalconForCausalLM(SCREAMING_SNAKE_CASE__   )
					model.to(SCREAMING_SNAKE_CASE__   )
					model.eval()
					_UpperCamelCase					:Union[str, Any]					     =	model(SCREAMING_SNAKE_CASE__					,				use_cache=SCREAMING_SNAKE_CASE__   )
					_UpperCamelCase					:Optional[Any]					     =	input_ids.shape[0]
					_UpperCamelCase					:Any					     =	model._convert_to_rw_cache(result.past_key_values   )
					_UpperCamelCase					:Optional[int]					     =	model._convert_cache_to_standard_format(SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__   )
					for layer in range(len(SCREAMING_SNAKE_CASE__   )   ):
								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   )      ->	Optional[Any]:

					"""simple docstring"""



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





		def   _UpperCamelCase( self   )      ->	Optional[Any]:

					"""simple docstring"""



					for model_class in self.all_generative_model_classes:
								_UpperCamelCase     ,      _UpperCamelCase					:Union[str, Any]					     =	self.model_tester.prepare_config_and_inputs_for_common()

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

								_UpperCamelCase					:List[str]					     =	model_class(SCREAMING_SNAKE_CASE__   ).to(SCREAMING_SNAKE_CASE__   )
								if "use_cache" not in inputs:
											_UpperCamelCase					:str					     =	True
								_UpperCamelCase					:str					     =	model(**SCREAMING_SNAKE_CASE__   )

								# 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

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

								_UpperCamelCase					:Union[str, Any]					     =	outputs['''past_key_values''']
								self.assertEqual(len(SCREAMING_SNAKE_CASE__   )					,				SCREAMING_SNAKE_CASE__   )

								_UpperCamelCase     ,      _UpperCamelCase					:int					     =	inputs['''input_ids'''].shape
								for i in range(SCREAMING_SNAKE_CASE__   ):
											if config.new_decoder_architecture:
														_UpperCamelCase					:Optional[int]					     =	config.num_attention_heads
											elif config.multi_query:
														_UpperCamelCase					:Union[str, 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      A(  unittest.TestCase		):

		"""simple docstring"""





		@slow
		def   _UpperCamelCase( self   )      ->	Union[str, Any]:

					"""simple docstring"""



					_UpperCamelCase					:str					     =	AutoTokenizer.from_pretrained('''Rocketknight1/falcon-rw-1b'''   )
					_UpperCamelCase					:List[str]					     =	FalconForCausalLM.from_pretrained('''Rocketknight1/falcon-rw-1b'''   )
					model.eval()
					model.to(SCREAMING_SNAKE_CASE__   )
					_UpperCamelCase					:str					     =	tokenizer('''My favorite food is'''					,				return_tensors='''pt'''   ).to(SCREAMING_SNAKE_CASE__   )

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

					_UpperCamelCase					:Dict					     =	model.generate(**SCREAMING_SNAKE_CASE__					,				do_sample=SCREAMING_SNAKE_CASE__					,				max_new_tokens=19   )
					_UpperCamelCase					:Dict					     =	tokenizer.batch_decode(SCREAMING_SNAKE_CASE__   )[0]

					self.assertEqual(SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__   )
		@slow
		def   _UpperCamelCase( self   )      ->	Tuple:

					"""simple docstring"""



					for repo in ["Rocketknight1/tiny-random-falcon-7b", "Rocketknight1/tiny-random-falcon-40b"]:
								_UpperCamelCase					:Optional[Any]					     =	AutoTokenizer.from_pretrained(SCREAMING_SNAKE_CASE__   )
								_UpperCamelCase					:str					     =	FalconForCausalLM.from_pretrained(SCREAMING_SNAKE_CASE__   )
								model.eval()
								model.to(SCREAMING_SNAKE_CASE__   )
								_UpperCamelCase					:Union[str, Any]					     =	tokenizer('''My favorite food is'''					,				return_tensors='''pt'''   ).to(SCREAMING_SNAKE_CASE__   )

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





		@slow
		def   _UpperCamelCase( self   )      ->	Optional[Any]:

					"""simple docstring"""



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

											# Test results are the same with and without cache
											_UpperCamelCase					:Union[str, Any]					     =	model.generate(**SCREAMING_SNAKE_CASE__					,				do_sample=SCREAMING_SNAKE_CASE__					,				max_new_tokens=20					,				use_cache=SCREAMING_SNAKE_CASE__   )
											_UpperCamelCase					:str					     =	model.generate(**SCREAMING_SNAKE_CASE__					,				do_sample=SCREAMING_SNAKE_CASE__					,				max_new_tokens=20					,				use_cache=SCREAMING_SNAKE_CASE__   )
											self.assertTrue((outputs_cache - outputs_no_cache).sum().item() == 0   )





"""simple docstring"""






def 				A_       ( snake_case__       ,					snake_case__ = " "		)					->  list:
			_UpperCamelCase					:List[str]					     =	[]

			_UpperCamelCase					:int					     =	0
			for index, char in enumerate(snake_case__		):
						if char == separator:
									split_words.append(string[last_index:index]		)
									_UpperCamelCase					:Dict					     =	index + 1
						elif index + 1 == len(snake_case__		):
									split_words.append(string[last_index : index + 1]		)
			return split_words


if __name__ == "__main__":
					from doctest import testmod

					testmod()

