



"""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        __snake_case       :




  def __init__( self     :						Optional[Any]						,					__lowerCAmelCase     :						Any						,					__lowerCAmelCase     :						Any=3						,					__lowerCAmelCase     :						List[Any]=7						,					__lowerCAmelCase     :						Optional[Any]=True						,					__lowerCAmelCase     :						Optional[int]=True						,					__lowerCAmelCase     :						Optional[int]=False						,					__lowerCAmelCase     :						Optional[Any]=True						,					__lowerCAmelCase     :						Optional[Any]=9_9						,					__lowerCAmelCase     :						List[Any]=3_2						,					__lowerCAmelCase     :						Any=5						,					__lowerCAmelCase     :						Any=4						,					__lowerCAmelCase     :						Union[str, Any]=3_7						,					__lowerCAmelCase     :						Optional[Any]="gelu"						,					__lowerCAmelCase     :						str=0.1						,					__lowerCAmelCase     :						Optional[Any]=0.1						,					__lowerCAmelCase     :						Optional[int]=5_1_2						,					__lowerCAmelCase     :						List[Any]=1_6						,					__lowerCAmelCase     :						List[Any]=2						,					__lowerCAmelCase     :						List[Any]=0.02						,					__lowerCAmelCase     :						List[str]=3						,					__lowerCAmelCase     :						Any=4						,					__lowerCAmelCase     :						int=None						,					):






         """simple docstring"""






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




  def 						SCREAMING_SNAKE_CASE				( self     :						Optional[Any]		):






         """simple docstring"""






         _lowerCamelCase						:				str    			= ids_tensor([self.batch_size, self.seq_length]						,					self.vocab_size		)

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

         _lowerCamelCase						:				List[str]    			= None

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

         _lowerCamelCase						:				Any    			= self.get_config()

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




  def 						SCREAMING_SNAKE_CASE				( self     :						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=__lowerCAmelCase						,					initializer_range=self.initializer_range						,					pad_token_id=1						,					new_decoder_architecture=__lowerCAmelCase						,					)




  def 						SCREAMING_SNAKE_CASE				( self     :						Optional[int]						,					__lowerCAmelCase     :						Optional[Any]						,					__lowerCAmelCase     :						List[str]						,					__lowerCAmelCase     :						Any						,					__lowerCAmelCase     :						Tuple						,					__lowerCAmelCase     :						List[str]						,					__lowerCAmelCase     :						str						,					__lowerCAmelCase     :						List[str]		):






         """simple docstring"""






         _lowerCamelCase						:				Union[str, Any]    			= FalconModel(config=__lowerCAmelCase		)
         model.to(__lowerCAmelCase		)
         model.eval()
         _lowerCamelCase						:				Union[str, Any]    			= model(__lowerCAmelCase						,					attention_mask=__lowerCAmelCase		)
         _lowerCamelCase						:				int    			= model(__lowerCAmelCase		)
         self.parent.assertEqual(result.last_hidden_state.shape						,					(self.batch_size, self.seq_length, self.hidden_size)		)




  def 						SCREAMING_SNAKE_CASE				( self     :						str						,					__lowerCAmelCase     :						Union[str, Any]						,					__lowerCAmelCase     :						str						,					__lowerCAmelCase     :						Tuple						,					__lowerCAmelCase     :						Optional[int]						,					__lowerCAmelCase     :						List[Any]						,					__lowerCAmelCase     :						Any						,					__lowerCAmelCase     :						Optional[int]						,					__lowerCAmelCase     :						List[str]						,					__lowerCAmelCase     :						Any						,					):






         """simple docstring"""






         _lowerCamelCase						:				Optional[Any]    			= True
         _lowerCamelCase						:				Any    			= FalconModel(__lowerCAmelCase		)
         model.to(__lowerCAmelCase		)
         model.eval()
         _lowerCamelCase						:				List[str]    			= model(
             __lowerCAmelCase						,					attention_mask=__lowerCAmelCase						,					encoder_hidden_states=__lowerCAmelCase						,					encoder_attention_mask=__lowerCAmelCase						,					)
         _lowerCamelCase						:				Optional[int]    			= model(
             __lowerCAmelCase						,					attention_mask=__lowerCAmelCase						,					encoder_hidden_states=__lowerCAmelCase						,					)
         _lowerCamelCase						:				int    			= model(__lowerCAmelCase						,					attention_mask=__lowerCAmelCase		)
         self.parent.assertEqual(result.last_hidden_state.shape						,					(self.batch_size, self.seq_length, self.hidden_size)		)




  def 						SCREAMING_SNAKE_CASE				( self     :						Any						,					__lowerCAmelCase     :						Dict						,					__lowerCAmelCase     :						str						,					__lowerCAmelCase     :						str						,					__lowerCAmelCase     :						Any						,					__lowerCAmelCase     :						List[Any]						,					__lowerCAmelCase     :						str						,					__lowerCAmelCase     :						Dict						,					__lowerCAmelCase     :						List[Any]						,					__lowerCAmelCase     :						str						,					):






         """simple docstring"""






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




  def 						SCREAMING_SNAKE_CASE				( self     :						int						,					__lowerCAmelCase     :						Union[str, Any]						,					__lowerCAmelCase     :						int						,					__lowerCAmelCase     :						int						,					__lowerCAmelCase     :						Any						,					__lowerCAmelCase     :						List[Any]						,					__lowerCAmelCase     :						List[str]						,					__lowerCAmelCase     :						Dict						,					__lowerCAmelCase     :						str						,					__lowerCAmelCase     :						List[str]						,					):






         """simple docstring"""






         _lowerCamelCase						:				Optional[int]    			= True
         _lowerCamelCase						:				int    			= True
         _lowerCamelCase						:				List[Any]    			= FalconForCausalLM(config=__lowerCAmelCase		)
         model.to(__lowerCAmelCase		)
         model.eval()

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

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

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

         _lowerCamelCase						:				str    			= model(
             __lowerCAmelCase						,					attention_mask=__lowerCAmelCase						,					encoder_hidden_states=__lowerCAmelCase						,					encoder_attention_mask=__lowerCAmelCase						,					output_hidden_states=__lowerCAmelCase						,					)['''hidden_states'''][0]
         _lowerCamelCase						:				str    			= 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
         _lowerCamelCase						:				Optional[Any]    			= ids_tensor((1,)						,					output_from_past.shape[-1]		).item()
         _lowerCamelCase						:				Dict    			= output_from_no_past[:, -3:, random_slice_idx].detach()
         _lowerCamelCase						:				List[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 						SCREAMING_SNAKE_CASE				( self     :						int		):






         """simple docstring"""






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






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




  def 						SCREAMING_SNAKE_CASE				( self     :						Dict		):






         """simple docstring"""






         _lowerCamelCase						:				Tuple    			= FalconModelTester(self		)
         _lowerCamelCase						:				List[str]    			= ConfigTester(self						,					config_class=__lowerCAmelCase						,					hidden_size=3_7		)




  def 						SCREAMING_SNAKE_CASE				( self     :						Union[str, Any]		):






         """simple docstring"""






         self.config_tester.run_common_tests()




  def 						SCREAMING_SNAKE_CASE				( self     :						str		):






         """simple docstring"""






         _lowerCamelCase						:				Dict    			= self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_model(*__lowerCAmelCase		)




  def 						SCREAMING_SNAKE_CASE				( self     :						Optional[int]		):






         """simple docstring"""






         _lowerCamelCase			,    *_lowerCamelCase						:				Optional[int]    			= self.model_tester.prepare_config_and_inputs()
         for alibi in [True, False]:
                _lowerCamelCase						:				Dict    			= alibi
                self.model_tester.create_and_check_model(__lowerCAmelCase						,					*__lowerCAmelCase		)




  def 						SCREAMING_SNAKE_CASE				( self     :						int		):






         """simple docstring"""






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




  def 						SCREAMING_SNAKE_CASE				( self     :						int		):






         """simple docstring"""






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




  def 						SCREAMING_SNAKE_CASE				( self     :						Union[str, Any]		):






         """simple docstring"""






         _lowerCamelCase			,    _lowerCamelCase						:				Optional[Any]    			= self.model_tester.prepare_config_and_inputs_for_common()
         _lowerCamelCase						:				List[Any]    			= input_dict['''input_ids''']
         _lowerCamelCase						:				Dict    			= FalconForCausalLM(__lowerCAmelCase		)
         model.to(__lowerCAmelCase		)
         model.eval()
         _lowerCamelCase						:				str    			= model(__lowerCAmelCase						,					use_cache=__lowerCAmelCase		)
         _lowerCamelCase						:				List[str]    			= input_ids.shape[0]
         _lowerCamelCase						:				Optional[int]    			= model._convert_to_rw_cache(result.past_key_values		)
         _lowerCamelCase						:				List[Any]    			= 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 						SCREAMING_SNAKE_CASE				( self     :						Dict		):






         """simple docstring"""






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




  def 						SCREAMING_SNAKE_CASE				( self     :						str		):






         """simple docstring"""






         for model_class in self.all_generative_model_classes:
                _lowerCamelCase			,    _lowerCamelCase						:				int    			= 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

                _lowerCamelCase						:				List[Any]    			= model_class(__lowerCAmelCase		).to(__lowerCAmelCase		)
                if "use_cache" not in inputs:
                       _lowerCamelCase						:				List[str]    			= True
                _lowerCamelCase						:				Optional[int]    			= 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

                _lowerCamelCase						:				Dict    			= (
                    getattr(__lowerCAmelCase						,					'''decoder_layers'''						,					__lowerCAmelCase		)
                    or getattr(__lowerCAmelCase						,					'''num_decoder_layers'''						,					__lowerCAmelCase		)
                    or config.num_hidden_layers
                )
                _lowerCamelCase						:				Any    			= getattr(__lowerCAmelCase						,					'''num_kv_heads'''						,					config.num_attention_heads		)
                _lowerCamelCase						:				int    			= getattr(__lowerCAmelCase						,					'''d_model'''						,					config.hidden_size		)
                _lowerCamelCase						:				Any    			= embed_dim // num_attention_heads

                _lowerCamelCase						:				Tuple    			= outputs['''past_key_values''']
                self.assertEqual(len(__lowerCAmelCase		)						,					__lowerCAmelCase		)

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




  @slow
  def 						SCREAMING_SNAKE_CASE				( self     :						Union[str, Any]		):






         """simple docstring"""






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

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

         _lowerCamelCase						:				Tuple    			= model.generate(**__lowerCAmelCase						,					do_sample=__lowerCAmelCase						,					max_new_tokens=1_9		)
         _lowerCamelCase						:				Optional[Any]    			= tokenizer.batch_decode(__lowerCAmelCase		)[0]

         self.assertEqual(__lowerCAmelCase						,					__lowerCAmelCase		)




  @slow
  def 						SCREAMING_SNAKE_CASE				( self     :						str		):






         """simple docstring"""






         for repo in ["Rocketknight1/tiny-random-falcon-7b", "Rocketknight1/tiny-random-falcon-40b"]:
                _lowerCamelCase						:				Optional[Any]    			= AutoTokenizer.from_pretrained(__lowerCAmelCase		)
                _lowerCamelCase						:				int    			= FalconForCausalLM.from_pretrained(__lowerCAmelCase		)
                model.eval()
                model.to(__lowerCAmelCase		)
                _lowerCamelCase						:				Optional[Any]    			= 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 						SCREAMING_SNAKE_CASE				( self     :						Dict		):






         """simple docstring"""






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

                       # Test results are the same with and without cache
                       _lowerCamelCase						:				Dict    			= model.generate(**__lowerCAmelCase						,					do_sample=__lowerCAmelCase						,					max_new_tokens=2_0						,					use_cache=__lowerCAmelCase		)
                       _lowerCamelCase						:				Optional[int]    			= 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'''




from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


a   :			Optional[int]					  =    {
    """configuration_git""": ["""GIT_PRETRAINED_CONFIG_ARCHIVE_MAP""", """GitConfig""", """GitVisionConfig"""],
    """processing_git""": ["""GitProcessor"""],
}

try:
							if not is_torch_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							a   :			Tuple					  =    [
							    """GIT_PRETRAINED_MODEL_ARCHIVE_LIST""",
							    """GitForCausalLM""",
							    """GitModel""",
							    """GitPreTrainedModel""",
							    """GitVisionModel""",
							]

if TYPE_CHECKING:
							from .configuration_git import GIT_PRETRAINED_CONFIG_ARCHIVE_MAP, GitConfig, GitVisionConfig
							from .processing_git import GitProcessor

							try:
														if not is_torch_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_git import (
														    GIT_PRETRAINED_MODEL_ARCHIVE_LIST,
														    GitForCausalLM,
														    GitModel,
														    GitPreTrainedModel,
														    GitVisionModel,
														)

else:
							import sys

							a   :			Tuple					  =    _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)

