



"""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 			_a :
			"""simple docstring"""



			def __init__(		self     :    str				,   __UpperCamelCase     :    Any				,   __UpperCamelCase     :    Tuple=1_3				,   __UpperCamelCase     :    List[Any]=7				,   __UpperCamelCase     :    Optional[int]=True				,   __UpperCamelCase     :    int=True				,   __UpperCamelCase     :    Dict=False				,   __UpperCamelCase     :    str=True				,   __UpperCamelCase     :    Union[str, Any]=9_9				,   __UpperCamelCase     :    Optional[Any]=3_2				,   __UpperCamelCase     :    str=5				,   __UpperCamelCase     :    Tuple=4				,   __UpperCamelCase     :    Optional[int]=3_7				,   __UpperCamelCase     :    List[str]="gelu"				,   __UpperCamelCase     :    Tuple=0.1				,   __UpperCamelCase     :    str=0.1				,   __UpperCamelCase     :    str=5_1_2				,   __UpperCamelCase     :    List[str]=1_6				,   __UpperCamelCase     :    Tuple=2				,   __UpperCamelCase     :    Optional[int]=0.0_2				,   __UpperCamelCase     :    List[str]=3				,   __UpperCamelCase     :    Tuple=4				,   __UpperCamelCase     :    Any=None				,   )->Any:
							_UpperCAmelCase					=    parent
							_UpperCAmelCase					=    batch_size
							_UpperCAmelCase					=    seq_length
							_UpperCAmelCase					=    is_training
							_UpperCAmelCase					=    use_input_mask
							_UpperCAmelCase					=    use_token_type_ids
							_UpperCAmelCase					=    use_labels
							_UpperCAmelCase					=    vocab_size
							_UpperCAmelCase					=    hidden_size
							_UpperCAmelCase					=    num_hidden_layers
							_UpperCAmelCase					=    num_attention_heads
							_UpperCAmelCase					=    intermediate_size
							_UpperCAmelCase					=    hidden_act
							_UpperCAmelCase					=    hidden_dropout_prob
							_UpperCAmelCase					=    attention_probs_dropout_prob
							_UpperCAmelCase					=    max_position_embeddings
							_UpperCAmelCase					=    type_vocab_size
							_UpperCAmelCase					=    type_sequence_label_size
							_UpperCAmelCase					=    initializer_range
							_UpperCAmelCase					=    num_labels
							_UpperCAmelCase					=    num_choices
							_UpperCAmelCase					=    scope



			def  lowercase__						(		self     :    Optional[int]   )->Union[str, Any]:
							_UpperCAmelCase					=    ids_tensor([self.batch_size, self.seq_length]				,   self.vocab_size   )

							_UpperCAmelCase					=    None
							if self.use_input_mask:
											_UpperCAmelCase					=    random_attention_mask([self.batch_size, self.seq_length]   )

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

							_UpperCAmelCase					=    None
							_UpperCAmelCase					=    None
							_UpperCAmelCase					=    None
							if self.use_labels:
											_UpperCAmelCase					=    ids_tensor([self.batch_size]				,   self.type_sequence_label_size   )
											_UpperCAmelCase					=    ids_tensor([self.batch_size, self.seq_length]				,   self.num_labels   )
											_UpperCAmelCase					=    ids_tensor([self.batch_size]				,   self.num_choices   )

							_UpperCAmelCase					=    self.get_config()

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



			def  lowercase__						(		self     :    Tuple   )->Any:
							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=__UpperCamelCase				,   initializer_range=self.initializer_range				,   )



			def  lowercase__						(		self     :    List[Any]				,   __UpperCamelCase     :    List[str]				,   __UpperCamelCase     :    Tuple				,   __UpperCamelCase     :    List[Any]				,   __UpperCamelCase     :    Union[str, Any]				,   __UpperCamelCase     :    Union[str, Any]				,   __UpperCamelCase     :    Optional[Any]				,   __UpperCamelCase     :    str   )->Any:
							_UpperCAmelCase					=    BioGptModel(config=__UpperCamelCase   )
							model.to(__UpperCamelCase   )
							model.eval()
							_UpperCAmelCase					=    model(__UpperCamelCase				,   attention_mask=__UpperCamelCase   )
							_UpperCAmelCase					=    model(__UpperCamelCase   )
							self.parent.assertEqual(result.last_hidden_state.shape				,   (self.batch_size, self.seq_length, self.hidden_size)   )



			def  lowercase__						(		self     :    int				,   __UpperCamelCase     :    Any				,   __UpperCamelCase     :    str				,   __UpperCamelCase     :    Union[str, Any]				,   __UpperCamelCase     :    int				,   __UpperCamelCase     :    Optional[int]				,   __UpperCamelCase     :    Optional[int]				,   __UpperCamelCase     :    Union[str, Any]				,   __UpperCamelCase     :    int				,   __UpperCamelCase     :    Union[str, Any]				,   )->Optional[int]:
							_UpperCAmelCase					=    BioGptForCausalLM(config=__UpperCamelCase   )
							model.to(__UpperCamelCase   )
							model.eval()
							_UpperCAmelCase					=    model(__UpperCamelCase				,   attention_mask=__UpperCamelCase				,   token_type_ids=__UpperCamelCase				,   labels=__UpperCamelCase   )
							self.parent.assertEqual(result.logits.shape				,   (self.batch_size, self.seq_length, self.vocab_size)   )



			def  lowercase__						(		self     :    Optional[int]				,   __UpperCamelCase     :    List[str]				,   __UpperCamelCase     :    List[str]				,   __UpperCamelCase     :    Optional[int]				,   __UpperCamelCase     :    Tuple				,   __UpperCamelCase     :    int				,   *__UpperCamelCase     :    Optional[int]   )->Union[str, Any]:
							_UpperCAmelCase					=    BioGptModel(config=__UpperCamelCase   )
							model.to(__UpperCamelCase   )
							model.eval()

							# create attention mask
							_UpperCAmelCase					=    torch.ones(input_ids.shape				,   dtype=torch.long				,   device=__UpperCamelCase   )
							_UpperCAmelCase					=    self.seq_length // 2
							_UpperCAmelCase					=    0

							# first forward pass
							_UpperCAmelCase		,						_UpperCAmelCase					=    model(__UpperCamelCase				,   attention_mask=__UpperCamelCase   ).to_tuple()

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

							# change a random masked slice from input_ids
							_UpperCAmelCase					=    ids_tensor((1,)				,   __UpperCamelCase   ).item() + 1
							_UpperCAmelCase					=    ids_tensor((self.batch_size, 1)				,   config.vocab_size   ).squeeze(-1   )
							_UpperCAmelCase					=    random_other_next_tokens

							# append to next input_ids and attn_mask
							_UpperCAmelCase					=    torch.cat([input_ids, next_tokens]				,   dim=-1   )
							_UpperCAmelCase					=    torch.cat(
							    [attn_mask, torch.ones((attn_mask.shape[0], 1)				,   dtype=torch.long				,   device=__UpperCamelCase   )]				,   dim=1				,   )

							# get two different outputs
							_UpperCAmelCase					=    model(__UpperCamelCase				,   attention_mask=__UpperCamelCase   )['''last_hidden_state''']
							_UpperCAmelCase					=    model(__UpperCamelCase				,   past_key_values=__UpperCamelCase				,   attention_mask=__UpperCamelCase   )['''last_hidden_state''']

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

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



			def  lowercase__						(		self     :    Tuple				,   __UpperCamelCase     :    List[Any]				,   __UpperCamelCase     :    Dict				,   __UpperCamelCase     :    Any				,   __UpperCamelCase     :    Any				,   __UpperCamelCase     :    Optional[int]				,   *__UpperCamelCase     :    Union[str, Any]   )->Tuple:
							_UpperCAmelCase					=    BioGptModel(config=__UpperCamelCase   ).to(__UpperCamelCase   ).eval()

							_UpperCAmelCase					=    torch.ones(input_ids.shape				,   dtype=torch.long				,   device=__UpperCamelCase   )

							# first forward pass
							_UpperCAmelCase					=    model(__UpperCamelCase				,   attention_mask=__UpperCamelCase				,   use_cache=__UpperCamelCase   )

							_UpperCAmelCase		,						_UpperCAmelCase					=    outputs.to_tuple()

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

							# append to next input_ids and
							_UpperCAmelCase					=    torch.cat([input_ids, next_tokens]				,   dim=-1   )
							_UpperCAmelCase					=    torch.cat([attention_mask, next_attn_mask]				,   dim=-1   )

							_UpperCAmelCase					=    model(__UpperCamelCase				,   attention_mask=__UpperCamelCase   )['''last_hidden_state''']
							_UpperCAmelCase					=    model(__UpperCamelCase				,   attention_mask=__UpperCamelCase				,   past_key_values=__UpperCamelCase   )[
							    '''last_hidden_state'''
							]

							# select random slice
							_UpperCAmelCase					=    ids_tensor((1,)				,   output_from_past.shape[-1]   ).item()
							_UpperCAmelCase					=    output_from_no_past[:, -3:, random_slice_idx].detach()
							_UpperCAmelCase					=    output_from_past[:, :, random_slice_idx].detach()

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

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



			def  lowercase__						(		self     :    List[str]				,   __UpperCamelCase     :    str				,   __UpperCamelCase     :    Any				,   __UpperCamelCase     :    Optional[Any]				,   __UpperCamelCase     :    str				,   __UpperCamelCase     :    Optional[int]				,   *__UpperCamelCase     :    Any				,   __UpperCamelCase     :    Optional[Any]=False   )->int:
							_UpperCAmelCase					=    BioGptForCausalLM(__UpperCamelCase   )
							model.to(__UpperCamelCase   )
							if gradient_checkpointing:
											model.gradient_checkpointing_enable()

							_UpperCAmelCase					=    model(__UpperCamelCase				,   labels=__UpperCamelCase   )
							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  lowercase__						(		self     :    Optional[Any]				,   __UpperCamelCase     :    Dict				,   *__UpperCamelCase     :    int   )->str:
							_UpperCAmelCase					=    BioGptModel(__UpperCamelCase   )
							_UpperCAmelCase					=    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.0_0_1   )
															self.parent.assertLessEqual(abs(torch.mean(model.state_dict()[key]   ) - 0.0   )				,   0.0_1   )



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



			def  lowercase__						(		self     :    List[Any]   )->Any:
							_UpperCAmelCase					=    self.prepare_config_and_inputs()
							(
							    (
							    _UpperCAmelCase       
							)		,						(
							    _UpperCAmelCase       
							)		,						(
							    _UpperCAmelCase       
							)		,						(
							    _UpperCAmelCase       
							)		,						(
							    _UpperCAmelCase       
							)		,						(
							    _UpperCAmelCase       
							)		,						(
							    _UpperCAmelCase       
							)		,						       
							)					=    config_and_inputs
							_UpperCAmelCase					=    {'''input_ids''': input_ids, '''attention_mask''': input_mask}
							return config, inputs_dict



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



			def  lowercase__						(		self     :    int   )->List[Any]:
							_UpperCAmelCase					=    BioGptModelTester(self   )
							_UpperCAmelCase					=    ConfigTester(self				,   config_class=__UpperCamelCase				,   hidden_size=3_7   )



			def  lowercase__						(		self     :    Dict   )->Tuple:
							self.config_tester.run_common_tests()



			def  lowercase__						(		self     :    Any   )->List[str]:
							_UpperCAmelCase					=    self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*__UpperCamelCase   )



			def  lowercase__						(		self     :    Any   )->Dict:
							_UpperCAmelCase					=    self.model_tester.prepare_config_and_inputs()
							for type in ["absolute", "relative_key", "relative_key_query"]:
											_UpperCAmelCase					=    type
											self.model_tester.create_and_check_model(*__UpperCamelCase   )



			def  lowercase__						(		self     :    Tuple   )->Union[str, Any]:
							_UpperCAmelCase					=    self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_biogpt_model_attention_mask_past(*__UpperCamelCase   )



			def  lowercase__						(		self     :    Optional[Any]   )->Dict:
							_UpperCAmelCase					=    self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_forward_and_backwards(*__UpperCamelCase				,   gradient_checkpointing=__UpperCamelCase   )



			def  lowercase__						(		self     :    Union[str, Any]   )->str:
							_UpperCAmelCase					=    self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_biogpt_model_past_large_inputs(*__UpperCamelCase   )



			def  lowercase__						(		self     :    Optional[Any]   )->Tuple:
							_UpperCAmelCase					=    self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_biogpt_weight_initialization(*__UpperCamelCase   )



			def  lowercase__						(		self     :    List[Any]   )->str:
							_UpperCAmelCase					=    self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_biogpt_for_token_classification(*__UpperCamelCase   )



			@slow
			def  lowercase__						(		self     :    Optional[Any]   )->List[str]:
							_UpperCAmelCase					=    BioGptForCausalLM.from_pretrained('''microsoft/biogpt'''   )
							model.to(__UpperCamelCase   )
							_UpperCAmelCase					=    BioGptTokenizer.from_pretrained('''microsoft/biogpt'''   )

							_UpperCAmelCase					=    '''left'''

							# Define PAD Token = EOS Token = 50256
							_UpperCAmelCase					=    tokenizer.eos_token
							_UpperCAmelCase					=    model.config.eos_token_id

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

							_UpperCAmelCase					=    tokenizer(__UpperCamelCase				,   return_tensors='''pt'''				,   padding=__UpperCamelCase   )
							_UpperCAmelCase					=    inputs['''input_ids'''].to(__UpperCamelCase   )

							_UpperCAmelCase					=    model.generate(
							    input_ids=__UpperCamelCase				,   attention_mask=inputs['''attention_mask'''].to(__UpperCamelCase   )				,   )

							_UpperCAmelCase					=    tokenizer(sentences[0]				,   return_tensors='''pt'''   ).input_ids.to(__UpperCamelCase   )
							_UpperCAmelCase					=    model.generate(input_ids=__UpperCamelCase   )

							_UpperCAmelCase					=    inputs_non_padded.shape[-1] - inputs['''attention_mask'''][-1].long().sum().cpu().item()
							_UpperCAmelCase					=    tokenizer(sentences[1]				,   return_tensors='''pt'''   ).input_ids.to(__UpperCamelCase   )
							_UpperCAmelCase					=    model.generate(input_ids=__UpperCamelCase				,   max_length=model.config.max_length - num_paddings   )

							_UpperCAmelCase					=    tokenizer.batch_decode(__UpperCamelCase				,   skip_special_tokens=__UpperCamelCase   )
							_UpperCAmelCase					=    tokenizer.decode(output_non_padded[0]				,   skip_special_tokens=__UpperCamelCase   )
							_UpperCAmelCase					=    tokenizer.decode(output_padded[0]				,   skip_special_tokens=__UpperCamelCase   )

							_UpperCAmelCase					=    [
							    '''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(__UpperCamelCase				,   __UpperCamelCase   )
							self.assertListEqual(__UpperCamelCase				,   [non_padded_sentence, padded_sentence]   )



			@slow
			def  lowercase__						(		self     :    Optional[int]   )->List[Any]:
							for model_name in BIOGPT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
											_UpperCAmelCase					=    BioGptModel.from_pretrained(__UpperCamelCase   )
											self.assertIsNotNone(__UpperCamelCase   )



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



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



@require_torch
class 			_a (					unittest.TestCase):
			"""simple docstring"""



			@slow
			def  lowercase__						(		self     :    Tuple   )->str:
							_UpperCAmelCase					=    BioGptForCausalLM.from_pretrained('''microsoft/biogpt'''   )
							_UpperCAmelCase					=    torch.tensor([[2, 4_8_0_5, 9, 6_5_6, 2_1]]   )
							_UpperCAmelCase					=    model(__UpperCamelCase   )[0]

							_UpperCAmelCase					=    4_2_3_8_4

							_UpperCAmelCase					=    torch.Size((1, 5, vocab_size)   )
							self.assertEqual(output.shape				,   __UpperCamelCase   )

							_UpperCAmelCase					=    torch.tensor(
							    [[[-9.5_2_3_6, -9.8_9_1_8, 1_0.4_5_5_7], [-1_1.0_4_6_9, -9.6_4_2_3, 8.1_0_2_2], [-8.8_6_6_4, -7.8_8_2_6, 5.5_3_2_5]]]   )

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



			@slow
			def  lowercase__						(		self     :    Dict   )->Optional[Any]:
							_UpperCAmelCase					=    BioGptTokenizer.from_pretrained('''microsoft/biogpt'''   )
							_UpperCAmelCase					=    BioGptForCausalLM.from_pretrained('''microsoft/biogpt'''   )
							model.to(__UpperCamelCase   )

							torch.manual_seed(0   )
							_UpperCAmelCase					=    tokenizer('''COVID-19 is'''				,   return_tensors='''pt'''   ).to(__UpperCamelCase   )
							_UpperCAmelCase					=    model.generate(
							    **__UpperCamelCase				,   min_length=1_0_0				,   max_length=1_0_2_4				,   num_beams=5				,   early_stopping=__UpperCamelCase				,   )
							_UpperCAmelCase					=    tokenizer.decode(output_ids[0]				,   skip_special_tokens=__UpperCamelCase   )

							_UpperCAmelCase					=    (
							    '''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(__UpperCamelCase				,   __UpperCamelCase   )








"""simple docstring"""


from typing import List, Optional, Union

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


__A   :							Any										=   logging.get_logger(__name__)

__A   :							Dict										=   {
    "huggingface/informer-tourism-monthly": (
        "https://huggingface.co/huggingface/informer-tourism-monthly/resolve/main/config.json"
    ),
    # See all Informer models at https://huggingface.co/models?filter=informer
}
class 			_a (					lowerCAmelCase):
			"""simple docstring"""
			UpperCamelCase__			      =	"""informer"""
			UpperCamelCase__			      =	{
			    """hidden_size""": """d_model""",
			    """num_attention_heads""": """encoder_attention_heads""",
			    """num_hidden_layers""": """encoder_layers""",
			}



			def __init__(		self     :    List[str]				,   __UpperCamelCase     :    Optional[int] = None				,   __UpperCamelCase     :    Optional[int] = None				,   __UpperCamelCase     :    str = "student_t"				,   __UpperCamelCase     :    str = "nll"				,   __UpperCamelCase     :    int = 1				,   __UpperCamelCase     :    List[int] = None				,   __UpperCamelCase     :    Optional[Union[str, bool]] = "mean"				,   __UpperCamelCase     :    int = 0				,   __UpperCamelCase     :    int = 0				,   __UpperCamelCase     :    int = 0				,   __UpperCamelCase     :    int = 0				,   __UpperCamelCase     :    Optional[List[int]] = None				,   __UpperCamelCase     :    Optional[List[int]] = None				,   __UpperCamelCase     :    int = 6_4				,   __UpperCamelCase     :    int = 3_2				,   __UpperCamelCase     :    int = 3_2				,   __UpperCamelCase     :    int = 2				,   __UpperCamelCase     :    int = 2				,   __UpperCamelCase     :    int = 2				,   __UpperCamelCase     :    int = 2				,   __UpperCamelCase     :    bool = True				,   __UpperCamelCase     :    str = "gelu"				,   __UpperCamelCase     :    float = 0.0_5				,   __UpperCamelCase     :    float = 0.1				,   __UpperCamelCase     :    float = 0.1				,   __UpperCamelCase     :    float = 0.1				,   __UpperCamelCase     :    float = 0.1				,   __UpperCamelCase     :    int = 1_0_0				,   __UpperCamelCase     :    float = 0.0_2				,   __UpperCamelCase     :    Optional[Any]=True				,   __UpperCamelCase     :    str = "prob"				,   __UpperCamelCase     :    int = 5				,   __UpperCamelCase     :    bool = True				,   **__UpperCamelCase     :    Union[str, Any]				,   )->Dict:
							# time series specific configuration
							_UpperCAmelCase					=    prediction_length
							_UpperCAmelCase					=    context_length or prediction_length
							_UpperCAmelCase					=    distribution_output
							_UpperCAmelCase					=    loss
							_UpperCAmelCase					=    input_size
							_UpperCAmelCase					=    num_time_features
							_UpperCAmelCase					=    lags_sequence if lags_sequence is not None else [1, 2, 3, 4, 5, 6, 7]
							_UpperCAmelCase					=    scaling
							_UpperCAmelCase					=    num_dynamic_real_features
							_UpperCAmelCase					=    num_static_real_features
							_UpperCAmelCase					=    num_static_categorical_features

							# set cardinality
							if cardinality and num_static_categorical_features > 0:
											if len(__UpperCamelCase   ) != num_static_categorical_features:
															raise ValueError(
															    '''The cardinality should be a list of the same length as `num_static_categorical_features`'''   )
											_UpperCAmelCase					=    cardinality
							else:
											_UpperCAmelCase					=    [0]

							# set embedding_dimension
							if embedding_dimension and num_static_categorical_features > 0:
											if len(__UpperCamelCase   ) != num_static_categorical_features:
															raise ValueError(
															    '''The embedding dimension should be a list of the same length as `num_static_categorical_features`'''   )
											_UpperCAmelCase					=    embedding_dimension
							else:
											_UpperCAmelCase					=    [min(5_0				,   (cat + 1) // 2   ) for cat in self.cardinality]

							_UpperCAmelCase					=    num_parallel_samples

							# Transformer architecture configuration
							_UpperCAmelCase					=    input_size * len(self.lags_sequence   ) + self._number_of_features
							_UpperCAmelCase					=    d_model
							_UpperCAmelCase					=    encoder_attention_heads
							_UpperCAmelCase					=    decoder_attention_heads
							_UpperCAmelCase					=    encoder_ffn_dim
							_UpperCAmelCase					=    decoder_ffn_dim
							_UpperCAmelCase					=    encoder_layers
							_UpperCAmelCase					=    decoder_layers

							_UpperCAmelCase					=    dropout
							_UpperCAmelCase					=    attention_dropout
							_UpperCAmelCase					=    activation_dropout
							_UpperCAmelCase					=    encoder_layerdrop
							_UpperCAmelCase					=    decoder_layerdrop

							_UpperCAmelCase					=    activation_function
							_UpperCAmelCase					=    init_std

							_UpperCAmelCase					=    use_cache

							# Informer
							_UpperCAmelCase					=    attention_type
							_UpperCAmelCase					=    sampling_factor
							_UpperCAmelCase					=    distil

							super().__init__(is_encoder_decoder=__UpperCamelCase				,   **__UpperCamelCase   )



			@property
			def  lowercase__						(		self     :    Optional[int]   )->int:
							return (
							    sum(self.embedding_dimension   )
							    + self.num_dynamic_real_features
							    + self.num_time_features
							    + self.num_static_real_features
							    + self.input_size * 2  # the log1p(abs(loc)) and log(scale) features
							)



