

import string




def 					_lowercase     (				a_				:					str			)				->	Optional[int]:




					'''simple docstring'''







					for key in range(len(string.ascii_uppercase			)			):
										__magic_name__							=    ''
										for symbol in message:
															if symbol in string.ascii_uppercase:
																				__magic_name__							=    string.ascii_uppercase.find(lowerCAmelCase__			)
																				__magic_name__							=    num - key
																				if num < 0:
																									__magic_name__							=    num + len(string.ascii_uppercase			)
																				__magic_name__							=    translated + string.ascii_uppercase[num]
															else:
																				__magic_name__							=    translated + symbol
										print(F'Decryption using Key #{key}: {translated}'			)




def 					_lowercase     (				)				->	Optional[Any]:




					'''simple docstring'''







					__magic_name__							=    input('Encrypted message: '			)
					__magic_name__							=    message.upper()
					decrypt(lowerCAmelCase__			)


if __name__ == "__main__":
						import doctest

						doctest.testmod()
						main()







import copy
import tempfile
import unittest

from transformers import MaMaaaConfig, is_torch_available
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device
from transformers.utils import cached_property

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
						import torch

						from transformers import MaMaaaForConditionalGeneration, MaMaaaModel, MaMaaaTokenizer
						from transformers.models.mam_aaa.modeling_mam_aaa import MaMaaaDecoder, MaMaaaEncoder




def 					_lowercase     (				a_				:					Optional[Any]					,a_				:					Dict					,a_				:					Any					,a_				:					Any=None					,a_				:					Any=None					,a_				:					List[str]=None					,a_				:					Union[str, Any]=None					,a_				:					Dict=None					,)				->	Optional[Any]:




					'''simple docstring'''







					if attention_mask is None:
										__magic_name__							=    input_ids.ne(config.pad_token_id				)
					if decoder_attention_mask is None:
										__magic_name__							=    decoder_input_ids.ne(config.pad_token_id				)
					if head_mask is None:
										__magic_name__							=    torch.ones(config.encoder_layers					,config.encoder_attention_heads					,device=a_				)
					if decoder_head_mask is None:
										__magic_name__							=    torch.ones(config.decoder_layers					,config.decoder_attention_heads					,device=a_				)
					if cross_attn_head_mask is None:
										__magic_name__							=    torch.ones(config.decoder_layers					,config.decoder_attention_heads					,device=a_				)
					return {
					    "input_ids": input_ids,
					    "decoder_input_ids": decoder_input_ids,
					    "attention_mask": attention_mask,
					    "decoder_attention_mask": attention_mask,
					    "head_mask": head_mask,
					    "decoder_head_mask": decoder_head_mask,
					    "cross_attn_head_mask": cross_attn_head_mask,
					}

class 				__UpperCamelCase				:







	def __init__(   self: Union[str, Any]  , __UpperCamelCase: Union[str, Any]  , __UpperCamelCase: List[Any]=13  , __UpperCamelCase: Tuple=7  , __UpperCamelCase: Dict=True  , __UpperCamelCase: Optional[int]=False  , __UpperCamelCase: str=99  , __UpperCamelCase: Optional[Any]=16  , __UpperCamelCase: List[Any]=2  , __UpperCamelCase: Optional[int]=4  , __UpperCamelCase: Tuple=4  , __UpperCamelCase: Optional[int]="relu"  , __UpperCamelCase: Optional[Any]=0.1  , __UpperCamelCase: Dict=0.1  , __UpperCamelCase: int=0.0  , __UpperCamelCase: int=0.0  , __UpperCamelCase: List[Any]=20  , __UpperCamelCase: Union[str, Any]=2  , __UpperCamelCase: List[Any]=1  , __UpperCamelCase: Tuple=0  , ):

						'''simple docstring'''





						__magic_name__							=    parent
						__magic_name__							=    batch_size
						__magic_name__							=    seq_length
						__magic_name__							=    is_training
						__magic_name__							=    use_labels
						__magic_name__							=    vocab_size
						__magic_name__							=    hidden_size
						__magic_name__							=    num_hidden_layers
						__magic_name__							=    num_attention_heads
						__magic_name__							=    intermediate_size
						__magic_name__							=    hidden_act
						__magic_name__							=    hidden_dropout_prob
						__magic_name__							=    attention_probs_dropout_prob
						__magic_name__							=    encoder_layerdrop
						__magic_name__							=    decoder_layerdrop
						__magic_name__							=    max_position_embeddings
						__magic_name__							=    eos_token_id
						__magic_name__							=    pad_token_id
						__magic_name__							=    bos_token_id







	def 	_SCREAMING_SNAKE_CASE							(   self: Dict      ):

						'''simple docstring'''





						__magic_name__							=    ids_tensor([self.batch_size, self.seq_length]  , self.vocab_size      )
						__magic_name__							=    self.eos_token_id  # Eos Token
						__magic_name__							=    ids_tensor([self.batch_size, self.seq_length]  , self.vocab_size      )

						# we need to clamp the input ids here to avoid having pad token in between
						# this is because for M2M100 the position_ids are prepared such that
						# all pad tokens have pos id = 2 and rest are between 2..seq_length
						# and the seq_length here is seq_length - num_pad_tokens
						# but when using past, there is no way of knowing if the past input ids had
						# pad tokens in them, which results in incorrect seq_lenth and which in turn results in
						# position_ids being off by num_pad_tokens in past input
						__magic_name__							=    input_ids.clamp(self.pad_token_id + 1      )
						__magic_name__							=    decoder_input_ids.clamp(self.pad_token_id + 1      )

						__magic_name__							=    self.get_config()
						__magic_name__							=    prepare_mam_aaa_inputs_dict(__UpperCamelCase  , __UpperCamelCase  , __UpperCamelCase      )
						return config, inputs_dict







	def 	_SCREAMING_SNAKE_CASE							(   self: Optional[int]      ):

						'''simple docstring'''





						return MaMaaaConfig(
						    vocab_size=self.vocab_size  , d_model=self.hidden_size  , encoder_layers=self.num_hidden_layers  , decoder_layers=self.num_hidden_layers  , encoder_attention_heads=self.num_attention_heads  , decoder_attention_heads=self.num_attention_heads  , encoder_ffn_dim=self.intermediate_size  , decoder_ffn_dim=self.intermediate_size  , dropout=self.hidden_dropout_prob  , attention_dropout=self.attention_probs_dropout_prob  , encoder_layerdrop=self.encoder_layerdrop  , decoder_layerdrop=self.decoder_layerdrop  , max_position_embeddings=self.max_position_embeddings  , eos_token_id=self.eos_token_id  , bos_token_id=self.bos_token_id  , pad_token_id=self.pad_token_id  , )







	def 	_SCREAMING_SNAKE_CASE							(   self: Optional[Any]      ):

						'''simple docstring'''





						__magic_name__,	__magic_name__							=    self.prepare_config_and_inputs()
						return config, inputs_dict







	def 	_SCREAMING_SNAKE_CASE							(   self: Tuple  , __UpperCamelCase: Tuple  , __UpperCamelCase: Union[str, Any]      ):

						'''simple docstring'''





						__magic_name__							=    MaMaaaModel(config=__UpperCamelCase      ).get_decoder().to(__UpperCamelCase      ).eval()
						__magic_name__							=    inputs_dict['input_ids']
						__magic_name__							=    inputs_dict['attention_mask']
						__magic_name__							=    inputs_dict['head_mask']

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

						__magic_name__,	__magic_name__							=    outputs.to_tuple()

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

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

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

						# select random slice
						__magic_name__							=    ids_tensor((1,)  , output_from_past.shape[-1]      ).item()
						__magic_name__							=    output_from_no_past[:, -3:, random_slice_idx].detach()
						__magic_name__							=    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-2      )      )







	def 	_SCREAMING_SNAKE_CASE							(   self: Union[str, Any]  , __UpperCamelCase: Any  , __UpperCamelCase: int      ):

						'''simple docstring'''





						__magic_name__							=    MaMaaaModel(config=__UpperCamelCase      ).to(__UpperCamelCase      ).eval()
						__magic_name__							=    model(**__UpperCamelCase      )

						__magic_name__							=    outputs.encoder_last_hidden_state
						__magic_name__							=    outputs.last_hidden_state

						with tempfile.TemporaryDirectory() as tmpdirname:
											__magic_name__							=    model.get_encoder()
											encoder.save_pretrained(__UpperCamelCase      )
											__magic_name__							=    MaMaaaEncoder.from_pretrained(__UpperCamelCase      ).to(__UpperCamelCase      )

						__magic_name__							=    encoder(inputs_dict['input_ids']  , attention_mask=inputs_dict['attention_mask']      )[
						    0
						]

						self.parent.assertTrue((encoder_last_hidden_state_a - encoder_last_hidden_state).abs().max().item() < 1E-3      )

						with tempfile.TemporaryDirectory() as tmpdirname:
											__magic_name__							=    model.get_decoder()
											decoder.save_pretrained(__UpperCamelCase      )
											__magic_name__							=    MaMaaaDecoder.from_pretrained(__UpperCamelCase      ).to(__UpperCamelCase      )

						__magic_name__							=    decoder(
						    input_ids=inputs_dict['decoder_input_ids']  , attention_mask=inputs_dict['decoder_attention_mask']  , encoder_hidden_states=__UpperCamelCase  , encoder_attention_mask=inputs_dict['attention_mask']  , )[0]

						self.parent.assertTrue((last_hidden_state_a - last_hidden_state).abs().max().item() < 1E-3      )




@require_torch
class 				__UpperCamelCase				(					SCREAMING_SNAKE_CASE  ,						SCREAMING_SNAKE_CASE  ,						SCREAMING_SNAKE_CASE  ,						unittest.TestCase			):
	_lowercase  :   Tuple       				=  (
	    (
	        MaMaaaModel,
	        MaMaaaForConditionalGeneration,
	    )
	    if is_torch_available()
	    else ()
	)
	_lowercase  :   Dict       				=  (MaMaaaForConditionalGeneration,) if is_torch_available() else ()
	_lowercase  :   Tuple       				=  (
	    {
	        "conversational": MaMaaaForConditionalGeneration,
	        "feature-extraction": MaMaaaModel,
	        "summarization": MaMaaaForConditionalGeneration,
	        "text2text-generation": MaMaaaForConditionalGeneration,
	        "translation": MaMaaaForConditionalGeneration,
	    }
	    if is_torch_available()
	    else {}
	)
	_lowercase  :   List[str]       				=  True
	_lowercase  :   Dict       				=  True
	_lowercase  :   Union[str, Any]       				=  False
	_lowercase  :   List[Any]       				=  False







	def 	_SCREAMING_SNAKE_CASE							(   self: Dict  , __UpperCamelCase: Any  , __UpperCamelCase: Optional[Any]  , __UpperCamelCase: List[str]  , __UpperCamelCase: Optional[Any]  , __UpperCamelCase: Tuple      ):

						'''simple docstring'''





						if pipeline_test_casse_name == "TranslationPipelineTests":
											# Get `ValueError: Translation requires a `src_lang` and a `tgt_lang` for this model`.
											# `M2M100Config` was never used in pipeline tests: cannot create a simple tokenizer.
											return True

						return False







	def 	_SCREAMING_SNAKE_CASE							(   self: Tuple      ):

						'''simple docstring'''





						__magic_name__							=    MaMaaaModelTester(self      )
						__magic_name__							=    ConfigTester(self  , config_class=__UpperCamelCase      )







	def 	_SCREAMING_SNAKE_CASE							(   self: List[Any]      ):

						'''simple docstring'''





						self.config_tester.run_common_tests()







	def 	_SCREAMING_SNAKE_CASE							(   self: List[Any]      ):

						'''simple docstring'''





						__magic_name__,	__magic_name__							=    self.model_tester.prepare_config_and_inputs()
						for model_class in self.all_model_classes:
											__magic_name__							=    model_class(__UpperCamelCase      )

											with tempfile.TemporaryDirectory() as tmpdirname:
																model.save_pretrained(__UpperCamelCase      )
																__magic_name__,	__magic_name__							=    model_class.from_pretrained(__UpperCamelCase  , output_loading_info=__UpperCamelCase      )
											self.assertEqual(info['missing_keys']  , []      )







	def 	_SCREAMING_SNAKE_CASE							(   self: List[Any]      ):

						'''simple docstring'''





						__magic_name__							=    self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_decoder_model_past_large_inputs(*__UpperCamelCase      )







	def 	_SCREAMING_SNAKE_CASE							(   self: List[Any]      ):

						'''simple docstring'''





						__magic_name__							=    self.model_tester.prepare_config_and_inputs_for_common()
						self.model_tester.check_encoder_decoder_model_standalone(*__UpperCamelCase      )







	def 	_SCREAMING_SNAKE_CASE							(   self: List[str]      ):

						'''simple docstring'''





						__magic_name__,	__magic_name__							=    self.model_tester.prepare_config_and_inputs_for_common()

						for model_class in (MaMaaaModel, MaMaaaForConditionalGeneration):
											__magic_name__							=    model_class(__UpperCamelCase      )
											model.to(__UpperCamelCase      )
											model.eval()

											__magic_name__							=    copy.deepcopy(self._prepare_for_class(__UpperCamelCase  , __UpperCamelCase      )      )

											if not self.is_encoder_decoder:
																__magic_name__							=    inputs['input_ids']
																del inputs["input_ids"]
											else:
																__magic_name__							=    inputs['input_ids']
																__magic_name__							=    inputs.get('decoder_input_ids'  , __UpperCamelCase      )
																del inputs["input_ids"]
																inputs.pop('decoder_input_ids'  , __UpperCamelCase      )

											__magic_name__							=    model.get_input_embeddings()
											if not self.is_encoder_decoder:
																__magic_name__							=    wte(__UpperCamelCase      )
											else:
																__magic_name__							=    wte(__UpperCamelCase      )
																__magic_name__							=    wte(__UpperCamelCase      )

											with torch.no_grad():
																model(**__UpperCamelCase      )[0]







	def 	_SCREAMING_SNAKE_CASE							(   self: Union[str, Any]      ):

						'''simple docstring'''





						__magic_name__,	__magic_name__							=    self.model_tester.prepare_config_and_inputs()
						__magic_name__							=    input_dict['input_ids']
						__magic_name__							=    input_ids.ne(1      ).to(__UpperCamelCase      )
						__magic_name__							=    MaMaaaForConditionalGeneration(__UpperCamelCase      ).eval().to(__UpperCamelCase      )
						if torch_device == "cuda":
											model.half()
						model.generate(__UpperCamelCase  , attention_mask=__UpperCamelCase      )
						model.generate(num_beams=4  , do_sample=__UpperCamelCase  , early_stopping=__UpperCamelCase  , num_return_sequences=3      )




def 					_lowercase     (				a_				:					List[Any]				)				->	Union[str, Any]:




					'''simple docstring'''







					return torch.tensor(a_					,dtype=torch.long					,device=a_				)


A__						=							1e-4


@require_torch
@require_sentencepiece
@require_tokenizers
@slow
class 				__UpperCamelCase				(					unittest.TestCase			):







	@cached_property
	def 	_SCREAMING_SNAKE_CASE							(   self: Any      ):

						'''simple docstring'''





						return MaMaaaTokenizer.from_pretrained('facebook/m2m100_418M'      )







	def 	_SCREAMING_SNAKE_CASE							(   self: int      ):

						'''simple docstring'''





						__magic_name__							=    MaMaaaModel.from_pretrained('facebook/m2m100_418M'      ).to(__UpperCamelCase      )
						__magic_name__							=    _long_tensor([[12_80_28, 98, 12, 3_05_27, 27_32, 1_59, 77_55, 6_19_04, 3_91_44, 38, 2]]      )
						__magic_name__							=    _long_tensor([[2, 12_80_28, 98, 12, 3_05_27, 27_32, 1_59, 77_55, 6_19_04, 3_91_44, 38]]      )
						__magic_name__							=    prepare_mam_aaa_inputs_dict(model.config  , __UpperCamelCase  , __UpperCamelCase      )
						with torch.no_grad():
											__magic_name__							=    model(**__UpperCamelCase      )[0]
						__magic_name__							=    torch.Size((1, 11, 10_24)      )
						self.assertEqual(output.shape  , __UpperCamelCase      )
						# change to expected output here
						__magic_name__							=    torch.tensor(
						    [[-0.7780, -0.1676, 0.1038], [-6.7556, -1.3992, 0.0567], [-7.5383, -0.5920, -0.2779]]  , device=__UpperCamelCase      )
						self.assertTrue(torch.allclose(output[:, :3, :3]  , __UpperCamelCase  , atol=__UpperCamelCase      )      )







	def 	_SCREAMING_SNAKE_CASE							(   self: str      ):

						'''simple docstring'''





						__magic_name__							=    MaMaaaForConditionalGeneration.from_pretrained('facebook/m2m100_418M'      ).to(__UpperCamelCase      )

						# change to intended input
						__magic_name__							=    _long_tensor([[12_80_28, 98, 12, 3_05_27, 27_32, 1_59, 77_55, 6_19_04, 3_91_44, 38, 2]]      )
						__magic_name__							=    _long_tensor([[2, 12_80_28, 98, 12, 3_05_27, 27_32, 1_59, 77_55, 6_19_04, 3_91_44, 38]]      )
						__magic_name__							=    prepare_mam_aaa_inputs_dict(model.config  , __UpperCamelCase  , __UpperCamelCase      )
						with torch.no_grad():
											__magic_name__							=    model(**__UpperCamelCase      )[0]
						__magic_name__							=    torch.Size((1, 11, model.config.vocab_size)      )
						self.assertEqual(output.shape  , __UpperCamelCase      )
						# change to expected output here
						__magic_name__							=    torch.tensor(
						    [[-1.0448, -1.0411, 3.7992], [-3.2191, -3.2386, -1.3451], [-3.6210, -3.5993, 0.4925]]  , device=__UpperCamelCase      )
						self.assertTrue(torch.allclose(output[:, :3, :3]  , __UpperCamelCase  , atol=__UpperCamelCase      )      )







	def 	_SCREAMING_SNAKE_CASE							(   self: Union[str, Any]      ):

						'''simple docstring'''





						__magic_name__							=    MaMaaaForConditionalGeneration.from_pretrained('facebook/m2m100_418M'      ).to(__UpperCamelCase      )
						__magic_name__							=    MaMaaaTokenizer.from_pretrained('facebook/m2m100_418M'  , src_lang='fr'  , tgt_lang='en'      )

						__magic_name__							=    [
						    'L\'affaire NSA souligne l\'absence totale de débat sur le renseignement',
						    'Selon moi, il y a deux niveaux de réponse de la part du gouvernement français.',
						    'Lorsque François Hollande téléphone à Barack Obama ou quand le ministre des affaires étrangères Laurent'
						    ' Fabius convoque l\'ambassadeur des Etats-Unis, ils réagissent à une vraie découverte, qui est celle de'
						    ' l\'ampleur de la surveillance américaine sur l\'ensemble des communications en France.',
						]

						# The below article tests that we don't add any hypotheses outside of the top n_beams
						__magic_name__							=    tokenizer(__UpperCamelCase  , padding=__UpperCamelCase  , return_tensors='pt'      )

						__magic_name__							=    model.generate(
						    input_ids=dct['input_ids'].to(__UpperCamelCase      )  , attention_mask=dct['attention_mask'].to(__UpperCamelCase      )  , num_beams=5  , forced_bos_token_id=tokenizer.get_lang_id('en'      )  , )

						__magic_name__							=    [
						    'The NSA case highlights the total absence of intelligence debate',
						    'I think there are two levels of response from the French government.',
						    'When François Hollande calls Barack Obama or when Foreign Minister Laurent Fabius calls the U.S.'
						    ' Ambassador, they respond to a real discovery, which is that of the scale of U.S. surveillance on all'
						    ' communications in France.',
						]

						__magic_name__							=    tokenizer.batch_decode(
						    hypotheses_batch.tolist()  , clean_up_tokenization_spaces=__UpperCamelCase  , skip_special_tokens=__UpperCamelCase      )
						assert generated == expected_en




