






"""simple docstring"""


import gc
import unittest

import numpy as np
import torch
from transformers import CLIPTextConfig, CLIPTextModelWithProjection, CLIPTokenizer

from diffusers import PriorTransformer, UnCLIPPipeline, UnCLIPScheduler, UNetaDConditionModel, UNetaDModel
from diffusers.pipelines.unclip.text_proj import UnCLIPTextProjModel
from diffusers.utils import load_numpy, nightly, slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu, skip_mps

from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_PARAMS
from ..test_pipelines_common import PipelineTesterMixin, assert_mean_pixel_difference


enable_full_determinism()




class 	__UpperCamelCase    (    UpperCamelCase      ,    unittest.TestCase	):
					lowercase_						:							Optional[Any]			=     UnCLIPPipeline
					lowercase_						:							Any			=     TEXT_TO_IMAGE_PARAMS - {
					    """negative_prompt""",
					    """height""",
					    """width""",
					    """negative_prompt_embeds""",
					    """guidance_scale""",
					    """prompt_embeds""",
					    """cross_attention_kwargs""",
					}
					lowercase_						:							Tuple			=     TEXT_TO_IMAGE_BATCH_PARAMS
					lowercase_						:							List[str]			=     [
					    """generator""",
					    """return_dict""",
					    """prior_num_inference_steps""",
					    """decoder_num_inference_steps""",
					    """super_res_num_inference_steps""",
					]
					lowercase_						:							Tuple			=     False
					@property
					def 					UpperCAmelCase__   (       self       :  Union[str, Any]      )  ->					List[str]:
											return 32
					@property
					def 					UpperCAmelCase__   (       self       :  List[Any]      )  ->					Dict:
											return 32
					@property
					def 					UpperCAmelCase__   (       self       :  Dict      )  ->					Union[str, Any]:
											return self.time_input_dim
					@property
					def 					UpperCAmelCase__   (       self       :  Optional[int]      )  ->					Optional[int]:
											return self.time_input_dim * 4
					@property
					def 					UpperCAmelCase__   (       self       :  Dict      )  ->					Any:
											return 100
					@property
					def 					UpperCAmelCase__   (       self       :  Optional[Any]      )  ->					Dict:
											lowerCAmelCase      :List[Any]				  = CLIPTokenizer.from_pretrained('hf-internal-testing/tiny-random-clip'      )
											return tokenizer
					@property
					def 					UpperCAmelCase__   (       self       :  Any      )  ->					str:
											torch.manual_seed(0      )
											lowerCAmelCase      :str				  = CLIPTextConfig(
											    bos_token_id=0    ,   eos_token_id=2    ,   hidden_size=self.text_embedder_hidden_size    ,   projection_dim=self.text_embedder_hidden_size    ,   intermediate_size=37    ,   layer_norm_eps=1e-0_5    ,   num_attention_heads=4    ,   num_hidden_layers=5    ,   pad_token_id=1    ,   vocab_size=1000    ,   )
											return CLIPTextModelWithProjection(UpperCAmelCase      )
					@property
					def 					UpperCAmelCase__   (       self       :  List[str]      )  ->					Optional[int]:
											torch.manual_seed(0      )

											lowerCAmelCase      :Union[str, Any]				  = {
											    'num_attention_heads': 2,
											    'attention_head_dim': 12,
											    'embedding_dim': self.text_embedder_hidden_size,
											    'num_layers': 1,
											}

											lowerCAmelCase      :Any				  = PriorTransformer(**UpperCAmelCase      )
											return model
					@property
					def 					UpperCAmelCase__   (       self       :  Optional[Any]      )  ->					int:
											torch.manual_seed(0      )

											lowerCAmelCase      :Union[str, Any]				  = {
											    'clip_embeddings_dim': self.text_embedder_hidden_size,
											    'time_embed_dim': self.time_embed_dim,
											    'cross_attention_dim': self.cross_attention_dim,
											}

											lowerCAmelCase      :Union[str, Any]				  = UnCLIPTextProjModel(**UpperCAmelCase      )
											return model
					@property
					def 					UpperCAmelCase__   (       self       :  int      )  ->					Optional[Any]:
											torch.manual_seed(0      )

											lowerCAmelCase      :Optional[Any]				  = {
											    'sample_size': 32,
											    # RGB in channels
											    'in_channels': 3,
											    # Out channels is double in channels because predicts mean and variance
											    'out_channels': 6,
											    'down_block_types': ('ResnetDownsampleBlock2D', 'SimpleCrossAttnDownBlock2D'),
											    'up_block_types': ('SimpleCrossAttnUpBlock2D', 'ResnetUpsampleBlock2D'),
											    'mid_block_type': 'UNetMidBlock2DSimpleCrossAttn',
											    'block_out_channels': (self.block_out_channels_a, self.block_out_channels_a * 2),
											    'layers_per_block': 1,
											    'cross_attention_dim': self.cross_attention_dim,
											    'attention_head_dim': 4,
											    'resnet_time_scale_shift': 'scale_shift',
											    'class_embed_type': 'identity',
											}

											lowerCAmelCase      :str				  = UNetaDConditionModel(**UpperCAmelCase      )
											return model
					@property
					def 					UpperCAmelCase__   (       self       :  List[Any]      )  ->					Union[str, Any]:
											return {
											    "sample_size": 64,
											    "layers_per_block": 1,
											    "down_block_types": ("ResnetDownsampleBlock2D", "ResnetDownsampleBlock2D"),
											    "up_block_types": ("ResnetUpsampleBlock2D", "ResnetUpsampleBlock2D"),
											    "block_out_channels": (self.block_out_channels_a, self.block_out_channels_a * 2),
											    "in_channels": 6,
											    "out_channels": 3,
											}
					@property
					def 					UpperCAmelCase__   (       self       :  str      )  ->					Tuple:
											torch.manual_seed(0      )

											lowerCAmelCase      :Tuple				  = UNetaDModel(**self.dummy_super_res_kwargs      )
											return model
					@property
					def 					UpperCAmelCase__   (       self       :  Optional[int]      )  ->					Any:
											# seeded differently to get different unet than `self.dummy_super_res_first`
											torch.manual_seed(1      )

											lowerCAmelCase      :Dict				  = UNetaDModel(**self.dummy_super_res_kwargs      )
											return model
					def 					UpperCAmelCase__   (       self       :  int      )  ->					str:
											lowerCAmelCase      :Union[str, Any]				  = self.dummy_prior
											lowerCAmelCase      :Dict				  = self.dummy_decoder
											lowerCAmelCase      :Any				  = self.dummy_text_proj
											lowerCAmelCase      :Optional[Any]				  = self.dummy_text_encoder
											lowerCAmelCase      :str				  = self.dummy_tokenizer
											lowerCAmelCase      :Optional[Any]				  = self.dummy_super_res_first
											lowerCAmelCase      :Tuple				  = self.dummy_super_res_last

											lowerCAmelCase      :Any				  = UnCLIPScheduler(
											    variance_type='fixed_small_log'    ,   prediction_type='sample'    ,   num_train_timesteps=1000    ,   clip_sample_range=5.0    ,   )

											lowerCAmelCase      :Any				  = UnCLIPScheduler(
											    variance_type='learned_range'    ,   prediction_type='epsilon'    ,   num_train_timesteps=1000    ,   )

											lowerCAmelCase      :int				  = UnCLIPScheduler(
											    variance_type='fixed_small_log'    ,   prediction_type='epsilon'    ,   num_train_timesteps=1000    ,   )

											lowerCAmelCase      :Tuple				  = {
											    'prior': prior,
											    'decoder': decoder,
											    'text_proj': text_proj,
											    'text_encoder': text_encoder,
											    'tokenizer': tokenizer,
											    'super_res_first': super_res_first,
											    'super_res_last': super_res_last,
											    'prior_scheduler': prior_scheduler,
											    'decoder_scheduler': decoder_scheduler,
											    'super_res_scheduler': super_res_scheduler,
											}

											return components
					def 					UpperCAmelCase__   (       self       :  List[str]    ,   UpperCAmelCase       :  Tuple    ,   UpperCAmelCase       :  Union[str, Any]=0      )  ->					Dict:
											if str(UpperCAmelCase      ).startswith('mps'      ):
																	lowerCAmelCase      :Optional[int]				  = torch.manual_seed(UpperCAmelCase      )
											else:
																	lowerCAmelCase      :int				  = torch.Generator(device=UpperCAmelCase      ).manual_seed(UpperCAmelCase      )
											lowerCAmelCase      :str				  = {
											    'prompt': 'horse',
											    'generator': generator,
											    'prior_num_inference_steps': 2,
											    'decoder_num_inference_steps': 2,
											    'super_res_num_inference_steps': 2,
											    'output_type': 'numpy',
											}
											return inputs
					def 					UpperCAmelCase__   (       self       :  int      )  ->					Dict:
											lowerCAmelCase      :Optional[int]				  = 'cpu'

											lowerCAmelCase      :Optional[int]				  = self.get_dummy_components()

											lowerCAmelCase      :Tuple				  = self.pipeline_class(**UpperCAmelCase      )
											lowerCAmelCase      :Tuple				  = pipe.to(UpperCAmelCase      )

											pipe.set_progress_bar_config(disable=UpperCAmelCase      )

											lowerCAmelCase      :Optional[int]				  = pipe(**self.get_dummy_inputs(UpperCAmelCase      )      )
											lowerCAmelCase      :Dict				  = output.images

											lowerCAmelCase      :Tuple				  = pipe(
											    **self.get_dummy_inputs(UpperCAmelCase      )    ,   return_dict=UpperCAmelCase    ,   )[0]

											lowerCAmelCase      :List[Any]				  = image[0, -3:, -3:, -1]
											lowerCAmelCase      :Union[str, Any]				  = image_from_tuple[0, -3:, -3:, -1]

											assert image.shape == (1, 64, 64, 3)

											lowerCAmelCase      :List[str]				  = np.array(
											    [
											        0.9_9_9_7,
											        0.9_9_8_8,
											        0.0_0_2_8,
											        0.9_9_9_7,
											        0.9_9_8_4,
											        0.9_9_6_5,
											        0.0_0_2_9,
											        0.9_9_8_6,
											        0.0_0_2_5,
											    ]      )

											assert np.abs(image_slice.flatten() - expected_slice      ).max() < 1e-2
											assert np.abs(image_from_tuple_slice.flatten() - expected_slice      ).max() < 1e-2
					def 					UpperCAmelCase__   (       self       :  Any      )  ->					Optional[int]:
											lowerCAmelCase      :List[str]				  = torch.device('cpu'      )




											class 	__UpperCamelCase    :
																lowercase_						:							List[Any]			=     1


											lowerCAmelCase      :Any				  = self.get_dummy_components()

											lowerCAmelCase      :Optional[Any]				  = self.pipeline_class(**UpperCAmelCase      )
											lowerCAmelCase      :Optional[int]				  = pipe.to(UpperCAmelCase      )

											lowerCAmelCase      :str				  = components['prior']
											lowerCAmelCase      :int				  = components['decoder']
											lowerCAmelCase      :List[str]				  = components['super_res_first']
											lowerCAmelCase      :List[str]				  = components['tokenizer']
											lowerCAmelCase      :List[Any]				  = components['text_encoder']

											lowerCAmelCase      :Dict				  = torch.Generator(device=UpperCAmelCase      ).manual_seed(0      )
											lowerCAmelCase      :Dict				  = prior.dtype
											lowerCAmelCase      :int				  = 1

											lowerCAmelCase      :List[Any]				  = (batch_size, prior.config.embedding_dim)
											lowerCAmelCase      :Any				  = pipe.prepare_latents(
											    UpperCAmelCase    ,   dtype=UpperCAmelCase    ,   device=UpperCAmelCase    ,   generator=UpperCAmelCase    ,   latents=UpperCAmelCase    ,   scheduler=DummyScheduler()      )
											lowerCAmelCase      :List[Any]				  = (batch_size, decoder.config.in_channels, decoder.config.sample_size, decoder.config.sample_size)
											lowerCAmelCase      :int				  = pipe.prepare_latents(
											    UpperCAmelCase    ,   dtype=UpperCAmelCase    ,   device=UpperCAmelCase    ,   generator=UpperCAmelCase    ,   latents=UpperCAmelCase    ,   scheduler=DummyScheduler()      )

											lowerCAmelCase      :Optional[int]				  = (
											    batch_size,
											    super_res_first.config.in_channels // 2,
											    super_res_first.config.sample_size,
											    super_res_first.config.sample_size,
											)
											lowerCAmelCase      :Union[str, Any]				  = pipe.prepare_latents(
											    UpperCAmelCase    ,   dtype=UpperCAmelCase    ,   device=UpperCAmelCase    ,   generator=UpperCAmelCase    ,   latents=UpperCAmelCase    ,   scheduler=DummyScheduler()      )

											pipe.set_progress_bar_config(disable=UpperCAmelCase      )

											lowerCAmelCase      :List[str]				  = 'this is a prompt example'

											lowerCAmelCase      :List[Any]				  = torch.Generator(device=UpperCAmelCase      ).manual_seed(0      )
											lowerCAmelCase      :Tuple				  = pipe(
											    [prompt]    ,   generator=UpperCAmelCase    ,   prior_num_inference_steps=2    ,   decoder_num_inference_steps=2    ,   super_res_num_inference_steps=2    ,   prior_latents=UpperCAmelCase    ,   decoder_latents=UpperCAmelCase    ,   super_res_latents=UpperCAmelCase    ,   output_type='np'    ,   )
											lowerCAmelCase      :int				  = output.images

											lowerCAmelCase      :Optional[Any]				  = tokenizer(
											    UpperCAmelCase    ,   padding='max_length'    ,   max_length=tokenizer.model_max_length    ,   return_tensors='pt'    ,   )
											lowerCAmelCase      :int				  = text_encoder(text_inputs.input_ids      )
											lowerCAmelCase      :Optional[Any]				  = text_inputs.attention_mask

											lowerCAmelCase      :List[Any]				  = torch.Generator(device=UpperCAmelCase      ).manual_seed(0      )
											lowerCAmelCase      :Union[str, Any]				  = pipe(
											    generator=UpperCAmelCase    ,   prior_num_inference_steps=2    ,   decoder_num_inference_steps=2    ,   super_res_num_inference_steps=2    ,   prior_latents=UpperCAmelCase    ,   decoder_latents=UpperCAmelCase    ,   super_res_latents=UpperCAmelCase    ,   text_model_output=UpperCAmelCase    ,   text_attention_mask=UpperCAmelCase    ,   output_type='np'    ,   )[0]

											# make sure passing text embeddings manually is identical
											assert np.abs(image - image_from_text      ).max() < 1e-4
					@skip_mps
					def 					UpperCAmelCase__   (       self       :  List[Any]      )  ->					Optional[int]:
											lowerCAmelCase      :int				  = torch_device == 'cpu'

											self._test_attention_slicing_forward_pass(test_max_difference=UpperCAmelCase    ,   expected_max_diff=0.0_1      )
					@skip_mps
					def 					UpperCAmelCase__   (       self       :  Optional[Any]      )  ->					str:
											lowerCAmelCase      :List[Any]				  = torch_device == 'cpu'
											lowerCAmelCase      :Tuple				  = True
											lowerCAmelCase      :Tuple				  = [
											    'prior_num_inference_steps',
											    'decoder_num_inference_steps',
											    'super_res_num_inference_steps',
											]

											self._test_inference_batch_single_identical(
											    test_max_difference=UpperCAmelCase    ,   relax_max_difference=UpperCAmelCase    ,   additional_params_copy_to_batched_inputs=UpperCAmelCase    ,   )
					def 					UpperCAmelCase__   (       self       :  List[str]      )  ->					Optional[Any]:
											lowerCAmelCase      :Optional[Any]				  = [
											    'prior_num_inference_steps',
											    'decoder_num_inference_steps',
											    'super_res_num_inference_steps',
											]

											if torch_device == "mps":
																	# TODO: MPS errors with larger batch sizes
																	lowerCAmelCase      :Dict				  = [2, 3]
																	self._test_inference_batch_consistent(
																	    batch_sizes=UpperCAmelCase    ,   additional_params_copy_to_batched_inputs=UpperCAmelCase    ,   )
											else:
																	self._test_inference_batch_consistent(
																	    additional_params_copy_to_batched_inputs=UpperCAmelCase      )
					@skip_mps
					def 					UpperCAmelCase__   (       self       :  Dict      )  ->					Optional[int]:
											return super().test_dict_tuple_outputs_equivalent()
					@skip_mps
					def 					UpperCAmelCase__   (       self       :  Tuple      )  ->					List[str]:
											return super().test_save_load_local()
					@skip_mps
					def 					UpperCAmelCase__   (       self       :  Tuple      )  ->					List[str]:
											return super().test_save_load_optional_components()




@nightly
class 	__UpperCamelCase    (    unittest.TestCase	):
					def 					UpperCAmelCase__   (       self       :  List[Any]      )  ->					str:
											# clean up the VRAM after each test
											super().tearDown()
											gc.collect()
											torch.cuda.empty_cache()
					def 					UpperCAmelCase__   (       self       :  List[Any]      )  ->					Optional[int]:
											lowerCAmelCase      :str				  = load_numpy(
											    'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main'
											    '/unclip/karlo_v1_alpha_horse_cpu.npy'      )

											lowerCAmelCase      :int				  = UnCLIPPipeline.from_pretrained('kakaobrain/karlo-v1-alpha'      )
											pipeline.set_progress_bar_config(disable=UpperCAmelCase      )

											lowerCAmelCase      :Tuple				  = torch.manual_seed(0      )
											lowerCAmelCase      :Union[str, Any]				  = pipeline(
											    'horse'    ,   num_images_per_prompt=1    ,   generator=UpperCAmelCase    ,   output_type='np'    ,   )

											lowerCAmelCase      :Union[str, Any]				  = output.images[0]

											assert image.shape == (256, 256, 3)
											assert np.abs(expected_image - image      ).max() < 1e-1




@slow
@require_torch_gpu
class 	__UpperCamelCase    (    unittest.TestCase	):
					def 					UpperCAmelCase__   (       self       :  str      )  ->					Tuple:
											# clean up the VRAM after each test
											super().tearDown()
											gc.collect()
											torch.cuda.empty_cache()
					def 					UpperCAmelCase__   (       self       :  Any      )  ->					str:
											lowerCAmelCase      :Tuple				  = load_numpy(
											    'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main'
											    '/unclip/karlo_v1_alpha_horse_fp16.npy'      )

											lowerCAmelCase      :Dict				  = UnCLIPPipeline.from_pretrained('kakaobrain/karlo-v1-alpha'    ,   torch_dtype=torch.floataa      )
											lowerCAmelCase      :Tuple				  = pipeline.to(UpperCAmelCase      )
											pipeline.set_progress_bar_config(disable=UpperCAmelCase      )

											lowerCAmelCase      :Tuple				  = torch.Generator(device='cpu'      ).manual_seed(0      )
											lowerCAmelCase      :int				  = pipeline(
											    'horse'    ,   generator=UpperCAmelCase    ,   output_type='np'    ,   )

											lowerCAmelCase      :Optional[Any]				  = output.images[0]

											assert image.shape == (256, 256, 3)

											assert_mean_pixel_difference(UpperCAmelCase    ,   UpperCAmelCase      )
					def 					UpperCAmelCase__   (       self       :  List[Any]      )  ->					int:
											torch.cuda.empty_cache()
											torch.cuda.reset_max_memory_allocated()
											torch.cuda.reset_peak_memory_stats()

											lowerCAmelCase      :Any				  = UnCLIPPipeline.from_pretrained('kakaobrain/karlo-v1-alpha'    ,   torch_dtype=torch.floataa      )
											lowerCAmelCase      :Optional[Any]				  = pipe.to(UpperCAmelCase      )
											pipe.set_progress_bar_config(disable=UpperCAmelCase      )
											pipe.enable_attention_slicing()
											pipe.enable_sequential_cpu_offload()

											lowerCAmelCase      :int				  = pipe(
											    'horse'    ,   num_images_per_prompt=1    ,   prior_num_inference_steps=2    ,   decoder_num_inference_steps=2    ,   super_res_num_inference_steps=2    ,   output_type='np'    ,   )

											lowerCAmelCase      :int				  = torch.cuda.max_memory_allocated()
											# make sure that less than 7 GB is allocated
											assert mem_bytes < 7 * 10**9







"""simple docstring"""


import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device


if is_torch_available():
		import torch

		from transformers import XLMProphetNetForConditionalGeneration, XLMProphetNetTokenizer




@require_torch
class 	__UpperCamelCase    (    unittest.TestCase	):
					@slow
					def 					UpperCAmelCase__   (       self       :  Tuple      )  ->					Union[str, Any]:
											lowerCAmelCase      :Any				  = XLMProphetNetForConditionalGeneration.from_pretrained('microsoft/xprophetnet-large-wiki100-cased'      )
											model.to(UpperCAmelCase      )

											# encoder-decoder outputs
											lowerCAmelCase      :Any				  = torch.tensor([[17, 9_6208, 10_3471, 2]]      ).to(UpperCAmelCase      )
											lowerCAmelCase      :Optional[int]				  = torch.tensor(
											    [[2, 250, 9953, 34, 6_9489, 1620, 32, 11_8424, 624, 210, 105, 2913, 1032, 351]]      ).to(UpperCAmelCase      )
											lowerCAmelCase      :Tuple				  = model(
											    input_ids=UpperCAmelCase    ,   attention_mask=UpperCAmelCase    ,   encoder_outputs=UpperCAmelCase    ,   decoder_input_ids=UpperCAmelCase      )
											lowerCAmelCase      :Tuple				  = output[0]
											lowerCAmelCase      :Any				  = torch.Size((1, 14, 25_0012)      )
											self.assertEqual(output_predited_logis.shape    ,   UpperCAmelCase      )
											lowerCAmelCase      :Optional[int]				  = torch.tensor(
											    [[[-6.3_9_8_6, -8.2_3_9_1, 1_2.5_1_8_9], [-6.3_2_8_9, -8.0_8_6_4, 1_2.6_2_1_1], [-6.2_4_1_8, -8.0_4_4_5, 1_2.7_9_6_8]]]      ).to(UpperCAmelCase      )
											self.assertTrue(torch.allclose(output_predited_logis[:, :3, :3]    ,   UpperCAmelCase    ,   atol=1e-4      )      )

											# encoder outputs
											lowerCAmelCase      :int				  = model.prophetnet.encoder(UpperCAmelCase      )[0]
											lowerCAmelCase      :int				  = torch.tensor(
											    [[[-1.4_2_6_0, -0.7_6_2_8, 0.8_4_5_3], [-1.4_7_1_9, -0.1_3_9_1, 0.7_8_0_7], [-1.7_6_7_8, 0.0_1_1_4, 0.4_6_4_6]]]      ).to(UpperCAmelCase      )
											lowerCAmelCase      :Optional[Any]				  = torch.Size((1, 4, 1024)      )
											self.assertEqual(encoder_outputs.shape    ,   UpperCAmelCase      )
											self.assertTrue(torch.allclose(encoder_outputs[:, :3, :3]    ,   UpperCAmelCase    ,   atol=1e-4      )      )

											# decoder outputs
											lowerCAmelCase      :Tuple				  = model.prophetnet.decoder(
											    UpperCAmelCase    ,   encoder_hidden_states=UpperCAmelCase    ,   )
											lowerCAmelCase      :Optional[Any]				  = decoder_outputs[1].view(1    ,   model.config.ngram    ,   14    ,   -1      )
											lowerCAmelCase      :Any				  = model.lm_head(UpperCAmelCase      )
											lowerCAmelCase      :Optional[int]				  = predicting_streams_logits[:, 0]
											self.assertTrue(torch.allclose(next_first_stream_logits[:, :3, :3]    ,   UpperCAmelCase    ,   atol=1e-4      )      )
					@slow
					def 					UpperCAmelCase__   (       self       :  List[Any]      )  ->					Optional[Any]:
											lowerCAmelCase      :Union[str, Any]				  = XLMProphetNetForConditionalGeneration.from_pretrained(
											    'microsoft/xprophetnet-large-wiki100-cased-xglue-ntg'      )
											model.to(UpperCAmelCase      )

											lowerCAmelCase      :Tuple				  = torch.tensor([[17, 9_6208, 10_3471, 2]]      ).to(UpperCAmelCase      )
											lowerCAmelCase      :Any				  = torch.tensor(
											    [[2, 250, 9953, 34, 6_9489, 1620, 32, 11_8424, 624, 210, 105, 2913, 1032, 351]]      ).to(UpperCAmelCase      )
											lowerCAmelCase      :Tuple				  = model(
											    input_ids=UpperCAmelCase    ,   attention_mask=UpperCAmelCase    ,   encoder_outputs=UpperCAmelCase    ,   decoder_input_ids=UpperCAmelCase      )
											lowerCAmelCase      :Dict				  = output[0]
											lowerCAmelCase      :List[str]				  = torch.Size((1, 14, 25_0012)      )
											self.assertEqual(output_predited_logis.shape    ,   UpperCAmelCase      )
											# compare the actual values for a slice.
											lowerCAmelCase      :List[Any]				  = torch.tensor(
											    [[[-9.2_2_5_3, -9.7_1_7_3, -6.3_5_2_9], [-7.6_7_0_1, -9.0_1_4_5, -1.9_3_8_2], [-8.0_1_9_5, -7.0_0_0_4, -0.1_5_2_3]]]      ).to(UpperCAmelCase      )

											self.assertTrue(torch.allclose(output_predited_logis[:, :3, :3]    ,   UpperCAmelCase    ,   atol=1e-4      )      )
					@slow
					def 					UpperCAmelCase__   (       self       :  Optional[Any]      )  ->					Optional[int]:
											lowerCAmelCase      :str				  = XLMProphetNetForConditionalGeneration.from_pretrained(
											    'microsoft/xprophetnet-large-wiki100-cased-xglue-ntg'      )
											model.to(UpperCAmelCase      )
											lowerCAmelCase      :Any				  = 512

											lowerCAmelCase      :Union[str, Any]				  = XLMProphetNetTokenizer.from_pretrained('microsoft/xprophetnet-large-wiki100-cased-xglue-ntg'      )

											lowerCAmelCase      :Optional[int]				  = (
											    'Microsoft Corporation intends to officially end free support for the Windows 7 operating system after'
											    ' January 14, 2020, according to the official portal of the organization. From that day, users of this'
											    ' system will not be able to receive security updates, which could make their computers vulnerable to'
											    ' cyber attacks.'
											)
											lowerCAmelCase      :Union[str, Any]				  = (
											    'орпорация Microsoft намерена официально прекратить бесплатную поддержку операционной системы Windows 7'
											    ' после 14 января 2020 года, сообщается на официальном портале организации . С указанного дня пользователи'
											    ' этой системы не смогут получать обновления безопасности, из-за чего их компьютеры могут стать уязвимыми'
											    ' к кибератакам.'
											)
											lowerCAmelCase      :Optional[Any]				  = (
											    '根据该组织的官方门户网站，微软公司打算在2020年1月14日之后正式终止对Windows 7操作系统的免费支持。从那时起，该系统的用户将无法接收安全更新，这可能会使他们的计算机容易受到网络攻击。'
											)

											lowerCAmelCase      :List[Any]				  = tokenizer(
											    [EN_SENTENCE, RU_SENTENCE, ZH_SENTENCE]    ,   padding=UpperCAmelCase    ,   max_length=255    ,   return_tensors='pt'      ).input_ids
											lowerCAmelCase      :List[str]				  = input_ids.to(UpperCAmelCase      )

											lowerCAmelCase      :Dict				  = model.generate(
											    UpperCAmelCase    ,   num_beams=10    ,   length_penalty=1.0    ,   no_repeat_ngram_size=3    ,   early_stopping=UpperCAmelCase      )
											lowerCAmelCase      :str				  = [tokenizer.decode(UpperCAmelCase    ,   skip_special_tokens=UpperCAmelCase      ) for g in summary_ids]
											lowerCAmelCase      :Dict				  = 'Microsoft to end Windows 7 free support after January 14, 2020'
											lowerCAmelCase      :Tuple				  = 'Microsoft намерена прекратить бесплатную поддержку Windows 7 после 14 января 2020 года'
											lowerCAmelCase      :Any				  = '微软打算终止对Windows 7操作系统的免费支持'
											self.assertListEqual(
											    [EXPECTED_TITLE_EN, EXPECTED_TITLE_RU, EXPECTED_TITLE_ZH]    ,   UpperCAmelCase    ,   )

											lowerCAmelCase      :List[str]				  = model.generate(
											    UpperCAmelCase    ,   num_beams=1    ,   length_penalty=1.0    ,   no_repeat_ngram_size=3    ,   early_stopping=UpperCAmelCase      )
											lowerCAmelCase      :Dict				  = [
											    tokenizer.convert_ids_to_tokens(UpperCAmelCase    ,   skip_special_tokens=UpperCAmelCase      ) for g in summary_ids_beama
											]
											lowerCAmelCase      :Optional[Any]				  = '▁Microsoft ▁to ▁end ▁free ▁support ▁for ▁Windows ▁7'.split(' '      )
											lowerCAmelCase      :Optional[int]				  = '▁Microsoft ▁намерен а ▁прекрати ть ▁бес плат ную ▁поддержку ▁Windows ▁7 ▁после ▁14 ▁января ▁2020 ▁года'.split(
											    ' '      )
											lowerCAmelCase      :Optional[Any]				  = '微软 公司 打算 终止 对 Windows ▁7 操作 系统的 免费 支持'.split(' '      )
											self.assertListEqual(
											    [EXPECTED_TITLE_EN_BEAM1_TOK, EXPECTED_TITLE_RU_BEAM1_TOK, EXPECTED_TITLE_ZH_BEAM1_TOK]    ,   UpperCAmelCase    ,   )