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




		"""simple docstring"""





		def __init__(     self							,  lowerCAmelCase__							,  lowerCAmelCase__=1_3							,  lowerCAmelCase__=7							,  lowerCAmelCase__=True							,  lowerCAmelCase__=True							,  lowerCAmelCase__=False							,  lowerCAmelCase__=True							,  lowerCAmelCase__=9_9							,  lowerCAmelCase__=3_2							,  lowerCAmelCase__=5							,  lowerCAmelCase__=4							,  lowerCAmelCase__=3_7							,  lowerCAmelCase__="gelu"							,  lowerCAmelCase__=0.1							,  lowerCAmelCase__=0.1							,  lowerCAmelCase__=5_1_2							,  lowerCAmelCase__=1_6							,  lowerCAmelCase__=2							,  lowerCAmelCase__=0.02							,  lowerCAmelCase__=3							,  lowerCAmelCase__=4							,  lowerCAmelCase__=None							,  ):
				__SCREAMING_SNAKE_CASE            = parent
				__SCREAMING_SNAKE_CASE            = batch_size
				__SCREAMING_SNAKE_CASE            = seq_length
				__SCREAMING_SNAKE_CASE            = is_training
				__SCREAMING_SNAKE_CASE            = use_input_mask
				__SCREAMING_SNAKE_CASE            = use_token_type_ids
				__SCREAMING_SNAKE_CASE            = use_labels
				__SCREAMING_SNAKE_CASE            = vocab_size
				__SCREAMING_SNAKE_CASE            = hidden_size
				__SCREAMING_SNAKE_CASE            = num_hidden_layers
				__SCREAMING_SNAKE_CASE            = num_attention_heads
				__SCREAMING_SNAKE_CASE            = intermediate_size
				__SCREAMING_SNAKE_CASE            = hidden_act
				__SCREAMING_SNAKE_CASE            = hidden_dropout_prob
				__SCREAMING_SNAKE_CASE            = attention_probs_dropout_prob
				__SCREAMING_SNAKE_CASE            = max_position_embeddings
				__SCREAMING_SNAKE_CASE            = type_vocab_size
				__SCREAMING_SNAKE_CASE            = type_sequence_label_size
				__SCREAMING_SNAKE_CASE            = initializer_range
				__SCREAMING_SNAKE_CASE            = num_labels
				__SCREAMING_SNAKE_CASE            = num_choices
				__SCREAMING_SNAKE_CASE            = scope




		def 	snake_case_     (     self):
				__SCREAMING_SNAKE_CASE            = ids_tensor([self.batch_size, self.seq_length]							,  self.vocab_size)

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

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

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

				__SCREAMING_SNAKE_CASE            = self.get_config()

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




		def 	snake_case_     (     self):
				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=lowerCAmelCase__							,  initializer_range=self.initializer_range							,  )




		def 	snake_case_     (     self							,  lowerCAmelCase__							,  lowerCAmelCase__							,  lowerCAmelCase__							,  lowerCAmelCase__							,  lowerCAmelCase__							,  lowerCAmelCase__							,  lowerCAmelCase__):
				__SCREAMING_SNAKE_CASE            = BioGptModel(config=lowerCAmelCase__)
				model.to(lowerCAmelCase__)
				model.eval()
				__SCREAMING_SNAKE_CASE            = model(lowerCAmelCase__							,  attention_mask=lowerCAmelCase__)
				__SCREAMING_SNAKE_CASE            = model(lowerCAmelCase__)
				self.parent.assertEqual(result.last_hidden_state.shape							,  (self.batch_size, self.seq_length, self.hidden_size))




		def 	snake_case_     (     self							,  lowerCAmelCase__							,  lowerCAmelCase__							,  lowerCAmelCase__							,  lowerCAmelCase__							,  lowerCAmelCase__							,  lowerCAmelCase__							,  lowerCAmelCase__							,  lowerCAmelCase__							,  lowerCAmelCase__							,  ):
				__SCREAMING_SNAKE_CASE            = BioGptForCausalLM(config=lowerCAmelCase__)
				model.to(lowerCAmelCase__)
				model.eval()
				__SCREAMING_SNAKE_CASE            = model(lowerCAmelCase__							,  attention_mask=lowerCAmelCase__							,  token_type_ids=lowerCAmelCase__							,  labels=lowerCAmelCase__)
				self.parent.assertEqual(result.logits.shape							,  (self.batch_size, self.seq_length, self.vocab_size))




		def 	snake_case_     (     self							,  lowerCAmelCase__							,  lowerCAmelCase__							,  lowerCAmelCase__							,  lowerCAmelCase__							,  lowerCAmelCase__							,  *lowerCAmelCase__):
				__SCREAMING_SNAKE_CASE            = BioGptModel(config=lowerCAmelCase__)
				model.to(lowerCAmelCase__)
				model.eval()

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

				# first forward pass
				__SCREAMING_SNAKE_CASE       ,__SCREAMING_SNAKE_CASE            = model(lowerCAmelCase__							,  attention_mask=lowerCAmelCase__).to_tuple()

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

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

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

				# get two different outputs
				__SCREAMING_SNAKE_CASE            = model(lowerCAmelCase__							,  attention_mask=lowerCAmelCase__)["""last_hidden_state"""]
				__SCREAMING_SNAKE_CASE            = model(lowerCAmelCase__							,  past_key_values=lowerCAmelCase__							,  attention_mask=lowerCAmelCase__)["""last_hidden_state"""]

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

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




		def 	snake_case_     (     self							,  lowerCAmelCase__							,  lowerCAmelCase__							,  lowerCAmelCase__							,  lowerCAmelCase__							,  lowerCAmelCase__							,  *lowerCAmelCase__):
				__SCREAMING_SNAKE_CASE            = BioGptModel(config=lowerCAmelCase__).to(lowerCAmelCase__).eval()

				__SCREAMING_SNAKE_CASE            = torch.ones(input_ids.shape							,  dtype=torch.long							,  device=lowerCAmelCase__)

				# first forward pass
				__SCREAMING_SNAKE_CASE            = model(lowerCAmelCase__							,  attention_mask=lowerCAmelCase__							,  use_cache=lowerCAmelCase__)

				__SCREAMING_SNAKE_CASE       ,__SCREAMING_SNAKE_CASE            = outputs.to_tuple()

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

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

				__SCREAMING_SNAKE_CASE            = model(lowerCAmelCase__							,  attention_mask=lowerCAmelCase__)["""last_hidden_state"""]
				__SCREAMING_SNAKE_CASE            = model(lowerCAmelCase__							,  attention_mask=lowerCAmelCase__							,  past_key_values=lowerCAmelCase__)[
				    """last_hidden_state"""
				]

				# select random slice
				__SCREAMING_SNAKE_CASE            = ids_tensor((1,)							,  output_from_past.shape[-1]).item()
				__SCREAMING_SNAKE_CASE            = output_from_no_past[:, -3:, random_slice_idx].detach()
				__SCREAMING_SNAKE_CASE            = 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 	snake_case_     (     self							,  lowerCAmelCase__							,  lowerCAmelCase__							,  lowerCAmelCase__							,  lowerCAmelCase__							,  lowerCAmelCase__							,  *lowerCAmelCase__							,  lowerCAmelCase__=False):
				__SCREAMING_SNAKE_CASE            = BioGptForCausalLM(lowerCAmelCase__)
				model.to(lowerCAmelCase__)
				if gradient_checkpointing:
						model.gradient_checkpointing_enable()

				__SCREAMING_SNAKE_CASE            = model(lowerCAmelCase__							,  labels=lowerCAmelCase__)
				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 	snake_case_     (     self							,  lowerCAmelCase__							,  *lowerCAmelCase__):
				__SCREAMING_SNAKE_CASE            = BioGptModel(lowerCAmelCase__)
				__SCREAMING_SNAKE_CASE            = 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_01)
								self.parent.assertLessEqual(abs(torch.mean(model.state_dict()[key]) - 0.0)							,  0.01)




		def 	snake_case_     (     self							,  lowerCAmelCase__							,  lowerCAmelCase__							,  lowerCAmelCase__							,  lowerCAmelCase__							,  lowerCAmelCase__							,  *lowerCAmelCase__):
				__SCREAMING_SNAKE_CASE            = self.num_labels
				__SCREAMING_SNAKE_CASE            = BioGptForTokenClassification(lowerCAmelCase__)
				model.to(lowerCAmelCase__)
				model.eval()
				__SCREAMING_SNAKE_CASE            = model(lowerCAmelCase__							,  attention_mask=lowerCAmelCase__							,  token_type_ids=lowerCAmelCase__)
				self.parent.assertEqual(result.logits.shape							,  (self.batch_size, self.seq_length, self.num_labels))




		def 	snake_case_     (     self):
				__SCREAMING_SNAKE_CASE            = 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
				)       ,
				)            = config_and_inputs
				__SCREAMING_SNAKE_CASE            = {"""input_ids""": input_ids, """attention_mask""": input_mask}
				return config, inputs_dict



@require_torch
class 						SCREAMING_SNAKE_CASE_ (						__a     ,				__a     ,				__a     ,				unittest.TestCase ):




		"""simple docstring"""





		__lowercase							:  str						   =		(
		    (BioGptModel, BioGptForCausalLM, BioGptForSequenceClassification, BioGptForTokenClassification)
		    if is_torch_available()
		    else ()
		)
		__lowercase							:  str						   =		(BioGptForCausalLM,) if is_torch_available() else ()
		__lowercase							:  Dict						   =		(
		    {
		        '''feature-extraction''': BioGptModel,
		        '''text-classification''': BioGptForSequenceClassification,
		        '''text-generation''': BioGptForCausalLM,
		        '''token-classification''': BioGptForTokenClassification,
		        '''zero-shot''': BioGptForSequenceClassification,
		    }
		    if is_torch_available()
		    else {}
		)
		__lowercase							:  Union[str, Any]						   =		False




		def 	snake_case_     (     self):
				__SCREAMING_SNAKE_CASE            = BioGptModelTester(self)
				__SCREAMING_SNAKE_CASE            = ConfigTester(self							,  config_class=lowerCAmelCase__							,  hidden_size=3_7)




		def 	snake_case_     (     self):
				self.config_tester.run_common_tests()




		def 	snake_case_     (     self):
				__SCREAMING_SNAKE_CASE            = self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_model(*lowerCAmelCase__)




		def 	snake_case_     (     self):
				__SCREAMING_SNAKE_CASE            = self.model_tester.prepare_config_and_inputs()
				for type in ["absolute", "relative_key", "relative_key_query"]:
						__SCREAMING_SNAKE_CASE            = type
						self.model_tester.create_and_check_model(*lowerCAmelCase__)




		def 	snake_case_     (     self):
				__SCREAMING_SNAKE_CASE            = self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_biogpt_model_attention_mask_past(*lowerCAmelCase__)




		def 	snake_case_     (     self):
				__SCREAMING_SNAKE_CASE            = self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_forward_and_backwards(*lowerCAmelCase__							,  gradient_checkpointing=lowerCAmelCase__)




		def 	snake_case_     (     self):
				__SCREAMING_SNAKE_CASE            = self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_biogpt_model_past_large_inputs(*lowerCAmelCase__)




		def 	snake_case_     (     self):
				__SCREAMING_SNAKE_CASE            = self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_biogpt_weight_initialization(*lowerCAmelCase__)




		def 	snake_case_     (     self):
				__SCREAMING_SNAKE_CASE            = self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_biogpt_for_token_classification(*lowerCAmelCase__)




		@slow
		def 	snake_case_     (     self):
				__SCREAMING_SNAKE_CASE            = BioGptForCausalLM.from_pretrained("""microsoft/biogpt""")
				model.to(lowerCAmelCase__)
				__SCREAMING_SNAKE_CASE            = BioGptTokenizer.from_pretrained("""microsoft/biogpt""")

				__SCREAMING_SNAKE_CASE            = """left"""

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

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

				__SCREAMING_SNAKE_CASE            = tokenizer(lowerCAmelCase__							,  return_tensors="""pt"""							,  padding=lowerCAmelCase__)
				__SCREAMING_SNAKE_CASE            = inputs["""input_ids"""].to(lowerCAmelCase__)

				__SCREAMING_SNAKE_CASE            = model.generate(
				    input_ids=lowerCAmelCase__							,  attention_mask=inputs["""attention_mask"""].to(lowerCAmelCase__)							,  )

				__SCREAMING_SNAKE_CASE            = tokenizer(sentences[0]							,  return_tensors="""pt""").input_ids.to(lowerCAmelCase__)
				__SCREAMING_SNAKE_CASE            = model.generate(input_ids=lowerCAmelCase__)

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

				__SCREAMING_SNAKE_CASE            = tokenizer.batch_decode(lowerCAmelCase__							,  skip_special_tokens=lowerCAmelCase__)
				__SCREAMING_SNAKE_CASE            = tokenizer.decode(output_non_padded[0]							,  skip_special_tokens=lowerCAmelCase__)
				__SCREAMING_SNAKE_CASE            = tokenizer.decode(output_padded[0]							,  skip_special_tokens=lowerCAmelCase__)

				__SCREAMING_SNAKE_CASE            = [
				    """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(lowerCAmelCase__							,  lowerCAmelCase__)
				self.assertListEqual(lowerCAmelCase__							,  [non_padded_sentence, padded_sentence])




		@slow
		def 	snake_case_     (     self):
				for model_name in BIOGPT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
						__SCREAMING_SNAKE_CASE            = BioGptModel.from_pretrained(lowerCAmelCase__)
						self.assertIsNotNone(lowerCAmelCase__)




		def 	snake_case_     (     self):
				__SCREAMING_SNAKE_CASE       ,__SCREAMING_SNAKE_CASE            = self.model_tester.prepare_config_and_inputs_for_common()
				__SCREAMING_SNAKE_CASE            = 3
				__SCREAMING_SNAKE_CASE            = input_dict["""input_ids"""]
				__SCREAMING_SNAKE_CASE            = input_ids.ne(1).to(lowerCAmelCase__)
				__SCREAMING_SNAKE_CASE            = ids_tensor([self.model_tester.batch_size]							,  self.model_tester.type_sequence_label_size)
				__SCREAMING_SNAKE_CASE            = BioGptForSequenceClassification(lowerCAmelCase__)
				model.to(lowerCAmelCase__)
				model.eval()
				__SCREAMING_SNAKE_CASE            = model(lowerCAmelCase__							,  attention_mask=lowerCAmelCase__							,  labels=lowerCAmelCase__)
				self.assertEqual(result.logits.shape							,  (self.model_tester.batch_size, self.model_tester.num_labels))




		def 	snake_case_     (     self):
				__SCREAMING_SNAKE_CASE       ,__SCREAMING_SNAKE_CASE            = self.model_tester.prepare_config_and_inputs_for_common()
				__SCREAMING_SNAKE_CASE            = 3
				__SCREAMING_SNAKE_CASE            = """multi_label_classification"""
				__SCREAMING_SNAKE_CASE            = input_dict["""input_ids"""]
				__SCREAMING_SNAKE_CASE            = input_ids.ne(1).to(lowerCAmelCase__)
				__SCREAMING_SNAKE_CASE            = ids_tensor(
				    [self.model_tester.batch_size, config.num_labels]							,  self.model_tester.type_sequence_label_size).to(torch.float)
				__SCREAMING_SNAKE_CASE            = BioGptForSequenceClassification(lowerCAmelCase__)
				model.to(lowerCAmelCase__)
				model.eval()
				__SCREAMING_SNAKE_CASE            = model(lowerCAmelCase__							,  attention_mask=lowerCAmelCase__							,  labels=lowerCAmelCase__)
				self.assertEqual(result.logits.shape							,  (self.model_tester.batch_size, self.model_tester.num_labels))



@require_torch
class 						SCREAMING_SNAKE_CASE_ (						unittest.TestCase ):




		"""simple docstring"""





		@slow
		def 	snake_case_     (     self):
				__SCREAMING_SNAKE_CASE            = BioGptForCausalLM.from_pretrained("""microsoft/biogpt""")
				__SCREAMING_SNAKE_CASE            = torch.tensor([[2, 4_8_0_5, 9, 6_5_6, 2_1]])
				__SCREAMING_SNAKE_CASE            = model(lowerCAmelCase__)[0]

				__SCREAMING_SNAKE_CASE            = 4_2_3_8_4

				__SCREAMING_SNAKE_CASE            = torch.Size((1, 5, vocab_size))
				self.assertEqual(output.shape							,  lowerCAmelCase__)

				__SCREAMING_SNAKE_CASE            = torch.tensor(
				    [[[-9.52_36, -9.89_18, 10.45_57], [-11.04_69, -9.64_23, 8.10_22], [-8.86_64, -7.88_26, 5.53_25]]])

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




		@slow
		def 	snake_case_     (     self):
				__SCREAMING_SNAKE_CASE            = BioGptTokenizer.from_pretrained("""microsoft/biogpt""")
				__SCREAMING_SNAKE_CASE            = BioGptForCausalLM.from_pretrained("""microsoft/biogpt""")
				model.to(lowerCAmelCase__)

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

				__SCREAMING_SNAKE_CASE            = (
				    """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(lowerCAmelCase__							,  lowerCAmelCase__)






"""simple docstring"""





__magic_name__       =			"0.18.2"

from .configuration_utils import ConfigMixin
from .utils import (
    OptionalDependencyNotAvailable,
    is_flax_available,
    is_inflect_available,
    is_invisible_watermark_available,
    is_k_diffusion_available,
    is_k_diffusion_version,
    is_librosa_available,
    is_note_seq_available,
    is_onnx_available,
    is_scipy_available,
    is_torch_available,
    is_torchsde_available,
    is_transformers_available,
    is_transformers_version,
    is_unidecode_available,
    logging,
)


try:
							if not is_onnx_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							from .utils.dummy_onnx_objects import *  # noqa F403
else:
							from .pipelines import OnnxRuntimeModel

try:
							if not is_torch_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							from .utils.dummy_pt_objects import *  # noqa F403
else:
							from .models import (
							    AutoencoderKL,
							    ControlNetModel,
							    ModelMixin,
							    PriorTransformer,
							    TaFilmDecoder,
							    TransformeraDModel,
							    UNetaDModel,
							    UNetaDConditionModel,
							    UNetaDModel,
							    UNetaDConditionModel,
							    VQModel,
							)
							from .optimization import (
							    get_constant_schedule,
							    get_constant_schedule_with_warmup,
							    get_cosine_schedule_with_warmup,
							    get_cosine_with_hard_restarts_schedule_with_warmup,
							    get_linear_schedule_with_warmup,
							    get_polynomial_decay_schedule_with_warmup,
							    get_scheduler,
							)
							from .pipelines import (
							    AudioPipelineOutput,
							    ConsistencyModelPipeline,
							    DanceDiffusionPipeline,
							    DDIMPipeline,
							    DDPMPipeline,
							    DiffusionPipeline,
							    DiTPipeline,
							    ImagePipelineOutput,
							    KarrasVePipeline,
							    LDMPipeline,
							    LDMSuperResolutionPipeline,
							    PNDMPipeline,
							    RePaintPipeline,
							    ScoreSdeVePipeline,
							)
							from .schedulers import (
							    CMStochasticIterativeScheduler,
							    DDIMInverseScheduler,
							    DDIMParallelScheduler,
							    DDIMScheduler,
							    DDPMParallelScheduler,
							    DDPMScheduler,
							    DEISMultistepScheduler,
							    DPMSolverMultistepInverseScheduler,
							    DPMSolverMultistepScheduler,
							    DPMSolverSinglestepScheduler,
							    EulerAncestralDiscreteScheduler,
							    EulerDiscreteScheduler,
							    HeunDiscreteScheduler,
							    IPNDMScheduler,
							    KarrasVeScheduler,
							    KDPMaAncestralDiscreteScheduler,
							    KDPMaDiscreteScheduler,
							    PNDMScheduler,
							    RePaintScheduler,
							    SchedulerMixin,
							    ScoreSdeVeScheduler,
							    UnCLIPScheduler,
							    UniPCMultistepScheduler,
							    VQDiffusionScheduler,
							)
							from .training_utils import EMAModel

try:
							if not (is_torch_available() and is_scipy_available()):
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							from .utils.dummy_torch_and_scipy_objects import *  # noqa F403
else:
							from .schedulers import LMSDiscreteScheduler

try:
							if not (is_torch_available() and is_torchsde_available()):
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							from .utils.dummy_torch_and_torchsde_objects import *  # noqa F403
else:
							from .schedulers import DPMSolverSDEScheduler

try:
							if not (is_torch_available() and is_transformers_available()):
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							from .utils.dummy_torch_and_transformers_objects import *  # noqa F403
else:
							from .pipelines import (
							    AltDiffusionImgaImgPipeline,
							    AltDiffusionPipeline,
							    AudioLDMPipeline,
							    CycleDiffusionPipeline,
							    IFImgaImgPipeline,
							    IFImgaImgSuperResolutionPipeline,
							    IFInpaintingPipeline,
							    IFInpaintingSuperResolutionPipeline,
							    IFPipeline,
							    IFSuperResolutionPipeline,
							    ImageTextPipelineOutput,
							    KandinskyImgaImgPipeline,
							    KandinskyInpaintPipeline,
							    KandinskyPipeline,
							    KandinskyPriorPipeline,
							    KandinskyVaaControlnetImgaImgPipeline,
							    KandinskyVaaControlnetPipeline,
							    KandinskyVaaImgaImgPipeline,
							    KandinskyVaaInpaintPipeline,
							    KandinskyVaaPipeline,
							    KandinskyVaaPriorEmbaEmbPipeline,
							    KandinskyVaaPriorPipeline,
							    LDMTextToImagePipeline,
							    PaintByExamplePipeline,
							    SemanticStableDiffusionPipeline,
							    ShapEImgaImgPipeline,
							    ShapEPipeline,
							    StableDiffusionAttendAndExcitePipeline,
							    StableDiffusionControlNetImgaImgPipeline,
							    StableDiffusionControlNetInpaintPipeline,
							    StableDiffusionControlNetPipeline,
							    StableDiffusionDepthaImgPipeline,
							    StableDiffusionDiffEditPipeline,
							    StableDiffusionImageVariationPipeline,
							    StableDiffusionImgaImgPipeline,
							    StableDiffusionInpaintPipeline,
							    StableDiffusionInpaintPipelineLegacy,
							    StableDiffusionInstructPixaPixPipeline,
							    StableDiffusionLatentUpscalePipeline,
							    StableDiffusionLDMaDPipeline,
							    StableDiffusionModelEditingPipeline,
							    StableDiffusionPanoramaPipeline,
							    StableDiffusionParadigmsPipeline,
							    StableDiffusionPipeline,
							    StableDiffusionPipelineSafe,
							    StableDiffusionPixaPixZeroPipeline,
							    StableDiffusionSAGPipeline,
							    StableDiffusionUpscalePipeline,
							    StableUnCLIPImgaImgPipeline,
							    StableUnCLIPPipeline,
							    TextToVideoSDPipeline,
							    TextToVideoZeroPipeline,
							    UnCLIPImageVariationPipeline,
							    UnCLIPPipeline,
							    UniDiffuserModel,
							    UniDiffuserPipeline,
							    UniDiffuserTextDecoder,
							    VersatileDiffusionDualGuidedPipeline,
							    VersatileDiffusionImageVariationPipeline,
							    VersatileDiffusionPipeline,
							    VersatileDiffusionTextToImagePipeline,
							    VideoToVideoSDPipeline,
							    VQDiffusionPipeline,
							)

try:
							if not (is_torch_available() and is_transformers_available() and is_invisible_watermark_available()):
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							from .utils.dummy_torch_and_transformers_and_invisible_watermark_objects import *  # noqa F403
else:
							from .pipelines import StableDiffusionXLImgaImgPipeline, StableDiffusionXLPipeline

try:
							if not (is_torch_available() and is_transformers_available() and is_k_diffusion_available()):
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							from .utils.dummy_torch_and_transformers_and_k_diffusion_objects import *  # noqa F403
else:
							from .pipelines import StableDiffusionKDiffusionPipeline

try:
							if not (is_torch_available() and is_transformers_available() and is_onnx_available()):
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							from .utils.dummy_torch_and_transformers_and_onnx_objects import *  # noqa F403
else:
							from .pipelines import (
							    OnnxStableDiffusionImgaImgPipeline,
							    OnnxStableDiffusionInpaintPipeline,
							    OnnxStableDiffusionInpaintPipelineLegacy,
							    OnnxStableDiffusionPipeline,
							    OnnxStableDiffusionUpscalePipeline,
							    StableDiffusionOnnxPipeline,
							)

try:
							if not (is_torch_available() and is_librosa_available()):
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							from .utils.dummy_torch_and_librosa_objects import *  # noqa F403
else:
							from .pipelines import AudioDiffusionPipeline, Mel

try:
							if not (is_transformers_available() and is_torch_available() and is_note_seq_available()):
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							from .utils.dummy_transformers_and_torch_and_note_seq_objects import *  # noqa F403
else:
							from .pipelines import SpectrogramDiffusionPipeline

try:
							if not is_flax_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							from .utils.dummy_flax_objects import *  # noqa F403
else:
							from .models.controlnet_flax import FlaxControlNetModel
							from .models.modeling_flax_utils import FlaxModelMixin
							from .models.unet_ad_condition_flax import FlaxUNetaDConditionModel
							from .models.vae_flax import FlaxAutoencoderKL
							from .pipelines import FlaxDiffusionPipeline
							from .schedulers import (
							    FlaxDDIMScheduler,
							    FlaxDDPMScheduler,
							    FlaxDPMSolverMultistepScheduler,
							    FlaxKarrasVeScheduler,
							    FlaxLMSDiscreteScheduler,
							    FlaxPNDMScheduler,
							    FlaxSchedulerMixin,
							    FlaxScoreSdeVeScheduler,
							)


try:
							if not (is_flax_available() and is_transformers_available()):
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							from .utils.dummy_flax_and_transformers_objects import *  # noqa F403
else:
							from .pipelines import (
							    FlaxStableDiffusionControlNetPipeline,
							    FlaxStableDiffusionImgaImgPipeline,
							    FlaxStableDiffusionInpaintPipeline,
							    FlaxStableDiffusionPipeline,
							)

try:
							if not (is_note_seq_available()):
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							from .utils.dummy_note_seq_objects import *  # noqa F403
else:
							from .pipelines import MidiProcessor




