'''simple docstring'''




import argparse
import json
from pathlib import Path

import requests
import torch
from huggingface_hub import cached_download, hf_hub_download, hf_hub_url
from PIL import Image

from transformers import DetaConfig, DetaForObjectDetection, DetaImageProcessor
from transformers.utils import logging


logging.set_verbosity_info()
snake_case  =			logging.get_logger(__name__)







def 			A_   ( ):
						_lowerCAmelCase		   =   DetaConfig(
						    num_queries=900  ,  encoder_ffn_dim=2_048  ,  decoder_ffn_dim=2_048  ,  num_feature_levels=5  ,  assign_first_stage=_A  ,  with_box_refine=_A  ,  two_stage=_A  ,  )

						# set labels
						_lowerCAmelCase		   =   91
						_lowerCAmelCase		   =   'huggingface/label-files'
						_lowerCAmelCase		   =   'coco-detection-id2label.json'
						_lowerCAmelCase		   =   json.load(open(cached_download(hf_hub_url(_A  ,  _A  ,  repo_type='dataset'    )    )  ,  'r'    )    )
						_lowerCAmelCase		   =   {int(_A    ): v for k, v in idalabel.items()}
						_lowerCAmelCase		   =   idalabel
						_lowerCAmelCase		   =   {v: k for k, v in idalabel.items()}

						return config







def 			A_   ( _lowerCamelCase			:							int    ):
						_lowerCAmelCase		   =   []

						# stem
						# fmt: off
						rename_keys.append(('backbone.0.body.conv1.weight', 'model.backbone.model.embedder.embedder.convolution.weight')    )
						rename_keys.append(('backbone.0.body.bn1.weight', 'model.backbone.model.embedder.embedder.normalization.weight')    )
						rename_keys.append(('backbone.0.body.bn1.bias', 'model.backbone.model.embedder.embedder.normalization.bias')    )
						rename_keys.append(('backbone.0.body.bn1.running_mean', 'model.backbone.model.embedder.embedder.normalization.running_mean')    )
						rename_keys.append(('backbone.0.body.bn1.running_var', 'model.backbone.model.embedder.embedder.normalization.running_var')    )
						# stages
						for stage_idx in range(len(config.backbone_config.depths    )    ):
												for layer_idx in range(config.backbone_config.depths[stage_idx]    ):
																		# shortcut
																		if layer_idx == 0:
																								rename_keys.append(
																								    (
																								        F"backbone.0.body.layer{stage_idx + 1}.{layer_idx}.downsample.0.weight",
																								        F"model.backbone.model.encoder.stages.{stage_idx}.layers.{layer_idx}.shortcut.convolution.weight",
																								    )    )
																								rename_keys.append(
																								    (
																								        F"backbone.0.body.layer{stage_idx + 1}.{layer_idx}.downsample.1.weight",
																								        F"model.backbone.model.encoder.stages.{stage_idx}.layers.{layer_idx}.shortcut.normalization.weight",
																								    )    )
																								rename_keys.append(
																								    (
																								        F"backbone.0.body.layer{stage_idx + 1}.{layer_idx}.downsample.1.bias",
																								        F"model.backbone.model.encoder.stages.{stage_idx}.layers.{layer_idx}.shortcut.normalization.bias",
																								    )    )
																								rename_keys.append(
																								    (
																								        F"backbone.0.body.layer{stage_idx + 1}.{layer_idx}.downsample.1.running_mean",
																								        F"model.backbone.model.encoder.stages.{stage_idx}.layers.{layer_idx}.shortcut.normalization.running_mean",
																								    )    )
																								rename_keys.append(
																								    (
																								        F"backbone.0.body.layer{stage_idx + 1}.{layer_idx}.downsample.1.running_var",
																								        F"model.backbone.model.encoder.stages.{stage_idx}.layers.{layer_idx}.shortcut.normalization.running_var",
																								    )    )
																		# 3 convs
																		for i in range(3    ):
																								rename_keys.append(
																								    (
																								        F"backbone.0.body.layer{stage_idx + 1}.{layer_idx}.conv{i+1}.weight",
																								        F"model.backbone.model.encoder.stages.{stage_idx}.layers.{layer_idx}.layer.{i}.convolution.weight",
																								    )    )
																								rename_keys.append(
																								    (
																								        F"backbone.0.body.layer{stage_idx + 1}.{layer_idx}.bn{i+1}.weight",
																								        F"model.backbone.model.encoder.stages.{stage_idx}.layers.{layer_idx}.layer.{i}.normalization.weight",
																								    )    )
																								rename_keys.append(
																								    (
																								        F"backbone.0.body.layer{stage_idx + 1}.{layer_idx}.bn{i+1}.bias",
																								        F"model.backbone.model.encoder.stages.{stage_idx}.layers.{layer_idx}.layer.{i}.normalization.bias",
																								    )    )
																								rename_keys.append(
																								    (
																								        F"backbone.0.body.layer{stage_idx + 1}.{layer_idx}.bn{i+1}.running_mean",
																								        F"model.backbone.model.encoder.stages.{stage_idx}.layers.{layer_idx}.layer.{i}.normalization.running_mean",
																								    )    )
																								rename_keys.append(
																								    (
																								        F"backbone.0.body.layer{stage_idx + 1}.{layer_idx}.bn{i+1}.running_var",
																								        F"model.backbone.model.encoder.stages.{stage_idx}.layers.{layer_idx}.layer.{i}.normalization.running_var",
																								    )    )
												# transformer encoder
						for i in range(config.encoder_layers    ):
												rename_keys.append((F"transformer.encoder.layers.{i}.self_attn.sampling_offsets.weight", F"model.encoder.layers.{i}.self_attn.sampling_offsets.weight")    )
												rename_keys.append((F"transformer.encoder.layers.{i}.self_attn.sampling_offsets.bias", F"model.encoder.layers.{i}.self_attn.sampling_offsets.bias")    )
												rename_keys.append((F"transformer.encoder.layers.{i}.self_attn.attention_weights.weight", F"model.encoder.layers.{i}.self_attn.attention_weights.weight")    )
												rename_keys.append((F"transformer.encoder.layers.{i}.self_attn.attention_weights.bias", F"model.encoder.layers.{i}.self_attn.attention_weights.bias")    )
												rename_keys.append((F"transformer.encoder.layers.{i}.self_attn.value_proj.weight", F"model.encoder.layers.{i}.self_attn.value_proj.weight")    )
												rename_keys.append((F"transformer.encoder.layers.{i}.self_attn.value_proj.bias", F"model.encoder.layers.{i}.self_attn.value_proj.bias")    )
												rename_keys.append((F"transformer.encoder.layers.{i}.self_attn.output_proj.weight", F"model.encoder.layers.{i}.self_attn.output_proj.weight")    )
												rename_keys.append((F"transformer.encoder.layers.{i}.self_attn.output_proj.bias", F"model.encoder.layers.{i}.self_attn.output_proj.bias")    )
												rename_keys.append((F"transformer.encoder.layers.{i}.norm1.weight", F"model.encoder.layers.{i}.self_attn_layer_norm.weight")    )
												rename_keys.append((F"transformer.encoder.layers.{i}.norm1.bias", F"model.encoder.layers.{i}.self_attn_layer_norm.bias")    )
												rename_keys.append((F"transformer.encoder.layers.{i}.linear1.weight", F"model.encoder.layers.{i}.fc1.weight")    )
												rename_keys.append((F"transformer.encoder.layers.{i}.linear1.bias", F"model.encoder.layers.{i}.fc1.bias")    )
												rename_keys.append((F"transformer.encoder.layers.{i}.linear2.weight", F"model.encoder.layers.{i}.fc2.weight")    )
												rename_keys.append((F"transformer.encoder.layers.{i}.linear2.bias", F"model.encoder.layers.{i}.fc2.bias")    )
												rename_keys.append((F"transformer.encoder.layers.{i}.norm2.weight", F"model.encoder.layers.{i}.final_layer_norm.weight")    )
												rename_keys.append((F"transformer.encoder.layers.{i}.norm2.bias", F"model.encoder.layers.{i}.final_layer_norm.bias")    )

						# transformer decoder
						for i in range(config.decoder_layers    ):
												rename_keys.append((F"transformer.decoder.layers.{i}.cross_attn.sampling_offsets.weight", F"model.decoder.layers.{i}.encoder_attn.sampling_offsets.weight")    )
												rename_keys.append((F"transformer.decoder.layers.{i}.cross_attn.sampling_offsets.bias", F"model.decoder.layers.{i}.encoder_attn.sampling_offsets.bias")    )
												rename_keys.append((F"transformer.decoder.layers.{i}.cross_attn.attention_weights.weight", F"model.decoder.layers.{i}.encoder_attn.attention_weights.weight")    )
												rename_keys.append((F"transformer.decoder.layers.{i}.cross_attn.attention_weights.bias", F"model.decoder.layers.{i}.encoder_attn.attention_weights.bias")    )
												rename_keys.append((F"transformer.decoder.layers.{i}.cross_attn.value_proj.weight", F"model.decoder.layers.{i}.encoder_attn.value_proj.weight")    )
												rename_keys.append((F"transformer.decoder.layers.{i}.cross_attn.value_proj.bias", F"model.decoder.layers.{i}.encoder_attn.value_proj.bias")    )
												rename_keys.append((F"transformer.decoder.layers.{i}.cross_attn.output_proj.weight", F"model.decoder.layers.{i}.encoder_attn.output_proj.weight")    )
												rename_keys.append((F"transformer.decoder.layers.{i}.cross_attn.output_proj.bias", F"model.decoder.layers.{i}.encoder_attn.output_proj.bias")    )
												rename_keys.append((F"transformer.decoder.layers.{i}.norm1.weight", F"model.decoder.layers.{i}.encoder_attn_layer_norm.weight")    )
												rename_keys.append((F"transformer.decoder.layers.{i}.norm1.bias", F"model.decoder.layers.{i}.encoder_attn_layer_norm.bias")    )
												rename_keys.append((F"transformer.decoder.layers.{i}.self_attn.out_proj.weight", F"model.decoder.layers.{i}.self_attn.out_proj.weight")    )
												rename_keys.append((F"transformer.decoder.layers.{i}.self_attn.out_proj.bias", F"model.decoder.layers.{i}.self_attn.out_proj.bias")    )
												rename_keys.append((F"transformer.decoder.layers.{i}.norm2.weight", F"model.decoder.layers.{i}.self_attn_layer_norm.weight")    )
												rename_keys.append((F"transformer.decoder.layers.{i}.norm2.bias", F"model.decoder.layers.{i}.self_attn_layer_norm.bias")    )
												rename_keys.append((F"transformer.decoder.layers.{i}.linear1.weight", F"model.decoder.layers.{i}.fc1.weight")    )
												rename_keys.append((F"transformer.decoder.layers.{i}.linear1.bias", F"model.decoder.layers.{i}.fc1.bias")    )
												rename_keys.append((F"transformer.decoder.layers.{i}.linear2.weight", F"model.decoder.layers.{i}.fc2.weight")    )
												rename_keys.append((F"transformer.decoder.layers.{i}.linear2.bias", F"model.decoder.layers.{i}.fc2.bias")    )
												rename_keys.append((F"transformer.decoder.layers.{i}.norm3.weight", F"model.decoder.layers.{i}.final_layer_norm.weight")    )
												rename_keys.append((F"transformer.decoder.layers.{i}.norm3.bias", F"model.decoder.layers.{i}.final_layer_norm.bias")    )

						# fmt: on

						return rename_keys







def 			A_   ( _lowerCamelCase			:							int  ,  _lowerCamelCase			:							str  ,  _lowerCamelCase			:							List[str]    ):
						_lowerCAmelCase		   =   dct.pop(_A    )
						_lowerCAmelCase		   =   val







def 			A_   ( _lowerCamelCase			:							int  ,  _lowerCamelCase			:							str    ):
						_lowerCAmelCase		   =   config.d_model
						for i in range(config.decoder_layers    ):
												# read in weights + bias of input projection layer of self-attention
												_lowerCAmelCase		   =   state_dict.pop(F"transformer.decoder.layers.{i}.self_attn.in_proj_weight"    )
												_lowerCAmelCase		   =   state_dict.pop(F"transformer.decoder.layers.{i}.self_attn.in_proj_bias"    )
												# next, add query, keys and values (in that order) to the state dict
												_lowerCAmelCase		   =   in_proj_weight[:hidden_size, :]
												_lowerCAmelCase		   =   in_proj_bias[:hidden_size]
												_lowerCAmelCase		   =   in_proj_weight[
												    hidden_size : hidden_size * 2, :
												]
												_lowerCAmelCase		   =   in_proj_bias[hidden_size : hidden_size * 2]
												_lowerCAmelCase		   =   in_proj_weight[-hidden_size:, :]
												_lowerCAmelCase		   =   in_proj_bias[-hidden_size:]







def 			A_   ( ):
						_lowerCAmelCase		   =   'http://images.cocodataset.org/val2017/000000039769.jpg'
						_lowerCAmelCase		   =   Image.open(requests.get(_A  ,  stream=_A    ).raw    )

						return im







@torch.no_grad()
def 			A_   ( _lowerCamelCase			:							Tuple  ,  _lowerCamelCase			:							int  ,  _lowerCamelCase			:							List[str]    ):
						_lowerCAmelCase		   =   get_deta_config()

						# load original state dict
						if model_name == "deta-resnet-50":
												_lowerCAmelCase		   =   'adet_checkpoint0011.pth'
						elif model_name == "deta-resnet-50-24-epochs":
												_lowerCAmelCase		   =   'adet_2x_checkpoint0023.pth'
						else:
												raise ValueError(F"Model name {model_name} not supported"    )
						_lowerCAmelCase		   =   hf_hub_download(repo_id='nielsr/deta-checkpoints'  ,  filename=_A    )
						_lowerCAmelCase		   =   torch.load(_A  ,  map_location='cpu'    )['model']

						# rename keys
						_lowerCAmelCase		   =   create_rename_keys(_A    )
						for src, dest in rename_keys:
												rename_key(_A  ,  _A  ,  _A    )
						read_in_decoder_q_k_v(_A  ,  _A    )

						# fix some prefixes
						for key in state_dict.copy().keys():
												if "transformer.decoder.class_embed" in key or "transformer.decoder.bbox_embed" in key:
																		_lowerCAmelCase		   =   state_dict.pop(_A    )
																		_lowerCAmelCase		   =   val
												if "input_proj" in key:
																		_lowerCAmelCase		   =   state_dict.pop(_A    )
																		_lowerCAmelCase		   =   val
												if "level_embed" in key or "pos_trans" in key or "pix_trans" in key or "enc_output" in key:
																		_lowerCAmelCase		   =   state_dict.pop(_A    )
																		_lowerCAmelCase		   =   val

												# finally, create HuggingFace model and load state dict
						_lowerCAmelCase		   =   DetaForObjectDetection(_A    )
						model.load_state_dict(_A    )
						model.eval()

						_lowerCAmelCase		   =   'cuda' if torch.cuda.is_available() else 'cpu'
						model.to(_A    )

						# load image processor
						_lowerCAmelCase		   =   DetaImageProcessor(format='coco_detection'    )

						# verify our conversion on image
						_lowerCAmelCase		   =   prepare_img()
						_lowerCAmelCase		   =   processor(images=_A  ,  return_tensors='pt'    )
						_lowerCAmelCase		   =   encoding['pixel_values']
						_lowerCAmelCase		   =   model(pixel_values.to(_A    )    )

						# verify logits
						if model_name == "deta-resnet-50":
												_lowerCAmelCase		   =   torch.tensor(
												    [[-7.3978, -2.5406, -4.1668], [-8.2684, -3.9933, -3.8096], [-7.0515, -3.7973, -5.8516]]    )
												_lowerCAmelCase		   =   torch.tensor([[0.5043, 0.4973, 0.9998], [0.2542, 0.5489, 0.4748], [0.5490, 0.2765, 0.0570]]    )
						elif model_name == "deta-resnet-50-24-epochs":
												_lowerCAmelCase		   =   torch.tensor(
												    [[-7.1688, -2.4857, -4.8669], [-7.8630, -3.8154, -4.2674], [-7.2730, -4.1865, -5.5323]]    )
												_lowerCAmelCase		   =   torch.tensor([[0.5021, 0.4971, 0.9994], [0.2546, 0.5486, 0.4731], [0.1686, 0.1986, 0.2142]]    )

						assert torch.allclose(outputs.logits[0, :3, :3]  ,  expected_logits.to(_A    )  ,  atol=1e-4    )
						assert torch.allclose(outputs.pred_boxes[0, :3, :3]  ,  expected_boxes.to(_A    )  ,  atol=1e-4    )
						print('Everything ok!'    )

						if pytorch_dump_folder_path:
												# Save model and processor
												logger.info(F"Saving PyTorch model and processor to {pytorch_dump_folder_path}..."    )
												Path(_A    ).mkdir(exist_ok=_A    )
												model.save_pretrained(_A    )
												processor.save_pretrained(_A    )

						# Push to hub
						if push_to_hub:
												print('Pushing model and processor to hub...'    )
												model.push_to_hub(F"jozhang97/{model_name}"    )
												processor.push_to_hub(F"jozhang97/{model_name}"    )


if __name__ == "__main__":
	snake_case  =			argparse.ArgumentParser()

	parser.add_argument(
	    '''--model_name''',
	    type=str,
	    default='''deta-resnet-50''',
	    choices=['''deta-resnet-50''', '''deta-resnet-50-24-epochs'''],
	    help='''Name of the model you\'d like to convert.''',
	)
	parser.add_argument(
	    '''--pytorch_dump_folder_path''',
	    default=None,
	    type=str,
	    help='''Path to the folder to output PyTorch model.''',
	)
	parser.add_argument(
	    '''--push_to_hub''', action='''store_true''', help='''Whether or not to push the converted model to the 🤗 hub.'''
	)
	snake_case  =			parser.parse_args()
	convert_deta_checkpoint(args.model_name, args.pytorch_dump_folder_path, args.push_to_hub)






'''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        SCREAMING_SNAKE_CASE   (				unittest.TestCase ):
  """simple docstring"""







  @slow
  def   a   (  self   :					List[str]					):


        """simple docstring"""



        _lowerCAmelCase		   =   XLMProphetNetForConditionalGeneration.from_pretrained('microsoft/xprophetnet-large-wiki100-cased'					)
        model.to(__lowerCAmelCase					)

        # encoder-decoder outputs
        _lowerCAmelCase		   =   torch.tensor([[17, 9_6208, 10_3471, 2]]					).to(__lowerCAmelCase					)
        _lowerCAmelCase		   =   torch.tensor(
            [[2, 250, 9953, 34, 6_9489, 1620, 32, 11_8424, 624, 210, 105, 2913, 1032, 351]]					).to(__lowerCAmelCase					)
        _lowerCAmelCase		   =   model(
            input_ids=__lowerCAmelCase					,					attention_mask=__lowerCAmelCase					,					encoder_outputs=__lowerCAmelCase					,					decoder_input_ids=__lowerCAmelCase					)
        _lowerCAmelCase		   =   output[0]
        _lowerCAmelCase		   =   torch.Size((1, 14, 25_0012)					)
        self.assertEqual(output_predited_logis.shape					,					__lowerCAmelCase					)
        _lowerCAmelCase		   =   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(__lowerCAmelCase					)
        self.assertTrue(torch.allclose(output_predited_logis[:, :3, :3]					,					__lowerCAmelCase					,					atol=1e-4					)					)

        # encoder outputs
        _lowerCAmelCase		   =   model.prophetnet.encoder(__lowerCAmelCase					)[0]
        _lowerCAmelCase		   =   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(__lowerCAmelCase					)
        _lowerCAmelCase		   =   torch.Size((1, 4, 1024)					)
        self.assertEqual(encoder_outputs.shape					,					__lowerCAmelCase					)
        self.assertTrue(torch.allclose(encoder_outputs[:, :3, :3]					,					__lowerCAmelCase					,					atol=1e-4					)					)

        # decoder outputs
        _lowerCAmelCase		   =   model.prophetnet.decoder(
            __lowerCAmelCase					,					encoder_hidden_states=__lowerCAmelCase					,					)
        _lowerCAmelCase		   =   decoder_outputs[1].view(1					,					model.config.ngram					,					14					,					-1					)
        _lowerCAmelCase		   =   model.lm_head(__lowerCAmelCase					)
        _lowerCAmelCase		   =   predicting_streams_logits[:, 0]
        self.assertTrue(torch.allclose(next_first_stream_logits[:, :3, :3]					,					__lowerCAmelCase					,					atol=1e-4					)					)



  @slow
  def   a   (  self   :					Tuple					):


        """simple docstring"""



        _lowerCAmelCase		   =   XLMProphetNetForConditionalGeneration.from_pretrained(
            'microsoft/xprophetnet-large-wiki100-cased-xglue-ntg'					)
        model.to(__lowerCAmelCase					)

        _lowerCAmelCase		   =   torch.tensor([[17, 9_6208, 10_3471, 2]]					).to(__lowerCAmelCase					)
        _lowerCAmelCase		   =   torch.tensor(
            [[2, 250, 9953, 34, 6_9489, 1620, 32, 11_8424, 624, 210, 105, 2913, 1032, 351]]					).to(__lowerCAmelCase					)
        _lowerCAmelCase		   =   model(
            input_ids=__lowerCAmelCase					,					attention_mask=__lowerCAmelCase					,					encoder_outputs=__lowerCAmelCase					,					decoder_input_ids=__lowerCAmelCase					)
        _lowerCAmelCase		   =   output[0]
        _lowerCAmelCase		   =   torch.Size((1, 14, 25_0012)					)
        self.assertEqual(output_predited_logis.shape					,					__lowerCAmelCase					)
        # compare the actual values for a slice.
        _lowerCAmelCase		   =   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(__lowerCAmelCase					)

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



  @slow
  def   a   (  self   :					int					):


        """simple docstring"""



        _lowerCAmelCase		   =   XLMProphetNetForConditionalGeneration.from_pretrained(
            'microsoft/xprophetnet-large-wiki100-cased-xglue-ntg'					)
        model.to(__lowerCAmelCase					)
        _lowerCAmelCase		   =   512

        _lowerCAmelCase		   =   XLMProphetNetTokenizer.from_pretrained('microsoft/xprophetnet-large-wiki100-cased-xglue-ntg'					)

        _lowerCAmelCase		   =   (
            '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		   =   (
            'орпорация Microsoft намерена официально прекратить бесплатную поддержку операционной системы Windows 7'
            ' после 14 января 2020 года, сообщается на официальном портале организации . С указанного дня пользователи'
            ' этой системы не смогут получать обновления безопасности, из-за чего их компьютеры могут стать уязвимыми'
            ' к кибератакам.'
        )
        _lowerCAmelCase		   =   (
            '根据该组织的官方门户网站，微软公司打算在2020年1月14日之后正式终止对Windows 7操作系统的免费支持。从那时起，该系统的用户将无法接收安全更新，这可能会使他们的计算机容易受到网络攻击。'
        )

        _lowerCAmelCase		   =   tokenizer(
            [EN_SENTENCE, RU_SENTENCE, ZH_SENTENCE]					,					padding=__lowerCAmelCase					,					max_length=255					,					return_tensors='pt'					).input_ids
        _lowerCAmelCase		   =   input_ids.to(__lowerCAmelCase					)

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

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





