



"""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	:		Union[str, Any]		,   __lowerCAmelCase	:		List[str]		,   __lowerCAmelCase	:		Any=3		,   __lowerCAmelCase	:		Any=7		,   __lowerCAmelCase	:		Optional[Any]=True		,   __lowerCAmelCase	:		Dict=True		,   __lowerCAmelCase	:		Tuple=False		,   __lowerCAmelCase	:		List[Any]=True		,   __lowerCAmelCase	:		Dict=9_9		,   __lowerCAmelCase	:		Optional[int]=3_2		,   __lowerCAmelCase	:		Optional[Any]=5		,   __lowerCAmelCase	:		Any=4		,   __lowerCAmelCase	:		Any=3_7		,   __lowerCAmelCase	:		Optional[int]="gelu"		,   __lowerCAmelCase	:		List[str]=0.1		,   __lowerCAmelCase	:		str=0.1		,   __lowerCAmelCase	:		List[Any]=5_1_2		,   __lowerCAmelCase	:		Optional[int]=1_6		,   __lowerCAmelCase	:		Any=2		,   __lowerCAmelCase	:		Optional[Any]=0.02		,   __lowerCAmelCase	:		Optional[int]=3		,   __lowerCAmelCase	:		List[Any]=4		,   __lowerCAmelCase	:		Optional[int]=None		,   ):






         """simple docstring"""






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




  def 		SCREAMING_SNAKE_CASE							(					self	:		str						):






         """simple docstring"""






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

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

         _lowerCamelCase		:							Dict            =					None

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

         _lowerCamelCase		:							Optional[Any]            =					self.get_config()

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




  def 		SCREAMING_SNAKE_CASE							(					self	:		List[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	:		Dict		,   __lowerCAmelCase	:		Optional[Any]		,   __lowerCAmelCase	:		Any		,   __lowerCAmelCase	:		Optional[Any]		,   __lowerCAmelCase	:		int		,   __lowerCAmelCase	:		Optional[int]		,   __lowerCAmelCase	:		Dict		,   __lowerCAmelCase	:		int						):






         """simple docstring"""






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




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






         """simple docstring"""






         _lowerCamelCase		:							Any            =					True
         _lowerCamelCase		:							Optional[int]            =					FalconModel(_lowerCAmelCase						)
         model.to(_lowerCAmelCase						)
         model.eval()
         _lowerCamelCase		:							List[Any]            =					model(
             _lowerCAmelCase		,   attention_mask=_lowerCAmelCase		,   encoder_hidden_states=_lowerCAmelCase		,   encoder_attention_mask=_lowerCAmelCase		,   )
         _lowerCamelCase		:							List[str]            =					model(
             _lowerCAmelCase		,   attention_mask=_lowerCAmelCase		,   encoder_hidden_states=_lowerCAmelCase		,   )
         _lowerCamelCase		:							str            =					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	:		Any		,   __lowerCAmelCase	:		Any		,   __lowerCAmelCase	:		Optional[Any]		,   __lowerCAmelCase	:		Optional[int]		,   __lowerCAmelCase	:		str		,   __lowerCAmelCase	:		Optional[int]		,   __lowerCAmelCase	:		Dict		,   __lowerCAmelCase	:		Optional[Any]		,   __lowerCAmelCase	:		List[str]		,   ):






         """simple docstring"""






         _lowerCamelCase		:							List[str]            =					FalconForCausalLM(config=_lowerCAmelCase						)
         model.to(_lowerCAmelCase						)
         model.eval()
         _lowerCamelCase		:							Dict            =					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	:		List[Any]		,   __lowerCAmelCase	:		Any		,   __lowerCAmelCase	:		List[str]		,   __lowerCAmelCase	:		Dict		,   __lowerCAmelCase	:		List[str]		,   __lowerCAmelCase	:		Any		,   __lowerCAmelCase	:		List[str]		,   __lowerCAmelCase	:		Tuple		,   __lowerCAmelCase	:		Any		,   __lowerCAmelCase	:		Dict		,   ):






         """simple docstring"""






         _lowerCamelCase		:							List[Any]            =					True
         _lowerCamelCase		:							Tuple            =					True
         _lowerCamelCase		:							Tuple            =					FalconForCausalLM(config=_lowerCAmelCase						)
         model.to(_lowerCAmelCase						)
         model.eval()

         # first forward pass
         _lowerCamelCase		:							Tuple            =					model(
             _lowerCAmelCase		,   attention_mask=_lowerCAmelCase		,   encoder_hidden_states=_lowerCAmelCase		,   encoder_attention_mask=_lowerCAmelCase		,   use_cache=_lowerCAmelCase		,   )
         _lowerCamelCase		:							Tuple            =					outputs.past_key_values

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

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

         _lowerCamelCase		:							List[str]            =					model(
             _lowerCAmelCase		,   attention_mask=_lowerCAmelCase		,   encoder_hidden_states=_lowerCAmelCase		,   encoder_attention_mask=_lowerCAmelCase		,   output_hidden_states=_lowerCAmelCase		,   )['''hidden_states'''][0]
         _lowerCamelCase		:							int            =					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		:							Any            =					ids_tensor((1,)		,   output_from_past.shape[-1]						).item()
         _lowerCamelCase		:							List[Any]            =					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	:		str						):






         """simple docstring"""






         _lowerCamelCase		:							Optional[int]            =					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__							:  Any         =		(
      (
          FalconModel,
          FalconForCausalLM,
          FalconForSequenceClassification,
          FalconForTokenClassification,
          FalconForQuestionAnswering,
      )
      if is_torch_available()
      else ()
  )
  snake_case__							:  List[Any]         =		(FalconForCausalLM,) if is_torch_available() else ()
  snake_case__							:  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 {}
  )
  snake_case__							:  Tuple         =		False
  snake_case__							:  Optional[int]         =		False




  def 		SCREAMING_SNAKE_CASE							(					self	:		List[str]						):






         """simple docstring"""






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




  def 		SCREAMING_SNAKE_CASE							(					self	:		Tuple						):






         """simple docstring"""






         self.config_tester.run_common_tests()




  def 		SCREAMING_SNAKE_CASE							(					self	:		int						):






         """simple docstring"""






         _lowerCamelCase		:							Optional[Any]            =					self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_model(*_lowerCAmelCase						)




  def 		SCREAMING_SNAKE_CASE							(					self	:		Any						):






         """simple docstring"""






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




  def 		SCREAMING_SNAKE_CASE							(					self	:		List[Any]						):






         """simple docstring"""






         _lowerCamelCase     ,       _lowerCamelCase		:							Dict            =					self.model_tester.prepare_config_and_inputs_for_common()
         _lowerCamelCase		:							Optional[int]            =					3
         _lowerCamelCase		:							Dict            =					input_dict['''input_ids''']
         _lowerCamelCase		:							Dict            =					input_ids.ne(1						).to(_lowerCAmelCase						)
         _lowerCamelCase		:							str            =					ids_tensor([self.model_tester.batch_size]		,   self.model_tester.type_sequence_label_size						)
         _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	:		Tuple						):






         """simple docstring"""






         _lowerCamelCase     ,       _lowerCamelCase		:							Tuple            =					self.model_tester.prepare_config_and_inputs_for_common()
         _lowerCamelCase		:							Union[str, Any]            =					3
         _lowerCamelCase		:							Union[str, Any]            =					'''single_label_classification'''
         _lowerCamelCase		:							str            =					input_dict['''input_ids''']
         _lowerCamelCase		:							Optional[Any]            =					input_ids.ne(1						).to(_lowerCAmelCase						)
         _lowerCamelCase		:							int            =					ids_tensor([self.model_tester.batch_size]		,   self.model_tester.type_sequence_label_size						)
         _lowerCamelCase		:							Optional[Any]            =					FalconForSequenceClassification(_lowerCAmelCase						)
         model.to(_lowerCAmelCase						)
         model.eval()
         _lowerCamelCase		:							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 		SCREAMING_SNAKE_CASE							(					self	:		List[Any]						):






         """simple docstring"""






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






         """simple docstring"""






         _lowerCamelCase     ,       _lowerCamelCase		:							Optional[int]            =					self.model_tester.prepare_config_and_inputs_for_common()
         _lowerCamelCase		:							str            =					3
         _lowerCamelCase		:							int            =					'''multi_label_classification'''
         _lowerCamelCase		:							Dict            =					input_dict['''input_ids''']
         _lowerCamelCase		:							Optional[Any]            =					input_ids.ne(1						).to(_lowerCAmelCase						)
         _lowerCamelCase		:							str            =					ids_tensor(
             [self.model_tester.batch_size, config.num_labels]		,   self.model_tester.type_sequence_label_size						).to(torch.float						)
         _lowerCamelCase		:							Tuple            =					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	:		Optional[Any]						):






         """simple docstring"""






         for model_class in self.all_generative_model_classes:
                _lowerCamelCase     ,       _lowerCamelCase		:							Union[str, Any]            =					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		:							Union[str, Any]            =					model_class(_lowerCAmelCase						).to(_lowerCAmelCase						)
                if "use_cache" not in inputs:
                       _lowerCamelCase		:							Tuple            =					True
                _lowerCamelCase		:							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		:							Optional[Any]            =					(
                    getattr(_lowerCAmelCase		,   '''decoder_layers'''		,   _lowerCAmelCase						)
                    or getattr(_lowerCAmelCase		,   '''num_decoder_layers'''		,   _lowerCAmelCase						)
                    or config.num_hidden_layers
                )
                _lowerCamelCase		:							Optional[int]            =					getattr(_lowerCAmelCase		,   '''num_kv_heads'''		,   config.num_attention_heads						)
                _lowerCamelCase		:							List[str]            =					getattr(_lowerCAmelCase		,   '''d_model'''		,   config.hidden_size						)
                _lowerCamelCase		:							Optional[int]            =					embed_dim // num_attention_heads

                _lowerCamelCase		:							Any            =					outputs['''past_key_values''']
                self.assertEqual(len(_lowerCAmelCase						)		,   _lowerCAmelCase						)

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






         """simple docstring"""






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

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

         _lowerCamelCase		:							Optional[int]            =					model.generate(**_lowerCAmelCase		,   do_sample=_lowerCAmelCase		,   max_new_tokens=1_9						)
         _lowerCamelCase		:							Dict            =					tokenizer.batch_decode(_lowerCAmelCase						)[0]

         self.assertEqual(_lowerCAmelCase		,   _lowerCAmelCase						)




  @slow
  def 		SCREAMING_SNAKE_CASE							(					self	:		Tuple						):






         """simple docstring"""






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






         """simple docstring"""






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

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






from transformers import DistilBertTokenizer, DistilBertTokenizerFast
from transformers.testing_utils import require_tokenizers, slow

from ..bert.test_tokenization_bert import BertTokenizationTest


@require_tokenizers
class      __lowerCAmelCase  (			a       ):






  """simple docstring"""





  _SCREAMING_SNAKE_CASE		     =							DistilBertTokenizer
  _SCREAMING_SNAKE_CASE		     =							DistilBertTokenizerFast
  _SCREAMING_SNAKE_CASE		     =							True



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




     """simple docstring"""
     snake_case_            =       DistilBertTokenizer.from_pretrained("distilbert-base-uncased"	)

     snake_case_            =       tokenizer.encode("sequence builders"     ,					add_special_tokens=_lowerCAmelCase	)
     snake_case_            =       tokenizer.encode("multi-sequence build"     ,					add_special_tokens=_lowerCAmelCase	)

     snake_case_            =       tokenizer.build_inputs_with_special_tokens(_lowerCAmelCase	)
     snake_case_            =       tokenizer.build_inputs_with_special_tokens(_lowerCAmelCase     ,					_lowerCAmelCase	)

     assert encoded_sentence == [tokenizer.cls_token_id] + text + [tokenizer.sep_token_id]
     assert encoded_pair == [tokenizer.cls_token_id] + text + [tokenizer.sep_token_id] + text_a + [
         tokenizer.sep_token_id
     ]




