

"""simple docstring"""




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 	UpperCAmelCase__   (				A__	,    A__	,    A__	,    A__=None	,    A__=None	,    A__=None	,    A__=None	,    A__=None	,    )      ->      Optional[int]:




   """simple docstring"""
   if attention_mask is None:
      lowerCamelCase__						=			input_ids.ne(config.pad_token_id   )
   if decoder_attention_mask is None:
      lowerCamelCase__						=			decoder_input_ids.ne(config.pad_token_id   )
   if head_mask is None:
      lowerCamelCase__						=			torch.ones(config.encoder_layers	,    config.encoder_attention_heads	,    device=A__   )
   if decoder_head_mask is None:
      lowerCamelCase__						=			torch.ones(config.decoder_layers	,    config.decoder_attention_heads	,    device=A__   )
   if cross_attn_head_mask is None:
      lowerCamelCase__						=			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 		_A       :





      def __init__(  self    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__=13    ,						SCREAMING_SNAKE_CASE__=7    ,						SCREAMING_SNAKE_CASE__=True    ,						SCREAMING_SNAKE_CASE__=False    ,						SCREAMING_SNAKE_CASE__=99    ,						SCREAMING_SNAKE_CASE__=16    ,						SCREAMING_SNAKE_CASE__=2    ,						SCREAMING_SNAKE_CASE__=4    ,						SCREAMING_SNAKE_CASE__=4    ,						SCREAMING_SNAKE_CASE__="relu"    ,						SCREAMING_SNAKE_CASE__=0.1    ,						SCREAMING_SNAKE_CASE__=0.1    ,						SCREAMING_SNAKE_CASE__=0.0    ,						SCREAMING_SNAKE_CASE__=0.0    ,						SCREAMING_SNAKE_CASE__=20    ,						SCREAMING_SNAKE_CASE__=2    ,						SCREAMING_SNAKE_CASE__=1    ,						SCREAMING_SNAKE_CASE__=0    ,						)   ->					str:
         lowerCamelCase__						=			parent
         lowerCamelCase__						=			batch_size
         lowerCamelCase__						=			seq_length
         lowerCamelCase__						=			is_training
         lowerCamelCase__						=			use_labels
         lowerCamelCase__						=			vocab_size
         lowerCamelCase__						=			hidden_size
         lowerCamelCase__						=			num_hidden_layers
         lowerCamelCase__						=			num_attention_heads
         lowerCamelCase__						=			intermediate_size
         lowerCamelCase__						=			hidden_act
         lowerCamelCase__						=			hidden_dropout_prob
         lowerCamelCase__						=			attention_probs_dropout_prob
         lowerCamelCase__						=			encoder_layerdrop
         lowerCamelCase__						=			decoder_layerdrop
         lowerCamelCase__						=			max_position_embeddings
         lowerCamelCase__						=			eos_token_id
         lowerCamelCase__						=			pad_token_id
         lowerCamelCase__						=			bos_token_id





      def 					_lowerCamelCase  (  self		)   ->					str:
         lowerCamelCase__						=			ids_tensor([self.batch_size, self.seq_length]    ,						self.vocab_size		)
         lowerCamelCase__						=			self.eos_token_id  # Eos Token
         lowerCamelCase__						=			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
         lowerCamelCase__						=			input_ids.clamp(self.pad_token_id + 1		)
         lowerCamelCase__						=			decoder_input_ids.clamp(self.pad_token_id + 1		)

         lowerCamelCase__						=			self.get_config()
         lowerCamelCase__						=			prepare_mam_aaa_inputs_dict(SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__		)
         return config, inputs_dict





      def 					_lowerCamelCase  (  self		)   ->					List[str]:
         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 					_lowerCamelCase  (  self		)   ->					Optional[Any]:
         lowerCamelCase__					,       lowerCamelCase__						=			self.prepare_config_and_inputs()
         return config, inputs_dict





      def 					_lowerCamelCase  (  self    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__		)   ->					List[Any]:
         lowerCamelCase__						=			MaMaaaModel(config=SCREAMING_SNAKE_CASE__		).get_decoder().to(SCREAMING_SNAKE_CASE__		).eval()
         lowerCamelCase__						=			inputs_dict["input_ids"]
         lowerCamelCase__						=			inputs_dict["attention_mask"]
         lowerCamelCase__						=			inputs_dict["head_mask"]

         # first forward pass
         lowerCamelCase__						=			model(SCREAMING_SNAKE_CASE__    ,						attention_mask=SCREAMING_SNAKE_CASE__    ,						head_mask=SCREAMING_SNAKE_CASE__    ,						use_cache=SCREAMING_SNAKE_CASE__		)

         lowerCamelCase__					,       lowerCamelCase__						=			outputs.to_tuple()

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

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

         lowerCamelCase__						=			model(SCREAMING_SNAKE_CASE__    ,						attention_mask=SCREAMING_SNAKE_CASE__		)["last_hidden_state"]
         lowerCamelCase__						=			model(SCREAMING_SNAKE_CASE__    ,						attention_mask=SCREAMING_SNAKE_CASE__    ,						past_key_values=SCREAMING_SNAKE_CASE__		)[
             "last_hidden_state"
         ]

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





      def 					_lowerCamelCase  (  self    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__		)   ->					List[str]:
         lowerCamelCase__						=			MaMaaaModel(config=SCREAMING_SNAKE_CASE__		).to(SCREAMING_SNAKE_CASE__		).eval()
         lowerCamelCase__						=			model(**SCREAMING_SNAKE_CASE__		)

         lowerCamelCase__						=			outputs.encoder_last_hidden_state
         lowerCamelCase__						=			outputs.last_hidden_state

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

         lowerCamelCase__						=			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:
            lowerCamelCase__						=			model.get_decoder()
            decoder.save_pretrained(SCREAMING_SNAKE_CASE__		)
            lowerCamelCase__						=			MaMaaaDecoder.from_pretrained(SCREAMING_SNAKE_CASE__		).to(SCREAMING_SNAKE_CASE__		)

         lowerCamelCase__						=			decoder(
             input_ids=inputs_dict["decoder_input_ids"]    ,						attention_mask=inputs_dict["decoder_attention_mask"]    ,						encoder_hidden_states=SCREAMING_SNAKE_CASE__    ,						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 		_A       (			__a				,       __a				,       __a				,       unittest.TestCase					):
      __a								=	(
          (
              MaMaaaModel,
              MaMaaaForConditionalGeneration,
          )
          if is_torch_available()
          else ()
      )
      __a								=	(MaMaaaForConditionalGeneration,) if is_torch_available() else ()
      __a								=	(
          {
              'conversational': MaMaaaForConditionalGeneration,
              'feature-extraction': MaMaaaModel,
              'summarization': MaMaaaForConditionalGeneration,
              'text2text-generation': MaMaaaForConditionalGeneration,
              'translation': MaMaaaForConditionalGeneration,
          }
          if is_torch_available()
          else {}
      )
      __a								=	True
      __a								=	True
      __a								=	False
      __a								=	False





      def 					_lowerCamelCase  (  self    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__		)   ->					Dict:
         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 					_lowerCamelCase  (  self		)   ->					Optional[Any]:
         lowerCamelCase__						=			MaMaaaModelTester(self		)
         lowerCamelCase__						=			ConfigTester(self    ,						config_class=SCREAMING_SNAKE_CASE__		)





      def 					_lowerCamelCase  (  self		)   ->					Optional[Any]:
         self.config_tester.run_common_tests()





      def 					_lowerCamelCase  (  self		)   ->					Optional[Any]:
         lowerCamelCase__					,       lowerCamelCase__						=			self.model_tester.prepare_config_and_inputs()
         for model_class in self.all_model_classes:
            lowerCamelCase__						=			model_class(SCREAMING_SNAKE_CASE__		)

            with tempfile.TemporaryDirectory() as tmpdirname:
               model.save_pretrained(SCREAMING_SNAKE_CASE__		)
               lowerCamelCase__					,       lowerCamelCase__						=			model_class.from_pretrained(SCREAMING_SNAKE_CASE__    ,						output_loading_info=SCREAMING_SNAKE_CASE__		)
            self.assertEqual(info["missing_keys"]    ,						[]		)





      def 					_lowerCamelCase  (  self		)   ->					str:
         lowerCamelCase__						=			self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_decoder_model_past_large_inputs(*SCREAMING_SNAKE_CASE__		)





      def 					_lowerCamelCase  (  self		)   ->					Union[str, Any]:
         lowerCamelCase__						=			self.model_tester.prepare_config_and_inputs_for_common()
         self.model_tester.check_encoder_decoder_model_standalone(*SCREAMING_SNAKE_CASE__		)





      def 					_lowerCamelCase  (  self		)   ->					Dict:
         lowerCamelCase__					,       lowerCamelCase__						=			self.model_tester.prepare_config_and_inputs_for_common()

         for model_class in (MaMaaaModel, MaMaaaForConditionalGeneration):
            lowerCamelCase__						=			model_class(SCREAMING_SNAKE_CASE__		)
            model.to(SCREAMING_SNAKE_CASE__		)
            model.eval()

            lowerCamelCase__						=			copy.deepcopy(self._prepare_for_class(SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__		)		)

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

            lowerCamelCase__						=			model.get_input_embeddings()
            if not self.is_encoder_decoder:
               lowerCamelCase__						=			wte(SCREAMING_SNAKE_CASE__		)
            else:
               lowerCamelCase__						=			wte(SCREAMING_SNAKE_CASE__		)
               lowerCamelCase__						=			wte(SCREAMING_SNAKE_CASE__		)

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





      def 					_lowerCamelCase  (  self		)   ->					Tuple:
         lowerCamelCase__					,       lowerCamelCase__						=			self.model_tester.prepare_config_and_inputs()
         lowerCamelCase__						=			input_dict["input_ids"]
         lowerCamelCase__						=			input_ids.ne(1		).to(SCREAMING_SNAKE_CASE__		)
         lowerCamelCase__						=			MaMaaaForConditionalGeneration(SCREAMING_SNAKE_CASE__		).eval().to(SCREAMING_SNAKE_CASE__		)
         if torch_device == "cuda":
            model.half()
         model.generate(SCREAMING_SNAKE_CASE__    ,						attention_mask=SCREAMING_SNAKE_CASE__		)
         model.generate(num_beams=4    ,						do_sample=SCREAMING_SNAKE_CASE__    ,						early_stopping=SCREAMING_SNAKE_CASE__    ,						num_return_sequences=3		)






def 	UpperCAmelCase__   (				A__   )      ->      Union[str, Any]:




   """simple docstring"""
   return torch.tensor(A__	,    dtype=torch.long	,    device=A__   )


SCREAMING_SNAKE_CASE_     :			int	  =			1e-4


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





      @cached_property
      def 					_lowerCamelCase  (  self		)   ->					Tuple:
         return MaMaaaTokenizer.from_pretrained("facebook/m2m100_418M"		)





      def 					_lowerCamelCase  (  self		)   ->					List[str]:
         lowerCamelCase__						=			MaMaaaModel.from_pretrained("facebook/m2m100_418M"		).to(SCREAMING_SNAKE_CASE__		)
         lowerCamelCase__						=			_long_tensor([[128028, 98, 12, 30527, 2732, 159, 7755, 61904, 39144, 38, 2]]		)
         lowerCamelCase__						=			_long_tensor([[2, 128028, 98, 12, 30527, 2732, 159, 7755, 61904, 39144, 38]]		)
         lowerCamelCase__						=			prepare_mam_aaa_inputs_dict(model.config    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__		)
         with torch.no_grad():
            lowerCamelCase__						=			model(**SCREAMING_SNAKE_CASE__		)[0]
         lowerCamelCase__						=			torch.Size((1, 11, 1024)		)
         self.assertEqual(output.shape    ,						SCREAMING_SNAKE_CASE__		)
         # change to expected output here
         lowerCamelCase__						=			torch.tensor(
             [[-0.77_80, -0.16_76, 0.10_38], [-6.75_56, -1.39_92, 0.05_67], [-7.53_83, -0.59_20, -0.27_79]]    ,						device=SCREAMING_SNAKE_CASE__		)
         self.assertTrue(torch.allclose(output[:, :3, :3]    ,						SCREAMING_SNAKE_CASE__    ,						atol=SCREAMING_SNAKE_CASE__		)		)





      def 					_lowerCamelCase  (  self		)   ->					List[str]:
         lowerCamelCase__						=			MaMaaaForConditionalGeneration.from_pretrained("facebook/m2m100_418M"		).to(SCREAMING_SNAKE_CASE__		)

         # change to intended input
         lowerCamelCase__						=			_long_tensor([[128028, 98, 12, 30527, 2732, 159, 7755, 61904, 39144, 38, 2]]		)
         lowerCamelCase__						=			_long_tensor([[2, 128028, 98, 12, 30527, 2732, 159, 7755, 61904, 39144, 38]]		)
         lowerCamelCase__						=			prepare_mam_aaa_inputs_dict(model.config    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__		)
         with torch.no_grad():
            lowerCamelCase__						=			model(**SCREAMING_SNAKE_CASE__		)[0]
         lowerCamelCase__						=			torch.Size((1, 11, model.config.vocab_size)		)
         self.assertEqual(output.shape    ,						SCREAMING_SNAKE_CASE__		)
         # change to expected output here
         lowerCamelCase__						=			torch.tensor(
             [[-1.04_48, -1.04_11, 3.79_92], [-3.21_91, -3.23_86, -1.34_51], [-3.62_10, -3.59_93, 0.49_25]]    ,						device=SCREAMING_SNAKE_CASE__		)
         self.assertTrue(torch.allclose(output[:, :3, :3]    ,						SCREAMING_SNAKE_CASE__    ,						atol=SCREAMING_SNAKE_CASE__		)		)





      def 					_lowerCamelCase  (  self		)   ->					str:
         lowerCamelCase__						=			MaMaaaForConditionalGeneration.from_pretrained("facebook/m2m100_418M"		).to(SCREAMING_SNAKE_CASE__		)
         lowerCamelCase__						=			MaMaaaTokenizer.from_pretrained("facebook/m2m100_418M"    ,						src_lang="fr"    ,						tgt_lang="en"		)

         lowerCamelCase__						=			[
             "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
         lowerCamelCase__						=			tokenizer(SCREAMING_SNAKE_CASE__    ,						padding=SCREAMING_SNAKE_CASE__    ,						return_tensors="pt"		)

         lowerCamelCase__						=			model.generate(
             input_ids=dct["input_ids"].to(SCREAMING_SNAKE_CASE__		)    ,						attention_mask=dct["attention_mask"].to(SCREAMING_SNAKE_CASE__		)    ,						num_beams=5    ,						forced_bos_token_id=tokenizer.get_lang_id("en"		)    ,						)

         lowerCamelCase__						=			[
             "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.",
         ]

         lowerCamelCase__						=			tokenizer.batch_decode(
             hypotheses_batch.tolist()    ,						clean_up_tokenization_spaces=SCREAMING_SNAKE_CASE__    ,						skip_special_tokens=SCREAMING_SNAKE_CASE__		)
         assert generated == expected_en







"""simple docstring"""




import os
from shutil import copyfile
from typing import List, Optional, Tuple

from tokenizers import processors

from ...tokenization_utils import AddedToken, BatchEncoding
from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import is_sentencepiece_available, logging


if is_sentencepiece_available():
     from .tokenization_nllb import NllbTokenizer
else:
     SCREAMING_SNAKE_CASE_     :			Dict	  =			None


SCREAMING_SNAKE_CASE_     :			int	  =			logging.get_logger(__name__)


SCREAMING_SNAKE_CASE_     :			int	  =			{'''vocab_file''': '''sentencepiece.bpe.model''', '''tokenizer_file''': '''tokenizer.json'''}

SCREAMING_SNAKE_CASE_     :			Optional[int]	  =			{
    '''vocab_file''': {
        '''facebook/nllb-200-distilled-600M''': (
            '''https://huggingface.co/facebook/nllb-200-distilled-600M/resolve/main/sentencepiece.bpe.model'''
        ),
    },
    '''tokenizer_file''': {
        '''facebook/nllb-200-distilled-600M''': (
            '''https://huggingface.co/facebook/nllb-200-distilled-600M/resolve/main/tokenizer.json'''
        ),
    },
}

SCREAMING_SNAKE_CASE_     :			Any	  =			{
    '''facebook/nllb-large-en-ro''': 1024,
    '''facebook/nllb-200-distilled-600M''': 1024,
}

# fmt: off
SCREAMING_SNAKE_CASE_     :			Optional[int]	  =			['''ace_Arab''', '''ace_Latn''', '''acm_Arab''', '''acq_Arab''', '''aeb_Arab''', '''afr_Latn''', '''ajp_Arab''', '''aka_Latn''', '''amh_Ethi''', '''apc_Arab''', '''arb_Arab''', '''ars_Arab''', '''ary_Arab''', '''arz_Arab''', '''asm_Beng''', '''ast_Latn''', '''awa_Deva''', '''ayr_Latn''', '''azb_Arab''', '''azj_Latn''', '''bak_Cyrl''', '''bam_Latn''', '''ban_Latn''', '''bel_Cyrl''', '''bem_Latn''', '''ben_Beng''', '''bho_Deva''', '''bjn_Arab''', '''bjn_Latn''', '''bod_Tibt''', '''bos_Latn''', '''bug_Latn''', '''bul_Cyrl''', '''cat_Latn''', '''ceb_Latn''', '''ces_Latn''', '''cjk_Latn''', '''ckb_Arab''', '''crh_Latn''', '''cym_Latn''', '''dan_Latn''', '''deu_Latn''', '''dik_Latn''', '''dyu_Latn''', '''dzo_Tibt''', '''ell_Grek''', '''eng_Latn''', '''epo_Latn''', '''est_Latn''', '''eus_Latn''', '''ewe_Latn''', '''fao_Latn''', '''pes_Arab''', '''fij_Latn''', '''fin_Latn''', '''fon_Latn''', '''fra_Latn''', '''fur_Latn''', '''fuv_Latn''', '''gla_Latn''', '''gle_Latn''', '''glg_Latn''', '''grn_Latn''', '''guj_Gujr''', '''hat_Latn''', '''hau_Latn''', '''heb_Hebr''', '''hin_Deva''', '''hne_Deva''', '''hrv_Latn''', '''hun_Latn''', '''hye_Armn''', '''ibo_Latn''', '''ilo_Latn''', '''ind_Latn''', '''isl_Latn''', '''ita_Latn''', '''jav_Latn''', '''jpn_Jpan''', '''kab_Latn''', '''kac_Latn''', '''kam_Latn''', '''kan_Knda''', '''kas_Arab''', '''kas_Deva''', '''kat_Geor''', '''knc_Arab''', '''knc_Latn''', '''kaz_Cyrl''', '''kbp_Latn''', '''kea_Latn''', '''khm_Khmr''', '''kik_Latn''', '''kin_Latn''', '''kir_Cyrl''', '''kmb_Latn''', '''kon_Latn''', '''kor_Hang''', '''kmr_Latn''', '''lao_Laoo''', '''lvs_Latn''', '''lij_Latn''', '''lim_Latn''', '''lin_Latn''', '''lit_Latn''', '''lmo_Latn''', '''ltg_Latn''', '''ltz_Latn''', '''lua_Latn''', '''lug_Latn''', '''luo_Latn''', '''lus_Latn''', '''mag_Deva''', '''mai_Deva''', '''mal_Mlym''', '''mar_Deva''', '''min_Latn''', '''mkd_Cyrl''', '''plt_Latn''', '''mlt_Latn''', '''mni_Beng''', '''khk_Cyrl''', '''mos_Latn''', '''mri_Latn''', '''zsm_Latn''', '''mya_Mymr''', '''nld_Latn''', '''nno_Latn''', '''nob_Latn''', '''npi_Deva''', '''nso_Latn''', '''nus_Latn''', '''nya_Latn''', '''oci_Latn''', '''gaz_Latn''', '''ory_Orya''', '''pag_Latn''', '''pan_Guru''', '''pap_Latn''', '''pol_Latn''', '''por_Latn''', '''prs_Arab''', '''pbt_Arab''', '''quy_Latn''', '''ron_Latn''', '''run_Latn''', '''rus_Cyrl''', '''sag_Latn''', '''san_Deva''', '''sat_Beng''', '''scn_Latn''', '''shn_Mymr''', '''sin_Sinh''', '''slk_Latn''', '''slv_Latn''', '''smo_Latn''', '''sna_Latn''', '''snd_Arab''', '''som_Latn''', '''sot_Latn''', '''spa_Latn''', '''als_Latn''', '''srd_Latn''', '''srp_Cyrl''', '''ssw_Latn''', '''sun_Latn''', '''swe_Latn''', '''swh_Latn''', '''szl_Latn''', '''tam_Taml''', '''tat_Cyrl''', '''tel_Telu''', '''tgk_Cyrl''', '''tgl_Latn''', '''tha_Thai''', '''tir_Ethi''', '''taq_Latn''', '''taq_Tfng''', '''tpi_Latn''', '''tsn_Latn''', '''tso_Latn''', '''tuk_Latn''', '''tum_Latn''', '''tur_Latn''', '''twi_Latn''', '''tzm_Tfng''', '''uig_Arab''', '''ukr_Cyrl''', '''umb_Latn''', '''urd_Arab''', '''uzn_Latn''', '''vec_Latn''', '''vie_Latn''', '''war_Latn''', '''wol_Latn''', '''xho_Latn''', '''ydd_Hebr''', '''yor_Latn''', '''yue_Hant''', '''zho_Hans''', '''zho_Hant''', '''zul_Latn''']


class 		_A       (			__a					):
      __a								=	VOCAB_FILES_NAMES
      __a								=	PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
      __a								=	PRETRAINED_VOCAB_FILES_MAP
      __a								=	['input_ids', 'attention_mask']
      __a								=	NllbTokenizer

      __a								=	[]
      __a								=	[]





      def __init__(  self    ,						SCREAMING_SNAKE_CASE__=None    ,						SCREAMING_SNAKE_CASE__=None    ,						SCREAMING_SNAKE_CASE__="<s>"    ,						SCREAMING_SNAKE_CASE__="</s>"    ,						SCREAMING_SNAKE_CASE__="</s>"    ,						SCREAMING_SNAKE_CASE__="<s>"    ,						SCREAMING_SNAKE_CASE__="<unk>"    ,						SCREAMING_SNAKE_CASE__="<pad>"    ,						SCREAMING_SNAKE_CASE__="<mask>"    ,						SCREAMING_SNAKE_CASE__=None    ,						SCREAMING_SNAKE_CASE__=None    ,						SCREAMING_SNAKE_CASE__=None    ,						SCREAMING_SNAKE_CASE__=False    ,						**SCREAMING_SNAKE_CASE__    ,						)   ->					Any:
         # Mask token behave like a normal word, i.e. include the space before it
         lowerCamelCase__						=			AddedToken(SCREAMING_SNAKE_CASE__    ,						lstrip=SCREAMING_SNAKE_CASE__    ,						rstrip=SCREAMING_SNAKE_CASE__		) if isinstance(SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__		) else mask_token
         lowerCamelCase__						=			legacy_behaviour
         super().__init__(
             vocab_file=SCREAMING_SNAKE_CASE__    ,						tokenizer_file=SCREAMING_SNAKE_CASE__    ,						bos_token=SCREAMING_SNAKE_CASE__    ,						eos_token=SCREAMING_SNAKE_CASE__    ,						sep_token=SCREAMING_SNAKE_CASE__    ,						cls_token=SCREAMING_SNAKE_CASE__    ,						unk_token=SCREAMING_SNAKE_CASE__    ,						pad_token=SCREAMING_SNAKE_CASE__    ,						mask_token=SCREAMING_SNAKE_CASE__    ,						src_lang=SCREAMING_SNAKE_CASE__    ,						tgt_lang=SCREAMING_SNAKE_CASE__    ,						additional_special_tokens=SCREAMING_SNAKE_CASE__    ,						legacy_behaviour=SCREAMING_SNAKE_CASE__    ,						**SCREAMING_SNAKE_CASE__    ,						)

         lowerCamelCase__						=			vocab_file
         lowerCamelCase__						=			False if not self.vocab_file else True

         lowerCamelCase__						=			FAIRSEQ_LANGUAGE_CODES.copy()

         if additional_special_tokens is not None:
            # Only add those special tokens if they are not already there.
            _additional_special_tokens.extend(
                [t for t in additional_special_tokens if t not in _additional_special_tokens]		)

         self.add_special_tokens({"additional_special_tokens": _additional_special_tokens}		)
         lowerCamelCase__						=			{
             lang_code: self.convert_tokens_to_ids(SCREAMING_SNAKE_CASE__		) for lang_code in FAIRSEQ_LANGUAGE_CODES
         }

         lowerCamelCase__						=			src_lang if src_lang is not None else "eng_Latn"
         lowerCamelCase__						=			self.convert_tokens_to_ids(self._src_lang		)
         lowerCamelCase__						=			tgt_lang
         self.set_src_lang_special_tokens(self._src_lang		)





      @property
      def 					_lowerCamelCase  (  self		)   ->					str:
         return self._src_lang





      @src_lang.setter
      def 					_lowerCamelCase  (  self    ,						SCREAMING_SNAKE_CASE__		)   ->					None:
         lowerCamelCase__						=			new_src_lang
         self.set_src_lang_special_tokens(self._src_lang		)





      def 					_lowerCamelCase  (  self    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__ = None		)   ->					List[int]:
         if token_ids_a is None:
            return self.prefix_tokens + token_ids_a + self.suffix_tokens
         # We don't expect to process pairs, but leave the pair logic for API consistency
         return self.prefix_tokens + token_ids_a + token_ids_a + self.suffix_tokens





      def 					_lowerCamelCase  (  self    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__ = None		)   ->					List[int]:
         lowerCamelCase__						=			[self.sep_token_id]
         lowerCamelCase__						=			[self.cls_token_id]

         if token_ids_a is None:
            return len(cls + token_ids_a + sep		) * [0]
         return len(cls + token_ids_a + sep + sep + token_ids_a + sep		) * [0]





      def 					_lowerCamelCase  (  self    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__    ,						**SCREAMING_SNAKE_CASE__		)   ->					Any:
         if src_lang is None or tgt_lang is None:
            raise ValueError("Translation requires a `src_lang` and a `tgt_lang` for this model"		)
         lowerCamelCase__						=			src_lang
         lowerCamelCase__						=			self(SCREAMING_SNAKE_CASE__    ,						add_special_tokens=SCREAMING_SNAKE_CASE__    ,						return_tensors=SCREAMING_SNAKE_CASE__    ,						**SCREAMING_SNAKE_CASE__		)
         lowerCamelCase__						=			self.convert_tokens_to_ids(SCREAMING_SNAKE_CASE__		)
         lowerCamelCase__						=			tgt_lang_id
         return inputs





      def 					_lowerCamelCase  (  self    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__ = "eng_Latn"    ,						SCREAMING_SNAKE_CASE__ = None    ,						SCREAMING_SNAKE_CASE__ = "fra_Latn"    ,						**SCREAMING_SNAKE_CASE__    ,						)   ->					BatchEncoding:
         lowerCamelCase__						=			src_lang
         lowerCamelCase__						=			tgt_lang
         return super().prepare_seqaseq_batch(SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__    ,						**SCREAMING_SNAKE_CASE__		)





      def 					_lowerCamelCase  (  self		)   ->					Any:
         return self.set_src_lang_special_tokens(self.src_lang		)





      def 					_lowerCamelCase  (  self		)   ->					Tuple:
         return self.set_tgt_lang_special_tokens(self.tgt_lang		)





      def 					_lowerCamelCase  (  self    ,						SCREAMING_SNAKE_CASE__		)   ->					None:
         lowerCamelCase__						=			self.convert_tokens_to_ids(SCREAMING_SNAKE_CASE__		)

         if self.legacy_behaviour:
            lowerCamelCase__						=			[]
            lowerCamelCase__						=			[self.eos_token_id, self.cur_lang_code]
         else:
            lowerCamelCase__						=			[self.cur_lang_code]
            lowerCamelCase__						=			[self.eos_token_id]

         lowerCamelCase__						=			self.convert_ids_to_tokens(self.prefix_tokens		)
         lowerCamelCase__						=			self.convert_ids_to_tokens(self.suffix_tokens		)

         lowerCamelCase__						=			processors.TemplateProcessing(
             single=prefix_tokens_str + ["$A"] + suffix_tokens_str    ,						pair=prefix_tokens_str + ["$A", "$B"] + suffix_tokens_str    ,						special_tokens=list(zip(prefix_tokens_str + suffix_tokens_str    ,						self.prefix_tokens + self.suffix_tokens		)		)    ,						)





      def 					_lowerCamelCase  (  self    ,						SCREAMING_SNAKE_CASE__		)   ->					None:
         lowerCamelCase__						=			self.convert_tokens_to_ids(SCREAMING_SNAKE_CASE__		)
         if self.legacy_behaviour:
            lowerCamelCase__						=			[]
            lowerCamelCase__						=			[self.eos_token_id, self.cur_lang_code]
         else:
            lowerCamelCase__						=			[self.cur_lang_code]
            lowerCamelCase__						=			[self.eos_token_id]

         lowerCamelCase__						=			self.convert_ids_to_tokens(self.prefix_tokens		)
         lowerCamelCase__						=			self.convert_ids_to_tokens(self.suffix_tokens		)

         lowerCamelCase__						=			processors.TemplateProcessing(
             single=prefix_tokens_str + ["$A"] + suffix_tokens_str    ,						pair=prefix_tokens_str + ["$A", "$B"] + suffix_tokens_str    ,						special_tokens=list(zip(prefix_tokens_str + suffix_tokens_str    ,						self.prefix_tokens + self.suffix_tokens		)		)    ,						)





      def 					_lowerCamelCase  (  self    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__ = None		)   ->					Tuple[str]:
         if not self.can_save_slow_tokenizer:
            raise ValueError(
                "Your fast tokenizer does not have the necessary information to save the vocabulary for a slow "
                "tokenizer."		)

         if not os.path.isdir(SCREAMING_SNAKE_CASE__		):
            logger.error(f'Vocabulary path ({save_directory}) should be a directory.'		)
            return
         lowerCamelCase__						=			os.path.join(
             SCREAMING_SNAKE_CASE__    ,						(filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["vocab_file"]		)

         if os.path.abspath(self.vocab_file		) != os.path.abspath(SCREAMING_SNAKE_CASE__		):
            copyfile(self.vocab_file    ,						SCREAMING_SNAKE_CASE__		)

         return (out_vocab_file,)




