



'''simple docstring'''
import inspect
import unittest

from transformers import DPTConfig
from transformers.file_utils import is_torch_available, is_vision_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, require_vision, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
					import torch
					from torch import nn

					from transformers import MODEL_MAPPING, DPTForDepthEstimation, DPTForSemanticSegmentation, DPTModel
					from transformers.models.dpt.modeling_dpt import DPT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
					from PIL import Image

					from transformers import DPTImageProcessor






class 							lowercase__     :





	def __init__(			self :    List[str]			,lowerCamelCase__ :    Tuple			,lowerCamelCase__ :    List[Any]=2			,lowerCamelCase__ :    Optional[int]=32			,lowerCamelCase__ :    Optional[Any]=16			,lowerCamelCase__ :    Optional[int]=3			,lowerCamelCase__ :    List[Any]=True			,lowerCamelCase__ :    str=True			,lowerCamelCase__ :    str=32			,lowerCamelCase__ :    Optional[Any]=4			,lowerCamelCase__ :    Union[str, Any]=[0, 1, 2, 3]			,lowerCamelCase__ :    Dict=4			,lowerCamelCase__ :    Union[str, Any]=37			,lowerCamelCase__ :    Optional[Any]="gelu"			,lowerCamelCase__ :    int=0.1			,lowerCamelCase__ :    Dict=0.1			,lowerCamelCase__ :    Union[str, Any]=0.0_2			,lowerCamelCase__ :    Dict=3			,lowerCamelCase__ :    Optional[int]=[1, 384, 24, 24]			,lowerCamelCase__ :    Tuple=True			,lowerCamelCase__ :    Optional[Any]=None			,):







							'''simple docstring'''
							_UpperCamelCase :		Tuple			    =       parent
							_UpperCamelCase :		Optional[int]			    =       batch_size
							_UpperCamelCase :		str			    =       image_size
							_UpperCamelCase :		str			    =       patch_size
							_UpperCamelCase :		int			    =       num_channels
							_UpperCamelCase :		Any			    =       is_training
							_UpperCamelCase :		str			    =       use_labels
							_UpperCamelCase :		List[Any]			    =       hidden_size
							_UpperCamelCase :		List[str]			    =       num_hidden_layers
							_UpperCamelCase :		int			    =       backbone_out_indices
							_UpperCamelCase :		Optional[int]			    =       num_attention_heads
							_UpperCamelCase :		int			    =       intermediate_size
							_UpperCamelCase :		Optional[Any]			    =       hidden_act
							_UpperCamelCase :		Optional[Any]			    =       hidden_dropout_prob
							_UpperCamelCase :		Tuple			    =       attention_probs_dropout_prob
							_UpperCamelCase :		Any			    =       initializer_range
							_UpperCamelCase :		List[str]			    =       num_labels
							_UpperCamelCase :		Tuple			    =       backbone_featmap_shape
							_UpperCamelCase :		Dict			    =       scope
							_UpperCamelCase :		Tuple			    =       is_hybrid
							# sequence length of DPT = num_patches + 1 (we add 1 for the [CLS] token)
							_UpperCamelCase :		Optional[int]			    =       (image_size // patch_size) ** 2
							_UpperCamelCase :		Dict			    =       num_patches + 1





	def      UpperCamelCase_  (			self :    str			):







							'''simple docstring'''
							_UpperCamelCase :		List[Any]			    =       floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]			)

							_UpperCamelCase :		int			    =       None
							if self.use_labels:
													_UpperCamelCase :		int			    =       ids_tensor([self.batch_size, self.image_size, self.image_size]			,self.num_labels			)

							_UpperCamelCase :		int			    =       self.get_config()

							return config, pixel_values, labels





	def      UpperCamelCase_  (			self :    List[Any]			):







							'''simple docstring'''
							_UpperCamelCase :		List[str]			    =       {
							    'global_padding': 'same',
							    'layer_type': 'bottleneck',
							    'depths': [3, 4, 9],
							    'out_features': ['stage1', 'stage2', 'stage3'],
							    'embedding_dynamic_padding': True,
							    'hidden_sizes': [96, 192, 384, 768],
							    'num_groups': 2,
							}

							return DPTConfig(
							    image_size=self.image_size			,patch_size=self.patch_size			,num_channels=self.num_channels			,hidden_size=self.hidden_size			,num_hidden_layers=self.num_hidden_layers			,backbone_out_indices=self.backbone_out_indices			,num_attention_heads=self.num_attention_heads			,intermediate_size=self.intermediate_size			,hidden_act=self.hidden_act			,hidden_dropout_prob=self.hidden_dropout_prob			,attention_probs_dropout_prob=self.attention_probs_dropout_prob			,is_decoder=lowerCamelCase__			,initializer_range=self.initializer_range			,is_hybrid=self.is_hybrid			,backbone_config=lowerCamelCase__			,backbone_featmap_shape=self.backbone_featmap_shape			,)





	def      UpperCamelCase_  (			self :    str			,lowerCamelCase__ :    str			,lowerCamelCase__ :    Optional[int]			,lowerCamelCase__ :    Optional[Any]			):







							'''simple docstring'''
							_UpperCamelCase :		Optional[int]			    =       DPTModel(config=lowerCamelCase__			)
							model.to(lowerCamelCase__			)
							model.eval()
							_UpperCamelCase :		List[Any]			    =       model(lowerCamelCase__			)
							self.parent.assertEqual(result.last_hidden_state.shape			,(self.batch_size, self.seq_length, self.hidden_size)			)





	def      UpperCamelCase_  (			self :    Any			,lowerCamelCase__ :    int			,lowerCamelCase__ :    str			,lowerCamelCase__ :    int			):







							'''simple docstring'''
							_UpperCamelCase :		Tuple			    =       self.num_labels
							_UpperCamelCase :		int			    =       DPTForDepthEstimation(lowerCamelCase__			)
							model.to(lowerCamelCase__			)
							model.eval()
							_UpperCamelCase :		int			    =       model(lowerCamelCase__			)
							self.parent.assertEqual(result.predicted_depth.shape			,(self.batch_size, self.image_size, self.image_size)			)





	def      UpperCamelCase_  (			self :    Optional[Any]			,lowerCamelCase__ :    List[str]			,lowerCamelCase__ :    Tuple			,lowerCamelCase__ :    List[str]			):







							'''simple docstring'''
							_UpperCamelCase :		Tuple			    =       self.num_labels
							_UpperCamelCase :		Tuple			    =       DPTForSemanticSegmentation(lowerCamelCase__			)
							model.to(lowerCamelCase__			)
							model.eval()
							_UpperCamelCase :		str			    =       model(lowerCamelCase__			,labels=lowerCamelCase__			)
							self.parent.assertEqual(
							    result.logits.shape			,(self.batch_size, self.num_labels, self.image_size, self.image_size)			)





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







							'''simple docstring'''
							_UpperCamelCase :		Optional[int]			    =       self.prepare_config_and_inputs()
							_UpperCamelCase    ,      _UpperCamelCase    ,      _UpperCamelCase :		List[Any]			    =       config_and_inputs
							_UpperCamelCase :		Optional[int]			    =       {'pixel_values': pixel_values}
							return config, inputs_dict






@require_torch
class 							lowercase__     (							lowercase						, lowercase						, unittest.TestCase       ):
	lowercase__      =      (DPTModel, DPTForDepthEstimation, DPTForSemanticSegmentation) if is_torch_available() else ()
	lowercase__      =      (
	    {
	        """depth-estimation""": DPTForDepthEstimation,
	        """feature-extraction""": DPTModel,
	        """image-segmentation""": DPTForSemanticSegmentation,
	    }
	    if is_torch_available()
	    else {}
	)

	lowercase__      =      False
	lowercase__      =      False
	lowercase__      =      False





	def      UpperCamelCase_  (			self :    str			):







							'''simple docstring'''
							_UpperCamelCase :		Tuple			    =       DPTModelTester(self			)
							_UpperCamelCase :		Dict			    =       ConfigTester(self			,config_class=lowerCamelCase__			,has_text_modality=lowerCamelCase__			,hidden_size=37			)





	def      UpperCamelCase_  (			self :    Optional[int]			):







							'''simple docstring'''
							self.config_tester.run_common_tests()





	@unittest.skip(reason='DPT does not use inputs_embeds'			)
	def      UpperCamelCase_  (			self :    Union[str, Any]			):







							'''simple docstring'''
							pass





	def      UpperCamelCase_  (			self :    str			):







							'''simple docstring'''
							_UpperCamelCase    ,      _UpperCamelCase :		Any			    =       self.model_tester.prepare_config_and_inputs_for_common()

							for model_class in self.all_model_classes:
													_UpperCamelCase :		int			    =       model_class(lowerCamelCase__			)
													self.assertIsInstance(model.get_input_embeddings()			,(nn.Module)			)
													_UpperCamelCase :		List[Any]			    =       model.get_output_embeddings()
													self.assertTrue(x is None or isinstance(lowerCamelCase__			,nn.Linear			)			)





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







							'''simple docstring'''
							_UpperCamelCase    ,      _UpperCamelCase :		Any			    =       self.model_tester.prepare_config_and_inputs_for_common()

							for model_class in self.all_model_classes:
													_UpperCamelCase :		Optional[int]			    =       model_class(lowerCamelCase__			)
													_UpperCamelCase :		int			    =       inspect.signature(model.forward			)
													# signature.parameters is an OrderedDict => so arg_names order is deterministic
													_UpperCamelCase :		Union[str, Any]			    =       [*signature.parameters.keys()]

													_UpperCamelCase :		Tuple			    =       ['pixel_values']
													self.assertListEqual(arg_names[:1]			,lowerCamelCase__			)





	def      UpperCamelCase_  (			self :    List[Any]			):







							'''simple docstring'''
							_UpperCamelCase :		Optional[Any]			    =       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*lowerCamelCase__			)





	def      UpperCamelCase_  (			self :    List[str]			):







							'''simple docstring'''
							_UpperCamelCase :		Optional[int]			    =       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_depth_estimation(*lowerCamelCase__			)





	def      UpperCamelCase_  (			self :    Dict			):







							'''simple docstring'''
							_UpperCamelCase :		Optional[int]			    =       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_semantic_segmentation(*lowerCamelCase__			)





	def      UpperCamelCase_  (			self :    List[str]			):







							'''simple docstring'''
							for model_class in self.all_model_classes:
													if model_class.__name__ == "DPTForDepthEstimation":
																			continue

													_UpperCamelCase    ,      _UpperCamelCase :		Optional[int]			    =       self.model_tester.prepare_config_and_inputs_for_common()
													_UpperCamelCase :		Union[str, Any]			    =       True

													if model_class in get_values(lowerCamelCase__			):
																			continue

													_UpperCamelCase :		int			    =       model_class(lowerCamelCase__			)
													model.to(lowerCamelCase__			)
													model.train()
													_UpperCamelCase :		List[str]			    =       self._prepare_for_class(lowerCamelCase__			,lowerCamelCase__			,return_labels=lowerCamelCase__			)
													_UpperCamelCase :		Any			    =       model(**lowerCamelCase__			).loss
													loss.backward()





	def      UpperCamelCase_  (			self :    str			):







							'''simple docstring'''
							for model_class in self.all_model_classes:
													if model_class.__name__ == "DPTForDepthEstimation":
																			continue

													_UpperCamelCase    ,      _UpperCamelCase :		Any			    =       self.model_tester.prepare_config_and_inputs_for_common()
													_UpperCamelCase :		List[Any]			    =       False
													_UpperCamelCase :		Optional[Any]			    =       True

													if model_class in get_values(lowerCamelCase__			) or not model_class.supports_gradient_checkpointing:
																			continue
													_UpperCamelCase :		Optional[Any]			    =       model_class(lowerCamelCase__			)
													model.to(lowerCamelCase__			)
													model.gradient_checkpointing_enable()
													model.train()
													_UpperCamelCase :		Union[str, Any]			    =       self._prepare_for_class(lowerCamelCase__			,lowerCamelCase__			,return_labels=lowerCamelCase__			)
													_UpperCamelCase :		Tuple			    =       model(**lowerCamelCase__			).loss
													loss.backward()





	def      UpperCamelCase_  (			self :    List[str]			):







							'''simple docstring'''
							_UpperCamelCase    ,      _UpperCamelCase :		List[Any]			    =       self.model_tester.prepare_config_and_inputs_for_common()

							_UpperCamelCase :		Optional[int]			    =       _config_zero_init(lowerCamelCase__			)
							for model_class in self.all_model_classes:
													_UpperCamelCase :		Any			    =       model_class(config=lowerCamelCase__			)
													# Skip the check for the backbone
													_UpperCamelCase :		List[str]			    =       []
													for name, module in model.named_modules():
																			if module.__class__.__name__ == "DPTViTHybridEmbeddings":
																									_UpperCamelCase :		Optional[int]			    =       [F'{name}.{key}' for key in module.state_dict().keys()]
																									break

													for name, param in model.named_parameters():
																			if param.requires_grad:
																									if name in backbone_params:
																															continue
																									self.assertIn(
																									    ((param.data.mean() * 1E9).round() / 1E9).item()			,[0.0, 1.0]			,msg=F'Parameter {name} of model {model_class} seems not properly initialized'			,)





	@unittest.skip('Will be fixed soon by reducing the size of the model used for common tests.'			)
	def      UpperCamelCase_  (			self :    Dict			):







							'''simple docstring'''
							pass





	@slow
	def      UpperCamelCase_  (			self :    Optional[int]			):







							'''simple docstring'''
							for model_name in DPT_PRETRAINED_MODEL_ARCHIVE_LIST[1:]:
													_UpperCamelCase :		Dict			    =       DPTModel.from_pretrained(lowerCamelCase__			)
													self.assertIsNotNone(lowerCamelCase__			)





	def      UpperCamelCase_  (			self :    Optional[Any]			):







							'''simple docstring'''
							# We do this test only for DPTForDepthEstimation since it is the only model that uses readout_type
							_UpperCamelCase    ,      _UpperCamelCase :		Any			    =       self.model_tester.prepare_config_and_inputs_for_common()
							_UpperCamelCase :		int			    =       'add'
							with self.assertRaises(lowerCamelCase__			):
													_UpperCamelCase :		Optional[int]			    =       DPTForDepthEstimation(lowerCamelCase__			)






def A__   (					):
						_UpperCamelCase :		Dict			    =       Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'							)
						return image






@require_torch
@require_vision
@slow
class 							lowercase__     (							unittest.TestCase       ):





	def      UpperCamelCase_  (			self :    Tuple			):







							'''simple docstring'''
							_UpperCamelCase :		Dict			    =       DPTImageProcessor.from_pretrained('Intel/dpt-hybrid-midas'			)
							_UpperCamelCase :		Optional[Any]			    =       DPTForDepthEstimation.from_pretrained('Intel/dpt-hybrid-midas'			).to(lowerCamelCase__			)

							_UpperCamelCase :		Union[str, Any]			    =       prepare_img()
							_UpperCamelCase :		Dict			    =       image_processor(images=lowerCamelCase__			,return_tensors='pt'			).to(lowerCamelCase__			)

							# forward pass
							with torch.no_grad():
													_UpperCamelCase :		Tuple			    =       model(**lowerCamelCase__			)
													_UpperCamelCase :		List[str]			    =       outputs.predicted_depth

							# verify the predicted depth
							_UpperCamelCase :		Optional[int]			    =       torch.Size((1, 384, 384)			)
							self.assertEqual(predicted_depth.shape			,lowerCamelCase__			)

							_UpperCamelCase :		List[str]			    =       torch.tensor(
							    [[[5.6_4_3_7, 5.6_1_4_6, 5.6_5_1_1], [5.4_3_7_1, 5.5_6_4_9, 5.5_9_5_8], [5.5_2_1_5, 5.5_1_8_4, 5.5_2_9_3]]]			).to(lowerCamelCase__			)

							self.assertTrue(torch.allclose(outputs.predicted_depth[:3, :3, :3] / 100			,lowerCamelCase__			,atol=1E-4			)			)







'''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:
					snake_case_			:     List[Any]  	=  None


snake_case_			:     Dict  	=  logging.get_logger(__name__)


snake_case_			:     Dict  	=  {'vocab_file': 'sentencepiece.bpe.model', 'tokenizer_file': 'tokenizer.json'}

snake_case_			:     List[str]  	=  {
    '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'
        ),
    },
}

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

# fmt: off
snake_case_			:     Optional[Any]  	=  ['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 							lowercase__     (							lowercase       ):
	lowercase__      =      VOCAB_FILES_NAMES
	lowercase__      =      PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
	lowercase__      =      PRETRAINED_VOCAB_FILES_MAP
	lowercase__      =      ["""input_ids""", """attention_mask"""]
	lowercase__      =      NllbTokenizer

	lowercase__      =      []
	lowercase__      =      []





	def __init__(			self :    List[Any]			,lowerCamelCase__ :    Optional[Any]=None			,lowerCamelCase__ :    Dict=None			,lowerCamelCase__ :    List[Any]="<s>"			,lowerCamelCase__ :    Dict="</s>"			,lowerCamelCase__ :    List[Any]="</s>"			,lowerCamelCase__ :    Union[str, Any]="<s>"			,lowerCamelCase__ :    List[Any]="<unk>"			,lowerCamelCase__ :    Any="<pad>"			,lowerCamelCase__ :    Optional[Any]="<mask>"			,lowerCamelCase__ :    Optional[Any]=None			,lowerCamelCase__ :    str=None			,lowerCamelCase__ :    Tuple=None			,lowerCamelCase__ :    Union[str, Any]=False			,**lowerCamelCase__ :    Optional[Any]			,):







							'''simple docstring'''
							# Mask token behave like a normal word, i.e. include the space before it
							_UpperCamelCase :		Optional[int]			    =       AddedToken(lowerCamelCase__			,lstrip=lowerCamelCase__			,rstrip=lowerCamelCase__			) if isinstance(lowerCamelCase__			,lowerCamelCase__			) else mask_token
							_UpperCamelCase :		Union[str, Any]			    =       legacy_behaviour
							super().__init__(
							    vocab_file=lowerCamelCase__			,tokenizer_file=lowerCamelCase__			,bos_token=lowerCamelCase__			,eos_token=lowerCamelCase__			,sep_token=lowerCamelCase__			,cls_token=lowerCamelCase__			,unk_token=lowerCamelCase__			,pad_token=lowerCamelCase__			,mask_token=lowerCamelCase__			,src_lang=lowerCamelCase__			,tgt_lang=lowerCamelCase__			,additional_special_tokens=lowerCamelCase__			,legacy_behaviour=lowerCamelCase__			,**lowerCamelCase__			,)

							_UpperCamelCase :		int			    =       vocab_file
							_UpperCamelCase :		int			    =       False if not self.vocab_file else True

							_UpperCamelCase :		Dict			    =       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}			)
							_UpperCamelCase :		List[str]			    =       {
							    lang_code: self.convert_tokens_to_ids(lowerCamelCase__			) for lang_code in FAIRSEQ_LANGUAGE_CODES
							}

							_UpperCamelCase :		List[str]			    =       src_lang if src_lang is not None else 'eng_Latn'
							_UpperCamelCase :		int			    =       self.convert_tokens_to_ids(self._src_lang			)
							_UpperCamelCase :		Dict			    =       tgt_lang
							self.set_src_lang_special_tokens(self._src_lang			)





	@property
	def      UpperCamelCase_  (			self :    Tuple			):







							'''simple docstring'''
							return self._src_lang





	@src_lang.setter
	def      UpperCamelCase_  (			self :    Union[str, Any]			,lowerCamelCase__ :    str			):







							'''simple docstring'''
							_UpperCamelCase :		str			    =       new_src_lang
							self.set_src_lang_special_tokens(self._src_lang			)





	def      UpperCamelCase_  (			self :    List[str]			,lowerCamelCase__ :    List[int]			,lowerCamelCase__ :    Optional[List[int]] = None			):







							'''simple docstring'''
							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      UpperCamelCase_  (			self :    Dict			,lowerCamelCase__ :    List[int]			,lowerCamelCase__ :    Optional[List[int]] = None			):







							'''simple docstring'''
							_UpperCamelCase :		Dict			    =       [self.sep_token_id]
							_UpperCamelCase :		List[str]			    =       [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      UpperCamelCase_  (			self :    Union[str, Any]			,lowerCamelCase__ :    str			,lowerCamelCase__ :    str			,lowerCamelCase__ :    Optional[str]			,lowerCamelCase__ :    Optional[str]			,**lowerCamelCase__ :    Dict			):







							'''simple docstring'''
							if src_lang is None or tgt_lang is None:
													raise ValueError('Translation requires a `src_lang` and a `tgt_lang` for this model'			)
							_UpperCamelCase :		Tuple			    =       src_lang
							_UpperCamelCase :		Optional[Any]			    =       self(lowerCamelCase__			,add_special_tokens=lowerCamelCase__			,return_tensors=lowerCamelCase__			,**lowerCamelCase__			)
							_UpperCamelCase :		Tuple			    =       self.convert_tokens_to_ids(lowerCamelCase__			)
							_UpperCamelCase :		str			    =       tgt_lang_id
							return inputs





	def      UpperCamelCase_  (			self :    int			,lowerCamelCase__ :    List[str]			,lowerCamelCase__ :    str = "eng_Latn"			,lowerCamelCase__ :    Optional[List[str]] = None			,lowerCamelCase__ :    str = "fra_Latn"			,**lowerCamelCase__ :    Union[str, Any]			,):







							'''simple docstring'''
							_UpperCamelCase :		Tuple			    =       src_lang
							_UpperCamelCase :		List[str]			    =       tgt_lang
							return super().prepare_seqaseq_batch(lowerCamelCase__			,lowerCamelCase__			,**lowerCamelCase__			)





	def      UpperCamelCase_  (			self :    Optional[int]			):







							'''simple docstring'''
							return self.set_src_lang_special_tokens(self.src_lang			)





	def      UpperCamelCase_  (			self :    Any			):







							'''simple docstring'''
							return self.set_tgt_lang_special_tokens(self.tgt_lang			)





	def      UpperCamelCase_  (			self :    str			,lowerCamelCase__ :    List[Any]			):







							'''simple docstring'''
							_UpperCamelCase :		int			    =       self.convert_tokens_to_ids(lowerCamelCase__			)

							if self.legacy_behaviour:
													_UpperCamelCase :		Optional[Any]			    =       []
													_UpperCamelCase :		int			    =       [self.eos_token_id, self.cur_lang_code]
							else:
													_UpperCamelCase :		List[Any]			    =       [self.cur_lang_code]
													_UpperCamelCase :		List[Any]			    =       [self.eos_token_id]

							_UpperCamelCase :		Union[str, Any]			    =       self.convert_ids_to_tokens(self.prefix_tokens			)
							_UpperCamelCase :		int			    =       self.convert_ids_to_tokens(self.suffix_tokens			)

							_UpperCamelCase :		Any			    =       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      UpperCamelCase_  (			self :    int			,lowerCamelCase__ :    str			):







							'''simple docstring'''
							_UpperCamelCase :		Any			    =       self.convert_tokens_to_ids(lowerCamelCase__			)
							if self.legacy_behaviour:
													_UpperCamelCase :		Tuple			    =       []
													_UpperCamelCase :		str			    =       [self.eos_token_id, self.cur_lang_code]
							else:
													_UpperCamelCase :		Tuple			    =       [self.cur_lang_code]
													_UpperCamelCase :		Optional[Any]			    =       [self.eos_token_id]

							_UpperCamelCase :		int			    =       self.convert_ids_to_tokens(self.prefix_tokens			)
							_UpperCamelCase :		List[Any]			    =       self.convert_ids_to_tokens(self.suffix_tokens			)

							_UpperCamelCase :		Optional[int]			    =       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      UpperCamelCase_  (			self :    Any			,lowerCamelCase__ :    str			,lowerCamelCase__ :    Optional[str] = None			):







							'''simple docstring'''
							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(lowerCamelCase__			):
													logger.error(F'Vocabulary path ({save_directory}) should be a directory.'			)
													return
							_UpperCamelCase :		List[Any]			    =       os.path.join(
							    lowerCamelCase__			,(filename_prefix + '-' if filename_prefix else '') + VOCAB_FILES_NAMES['vocab_file']			)

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

							return (out_vocab_file,)


