

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_mbartaa import MBartaaTokenizer
else:
		lowerCamelCase   					=  None


lowerCamelCase   					=  logging.get_logger(__name__)

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

lowerCamelCase   					=  {
    '''vocab_file''': {
        '''facebook/mbart-large-50-one-to-many-mmt''': (
            '''https://huggingface.co/facebook/mbart-large-50-one-to-many-mmt/resolve/main/sentencepiece.bpe.model'''
        ),
    },
    '''tokenizer_file''': {
        '''facebook/mbart-large-50-one-to-many-mmt''': (
            '''https://huggingface.co/facebook/mbart-large-50-one-to-many-mmt/resolve/main/tokenizer.json'''
        ),
    },
}

lowerCamelCase   					=  {
    '''facebook/mbart-large-50-one-to-many-mmt''': 1_0_2_4,
}

# fmt: off
lowerCamelCase   					=  ['''ar_AR''', '''cs_CZ''', '''de_DE''', '''en_XX''', '''es_XX''', '''et_EE''', '''fi_FI''', '''fr_XX''', '''gu_IN''', '''hi_IN''', '''it_IT''', '''ja_XX''', '''kk_KZ''', '''ko_KR''', '''lt_LT''', '''lv_LV''', '''my_MM''', '''ne_NP''', '''nl_XX''', '''ro_RO''', '''ru_RU''', '''si_LK''', '''tr_TR''', '''vi_VN''', '''zh_CN''', '''af_ZA''', '''az_AZ''', '''bn_IN''', '''fa_IR''', '''he_IL''', '''hr_HR''', '''id_ID''', '''ka_GE''', '''km_KH''', '''mk_MK''', '''ml_IN''', '''mn_MN''', '''mr_IN''', '''pl_PL''', '''ps_AF''', '''pt_XX''', '''sv_SE''', '''sw_KE''', '''ta_IN''', '''te_IN''', '''th_TH''', '''tl_XX''', '''uk_UA''', '''ur_PK''', '''xh_ZA''', '''gl_ES''', '''sl_SI''']





class      snake_case_      (					_a				):


							"""simple docstring"""





							__UpperCAmelCase      =VOCAB_FILES_NAMES
							__UpperCAmelCase      =PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
							__UpperCAmelCase      =PRETRAINED_VOCAB_FILES_MAP
							__UpperCAmelCase      =["""input_ids""", """attention_mask"""]
							__UpperCAmelCase      =MBartaaTokenizer

							__UpperCAmelCase      =[]
							__UpperCAmelCase      =[]




							def __init__(			self       ,    _A=None       ,    _A=None       ,    _A=None       ,    _A=None       ,    _A="</s>"       ,    _A="</s>"       ,    _A="<s>"       ,    _A="<unk>"       ,    _A="<pad>"       ,    _A="<mask>"       ,    **_A       ,    ):
												# Mask token behave like a normal word, i.e. include the space before it
												__lowerCAmelCase       =				AddedToken(_A       ,    lstrip=_A       ,    rstrip=_A				) if isinstance(_A       ,    _A				) else mask_token

												__lowerCAmelCase       =				kwargs.get('additional_special_tokens'       ,    []				)
												kwargs["additional_special_tokens"] += [
												    code for code in FAIRSEQ_LANGUAGE_CODES if code not in kwargs["additional_special_tokens"]
												]

												super().__init__(
												    _A       ,    src_lang=_A       ,    tgt_lang=_A       ,    tokenizer_file=_A       ,    eos_token=_A       ,    sep_token=_A       ,    cls_token=_A       ,    unk_token=_A       ,    pad_token=_A       ,    mask_token=_A       ,    **_A       ,    )

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

												__lowerCAmelCase       =				{
												    lang_code: self.convert_tokens_to_ids(_A				) for lang_code in FAIRSEQ_LANGUAGE_CODES
												}

												__lowerCAmelCase       =				src_lang if src_lang is not None else 'en_XX'
												__lowerCAmelCase       =				tgt_lang
												__lowerCAmelCase       =				self.lang_code_to_id[self._src_lang]
												self.set_src_lang_special_tokens(self._src_lang				)




							@property
							def 							A__	(			self				):
												return self._src_lang




							@src_lang.setter
							def 							A__	(			self       ,    _A				):
												__lowerCAmelCase       =				new_src_lang
												self.set_src_lang_special_tokens(self._src_lang				)




							def 							A__	(			self       ,    _A       ,    _A = 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 							A__	(			self       ,    _A       ,    _A = "en_XX"       ,    _A = None       ,    _A = "ro_RO"       ,    **_A       ,    ):
												__lowerCAmelCase       =				src_lang
												__lowerCAmelCase       =				tgt_lang
												return super().prepare_seqaseq_batch(_A       ,    _A       ,    **_A				)




							def 							A__	(			self				):
												return self.set_src_lang_special_tokens(self.src_lang				)




							def 							A__	(			self				):
												return self.set_tgt_lang_special_tokens(self.tgt_lang				)




							def 							A__	(			self       ,    _A				):
												__lowerCAmelCase       =				self.convert_tokens_to_ids(_A				)
												__lowerCAmelCase       =				[self.cur_lang_code_id]
												__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 							A__	(			self       ,    _A				):
												__lowerCAmelCase       =				self.convert_tokens_to_ids(_A				)
												__lowerCAmelCase       =				[self.cur_lang_code_id]
												__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 							A__	(			self       ,    _A       ,    _A       ,    _A       ,    _A       ,    **_A				):
												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(_A       ,    add_special_tokens=_A       ,    return_tensors=_A       ,    **_A				)
												__lowerCAmelCase       =				self.convert_tokens_to_ids(_A				)
												__lowerCAmelCase       =				tgt_lang_id
												return inputs




							def 							A__	(			self       ,    _A       ,    _A = 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
												__lowerCAmelCase       =				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,)









import copy

from ...configuration_utils import PretrainedConfig
from ...utils import logging


lowerCamelCase   					=  logging.get_logger(__name__)

lowerCamelCase   					=  {}





class      snake_case_      (					_a				):


							"""simple docstring"""





							__UpperCAmelCase      ="""fsmt_decoder"""




							def __init__(			self       ,    _A=0       ,    _A=0				):
												super().__init__()
												__lowerCAmelCase       =				vocab_size
												__lowerCAmelCase       =				bos_token_id





class      snake_case_      (					_a				):


							"""simple docstring"""





							__UpperCAmelCase      ="""fsmt"""
							__UpperCAmelCase      ={"""num_attention_heads""": """encoder_attention_heads""", """hidden_size""": """d_model"""}




							def __init__(			self       ,    _A=["en", "de"]       ,    _A=4_2_0_2_4       ,    _A=4_2_0_2_4       ,    _A="relu"       ,    _A=1_0_2_4       ,    _A=2_0_0       ,    _A=1_0_2_4       ,    _A=4_0_9_6       ,    _A=1_2       ,    _A=1_6       ,    _A=0.0       ,    _A=4_0_9_6       ,    _A=1_2       ,    _A=1_6       ,    _A=0.0       ,    _A=0.0       ,    _A=0.1       ,    _A=0.0       ,    _A=0.02       ,    _A=2       ,    _A=True       ,    _A=True       ,    _A=False       ,    _A=5       ,    _A=1.0       ,    _A=False       ,    _A=True       ,    _A=1       ,    _A=0       ,    _A=2       ,    _A=2       ,    **_A       ,    ):
												__lowerCAmelCase       =				langs
												__lowerCAmelCase       =				src_vocab_size
												__lowerCAmelCase       =				tgt_vocab_size
												__lowerCAmelCase       =				d_model  # encoder_embed_dim and decoder_embed_dim

												__lowerCAmelCase       =				encoder_ffn_dim
												__lowerCAmelCase       =				__lowerCAmelCase       =				encoder_layers
												__lowerCAmelCase       =				encoder_attention_heads
												__lowerCAmelCase       =				encoder_layerdrop
												__lowerCAmelCase       =				decoder_layerdrop
												__lowerCAmelCase       =				decoder_ffn_dim
												__lowerCAmelCase       =				decoder_layers
												__lowerCAmelCase       =				decoder_attention_heads
												__lowerCAmelCase       =				max_position_embeddings
												__lowerCAmelCase       =				init_std  # Normal(0, this parameter)
												__lowerCAmelCase       =				activation_function

												__lowerCAmelCase       =				DecoderConfig(vocab_size=_A       ,    bos_token_id=_A				)
												if "decoder" in common_kwargs:
																	del common_kwargs["decoder"]

												__lowerCAmelCase       =				scale_embedding  # scale factor will be sqrt(d_model) if True

												# 3 Types of Dropout
												__lowerCAmelCase       =				attention_dropout
												__lowerCAmelCase       =				activation_dropout
												__lowerCAmelCase       =				dropout

												__lowerCAmelCase       =				use_cache
												super().__init__(
												    pad_token_id=_A       ,    bos_token_id=_A       ,    eos_token_id=_A       ,    decoder_start_token_id=_A       ,    is_encoder_decoder=_A       ,    tie_word_embeddings=_A       ,    forced_eos_token_id=_A       ,    max_length=_A       ,    num_beams=_A       ,    length_penalty=_A       ,    early_stopping=_A       ,    **_A       ,    )




							def 							A__	(			self				):
												__lowerCAmelCase       =				copy.deepcopy(self.__dict__				)
												__lowerCAmelCase       =				self.decoder.to_dict()
												__lowerCAmelCase       =				self.__class__.model_type
												return output






