

import inspect
import unittest

from huggingface_hub import hf_hub_download

from transformers import ConvNextConfig, UperNetConfig
from transformers.testing_utils import require_torch, require_torch_multi_gpu, require_vision, slow, torch_device
from transformers.utils import is_torch_available, is_vision_available

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 transformers import UperNetForSemanticSegmentation
     from transformers.models.upernet.modeling_upernet import UPERNET_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
     from PIL import Image

     from transformers import AutoImageProcessor





class  __UpperCAmelCase					:



   def __init__(							self							:					int,		__A							:					Optional[int],		__A							:					Union[str, Any]=1_3,		__A							:					Union[str, Any]=3_2,		__A							:					Dict=3,		__A							:					Dict=4,		__A							:					Any=[1_0, 2_0, 3_0, 4_0],		__A							:					Any=[2, 2, 3, 2],		__A							:					Union[str, Any]=True,		__A							:					int=True,		__A							:					Dict=3_7,		__A							:					Union[str, Any]="gelu",		__A							:					int=1_0,		__A							:					Dict=0.0_2,		__A							:					List[str]=["stage2", "stage3", "stage4"],		__A							:					List[Any]=3,		__A							:					List[str]=None,		):
     UpperCAmelCase	:							Any						=			parent
     UpperCAmelCase	:							Union[str, Any]						=			batch_size
     UpperCAmelCase	:							int						=			image_size
     UpperCAmelCase	:							List[Any]						=			num_channels
     UpperCAmelCase	:							Tuple						=			num_stages
     UpperCAmelCase	:							Union[str, Any]						=			hidden_sizes
     UpperCAmelCase	:							int						=			depths
     UpperCAmelCase	:							Tuple						=			is_training
     UpperCAmelCase	:							Optional[int]						=			use_labels
     UpperCAmelCase	:							int						=			intermediate_size
     UpperCAmelCase	:							Any						=			hidden_act
     UpperCAmelCase	:							Optional[Any]						=			type_sequence_label_size
     UpperCAmelCase	:							Optional[int]						=			initializer_range
     UpperCAmelCase	:							Any						=			out_features
     UpperCAmelCase	:							List[str]						=			num_labels
     UpperCAmelCase	:							str						=			scope
     UpperCAmelCase	:							Union[str, Any]						=			num_stages



   def 	__magic_name__   (							self							:					Union[str, Any]						):
     UpperCAmelCase	:							str						=			floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]						)

     UpperCAmelCase	:							List[Any]						=			None
     if self.use_labels:
       UpperCAmelCase	:							str						=			ids_tensor([self.batch_size],		self.type_sequence_label_size						)

     UpperCAmelCase	:							Optional[int]						=			self.get_config()

     return config, pixel_values, labels



   def 	__magic_name__   (							self							:					str						):
     return ConvNextConfig(
         num_channels=self.num_channels,		num_stages=self.num_stages,		hidden_sizes=self.hidden_sizes,		depths=self.depths,		is_training=self.is_training,		intermediate_size=self.intermediate_size,		hidden_act=self.hidden_act,		out_features=self.out_features,		)



   def 	__magic_name__   (							self							:					Dict						):
     return UperNetConfig(
         backbone_config=self.get_backbone_config(),		hidden_size=5_1_2,		pool_scales=[1, 2, 3, 6],		use_auxiliary_head=__A,		auxiliary_loss_weight=0.4,		auxiliary_in_channels=4_0,		auxiliary_channels=2_5_6,		auxiliary_num_convs=1,		auxiliary_concat_input=__A,		loss_ignore_index=2_5_5,		num_labels=self.num_labels,		)



   def 	__magic_name__   (							self							:					int,		__A							:					Any,		__A							:					List[str],		__A							:					Union[str, Any]						):
     UpperCAmelCase	:							Optional[int]						=			UperNetForSemanticSegmentation(config=__A						)
     model.to(__A						)
     model.eval()
     UpperCAmelCase	:							Union[str, Any]						=			model(__A						)
     self.parent.assertEqual(
         result.logits.shape,		(self.batch_size, self.num_labels, self.image_size, self.image_size)						)





   def 	__magic_name__   (							self							:					Tuple						):
     UpperCAmelCase	:							Dict						=			self.prepare_config_and_inputs()
     (
         (
         UpperCAmelCase
     )			,						(
         UpperCAmelCase
     )			,						(
         UpperCAmelCase
     )			,						
     )	:							List[Any]						=			config_and_inputs
     UpperCAmelCase	:							str						=			{'''pixel_values''': pixel_values}
     return config, inputs_dict






@require_torch
class  __UpperCAmelCase					(	lowerCamelCase__      ,  lowerCamelCase__      ,  unittest.TestCase						):
   UpperCamelCase       					=					(UperNetForSemanticSegmentation,) if is_torch_available() else ()
   UpperCamelCase       					=					{"""image-segmentation""": UperNetForSemanticSegmentation} if is_torch_available() else {}
   UpperCamelCase       					=					False
   UpperCamelCase       					=					False
   UpperCamelCase       					=					False
   UpperCamelCase       					=					False
   UpperCamelCase       					=					False
   UpperCamelCase       					=					False



   def 	__magic_name__   (							self							:					Optional[Any]						):
     UpperCAmelCase	:							List[str]						=			UperNetModelTester(self						)
     UpperCAmelCase	:							Tuple						=			ConfigTester(self,		config_class=__A,		has_text_modality=__A,		hidden_size=3_7						)



   def 	__magic_name__   (							self							:					Optional[int]						):
     self.create_and_test_config_common_properties()
     self.config_tester.create_and_test_config_to_json_string()
     self.config_tester.create_and_test_config_to_json_file()
     self.config_tester.create_and_test_config_from_and_save_pretrained()
     self.config_tester.create_and_test_config_with_num_labels()
     self.config_tester.check_config_can_be_init_without_params()
     self.config_tester.check_config_arguments_init()



   def 	__magic_name__   (							self							:					Union[str, Any]						):
     return



   def 	__magic_name__   (							self							:					Optional[int]						):
     UpperCAmelCase			,						UpperCAmelCase	:							int						=			self.model_tester.prepare_config_and_inputs_for_common()

     for model_class in self.all_model_classes:
       UpperCAmelCase	:							str						=			model_class(__A						)
       UpperCAmelCase	:							List[str]						=			inspect.signature(model.forward						)
       # signature.parameters is an OrderedDict => so arg_names order is deterministic
       UpperCAmelCase	:							Optional[Any]						=			[*signature.parameters.keys()]

       UpperCAmelCase	:							List[Any]						=			['''pixel_values''']
       self.assertListEqual(arg_names[:1],		__A						)



   def 	__magic_name__   (							self							:					str						):
     UpperCAmelCase	:							int						=			self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_semantic_segmentation(*__A						)



   @unittest.skip(reason='''UperNet does not use inputs_embeds'''						)
   def 	__magic_name__   (							self							:					Optional[int]						):
     pass



   @unittest.skip(reason='''UperNet does not support input and output embeddings'''						)
   def 	__magic_name__   (							self							:					Union[str, Any]						):
     pass



   @unittest.skip(reason='''UperNet does not have a base model'''						)
   def 	__magic_name__   (							self							:					int						):
     pass



   @unittest.skip(reason='''UperNet does not have a base model'''						)
   def 	__magic_name__   (							self							:					Union[str, Any]						):
     pass



   @require_torch_multi_gpu
   @unittest.skip(reason='''UperNet has some layers using `add_module` which doesn\'t work well with `nn.DataParallel`'''						)
   def 	__magic_name__   (							self							:					Optional[Any]						):
     pass



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



   def 	__magic_name__   (							self							:					int						):
     def check_hidden_states_output(__A							:					Optional[int],		__A							:					Union[str, Any],		__A							:					Tuple						):
       UpperCAmelCase	:							Union[str, Any]						=			model_class(__A						)
       model.to(__A						)
       model.eval()

       with torch.no_grad():
         UpperCAmelCase	:							str						=			model(**self._prepare_for_class(__A,		__A						)						)

       UpperCAmelCase	:							List[str]						=			outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

       UpperCAmelCase	:							Union[str, Any]						=			self.model_tester.num_stages
       self.assertEqual(len(__A						),		expected_num_stages + 1						)

       # ConvNext's feature maps are of shape (batch_size, num_channels, height, width)
       self.assertListEqual(
           list(hidden_states[0].shape[-2:]						),		[self.model_tester.image_size // 4, self.model_tester.image_size // 4],		)

     UpperCAmelCase			,						UpperCAmelCase	:							List[str]						=			self.model_tester.prepare_config_and_inputs_for_common()

     for model_class in self.all_model_classes:
       UpperCAmelCase	:							Optional[Any]						=			True
       check_hidden_states_output(__A,		__A,		__A						)

       # check that output_hidden_states also work using config
       del inputs_dict["output_hidden_states"]
       UpperCAmelCase	:							Tuple						=			True

       check_hidden_states_output(__A,		__A,		__A						)



   def 	__magic_name__   (							self							:					Union[str, Any]						):
     UpperCAmelCase			,						UpperCAmelCase	:							Union[str, Any]						=			self.model_tester.prepare_config_and_inputs_for_common()

     UpperCAmelCase	:							int						=			_config_zero_init(__A						)
     UpperCAmelCase	:							Optional[Any]						=			_config_zero_init(configs_no_init.backbone_config						)
     for model_class in self.all_model_classes:
       UpperCAmelCase	:							Union[str, Any]						=			model_class(config=__A						)
       for name, param in model.named_parameters():
         if param.requires_grad:
           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(reason='''UperNet does not have tied weights'''						)
   def 	__magic_name__   (							self							:					Union[str, Any]						):
     pass





   @slow
   def 	__magic_name__   (							self							:					Any						):
     for model_name in UPERNET_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
       UpperCAmelCase	:							List[Any]						=			UperNetForSemanticSegmentation.from_pretrained(__A						)
       self.assertIsNotNone(__A						)






def       a__					(		)  ->						Dict:
  UpperCAmelCase	:							Tuple						=			hf_hub_download(
      repo_id='''hf-internal-testing/fixtures_ade20k'''    ,			repo_type='''dataset'''    ,			filename='''ADE_val_00000001.jpg'''      )
  UpperCAmelCase	:							str						=			Image.open(UpperCAmelCase      ).convert('''RGB'''      )
  return image






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



   def 	__magic_name__   (							self							:					Dict						):
     UpperCAmelCase	:							int						=			AutoImageProcessor.from_pretrained('''openmmlab/upernet-swin-tiny'''						)
     UpperCAmelCase	:							Union[str, Any]						=			UperNetForSemanticSegmentation.from_pretrained('''openmmlab/upernet-swin-tiny'''						).to(__A						)

     UpperCAmelCase	:							Optional[Any]						=			prepare_img()
     UpperCAmelCase	:							Tuple						=			processor(images=__A,		return_tensors='''pt'''						).to(__A						)

     with torch.no_grad():
       UpperCAmelCase	:							Union[str, Any]						=			model(**__A						)

     UpperCAmelCase	:							Union[str, Any]						=			torch.Size((1, model.config.num_labels, 5_1_2, 5_1_2)						)
     self.assertEqual(outputs.logits.shape,		__A						)

     UpperCAmelCase	:							Union[str, Any]						=			torch.tensor(
         [[-7.5_9_5_8, -7.5_9_5_8, -7.4_3_0_2], [-7.5_9_5_8, -7.5_9_5_8, -7.4_3_0_2], [-7.4_7_9_7, -7.4_7_9_7, -7.3_0_6_8]]						).to(__A						)
     self.assertTrue(torch.allclose(outputs.logits[0, 0, :3, :3],		__A,		atol=1E-4						)						)





   def 	__magic_name__   (							self							:					Union[str, Any]						):
     UpperCAmelCase	:							List[str]						=			AutoImageProcessor.from_pretrained('''openmmlab/upernet-convnext-tiny'''						)
     UpperCAmelCase	:							List[Any]						=			UperNetForSemanticSegmentation.from_pretrained('''openmmlab/upernet-convnext-tiny'''						).to(__A						)

     UpperCAmelCase	:							Any						=			prepare_img()
     UpperCAmelCase	:							Dict						=			processor(images=__A,		return_tensors='''pt'''						).to(__A						)

     with torch.no_grad():
       UpperCAmelCase	:							Tuple						=			model(**__A						)

     UpperCAmelCase	:							Dict						=			torch.Size((1, model.config.num_labels, 5_1_2, 5_1_2)						)
     self.assertEqual(outputs.logits.shape,		__A						)

     UpperCAmelCase	:							Dict						=			torch.tensor(
         [[-8.8_1_1_0, -8.8_1_1_0, -8.6_5_2_1], [-8.8_1_1_0, -8.8_1_1_0, -8.6_5_2_1], [-8.7_7_4_6, -8.7_7_4_6, -8.6_1_3_0]]						).to(__A						)
     self.assertTrue(torch.allclose(outputs.logits[0, 0, :3, :3],		__A,		atol=1E-4						)						)








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


_lowerCamelCase    :       str        =							logging.get_logger(__name__)


_lowerCamelCase    :       str        =							{"vocab_file": "sentencepiece.bpe.model", "tokenizer_file": "tokenizer.json"}

_lowerCamelCase    :       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"
        ),
    },
}

_lowerCamelCase    :       Any        =							{
    "facebook/nllb-large-en-ro": 1_0_2_4,
    "facebook/nllb-200-distilled-600M": 1_0_2_4,
}

# fmt: off
_lowerCamelCase    :       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  __UpperCAmelCase					(	lowerCamelCase__						):
   UpperCamelCase       					=					VOCAB_FILES_NAMES
   UpperCamelCase       					=					PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
   UpperCamelCase       					=					PRETRAINED_VOCAB_FILES_MAP
   UpperCamelCase       					=					["""input_ids""", """attention_mask"""]
   UpperCamelCase       					=					NllbTokenizer

   UpperCamelCase       					=					[]
   UpperCamelCase       					=					[]



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

     UpperCAmelCase	:							Optional[int]						=			vocab_file
     UpperCAmelCase	:							Optional[Any]						=			False if not self.vocab_file else True

     UpperCAmelCase	:							Optional[int]						=			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[Any]						=			{
         lang_code: self.convert_tokens_to_ids(__A						) for lang_code in FAIRSEQ_LANGUAGE_CODES
     }

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



   @property
   def 	__magic_name__   (							self							:					Optional[int]						):
     return self._src_lang



   @src_lang.setter
   def 	__magic_name__   (							self							:					Union[str, Any],		__A							:					str						):
     UpperCAmelCase	:							Tuple						=			new_src_lang
     self.set_src_lang_special_tokens(self._src_lang						)



   def 	__magic_name__   (							self							:					Any,		__A							:					List[int],		__A							:					Optional[List[int]] = None						):
     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 	__magic_name__   (							self							:					Tuple,		__A							:					List[int],		__A							:					Optional[List[int]] = None						):
     UpperCAmelCase	:							Union[str, Any]						=			[self.sep_token_id]
     UpperCAmelCase	:							Any						=			[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 	__magic_name__   (							self							:					str,		__A							:					Optional[int],		__A							:					str,		__A							:					Optional[str],		__A							:					Optional[str],		**__A							:					Union[str, 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'''						)
     UpperCAmelCase	:							Optional[Any]						=			src_lang
     UpperCAmelCase	:							Optional[Any]						=			self(__A,		add_special_tokens=__A,		return_tensors=__A,		**__A						)
     UpperCAmelCase	:							Union[str, Any]						=			self.convert_tokens_to_ids(__A						)
     UpperCAmelCase	:							int						=			tgt_lang_id
     return inputs



   def 	__magic_name__   (							self							:					List[str],		__A							:					List[str],		__A							:					str = "eng_Latn",		__A							:					Optional[List[str]] = None,		__A							:					str = "fra_Latn",		**__A							:					Tuple,		):
     UpperCAmelCase	:							Any						=			src_lang
     UpperCAmelCase	:							Tuple						=			tgt_lang
     return super().prepare_seqaseq_batch(__A,		__A,		**__A						)



   def 	__magic_name__   (							self							:					List[str]						):
     return self.set_src_lang_special_tokens(self.src_lang						)



   def 	__magic_name__   (							self							:					Optional[Any]						):
     return self.set_tgt_lang_special_tokens(self.tgt_lang						)



   def 	__magic_name__   (							self							:					Union[str, Any],		__A							:					List[str]						):
     UpperCAmelCase	:							int						=			self.convert_tokens_to_ids(__A						)

     if self.legacy_behaviour:
       UpperCAmelCase	:							Tuple						=			[]
       UpperCAmelCase	:							Optional[int]						=			[self.eos_token_id, self.cur_lang_code]
     else:
       UpperCAmelCase	:							Any						=			[self.cur_lang_code]
       UpperCAmelCase	:							Optional[Any]						=			[self.eos_token_id]

     UpperCAmelCase	:							Dict						=			self.convert_ids_to_tokens(self.prefix_tokens						)
     UpperCAmelCase	:							Union[str, Any]						=			self.convert_ids_to_tokens(self.suffix_tokens						)

     UpperCAmelCase	:							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 	__magic_name__   (							self							:					Dict,		__A							:					str						):
     UpperCAmelCase	:							Optional[int]						=			self.convert_tokens_to_ids(__A						)
     if self.legacy_behaviour:
       UpperCAmelCase	:							List[Any]						=			[]
       UpperCAmelCase	:							Any						=			[self.eos_token_id, self.cur_lang_code]
     else:
       UpperCAmelCase	:							int						=			[self.cur_lang_code]
       UpperCAmelCase	:							List[Any]						=			[self.eos_token_id]

     UpperCAmelCase	:							str						=			self.convert_ids_to_tokens(self.prefix_tokens						)
     UpperCAmelCase	:							List[Any]						=			self.convert_ids_to_tokens(self.suffix_tokens						)

     UpperCAmelCase	:							List[str]						=			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 	__magic_name__   (							self							:					Dict,		__A							:					str,		__A							:					Optional[str] = None						):
     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(__A						):
       logger.error(F'''Vocabulary path ({save_directory}) should be a directory.'''						)
       return
     UpperCAmelCase	:							Tuple						=			os.path.join(
         __A,		(filename_prefix + '''-''' if filename_prefix else '''''') + VOCAB_FILES_NAMES['''vocab_file''']						)

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

     return (out_vocab_file,)





