



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


	def __init__(self : Tuple,					__UpperCAmelCase : Union[str, Any],					__UpperCAmelCase : Any=3,					__UpperCAmelCase : Optional[Any]=7,					__UpperCAmelCase : str=True,					__UpperCAmelCase : int=True,					__UpperCAmelCase : Optional[Any]=False,					__UpperCAmelCase : str=True,					__UpperCAmelCase : List[str]=99,					__UpperCAmelCase : Optional[int]=32,					__UpperCAmelCase : List[Any]=5,					__UpperCAmelCase : Union[str, Any]=4,					__UpperCAmelCase : Dict=37,					__UpperCAmelCase : str="gelu",					__UpperCAmelCase : Optional[int]=0.1,					__UpperCAmelCase : int=0.1,					__UpperCAmelCase : Any=512,					__UpperCAmelCase : List[Any]=16,					__UpperCAmelCase : List[str]=2,					__UpperCAmelCase : Dict=0.02,					__UpperCAmelCase : Optional[int]=3,					__UpperCAmelCase : Dict=4,					__UpperCAmelCase : Union[str, Any]=None,					)     ->			List[Any]:

					"""simple docstring"""

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


	def 				lowercase__  (self : List[str]      )     ->			Optional[int]:

					"""simple docstring"""

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

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

					SCREAMING_SNAKE_CASE  :						Union[str, Any]      					= None

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

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


	def 				lowercase__  (self : Union[str, Any]      )     ->			Union[str, Any]:

					"""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=__UpperCAmelCase,					initializer_range=self.initializer_range,					pad_token_id=1,					new_decoder_architecture=__UpperCAmelCase,					)


	def 				lowercase__  (self : List[str],					__UpperCAmelCase : Optional[Any],					__UpperCAmelCase : Optional[Any],					__UpperCAmelCase : Tuple,					__UpperCAmelCase : Any,					__UpperCAmelCase : List[str],					__UpperCAmelCase : List[Any],					__UpperCAmelCase : Dict      )     ->			Union[str, Any]:

					"""simple docstring"""

					SCREAMING_SNAKE_CASE  :						int      					= FalconModel(config=__UpperCAmelCase      )
					model.to(__UpperCAmelCase      )
					model.eval()
					SCREAMING_SNAKE_CASE  :						Optional[int]      					= model(__UpperCAmelCase,					attention_mask=__UpperCAmelCase      )
					SCREAMING_SNAKE_CASE  :						List[Any]      					= model(__UpperCAmelCase      )
					self.parent.assertEqual(result.last_hidden_state.shape,					(self.batch_size, self.seq_length, self.hidden_size)      )


	def 				lowercase__  (self : int,					__UpperCAmelCase : str,					__UpperCAmelCase : Dict,					__UpperCAmelCase : List[Any],					__UpperCAmelCase : List[Any],					__UpperCAmelCase : str,					__UpperCAmelCase : str,					__UpperCAmelCase : Dict,					__UpperCAmelCase : List[Any],					__UpperCAmelCase : Optional[Any],					)     ->			Optional[int]:

					"""simple docstring"""

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


	def 				lowercase__  (self : str,					__UpperCAmelCase : str,					__UpperCAmelCase : List[Any],					__UpperCAmelCase : int,					__UpperCAmelCase : Tuple,					__UpperCAmelCase : Tuple,					__UpperCAmelCase : int,					__UpperCAmelCase : Union[str, Any],					__UpperCAmelCase : Union[str, Any],					__UpperCAmelCase : Tuple,					)     ->			Any:

					"""simple docstring"""

					SCREAMING_SNAKE_CASE  :						Union[str, Any]      					= FalconForCausalLM(config=__UpperCAmelCase      )
					model.to(__UpperCAmelCase      )
					model.eval()
					SCREAMING_SNAKE_CASE  :						List[str]      					= model(__UpperCAmelCase,					attention_mask=__UpperCAmelCase,					labels=__UpperCAmelCase      )
					self.parent.assertEqual(result.logits.shape,					(self.batch_size, self.seq_length, self.vocab_size)      )


	def 				lowercase__  (self : Dict,					__UpperCAmelCase : Any,					__UpperCAmelCase : Tuple,					__UpperCAmelCase : List[Any],					__UpperCAmelCase : Optional[int],					__UpperCAmelCase : str,					__UpperCAmelCase : int,					__UpperCAmelCase : List[Any],					__UpperCAmelCase : Optional[int],					__UpperCAmelCase : List[Any],					)     ->			List[Any]:

					"""simple docstring"""

					SCREAMING_SNAKE_CASE  :						Optional[Any]      					= True
					SCREAMING_SNAKE_CASE  :						Optional[int]      					= True
					SCREAMING_SNAKE_CASE  :						Any      					= FalconForCausalLM(config=__UpperCAmelCase      )
					model.to(__UpperCAmelCase      )
					model.eval()

					# first forward pass
					SCREAMING_SNAKE_CASE  :						Union[str, Any]      					= model(
					    __UpperCAmelCase,					attention_mask=__UpperCAmelCase,					encoder_hidden_states=__UpperCAmelCase,					encoder_attention_mask=__UpperCAmelCase,					use_cache=__UpperCAmelCase,					)
					SCREAMING_SNAKE_CASE  :						Tuple      					= outputs.past_key_values

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

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

					SCREAMING_SNAKE_CASE  :						Optional[Any]      					= model(
					    __UpperCAmelCase,					attention_mask=__UpperCAmelCase,					encoder_hidden_states=__UpperCAmelCase,					encoder_attention_mask=__UpperCAmelCase,					output_hidden_states=__UpperCAmelCase,					)['''hidden_states'''][0]
					SCREAMING_SNAKE_CASE  :						Tuple      					= model(
					    __UpperCAmelCase,					attention_mask=__UpperCAmelCase,					encoder_hidden_states=__UpperCAmelCase,					encoder_attention_mask=__UpperCAmelCase,					past_key_values=__UpperCAmelCase,					output_hidden_states=__UpperCAmelCase,					)['''hidden_states'''][0]

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






	def 				lowercase__  (self : Tuple      )     ->			Any:

					"""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
					)					,					
					)  :						List[str]      					= config_and_inputs
					SCREAMING_SNAKE_CASE  :						Optional[int]      					= {'''input_ids''': input_ids, '''attention_mask''': input_mask}
					return config, inputs_dict



@require_torch
class 	a__     (				_lowercase,			_lowercase,			_lowercase,			unittest.TestCase	):
	__magic_name__		:    Optional[int]	    =     (
	    (
	        FalconModel,
	        FalconForCausalLM,
	        FalconForSequenceClassification,
	        FalconForTokenClassification,
	        FalconForQuestionAnswering,
	    )
	    if is_torch_available()
	    else ()
	)
	__magic_name__		:    List[Any]	    =     (FalconForCausalLM,) if is_torch_available() else ()
	__magic_name__		:    Union[str, Any]	    =     (
	    {
	        "feature-extraction": FalconModel,
	        "text-classification": FalconForSequenceClassification,
	        "text-generation": FalconForCausalLM,
	        "question-answering": FalconForQuestionAnswering,
	        "token-classification": FalconForTokenClassification,
	        "zero-shot": FalconForSequenceClassification,
	    }
	    if is_torch_available()
	    else {}
	)
	__magic_name__		:    Dict	    =     False
	__magic_name__		:    Any	    =     False


	def 				lowercase__  (self : List[Any]      )     ->			Union[str, Any]:

					"""simple docstring"""

					SCREAMING_SNAKE_CASE  :						Optional[Any]      					= FalconModelTester(self      )
					SCREAMING_SNAKE_CASE  :						List[Any]      					= ConfigTester(self,					config_class=__UpperCAmelCase,					hidden_size=37      )


	def 				lowercase__  (self : Tuple      )     ->			Dict:

					"""simple docstring"""

					self.config_tester.run_common_tests()


	def 				lowercase__  (self : Optional[Any]      )     ->			Union[str, Any]:

					"""simple docstring"""

					SCREAMING_SNAKE_CASE  :						Optional[int]      					= self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_model(*__UpperCAmelCase      )


	def 				lowercase__  (self : Dict      )     ->			Tuple:

					"""simple docstring"""

					SCREAMING_SNAKE_CASE					,					*SCREAMING_SNAKE_CASE  :						Optional[Any]      					= self.model_tester.prepare_config_and_inputs()
					for alibi in [True, False]:
									SCREAMING_SNAKE_CASE  :						Optional[Any]      					= alibi
									self.model_tester.create_and_check_model(__UpperCAmelCase,					*__UpperCAmelCase      )


	def 				lowercase__  (self : int      )     ->			List[Any]:

					"""simple docstring"""

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


	def 				lowercase__  (self : Optional[Any]      )     ->			Tuple:

					"""simple docstring"""

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


	def 				lowercase__  (self : Union[str, Any]      )     ->			int:

					"""simple docstring"""

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

					"""simple docstring"""

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






	def 				lowercase__  (self : Optional[int]      )     ->			Optional[Any]:

					"""simple docstring"""

					for model_class in self.all_generative_model_classes:
									SCREAMING_SNAKE_CASE					,					SCREAMING_SNAKE_CASE  :						int      					= self.model_tester.prepare_config_and_inputs_for_common()

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

									SCREAMING_SNAKE_CASE  :						Optional[int]      					= model_class(__UpperCAmelCase      ).to(__UpperCAmelCase      )
									if "use_cache" not in inputs:
													SCREAMING_SNAKE_CASE  :						List[str]      					= True
									SCREAMING_SNAKE_CASE  :						Tuple      					= model(**__UpperCAmelCase      )

									# 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  :						List[str]      					= (
									    getattr(__UpperCAmelCase,					'''decoder_layers''',					__UpperCAmelCase      )
									    or getattr(__UpperCAmelCase,					'''num_decoder_layers''',					__UpperCAmelCase      )
									    or config.num_hidden_layers
									)
									SCREAMING_SNAKE_CASE  :						Dict      					= getattr(__UpperCAmelCase,					'''num_kv_heads''',					config.num_attention_heads      )
									SCREAMING_SNAKE_CASE  :						Tuple      					= getattr(__UpperCAmelCase,					'''d_model''',					config.hidden_size      )
									SCREAMING_SNAKE_CASE  :						List[str]      					= embed_dim // num_attention_heads

									SCREAMING_SNAKE_CASE  :						int      					= outputs['''past_key_values''']
									self.assertEqual(len(__UpperCAmelCase      ),					__UpperCAmelCase      )

									SCREAMING_SNAKE_CASE					,					SCREAMING_SNAKE_CASE  :						List[Any]      					= inputs['''input_ids'''].shape
									for i in range(__UpperCAmelCase      ):
													if config.new_decoder_architecture:
																	SCREAMING_SNAKE_CASE  :						Optional[Any]      					= config.num_attention_heads
													elif config.multi_query:
																	SCREAMING_SNAKE_CASE  :						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	):


	@slow
	def 				lowercase__  (self : List[str]      )     ->			Dict:

					"""simple docstring"""

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

					SCREAMING_SNAKE_CASE  :						Optional[int]      					= (
					    '''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(**__UpperCAmelCase,					do_sample=__UpperCAmelCase,					max_new_tokens=19      )
					SCREAMING_SNAKE_CASE  :						List[str]      					= tokenizer.batch_decode(__UpperCAmelCase      )[0]

					self.assertEqual(__UpperCAmelCase,					__UpperCAmelCase      )


	@slow
	def 				lowercase__  (self : Tuple      )     ->			Any:

					"""simple docstring"""

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

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






	@slow
	def 				lowercase__  (self : List[str]      )     ->			Dict:

					"""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  :						Tuple      					= AutoTokenizer.from_pretrained(__UpperCAmelCase      )
													SCREAMING_SNAKE_CASE  :						Optional[Any]      					= FalconForCausalLM.from_pretrained(__UpperCAmelCase      )
													model.eval()
													model.to(device=__UpperCAmelCase      )
													SCREAMING_SNAKE_CASE  :						Optional[int]      					= tokenizer('''My favorite food is''',					return_tensors='''pt'''      ).to(__UpperCAmelCase      )

													# Test results are the same with and without cache
													SCREAMING_SNAKE_CASE  :						Optional[int]      					= model.generate(**__UpperCAmelCase,					do_sample=__UpperCAmelCase,					max_new_tokens=20,					use_cache=__UpperCAmelCase      )
													SCREAMING_SNAKE_CASE  :						Dict      					= model.generate(**__UpperCAmelCase,					do_sample=__UpperCAmelCase,					max_new_tokens=20,					use_cache=__UpperCAmelCase      )
													self.assertTrue((outputs_cache - outputs_no_cache).sum().item() == 0      )









'''simple docstring'''

from ...configuration_utils import PretrainedConfig
from ...utils import logging


snake_case_			=     logging.get_logger(__name__)

snake_case_			=     {
    """microsoft/markuplm-base""": """https://huggingface.co/microsoft/markuplm-base/resolve/main/config.json""",
    """microsoft/markuplm-large""": """https://huggingface.co/microsoft/markuplm-large/resolve/main/config.json""",
}


class 	a__     (				_lowercase	):
	__magic_name__		:    List[Any]	    =     "markuplm"


	def __init__(self : List[Any],					__UpperCAmelCase : int=30522,					__UpperCAmelCase : Tuple=768,					__UpperCAmelCase : str=12,					__UpperCAmelCase : List[Any]=12,					__UpperCAmelCase : Tuple=3072,					__UpperCAmelCase : Union[str, Any]="gelu",					__UpperCAmelCase : Union[str, Any]=0.1,					__UpperCAmelCase : str=0.1,					__UpperCAmelCase : Union[str, Any]=512,					__UpperCAmelCase : Dict=2,					__UpperCAmelCase : int=0.02,					__UpperCAmelCase : Optional[Any]=1e-12,					__UpperCAmelCase : Union[str, Any]=0,					__UpperCAmelCase : Optional[Any]=0,					__UpperCAmelCase : Union[str, Any]=2,					__UpperCAmelCase : int=256,					__UpperCAmelCase : Tuple=1024,					__UpperCAmelCase : Optional[Any]=216,					__UpperCAmelCase : str=1001,					__UpperCAmelCase : Optional[Any]=32,					__UpperCAmelCase : Dict=50,					__UpperCAmelCase : Union[str, Any]="absolute",					__UpperCAmelCase : Tuple=True,					__UpperCAmelCase : List[str]=None,					**__UpperCAmelCase : Union[str, Any],					)     ->			Union[str, Any]:

					"""simple docstring"""

					super().__init__(
					    pad_token_id=__UpperCAmelCase,					bos_token_id=__UpperCAmelCase,					eos_token_id=__UpperCAmelCase,					**__UpperCAmelCase,					)
					SCREAMING_SNAKE_CASE  :						List[Any]      					= vocab_size
					SCREAMING_SNAKE_CASE  :						Dict      					= hidden_size
					SCREAMING_SNAKE_CASE  :						Optional[Any]      					= num_hidden_layers
					SCREAMING_SNAKE_CASE  :						Dict      					= num_attention_heads
					SCREAMING_SNAKE_CASE  :						Any      					= hidden_act
					SCREAMING_SNAKE_CASE  :						Tuple      					= intermediate_size
					SCREAMING_SNAKE_CASE  :						Tuple      					= hidden_dropout_prob
					SCREAMING_SNAKE_CASE  :						List[str]      					= attention_probs_dropout_prob
					SCREAMING_SNAKE_CASE  :						List[str]      					= max_position_embeddings
					SCREAMING_SNAKE_CASE  :						Dict      					= type_vocab_size
					SCREAMING_SNAKE_CASE  :						Tuple      					= initializer_range
					SCREAMING_SNAKE_CASE  :						Optional[Any]      					= layer_norm_eps
					SCREAMING_SNAKE_CASE  :						int      					= position_embedding_type
					SCREAMING_SNAKE_CASE  :						List[Any]      					= use_cache
					SCREAMING_SNAKE_CASE  :						int      					= classifier_dropout
					# additional properties
					SCREAMING_SNAKE_CASE  :						List[Any]      					= max_depth
					SCREAMING_SNAKE_CASE  :						Any      					= max_xpath_tag_unit_embeddings
					SCREAMING_SNAKE_CASE  :						int      					= max_xpath_subs_unit_embeddings
					SCREAMING_SNAKE_CASE  :						Dict      					= tag_pad_id
					SCREAMING_SNAKE_CASE  :						Optional[int]      					= subs_pad_id
					SCREAMING_SNAKE_CASE  :						int      					= xpath_unit_hidden_size




