






'''simple docstring'''
import math
import unittest

from transformers import BioGptConfig, 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 (
      BioGptForCausalLM,
      BioGptForSequenceClassification,
      BioGptForTokenClassification,
      BioGptModel,
      BioGptTokenizer,
  )
  from transformers.models.biogpt.modeling_biogpt import BIOGPT_PRETRAINED_MODEL_ARCHIVE_LIST






class        __SCREAMING_SNAKE_CASE :




 def __init__( self		:							Optional[Any]   , __lowercase		:							str   , __lowercase		:							str=13   , __lowercase		:							Union[str, Any]=7   , __lowercase		:							Union[str, Any]=True   , __lowercase		:							Union[str, Any]=True   , __lowercase		:							Optional[int]=False   , __lowercase		:							str=True   , __lowercase		:							List[Any]=99   , __lowercase		:							int=32   , __lowercase		:							List[Any]=5   , __lowercase		:							Optional[Any]=4   , __lowercase		:							Dict=37   , __lowercase		:							int="gelu"   , __lowercase		:							List[Any]=0.1   , __lowercase		:							Optional[int]=0.1   , __lowercase		:							Tuple=5_12   , __lowercase		:							str=16   , __lowercase		:							Union[str, Any]=2   , __lowercase		:							Dict=0.02   , __lowercase		:							Optional[int]=3   , __lowercase		:							Any=4   , __lowercase		:							Any=None   , )		->  Tuple:
       SCREAMING_SNAKE_CASE__       :			Optional[Any]													=parent
       SCREAMING_SNAKE_CASE__       :			Any													=batch_size
       SCREAMING_SNAKE_CASE__       :			List[Any]													=seq_length
       SCREAMING_SNAKE_CASE__       :			Optional[int]													=is_training
       SCREAMING_SNAKE_CASE__       :			Optional[int]													=use_input_mask
       SCREAMING_SNAKE_CASE__       :			List[str]													=use_token_type_ids
       SCREAMING_SNAKE_CASE__       :			List[str]													=use_labels
       SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=vocab_size
       SCREAMING_SNAKE_CASE__       :			List[str]													=hidden_size
       SCREAMING_SNAKE_CASE__       :			Any													=num_hidden_layers
       SCREAMING_SNAKE_CASE__       :			Tuple													=num_attention_heads
       SCREAMING_SNAKE_CASE__       :			Any													=intermediate_size
       SCREAMING_SNAKE_CASE__       :			List[Any]													=hidden_act
       SCREAMING_SNAKE_CASE__       :			int													=hidden_dropout_prob
       SCREAMING_SNAKE_CASE__       :			str													=attention_probs_dropout_prob
       SCREAMING_SNAKE_CASE__       :			Tuple													=max_position_embeddings
       SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=type_vocab_size
       SCREAMING_SNAKE_CASE__       :			List[str]													=type_sequence_label_size
       SCREAMING_SNAKE_CASE__       :			Tuple													=initializer_range
       SCREAMING_SNAKE_CASE__       :			Any													=num_labels
       SCREAMING_SNAKE_CASE__       :			Optional[Any]													=num_choices
       SCREAMING_SNAKE_CASE__       :			Tuple													=scope




 def        __magic_name__		( self		:							Optional[Any] )		->  str:
       SCREAMING_SNAKE_CASE__       :			List[Any]													=ids_tensor([self.batch_size, self.seq_length]   , self.vocab_size )

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

       SCREAMING_SNAKE_CASE__       :			int													=None
       if self.use_token_type_ids:
             SCREAMING_SNAKE_CASE__       :			str													=ids_tensor([self.batch_size, self.seq_length]   , self.type_vocab_size )

       SCREAMING_SNAKE_CASE__       :			str													=None
       SCREAMING_SNAKE_CASE__       :			Tuple													=None
       SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=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__       :			Any													=ids_tensor([self.batch_size]   , self.num_choices )

       SCREAMING_SNAKE_CASE__       :			Dict													=self.get_config()

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




 def        __magic_name__		( self		:							str )		->  List[str]:
       return BioGptConfig(
           vocab_size=self.vocab_size   , hidden_size=self.hidden_size   , num_hidden_layers=self.num_hidden_layers   , num_attention_heads=self.num_attention_heads   , intermediate_size=self.intermediate_size   , hidden_act=self.hidden_act   , hidden_dropout_prob=self.hidden_dropout_prob   , attention_probs_dropout_prob=self.attention_probs_dropout_prob   , max_position_embeddings=self.max_position_embeddings   , type_vocab_size=self.type_vocab_size   , is_decoder=__SCREAMING_SNAKE_CASE   , initializer_range=self.initializer_range   , )




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




 def        __magic_name__		( self		:							List[Any]   , __lowercase		:							Dict   , __lowercase		:							Tuple   , __lowercase		:							Tuple   , __lowercase		:							List[Any]   , __lowercase		:							Dict   , __lowercase		:							List[str]   , __lowercase		:							Optional[int]   , __lowercase		:							List[str]   , __lowercase		:							Optional[Any]   , )		->  str:
       SCREAMING_SNAKE_CASE__       :			str													=BioGptForCausalLM(config=__SCREAMING_SNAKE_CASE )
       model.to(__SCREAMING_SNAKE_CASE )
       model.eval()
       SCREAMING_SNAKE_CASE__       :			Tuple													=model(__SCREAMING_SNAKE_CASE   , attention_mask=__SCREAMING_SNAKE_CASE   , token_type_ids=__SCREAMING_SNAKE_CASE   , labels=__SCREAMING_SNAKE_CASE )
       self.parent.assertEqual(result.logits.shape   , (self.batch_size, self.seq_length, self.vocab_size) )




 def        __magic_name__		( self		:							Dict   , __lowercase		:							int   , __lowercase		:							List[Any]   , __lowercase		:							Any   , __lowercase		:							List[Any]   , __lowercase		:							List[Any]   , *__lowercase		:							Any )		->  Union[str, Any]:
       SCREAMING_SNAKE_CASE__       :			Tuple													=BioGptModel(config=__SCREAMING_SNAKE_CASE )
       model.to(__SCREAMING_SNAKE_CASE )
       model.eval()

       # create attention mask
       SCREAMING_SNAKE_CASE__       :			Dict													=torch.ones(input_ids.shape   , dtype=torch.long   , device=__SCREAMING_SNAKE_CASE )
       SCREAMING_SNAKE_CASE__       :			Tuple													=self.seq_length // 2
       SCREAMING_SNAKE_CASE__       :			Optional[Any]													=0

       # first forward pass
       SCREAMING_SNAKE_CASE__						,		SCREAMING_SNAKE_CASE__       :			Any													=model(__SCREAMING_SNAKE_CASE   , attention_mask=__SCREAMING_SNAKE_CASE ).to_tuple()

       # create hypothetical next token and extent to next_input_ids
       SCREAMING_SNAKE_CASE__       :			Dict													=ids_tensor((self.batch_size, 1)   , config.vocab_size )

       # change a random masked slice from input_ids
       SCREAMING_SNAKE_CASE__       :			Optional[int]													=ids_tensor((1,)   , __SCREAMING_SNAKE_CASE ).item() + 1
       SCREAMING_SNAKE_CASE__       :			Dict													=ids_tensor((self.batch_size, 1)   , config.vocab_size ).squeeze(-1 )
       SCREAMING_SNAKE_CASE__       :			str													=random_other_next_tokens

       # append to next input_ids and attn_mask
       SCREAMING_SNAKE_CASE__       :			List[Any]													=torch.cat([input_ids, next_tokens]   , dim=-1 )
       SCREAMING_SNAKE_CASE__       :			List[str]													=torch.cat(
           [attn_mask, torch.ones((attn_mask.shape[0], 1)   , dtype=torch.long   , device=__SCREAMING_SNAKE_CASE )]   , dim=1   , )

       # get two different outputs
       SCREAMING_SNAKE_CASE__       :			Dict													=model(__SCREAMING_SNAKE_CASE   , attention_mask=__SCREAMING_SNAKE_CASE )['''last_hidden_state''']
       SCREAMING_SNAKE_CASE__       :			List[str]													=model(__SCREAMING_SNAKE_CASE   , past_key_values=__SCREAMING_SNAKE_CASE   , attention_mask=__SCREAMING_SNAKE_CASE )['''last_hidden_state''']

       # select random slice
       SCREAMING_SNAKE_CASE__       :			str													=ids_tensor((1,)   , output_from_past.shape[-1] ).item()
       SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=output_from_no_past[:, -1, random_slice_idx].detach()
       SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=output_from_past[:, 0, random_slice_idx].detach()

       # test that outputs are equal for slice
       self.parent.assertTrue(torch.allclose(__SCREAMING_SNAKE_CASE   , __SCREAMING_SNAKE_CASE   , atol=1e-3 ) )




 def        __magic_name__		( self		:							Tuple   , __lowercase		:							Optional[Any]   , __lowercase		:							Dict   , __lowercase		:							Optional[Any]   , __lowercase		:							int   , __lowercase		:							Tuple   , *__lowercase		:							Union[str, Any] )		->  Optional[Any]:
       SCREAMING_SNAKE_CASE__       :			Dict													=BioGptModel(config=__SCREAMING_SNAKE_CASE ).to(__SCREAMING_SNAKE_CASE ).eval()

       SCREAMING_SNAKE_CASE__       :			str													=torch.ones(input_ids.shape   , dtype=torch.long   , device=__SCREAMING_SNAKE_CASE )

       # first forward pass
       SCREAMING_SNAKE_CASE__       :			Dict													=model(__SCREAMING_SNAKE_CASE   , attention_mask=__SCREAMING_SNAKE_CASE   , use_cache=__SCREAMING_SNAKE_CASE )

       SCREAMING_SNAKE_CASE__						,		SCREAMING_SNAKE_CASE__       :			Any													=outputs.to_tuple()

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

       # append to next input_ids and
       SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=torch.cat([input_ids, next_tokens]   , dim=-1 )
       SCREAMING_SNAKE_CASE__       :			int													=torch.cat([attention_mask, next_attn_mask]   , dim=-1 )

       SCREAMING_SNAKE_CASE__       :			Optional[Any]													=model(__SCREAMING_SNAKE_CASE   , attention_mask=__SCREAMING_SNAKE_CASE )['''last_hidden_state''']
       SCREAMING_SNAKE_CASE__       :			Dict													=model(__SCREAMING_SNAKE_CASE   , attention_mask=__SCREAMING_SNAKE_CASE   , past_key_values=__SCREAMING_SNAKE_CASE )[
           '''last_hidden_state'''
       ]

       # select random slice
       SCREAMING_SNAKE_CASE__       :			Tuple													=ids_tensor((1,)   , output_from_past.shape[-1] ).item()
       SCREAMING_SNAKE_CASE__       :			int													=output_from_no_past[:, -3:, random_slice_idx].detach()
       SCREAMING_SNAKE_CASE__       :			Optional[Any]													=output_from_past[:, :, random_slice_idx].detach()

       self.parent.assertTrue(output_from_past_slice.shape[1] == next_tokens.shape[1] )

       # test that outputs are equal for slice
       self.parent.assertTrue(torch.allclose(__SCREAMING_SNAKE_CASE   , __SCREAMING_SNAKE_CASE   , atol=1e-3 ) )




 def        __magic_name__		( self		:							List[Any]   , __lowercase		:							Any   , __lowercase		:							int   , __lowercase		:							Union[str, Any]   , __lowercase		:							str   , __lowercase		:							List[str]   , *__lowercase		:							str   , __lowercase		:							List[str]=False )		->  Dict:
       SCREAMING_SNAKE_CASE__       :			int													=BioGptForCausalLM(__SCREAMING_SNAKE_CASE )
       model.to(__SCREAMING_SNAKE_CASE )
       if gradient_checkpointing:
             model.gradient_checkpointing_enable()

       SCREAMING_SNAKE_CASE__       :			int													=model(__SCREAMING_SNAKE_CASE   , labels=__SCREAMING_SNAKE_CASE )
       self.parent.assertEqual(result.loss.shape   , () )
       self.parent.assertEqual(result.logits.shape   , (self.batch_size, self.seq_length, self.vocab_size) )
       result.loss.backward()




 def        __magic_name__		( self		:							str   , __lowercase		:							Optional[Any]   , *__lowercase		:							Union[str, Any] )		->  str:
       SCREAMING_SNAKE_CASE__       :			Tuple													=BioGptModel(__SCREAMING_SNAKE_CASE )
       SCREAMING_SNAKE_CASE__       :			Dict													=model.config.initializer_range / math.sqrt(2 * model.config.num_hidden_layers )
       for key in model.state_dict().keys():
             if "c_proj" in key and "weight" in key:
                   self.parent.assertLessEqual(abs(torch.std(model.state_dict()[key] ) - model_std )   , 0.001 )
                   self.parent.assertLessEqual(abs(torch.mean(model.state_dict()[key] ) - 0.0 )   , 0.01 )




 def        __magic_name__		( self		:							Optional[Any]   , __lowercase		:							Tuple   , __lowercase		:							str   , __lowercase		:							Optional[Any]   , __lowercase		:							str   , __lowercase		:							List[Any]   , *__lowercase		:							List[Any] )		->  Tuple:
       SCREAMING_SNAKE_CASE__       :			List[str]													=self.num_labels
       SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=BioGptForTokenClassification(__SCREAMING_SNAKE_CASE )
       model.to(__SCREAMING_SNAKE_CASE )
       model.eval()
       SCREAMING_SNAKE_CASE__       :			int													=model(__SCREAMING_SNAKE_CASE   , attention_mask=__SCREAMING_SNAKE_CASE   , token_type_ids=__SCREAMING_SNAKE_CASE )
       self.parent.assertEqual(result.logits.shape   , (self.batch_size, self.seq_length, self.num_labels) )




 def        __magic_name__		( self		:							Dict )		->  Optional[Any]:
       SCREAMING_SNAKE_CASE__       :			str													=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__	
       )						,			
       )       :			Union[str, Any]													=config_and_inputs
       SCREAMING_SNAKE_CASE__       :			Dict													={'''input_ids''': input_ids, '''attention_mask''': input_mask}
       return config, inputs_dict






@require_torch
class        __SCREAMING_SNAKE_CASE (     lowerCAmelCase_		,			lowerCAmelCase_		,			lowerCAmelCase_		,			unittest.TestCase			):
 snake_case_												=							(
     (BioGptModel, BioGptForCausalLM, BioGptForSequenceClassification, BioGptForTokenClassification)
     if is_torch_available()
     else ()
 )
 snake_case_												=							(BioGptForCausalLM,) if is_torch_available() else ()
 snake_case_												=							(
     {
         """feature-extraction""": BioGptModel,
         """text-classification""": BioGptForSequenceClassification,
         """text-generation""": BioGptForCausalLM,
         """token-classification""": BioGptForTokenClassification,
         """zero-shot""": BioGptForSequenceClassification,
     }
     if is_torch_available()
     else {}
 )
 snake_case_												=							False




 def        __magic_name__		( self		:							List[Any] )		->  Tuple:
       SCREAMING_SNAKE_CASE__       :			Tuple													=BioGptModelTester(self )
       SCREAMING_SNAKE_CASE__       :			Optional[Any]													=ConfigTester(self   , config_class=__SCREAMING_SNAKE_CASE   , hidden_size=37 )




 def        __magic_name__		( self		:							Tuple )		->  Optional[int]:
       self.config_tester.run_common_tests()




 def        __magic_name__		( self		:							List[str] )		->  List[str]:
       SCREAMING_SNAKE_CASE__       :			Optional[Any]													=self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_model(*__SCREAMING_SNAKE_CASE )




 def        __magic_name__		( self		:							List[str] )		->  int:
       SCREAMING_SNAKE_CASE__       :			Optional[Any]													=self.model_tester.prepare_config_and_inputs()
       for type in ["absolute", "relative_key", "relative_key_query"]:
             SCREAMING_SNAKE_CASE__       :			List[Any]													=type
             self.model_tester.create_and_check_model(*__SCREAMING_SNAKE_CASE )




 def        __magic_name__		( self		:							List[str] )		->  Optional[int]:
       SCREAMING_SNAKE_CASE__       :			Tuple													=self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_biogpt_model_attention_mask_past(*__SCREAMING_SNAKE_CASE )




 def        __magic_name__		( self		:							List[str] )		->  Optional[int]:
       SCREAMING_SNAKE_CASE__       :			Optional[int]													=self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_forward_and_backwards(*__SCREAMING_SNAKE_CASE   , gradient_checkpointing=__SCREAMING_SNAKE_CASE )




 def        __magic_name__		( self		:							Dict )		->  List[Any]:
       SCREAMING_SNAKE_CASE__       :			List[Any]													=self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_biogpt_model_past_large_inputs(*__SCREAMING_SNAKE_CASE )




 def        __magic_name__		( self		:							List[str] )		->  List[Any]:
       SCREAMING_SNAKE_CASE__       :			int													=self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_biogpt_weight_initialization(*__SCREAMING_SNAKE_CASE )




 def        __magic_name__		( self		:							List[Any] )		->  Any:
       SCREAMING_SNAKE_CASE__       :			List[Any]													=self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_biogpt_for_token_classification(*__SCREAMING_SNAKE_CASE )




 @slow
 def        __magic_name__		( self		:							str )		->  str:
       SCREAMING_SNAKE_CASE__       :			int													=BioGptForCausalLM.from_pretrained('''microsoft/biogpt''' )
       model.to(__SCREAMING_SNAKE_CASE )
       SCREAMING_SNAKE_CASE__       :			List[Any]													=BioGptTokenizer.from_pretrained('''microsoft/biogpt''' )

       SCREAMING_SNAKE_CASE__       :			Any													='''left'''

       # Define PAD Token = EOS Token = 50256
       SCREAMING_SNAKE_CASE__       :			int													=tokenizer.eos_token
       SCREAMING_SNAKE_CASE__       :			Optional[int]													=model.config.eos_token_id

       # use different length sentences to test batching
       SCREAMING_SNAKE_CASE__       :			Dict													=[
           '''Hello, my dog is a little''',
           '''Today, I''',
       ]

       SCREAMING_SNAKE_CASE__       :			Any													=tokenizer(__SCREAMING_SNAKE_CASE   , return_tensors='''pt'''   , padding=__SCREAMING_SNAKE_CASE )
       SCREAMING_SNAKE_CASE__       :			str													=inputs['''input_ids'''].to(__SCREAMING_SNAKE_CASE )

       SCREAMING_SNAKE_CASE__       :			Optional[int]													=model.generate(
           input_ids=__SCREAMING_SNAKE_CASE   , attention_mask=inputs['''attention_mask'''].to(__SCREAMING_SNAKE_CASE )   , )

       SCREAMING_SNAKE_CASE__       :			Optional[Any]													=tokenizer(sentences[0]   , return_tensors='''pt''' ).input_ids.to(__SCREAMING_SNAKE_CASE )
       SCREAMING_SNAKE_CASE__       :			List[Any]													=model.generate(input_ids=__SCREAMING_SNAKE_CASE )

       SCREAMING_SNAKE_CASE__       :			str													=inputs_non_padded.shape[-1] - inputs['''attention_mask'''][-1].long().sum().cpu().item()
       SCREAMING_SNAKE_CASE__       :			List[Any]													=tokenizer(sentences[1]   , return_tensors='''pt''' ).input_ids.to(__SCREAMING_SNAKE_CASE )
       SCREAMING_SNAKE_CASE__       :			List[str]													=model.generate(input_ids=__SCREAMING_SNAKE_CASE   , max_length=model.config.max_length - num_paddings )

       SCREAMING_SNAKE_CASE__       :			Optional[int]													=tokenizer.batch_decode(__SCREAMING_SNAKE_CASE   , skip_special_tokens=__SCREAMING_SNAKE_CASE )
       SCREAMING_SNAKE_CASE__       :			Tuple													=tokenizer.decode(output_non_padded[0]   , skip_special_tokens=__SCREAMING_SNAKE_CASE )
       SCREAMING_SNAKE_CASE__       :			Tuple													=tokenizer.decode(output_padded[0]   , skip_special_tokens=__SCREAMING_SNAKE_CASE )

       SCREAMING_SNAKE_CASE__       :			List[Any]													=[
           '''Hello, my dog is a little bit bigger than a little bit.''',
           '''Today, I have a good idea of how to use the information''',
       ]
       self.assertListEqual(__SCREAMING_SNAKE_CASE   , __SCREAMING_SNAKE_CASE )
       self.assertListEqual(__SCREAMING_SNAKE_CASE   , [non_padded_sentence, padded_sentence] )




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

       for model_name in BIOGPT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
             SCREAMING_SNAKE_CASE__       :			Optional[Any]													=BioGptModel.from_pretrained(__SCREAMING_SNAKE_CASE )
             self.assertIsNotNone(__SCREAMING_SNAKE_CASE )




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




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






@require_torch
class        __SCREAMING_SNAKE_CASE (     unittest.TestCase			):




 @slow
 def        __magic_name__		( self		:							Dict )		->  int:
       SCREAMING_SNAKE_CASE__       :			str													=BioGptForCausalLM.from_pretrained('''microsoft/biogpt''' )
       SCREAMING_SNAKE_CASE__       :			Tuple													=torch.tensor([[2, 48_05, 9, 6_56, 21]] )
       SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=model(__SCREAMING_SNAKE_CASE )[0]

       SCREAMING_SNAKE_CASE__       :			Optional[int]													=4_23_84

       SCREAMING_SNAKE_CASE__       :			Optional[Any]													=torch.Size((1, 5, vocab_size) )
       self.assertEqual(output.shape   , __SCREAMING_SNAKE_CASE )

       SCREAMING_SNAKE_CASE__       :			Dict													=torch.tensor(
           [[[-9.5236, -9.8918, 10.4557], [-11.0469, -9.6423, 8.1022], [-8.8664, -7.8826, 5.5325]]] )

       self.assertTrue(torch.allclose(output[:, :3, :3]   , __SCREAMING_SNAKE_CASE   , atol=1e-4 ) )




 @slow
 def        __magic_name__		( self		:							Optional[Any] )		->  List[Any]:
       SCREAMING_SNAKE_CASE__       :			Optional[Any]													=BioGptTokenizer.from_pretrained('''microsoft/biogpt''' )
       SCREAMING_SNAKE_CASE__       :			Dict													=BioGptForCausalLM.from_pretrained('''microsoft/biogpt''' )
       model.to(__SCREAMING_SNAKE_CASE )

       torch.manual_seed(0 )
       SCREAMING_SNAKE_CASE__       :			List[Any]													=tokenizer('''COVID-19 is'''   , return_tensors='''pt''' ).to(__SCREAMING_SNAKE_CASE )
       SCREAMING_SNAKE_CASE__       :			str													=model.generate(
           **__SCREAMING_SNAKE_CASE   , min_length=1_00   , max_length=10_24   , num_beams=5   , early_stopping=__SCREAMING_SNAKE_CASE   , )
       SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=tokenizer.decode(output_ids[0]   , skip_special_tokens=__SCREAMING_SNAKE_CASE )

       SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=(
           '''COVID-19 is a global pandemic caused by severe acute respiratory syndrome coronavirus 2 (SARS-CoV-2), the'''
           ''' causative agent of coronavirus disease 2019 (COVID-19), which has spread to more than 200 countries and'''
           ''' territories, including the United States (US), Canada, Australia, New Zealand, the United Kingdom (UK),'''
           ''' and the United States of America (USA), as of March 11, 2020, with more than 800,000 confirmed cases and'''
           ''' more than 800,000 deaths.'''
       )
       self.assertEqual(__SCREAMING_SNAKE_CASE   , __SCREAMING_SNAKE_CASE )









'''simple docstring'''
from scipy.stats import pearsonr

import datasets


a_					=	'\nPearson correlation coefficient and p-value for testing non-correlation.\nThe Pearson correlation coefficient measures the linear relationship between two datasets. The calculation of the p-value relies on the assumption that each dataset is normally distributed. Like other correlation coefficients, this one varies between -1 and +1 with 0 implying no correlation. Correlations of -1 or +1 imply an exact linear relationship. Positive correlations imply that as x increases, so does y. Negative correlations imply that as x increases, y decreases.\nThe p-value roughly indicates the probability of an uncorrelated system producing datasets that have a Pearson correlation at least as extreme as the one computed from these datasets.\n'


a_					=	'\nArgs:\n    predictions (`list` of `int`): Predicted class labels, as returned by a model.\n    references (`list` of `int`): Ground truth labels.\n    return_pvalue (`boolean`): If `True`, returns the p-value, along with the correlation coefficient. If `False`, returns only the correlation coefficient. Defaults to `False`.\n\nReturns:\n    pearsonr (`float`): Pearson correlation coefficient. Minimum possible value is -1. Maximum possible value is 1. Values of 1 and -1 indicate exact linear positive and negative relationships, respectively. A value of 0 implies no correlation.\n    p-value (`float`): P-value, which roughly indicates the probability of an The p-value roughly indicates the probability of an uncorrelated system producing datasets that have a Pearson correlation at least as extreme as the one computed from these datasets. Minimum possible value is 0. Maximum possible value is 1. Higher values indicate higher probabilities.\n\nExamples:\n\n    Example 1-A simple example using only predictions and references.\n        >>> pearsonr_metric = datasets.load_metric("pearsonr")\n        >>> results = pearsonr_metric.compute(predictions=[10, 9, 2.5, 6, 4], references=[1, 2, 3, 4, 5])\n        >>> print(round(results[\'pearsonr\'], 2))\n        -0.74\n\n    Example 2-The same as Example 1, but that also returns the `p-value`.\n        >>> pearsonr_metric = datasets.load_metric("pearsonr")\n        >>> results = pearsonr_metric.compute(predictions=[10, 9, 2.5, 6, 4], references=[1, 2, 3, 4, 5], return_pvalue=True)\n        >>> print(sorted(list(results.keys())))\n        [\'p-value\', \'pearsonr\']\n        >>> print(round(results[\'pearsonr\'], 2))\n        -0.74\n        >>> print(round(results[\'p-value\'], 2))\n        0.15\n'


a_					=	'\n@article{2020SciPy-NMeth,\nauthor  = {Virtanen, Pauli and Gommers, Ralf and Oliphant, Travis E. and\n      Haberland, Matt and Reddy, Tyler and Cournapeau, David and\n      Burovski, Evgeni and Peterson, Pearu and Weckesser, Warren and\n      Bright, Jonathan and {van der Walt}, St{\'e}fan J. and\n      Brett, Matthew and Wilson, Joshua and Millman, K. Jarrod and\n      Mayorov, Nikolay and Nelson, Andrew R. J. and Jones, Eric and\n      Kern, Robert and Larson, Eric and Carey, C J and\n      Polat, Ilhan and Feng, Yu and Moore, Eric W. and\n      {VanderPlas}, Jake and Laxalde, Denis and Perktold, Josef and\n      Cimrman, Robert and Henriksen, Ian and Quintero, E. A. and\n      Harris, Charles R. and Archibald, Anne M. and\n      Ribeiro, Antonio H. and Pedregosa, Fabian and\n      {van Mulbregt}, Paul and {SciPy 1.0 Contributors}},\ntitle   = {{{SciPy} 1.0: Fundamental Algorithms for Scientific\n      Computing in Python}},\njournal = {Nature Methods},\nyear    = {2020},\nvolume  = {17},\npages   = {261--272},\nadsurl  = {https://rdcu.be/b08Wh},\ndoi = {10.1038/s41592-019-0686-2},\n}\n'






@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION		,			_KWARGS_DESCRIPTION			)
class        __SCREAMING_SNAKE_CASE (     datasets.Metric			):




 def        __magic_name__		( self		:							List[Any] )		->  Any:
       return datasets.MetricInfo(
           description=_DESCRIPTION   , citation=_CITATION   , inputs_description=_KWARGS_DESCRIPTION   , features=datasets.Features(
               {
                   '''predictions''': datasets.Value('''float''' ),
                   '''references''': datasets.Value('''float''' ),
               } )   , reference_urls=['''https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.pearsonr.html''']   , )




 def        __magic_name__		( self		:							Optional[int]   , __lowercase		:							List[Any]   , __lowercase		:							List[Any]   , __lowercase		:							str=False )		->  int:
       if return_pvalue:
             SCREAMING_SNAKE_CASE__       :			List[str]													=pearsonr(__lowercase   , __lowercase )
             return {"pearsonr": results[0], "p-value": results[1]}
       else:
             return {"pearsonr": float(pearsonr(__lowercase   , __lowercase )[0] )}