





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			:					str       ,  _snake_case			:					List[str]       ,  _snake_case			:					Optional[int]=3       ,  _snake_case			:					Dict=7       ,  _snake_case			:					Dict=True       ,  _snake_case			:					List[Any]=True       ,  _snake_case			:					Any=False       ,  _snake_case			:					List[str]=True       ,  _snake_case			:					int=99       ,  _snake_case			:					str=32       ,  _snake_case			:					Tuple=5       ,  _snake_case			:					str=4       ,  _snake_case			:					Any=37       ,  _snake_case			:					Optional[Any]="gelu"       ,  _snake_case			:					int=0.1       ,  _snake_case			:					Union[str, Any]=0.1       ,  _snake_case			:					List[str]=512       ,  _snake_case			:					Union[str, Any]=16       ,  _snake_case			:					Union[str, Any]=2       ,  _snake_case			:					Any=0.02       ,  _snake_case			:					Union[str, Any]=3       ,  _snake_case			:					Optional[Any]=4       ,  _snake_case			:					List[Any]=None       ,  )->Tuple:






   '''simple docstring'''

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






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






   '''simple docstring'''

   __lowerCAmelCase					:	Tuple      =       ids_tensor([self.batch_size, self.seq_length]       ,  self.vocab_size      )

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

   __lowerCAmelCase					:	Dict      =       None

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

   __lowerCAmelCase					:	int      =       self.get_config()

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






  def 				UpperCAmelCase__						(							self			:					str      )->int:






   '''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 				UpperCAmelCase__						(							self			:					Dict       ,  _snake_case			:					List[str]       ,  _snake_case			:					Optional[Any]       ,  _snake_case			:					Tuple       ,  _snake_case			:					Optional[Any]       ,  _snake_case			:					Dict       ,  _snake_case			:					Dict       ,  _snake_case			:					Dict      )->Optional[int]:






   '''simple docstring'''

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






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






   '''simple docstring'''

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






  def 				UpperCAmelCase__						(							self			:					Any       ,  _snake_case			:					int       ,  _snake_case			:					int       ,  _snake_case			:					int       ,  _snake_case			:					List[str]       ,  _snake_case			:					int       ,  _snake_case			:					Tuple       ,  _snake_case			:					str       ,  _snake_case			:					Tuple       ,  _snake_case			:					Dict       ,  )->Union[str, Any]:






   '''simple docstring'''

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






  def 				UpperCAmelCase__						(							self			:					List[str]       ,  _snake_case			:					Optional[int]       ,  _snake_case			:					List[str]       ,  _snake_case			:					Optional[Any]       ,  _snake_case			:					Any       ,  _snake_case			:					str       ,  _snake_case			:					Optional[int]       ,  _snake_case			:					Optional[int]       ,  _snake_case			:					Dict       ,  _snake_case			:					Union[str, Any]       ,  )->int:






   '''simple docstring'''

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

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

   # create hypothetical multiple next token and extent to next_input_ids
   __lowerCAmelCase					:	Dict      =       ids_tensor((self.batch_size, 3)       ,  config.vocab_size      )
   __lowerCAmelCase					:	Union[str, 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					:	Optional[int]      =       torch.cat([input_mask, next_mask]       ,  dim=-1      )

   __lowerCAmelCase					:	Optional[int]      =       model(
       __UpperCAmelCase       ,  attention_mask=__UpperCAmelCase       ,  encoder_hidden_states=__UpperCAmelCase       ,  encoder_attention_mask=__UpperCAmelCase       ,  output_hidden_states=__UpperCAmelCase       ,  )["""hidden_states"""][0]
   __lowerCAmelCase					:	Optional[int]      =       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
   __lowerCAmelCase					:	str      =       ids_tensor((1,)       ,  output_from_past.shape[-1]      ).item()
   __lowerCAmelCase					:	int      =       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(__UpperCAmelCase       ,  __UpperCAmelCase       ,  atol=1E-3      )      )






  def 				UpperCAmelCase__						(							self			:					List[str]      )->List[str]:






   '''simple docstring'''

   __lowerCAmelCase					:	Dict      =       self.prepare_config_and_inputs()
   (
       __lowerCAmelCase					
   )					:	int      =       config_and_inputs
   __lowerCAmelCase					:	int      =       {"""input_ids""": input_ids, """attention_mask""": input_mask}
   return config, inputs_dict






@require_torch
class        snake_case_    (		__SCREAMING_SNAKE_CASE					,__SCREAMING_SNAKE_CASE					,__SCREAMING_SNAKE_CASE					,unittest.TestCase						):
  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			:					Tuple      )->Any:






   '''simple docstring'''

   __lowerCAmelCase					:	Tuple      =       FalconModelTester(self      )
   __lowerCAmelCase					:	str      =       ConfigTester(self       ,  config_class=__UpperCAmelCase       ,  hidden_size=37      )






  def 				UpperCAmelCase__						(							self			:					int      )->int:






   '''simple docstring'''

   self.config_tester.run_common_tests()






  def 				UpperCAmelCase__						(							self			:					Tuple      )->str:






   '''simple docstring'''

   __lowerCAmelCase					:	List[Any]      =       self.model_tester.prepare_config_and_inputs()
   self.model_tester.create_and_check_model(*__UpperCAmelCase      )






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






   '''simple docstring'''

   __lowerCAmelCase					:	List[str]      =       self.model_tester.prepare_config_and_inputs()
   for alibi in [True, False]:
    __lowerCAmelCase					:	int      =       alibi
    self.model_tester.create_and_check_model(__UpperCAmelCase       ,  *__UpperCAmelCase      )






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






   '''simple docstring'''

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






  def 				UpperCAmelCase__						(							self			:					Dict      )->str:






   '''simple docstring'''

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






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






   '''simple docstring'''

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






   '''simple docstring'''

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






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






   '''simple docstring'''

   for model_class in self.all_generative_model_classes:
    __lowerCAmelCase					:	Tuple      =       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

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

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

    __lowerCAmelCase					:	List[str]      =       outputs["""past_key_values"""]
    self.assertEqual(len(__UpperCAmelCase      )       ,  __UpperCAmelCase      )

    __lowerCAmelCase					:	Union[str, Any]      =       inputs["""input_ids"""].shape
    for i in range(__UpperCAmelCase      ):
     if config.new_decoder_architecture:
      __lowerCAmelCase					:	str      =       config.num_attention_heads
     elif config.multi_query:
      __lowerCAmelCase					:	Dict      =       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 				UpperCAmelCase__						(							self			:					str      )->Optional[Any]:






   '''simple docstring'''

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

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

   __lowerCAmelCase					:	List[Any]      =       model.generate(**__UpperCAmelCase       ,  do_sample=__UpperCAmelCase       ,  max_new_tokens=19      )
   __lowerCAmelCase					:	Tuple      =       tokenizer.batch_decode(__UpperCAmelCase      )[0]

   self.assertEqual(__UpperCAmelCase       ,  __UpperCAmelCase      )






  @slow
  def 				UpperCAmelCase__						(							self			:					List[Any]      )->List[str]:






   '''simple docstring'''

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






   '''simple docstring'''

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

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






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


_UpperCAmelCase             =							logging.get_logger(__name__)

_UpperCAmelCase             =							{
    'microsoft/biogpt': 'https://huggingface.co/microsoft/biogpt/resolve/main/config.json',
    # See all BioGPT models at https://huggingface.co/models?filter=biogpt
}






class        snake_case_    (		__lowercase						):
  A_      							=   'biogpt'






  def __init__(							self			:					int       ,  _snake_case			:					Any=42384       ,  _snake_case			:					Any=1024       ,  _snake_case			:					List[Any]=24       ,  _snake_case			:					Any=16       ,  _snake_case			:					List[str]=4096       ,  _snake_case			:					Dict="gelu"       ,  _snake_case			:					Tuple=0.1       ,  _snake_case			:					str=0.1       ,  _snake_case			:					Tuple=1024       ,  _snake_case			:					Tuple=0.02       ,  _snake_case			:					Tuple=1E-12       ,  _snake_case			:					Optional[int]=True       ,  _snake_case			:					Optional[int]=True       ,  _snake_case			:					Any=0.0       ,  _snake_case			:					Tuple=0.0       ,  _snake_case			:					str=1       ,  _snake_case			:					Dict=0       ,  _snake_case			:					str=2       ,  **_snake_case			:					Union[str, Any]       ,  )->Dict:






   '''simple docstring'''

   __lowerCAmelCase					:	List[Any]      =       vocab_size
   __lowerCAmelCase					:	Dict      =       max_position_embeddings
   __lowerCAmelCase					:	str      =       hidden_size
   __lowerCAmelCase					:	Dict      =       num_hidden_layers
   __lowerCAmelCase					:	List[Any]      =       num_attention_heads
   __lowerCAmelCase					:	Optional[Any]      =       intermediate_size
   __lowerCAmelCase					:	int      =       hidden_act
   __lowerCAmelCase					:	Any      =       hidden_dropout_prob
   __lowerCAmelCase					:	Any      =       attention_probs_dropout_prob
   __lowerCAmelCase					:	Any      =       initializer_range
   __lowerCAmelCase					:	int      =       layer_norm_eps
   __lowerCAmelCase					:	Optional[int]      =       scale_embedding
   __lowerCAmelCase					:	List[Any]      =       use_cache
   __lowerCAmelCase					:	str      =       layerdrop
   __lowerCAmelCase					:	Dict      =       activation_dropout
   super().__init__(pad_token_id=_snake_case       ,  bos_token_id=_snake_case       ,  eos_token_id=_snake_case       ,  **_snake_case      )