

"""simple docstring"""




import inspect
import unittest

import numpy as np

from tests.test_modeling_common import floats_tensor
from transformers import MaskaFormerConfig, is_torch_available, is_vision_available
from transformers.testing_utils import require_torch, require_torch_multi_gpu, require_vision, slow, torch_device
from transformers.utils import cached_property

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
     import torch

     from transformers import MaskaFormerForUniversalSegmentation, MaskaFormerModel

     if is_vision_available():
          from transformers import MaskaFormerImageProcessor

if is_vision_available():
     from PIL import Image


class 		_A       :





      def __init__(  self    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__=2    ,						SCREAMING_SNAKE_CASE__=True    ,						SCREAMING_SNAKE_CASE__=False    ,						SCREAMING_SNAKE_CASE__=10    ,						SCREAMING_SNAKE_CASE__=3    ,						SCREAMING_SNAKE_CASE__=32 * 8    ,						SCREAMING_SNAKE_CASE__=32 * 8    ,						SCREAMING_SNAKE_CASE__=4    ,						SCREAMING_SNAKE_CASE__=64    ,						)   ->					List[Any]:
         lowerCamelCase__						=			parent
         lowerCamelCase__						=			batch_size
         lowerCamelCase__						=			is_training
         lowerCamelCase__						=			use_auxiliary_loss
         lowerCamelCase__						=			num_queries
         lowerCamelCase__						=			num_channels
         lowerCamelCase__						=			min_size
         lowerCamelCase__						=			max_size
         lowerCamelCase__						=			num_labels
         lowerCamelCase__						=			hidden_dim
         lowerCamelCase__						=			hidden_dim





      def 					_lowerCamelCase  (  self		)   ->					int:
         lowerCamelCase__						=			floats_tensor([self.batch_size, self.num_channels, self.min_size, self.max_size]		).to(
             _SCREAMING_SNAKE_CASE		)

         lowerCamelCase__						=			torch.ones([self.batch_size, self.min_size, self.max_size]    ,						device=_SCREAMING_SNAKE_CASE		)

         lowerCamelCase__						=			(
             torch.rand([self.batch_size, self.num_labels, self.min_size, self.max_size]    ,						device=_SCREAMING_SNAKE_CASE		) > 0.5
         ).float()
         lowerCamelCase__						=			(torch.rand((self.batch_size, self.num_labels)    ,						device=_SCREAMING_SNAKE_CASE		) > 0.5).long()

         lowerCamelCase__						=			self.get_config()
         return config, pixel_values, pixel_mask, mask_labels, class_labels





      def 					_lowerCamelCase  (  self		)   ->					Optional[Any]:
         lowerCamelCase__						=			MaskaFormerConfig(
             hidden_size=self.hidden_dim    ,						)
         lowerCamelCase__						=			self.num_queries
         lowerCamelCase__						=			self.num_labels

         lowerCamelCase__						=			[1, 1, 1, 1]
         lowerCamelCase__						=			self.num_channels

         lowerCamelCase__						=			64
         lowerCamelCase__						=			128
         lowerCamelCase__						=			self.hidden_dim
         lowerCamelCase__						=			self.hidden_dim
         lowerCamelCase__						=			self.hidden_dim
         return config





      def 					_lowerCamelCase  (  self		)   ->					str:
         lowerCamelCase__					,       lowerCamelCase__					,       lowerCamelCase__					,       lowerCamelCase__					,       lowerCamelCase__						=			self.prepare_config_and_inputs()
         lowerCamelCase__						=			{"pixel_values": pixel_values, "pixel_mask": pixel_mask}
         return config, inputs_dict





      def 					_lowerCamelCase  (  self    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__		)   ->					Union[str, Any]:
         lowerCamelCase__						=			output.encoder_hidden_states
         lowerCamelCase__						=			output.pixel_decoder_hidden_states
         lowerCamelCase__						=			output.transformer_decoder_hidden_states

         self.parent.assertTrue(len(_SCREAMING_SNAKE_CASE		)    ,						len(config.backbone_config.depths		)		)
         self.parent.assertTrue(len(_SCREAMING_SNAKE_CASE		)    ,						len(config.backbone_config.depths		)		)
         self.parent.assertTrue(len(_SCREAMING_SNAKE_CASE		)    ,						config.decoder_layers		)





      def 					_lowerCamelCase  (  self    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__=False		)   ->					Tuple:






         with torch.no_grad():
            lowerCamelCase__						=			MaskaFormerModel(config=_SCREAMING_SNAKE_CASE		)
            model.to(_SCREAMING_SNAKE_CASE		)
            model.eval()

            lowerCamelCase__						=			model(pixel_values=_SCREAMING_SNAKE_CASE    ,						pixel_mask=_SCREAMING_SNAKE_CASE		)
            lowerCamelCase__						=			model(_SCREAMING_SNAKE_CASE    ,						output_hidden_states=_SCREAMING_SNAKE_CASE		)

         self.parent.assertEqual(
             output.transformer_decoder_last_hidden_state.shape    ,						(self.batch_size, self.num_queries, self.hidden_dim)    ,						)
         # let's ensure the other two hidden state exists
         self.parent.assertTrue(output.pixel_decoder_last_hidden_state is not None		)
         self.parent.assertTrue(output.encoder_last_hidden_state is not None		)

         if output_hidden_states:
            self.check_output_hidden_state(_SCREAMING_SNAKE_CASE    ,						_SCREAMING_SNAKE_CASE		)





      def 					_lowerCamelCase  (  self    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__		)   ->					List[Any]:
         lowerCamelCase__						=			MaskaFormerForUniversalSegmentation(config=_SCREAMING_SNAKE_CASE		)
         model.to(_SCREAMING_SNAKE_CASE		)
         model.eval()

         def comm_check_on_output(SCREAMING_SNAKE_CASE__		):
            # let's still check that all the required stuff is there
            self.parent.assertTrue(result.transformer_decoder_last_hidden_state is not None		)
            self.parent.assertTrue(result.pixel_decoder_last_hidden_state is not None		)
            self.parent.assertTrue(result.encoder_last_hidden_state is not None		)
            # okay, now we need to check the logits shape
            # due to the encoder compression, masks have a //4 spatial size
            self.parent.assertEqual(
                result.masks_queries_logits.shape    ,						(self.batch_size, self.num_queries, self.min_size // 4, self.max_size // 4)    ,						)
            # + 1 for null class
            self.parent.assertEqual(
                result.class_queries_logits.shape    ,						(self.batch_size, self.num_queries, self.num_labels + 1)		)

         with torch.no_grad():
            lowerCamelCase__						=			model(pixel_values=_SCREAMING_SNAKE_CASE    ,						pixel_mask=_SCREAMING_SNAKE_CASE		)
            lowerCamelCase__						=			model(_SCREAMING_SNAKE_CASE		)

            comm_check_on_output(_SCREAMING_SNAKE_CASE		)

            lowerCamelCase__						=			model(
                pixel_values=_SCREAMING_SNAKE_CASE    ,						pixel_mask=_SCREAMING_SNAKE_CASE    ,						mask_labels=_SCREAMING_SNAKE_CASE    ,						class_labels=_SCREAMING_SNAKE_CASE		)

         comm_check_on_output(_SCREAMING_SNAKE_CASE		)

         self.parent.assertTrue(result.loss is not None		)
         self.parent.assertEqual(result.loss.shape    ,						torch.Size([1]		)		)






@require_torch
class 		_A       (			__a				,       __a				,       unittest.TestCase					):
      __a								=	(MaskaFormerModel, MaskaFormerForUniversalSegmentation) if is_torch_available() else ()
      __a								=	{'feature-extraction': MaskaFormerModel} if is_torch_available() else {}

      __a								=	False
      __a								=	False
      __a								=	False
      __a								=	False





      def 					_lowerCamelCase  (  self		)   ->					List[str]:
         lowerCamelCase__						=			MaskaFormerModelTester(self		)
         lowerCamelCase__						=			ConfigTester(self    ,						config_class=_SCREAMING_SNAKE_CASE    ,						has_text_modality=_SCREAMING_SNAKE_CASE		)





      def 					_lowerCamelCase  (  self		)   ->					Tuple:
         self.config_tester.run_common_tests()





      def 					_lowerCamelCase  (  self		)   ->					List[Any]:
         lowerCamelCase__					,       lowerCamelCase__						=			self.model_tester.prepare_config_and_inputs_for_common()
         self.model_tester.create_and_check_maskaformer_model(_SCREAMING_SNAKE_CASE    ,						**_SCREAMING_SNAKE_CASE    ,						output_hidden_states=_SCREAMING_SNAKE_CASE		)





      def 					_lowerCamelCase  (  self		)   ->					Tuple:
         lowerCamelCase__						=			self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_maskaformer_instance_segmentation_head_model(*_SCREAMING_SNAKE_CASE		)





      @unittest.skip(reason="Mask2Former does not use inputs_embeds"		)
      def 					_lowerCamelCase  (  self		)   ->					Any:
         pass





      @unittest.skip(reason="Mask2Former does not have a get_input_embeddings method"		)
      def 					_lowerCamelCase  (  self		)   ->					Tuple:
         pass





      @unittest.skip(reason="Mask2Former is not a generative model"		)
      def 					_lowerCamelCase  (  self		)   ->					Dict:
         pass





      @unittest.skip(reason="Mask2Former does not use token embeddings"		)
      def 					_lowerCamelCase  (  self		)   ->					Tuple:
         pass





      @require_torch_multi_gpu
      @unittest.skip(
          reason="Mask2Former has some layers using `add_module` which doesn't work well with `nn.DataParallel`"		)
      def 					_lowerCamelCase  (  self		)   ->					str:
         pass





      @unittest.skip("Will be fixed soon by reducing the size of the model used for common tests."		)
      def 					_lowerCamelCase  (  self		)   ->					Optional[int]:
         pass





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

         for model_class in self.all_model_classes:
            lowerCamelCase__						=			model_class(_SCREAMING_SNAKE_CASE		)
            lowerCamelCase__						=			inspect.signature(model.forward		)
            # signature.parameters is an OrderedDict => so arg_names order is deterministic
            lowerCamelCase__						=			[*signature.parameters.keys()]

            lowerCamelCase__						=			["pixel_values"]
            self.assertListEqual(arg_names[:1]    ,						_SCREAMING_SNAKE_CASE		)





      @slow
      def 					_lowerCamelCase  (  self		)   ->					str:






         for model_name in ["facebook/mask2former-swin-small-coco-instance"]:
            lowerCamelCase__						=			MaskaFormerModel.from_pretrained(_SCREAMING_SNAKE_CASE		)
            self.assertIsNotNone(_SCREAMING_SNAKE_CASE		)





      def 					_lowerCamelCase  (  self		)   ->					int:
         lowerCamelCase__						=			(self.model_tester.min_size,) * 2
         lowerCamelCase__						=			{
             "pixel_values": torch.randn((2, 3, *size)    ,						device=_SCREAMING_SNAKE_CASE		),
             "mask_labels": torch.randn((2, 10, *size)    ,						device=_SCREAMING_SNAKE_CASE		),
             "class_labels": torch.zeros(2    ,						10    ,						device=_SCREAMING_SNAKE_CASE		).long(),
         }
         lowerCamelCase__						=			self.model_tester.get_config()

         lowerCamelCase__						=			MaskaFormerForUniversalSegmentation(_SCREAMING_SNAKE_CASE		).to(_SCREAMING_SNAKE_CASE		)
         lowerCamelCase__						=			model(**_SCREAMING_SNAKE_CASE		)
         self.assertTrue(outputs.loss is not None		)





      def 					_lowerCamelCase  (  self		)   ->					Dict:
         lowerCamelCase__					,       lowerCamelCase__						=			self.model_tester.prepare_config_and_inputs_for_common()
         self.model_tester.create_and_check_maskaformer_model(_SCREAMING_SNAKE_CASE    ,						**_SCREAMING_SNAKE_CASE    ,						output_hidden_states=_SCREAMING_SNAKE_CASE		)





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

         for model_class in self.all_model_classes:
            lowerCamelCase__						=			model_class(_SCREAMING_SNAKE_CASE		).to(_SCREAMING_SNAKE_CASE		)
            lowerCamelCase__						=			model(**_SCREAMING_SNAKE_CASE    ,						output_attentions=_SCREAMING_SNAKE_CASE		)
            self.assertTrue(outputs.attentions is not None		)





      def 					_lowerCamelCase  (  self		)   ->					Dict:






         if not self.model_tester.is_training:
            return

         lowerCamelCase__						=			self.all_model_classes[1]
         lowerCamelCase__					,       lowerCamelCase__					,       lowerCamelCase__					,       lowerCamelCase__					,       lowerCamelCase__						=			self.model_tester.prepare_config_and_inputs()

         lowerCamelCase__						=			model_class(_SCREAMING_SNAKE_CASE		)
         model.to(_SCREAMING_SNAKE_CASE		)
         model.train()

         lowerCamelCase__						=			model(_SCREAMING_SNAKE_CASE    ,						mask_labels=_SCREAMING_SNAKE_CASE    ,						class_labels=_SCREAMING_SNAKE_CASE		).loss
         loss.backward()





      def 					_lowerCamelCase  (  self		)   ->					str:
         lowerCamelCase__						=			self.all_model_classes[1]
         lowerCamelCase__					,       lowerCamelCase__					,       lowerCamelCase__					,       lowerCamelCase__					,       lowerCamelCase__						=			self.model_tester.prepare_config_and_inputs()
         lowerCamelCase__						=			True
         lowerCamelCase__						=			True

         lowerCamelCase__						=			model_class(_SCREAMING_SNAKE_CASE		).to(_SCREAMING_SNAKE_CASE		)
         model.train()

         lowerCamelCase__						=			model(_SCREAMING_SNAKE_CASE    ,						mask_labels=_SCREAMING_SNAKE_CASE    ,						class_labels=_SCREAMING_SNAKE_CASE		)

         lowerCamelCase__						=			outputs.encoder_hidden_states[0]
         encoder_hidden_states.retain_grad()

         lowerCamelCase__						=			outputs.pixel_decoder_hidden_states[0]
         pixel_decoder_hidden_states.retain_grad()

         lowerCamelCase__						=			outputs.transformer_decoder_hidden_states[0]
         transformer_decoder_hidden_states.retain_grad()

         lowerCamelCase__						=			outputs.attentions[0]
         attentions.retain_grad()

         outputs.loss.backward(retain_graph=_SCREAMING_SNAKE_CASE		)

         self.assertIsNotNone(encoder_hidden_states.grad		)
         self.assertIsNotNone(pixel_decoder_hidden_states.grad		)
         self.assertIsNotNone(transformer_decoder_hidden_states.grad		)
         self.assertIsNotNone(attentions.grad		)






SCREAMING_SNAKE_CASE_     :			Any	  =     1e-4



def 	UpperCAmelCase__   (				)      ->      Dict:




   """simple docstring"""
   lowerCamelCase__						=			Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"   )
   return image


@require_vision
@slow
class 		_A       (			unittest.TestCase					):





      @cached_property
      def 					_lowerCamelCase  (  self		)   ->					Any:
         return "facebook/mask2former-swin-small-coco-instance"





      @cached_property
      def 					_lowerCamelCase  (  self		)   ->					Any:
         return MaskaFormerImageProcessor.from_pretrained(self.model_checkpoints		) if is_vision_available() else None





      def 					_lowerCamelCase  (  self		)   ->					Optional[Any]:
         lowerCamelCase__						=			MaskaFormerModel.from_pretrained(self.model_checkpoints		).to(_SCREAMING_SNAKE_CASE		)
         lowerCamelCase__						=			self.default_image_processor
         lowerCamelCase__						=			prepare_img()
         lowerCamelCase__						=			image_processor(_SCREAMING_SNAKE_CASE    ,						return_tensors="pt"		).to(_SCREAMING_SNAKE_CASE		)
         lowerCamelCase__						=			inputs["pixel_values"].shape
         # check size is divisible by 32
         self.assertTrue((inputs_shape[-1] % 32) == 0 and (inputs_shape[-2] % 32) == 0		)
         # check size
         self.assertEqual(_SCREAMING_SNAKE_CASE    ,						(1, 3, 384, 384)		)

         with torch.no_grad():
            lowerCamelCase__						=			model(**_SCREAMING_SNAKE_CASE		)

         lowerCamelCase__						=			torch.tensor(
             [[-0.27_90, -1.07_17, -1.16_68], [-0.51_28, -0.31_28, -0.49_87], [-0.58_32, 0.19_71, -0.01_97]]		).to(_SCREAMING_SNAKE_CASE		)
         self.assertTrue(
             torch.allclose(
                 outputs.encoder_last_hidden_state[0, 0, :3, :3]    ,						_SCREAMING_SNAKE_CASE    ,						atol=_SCREAMING_SNAKE_CASE		)		)

         lowerCamelCase__						=			torch.tensor(
             [[0.89_73, 1.18_47, 1.17_76], [1.19_34, 1.50_40, 1.51_28], [1.11_53, 1.44_86, 1.49_51]]		).to(_SCREAMING_SNAKE_CASE		)
         self.assertTrue(
             torch.allclose(
                 outputs.pixel_decoder_last_hidden_state[0, 0, :3, :3]    ,						_SCREAMING_SNAKE_CASE    ,						atol=_SCREAMING_SNAKE_CASE		)		)

         lowerCamelCase__						=			torch.tensor(
             [[2.11_52, 1.70_00, -0.86_03], [1.58_08, 1.80_04, -0.93_53], [1.60_43, 1.74_95, -0.59_99]]		).to(_SCREAMING_SNAKE_CASE		)
         self.assertTrue(
             torch.allclose(
                 outputs.transformer_decoder_last_hidden_state[0, :3, :3]    ,						_SCREAMING_SNAKE_CASE    ,						atol=_SCREAMING_SNAKE_CASE		)		)





      def 					_lowerCamelCase  (  self		)   ->					Any:
         lowerCamelCase__						=			MaskaFormerForUniversalSegmentation.from_pretrained(self.model_checkpoints		).to(_SCREAMING_SNAKE_CASE		).eval()
         lowerCamelCase__						=			self.default_image_processor
         lowerCamelCase__						=			prepare_img()
         lowerCamelCase__						=			image_processor(_SCREAMING_SNAKE_CASE    ,						return_tensors="pt"		).to(_SCREAMING_SNAKE_CASE		)
         lowerCamelCase__						=			inputs["pixel_values"].shape
         # check size is divisible by 32
         self.assertTrue((inputs_shape[-1] % 32) == 0 and (inputs_shape[-2] % 32) == 0		)
         # check size
         self.assertEqual(_SCREAMING_SNAKE_CASE    ,						(1, 3, 384, 384)		)

         with torch.no_grad():
            lowerCamelCase__						=			model(**_SCREAMING_SNAKE_CASE		)
         # masks_queries_logits
         lowerCamelCase__						=			outputs.masks_queries_logits
         self.assertEqual(
             masks_queries_logits.shape    ,						(1, model.config.num_queries, inputs_shape[-2] // 4, inputs_shape[-1] // 4)		)
         lowerCamelCase__						=			[
             [-8.78_39, -9.00_56, -8.81_21],
             [-7.41_04, -7.03_13, -6.54_01],
             [-6.61_05, -6.34_27, -6.46_75],
         ]
         lowerCamelCase__						=			torch.tensor(_SCREAMING_SNAKE_CASE		).to(_SCREAMING_SNAKE_CASE		)
         self.assertTrue(torch.allclose(masks_queries_logits[0, 0, :3, :3]    ,						_SCREAMING_SNAKE_CASE    ,						atol=_SCREAMING_SNAKE_CASE		)		)
         # class_queries_logits
         lowerCamelCase__						=			outputs.class_queries_logits
         self.assertEqual(class_queries_logits.shape    ,						(1, model.config.num_queries, model.config.num_labels + 1)		)
         lowerCamelCase__						=			torch.tensor(
             [
                 [1.83_24, -8.08_35, -4.19_22],
                 [0.84_50, -9.00_50, -3.60_53],
                 [0.30_45, -7.72_93, -3.02_75],
             ]		).to(_SCREAMING_SNAKE_CASE		)
         self.assertTrue(torch.allclose(outputs.class_queries_logits[0, :3, :3]    ,						_SCREAMING_SNAKE_CASE    ,						atol=_SCREAMING_SNAKE_CASE		)		)





      def 					_lowerCamelCase  (  self		)   ->					List[str]:
         lowerCamelCase__						=			MaskaFormerForUniversalSegmentation.from_pretrained(self.model_checkpoints		).to(_SCREAMING_SNAKE_CASE		).eval()
         lowerCamelCase__						=			self.default_image_processor

         lowerCamelCase__						=			image_processor(
             [np.zeros((3, 800, 1333)		), np.zeros((3, 800, 1333)		)]    ,						segmentation_maps=[np.zeros((384, 384)		).astype(np.floataa		), np.zeros((384, 384)		).astype(np.floataa		)]    ,						return_tensors="pt"    ,						)

         lowerCamelCase__						=			inputs["pixel_values"].to(_SCREAMING_SNAKE_CASE		)
         lowerCamelCase__						=			[el.to(_SCREAMING_SNAKE_CASE		) for el in inputs["mask_labels"]]
         lowerCamelCase__						=			[el.to(_SCREAMING_SNAKE_CASE		) for el in inputs["class_labels"]]

         with torch.no_grad():
            lowerCamelCase__						=			model(**_SCREAMING_SNAKE_CASE		)

         self.assertTrue(outputs.loss is not None		)







"""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,)




