






"""simple docstring"""







from collections import OrderedDict

from ...utils import logging
from .auto_factory import _BaseAutoModelClass, _LazyAutoMapping, auto_class_update
from .configuration_auto import CONFIG_MAPPING_NAMES


_UpperCamelCase					      =  logging.get_logger(__name__)


_UpperCamelCase					      =  OrderedDict(
    [
        # Base model mapping
        ("""albert""", """FlaxAlbertModel"""),
        ("""bart""", """FlaxBartModel"""),
        ("""beit""", """FlaxBeitModel"""),
        ("""bert""", """FlaxBertModel"""),
        ("""big_bird""", """FlaxBigBirdModel"""),
        ("""blenderbot""", """FlaxBlenderbotModel"""),
        ("""blenderbot-small""", """FlaxBlenderbotSmallModel"""),
        ("""clip""", """FlaxCLIPModel"""),
        ("""distilbert""", """FlaxDistilBertModel"""),
        ("""electra""", """FlaxElectraModel"""),
        ("""gpt-sw3""", """FlaxGPT2Model"""),
        ("""gpt2""", """FlaxGPT2Model"""),
        ("""gpt_neo""", """FlaxGPTNeoModel"""),
        ("""gptj""", """FlaxGPTJModel"""),
        ("""longt5""", """FlaxLongT5Model"""),
        ("""marian""", """FlaxMarianModel"""),
        ("""mbart""", """FlaxMBartModel"""),
        ("""mt5""", """FlaxMT5Model"""),
        ("""opt""", """FlaxOPTModel"""),
        ("""pegasus""", """FlaxPegasusModel"""),
        ("""regnet""", """FlaxRegNetModel"""),
        ("""resnet""", """FlaxResNetModel"""),
        ("""roberta""", """FlaxRobertaModel"""),
        ("""roberta-prelayernorm""", """FlaxRobertaPreLayerNormModel"""),
        ("""roformer""", """FlaxRoFormerModel"""),
        ("""t5""", """FlaxT5Model"""),
        ("""vision-text-dual-encoder""", """FlaxVisionTextDualEncoderModel"""),
        ("""vit""", """FlaxViTModel"""),
        ("""wav2vec2""", """FlaxWav2Vec2Model"""),
        ("""whisper""", """FlaxWhisperModel"""),
        ("""xglm""", """FlaxXGLMModel"""),
        ("""xlm-roberta""", """FlaxXLMRobertaModel"""),
    ]
)

_UpperCamelCase					      =  OrderedDict(
    [
        # Model for pre-training mapping
        ("""albert""", """FlaxAlbertForPreTraining"""),
        ("""bart""", """FlaxBartForConditionalGeneration"""),
        ("""bert""", """FlaxBertForPreTraining"""),
        ("""big_bird""", """FlaxBigBirdForPreTraining"""),
        ("""electra""", """FlaxElectraForPreTraining"""),
        ("""longt5""", """FlaxLongT5ForConditionalGeneration"""),
        ("""mbart""", """FlaxMBartForConditionalGeneration"""),
        ("""mt5""", """FlaxMT5ForConditionalGeneration"""),
        ("""roberta""", """FlaxRobertaForMaskedLM"""),
        ("""roberta-prelayernorm""", """FlaxRobertaPreLayerNormForMaskedLM"""),
        ("""roformer""", """FlaxRoFormerForMaskedLM"""),
        ("""t5""", """FlaxT5ForConditionalGeneration"""),
        ("""wav2vec2""", """FlaxWav2Vec2ForPreTraining"""),
        ("""whisper""", """FlaxWhisperForConditionalGeneration"""),
        ("""xlm-roberta""", """FlaxXLMRobertaForMaskedLM"""),
    ]
)

_UpperCamelCase					      =  OrderedDict(
    [
        # Model for Masked LM mapping
        ("""albert""", """FlaxAlbertForMaskedLM"""),
        ("""bart""", """FlaxBartForConditionalGeneration"""),
        ("""bert""", """FlaxBertForMaskedLM"""),
        ("""big_bird""", """FlaxBigBirdForMaskedLM"""),
        ("""distilbert""", """FlaxDistilBertForMaskedLM"""),
        ("""electra""", """FlaxElectraForMaskedLM"""),
        ("""mbart""", """FlaxMBartForConditionalGeneration"""),
        ("""roberta""", """FlaxRobertaForMaskedLM"""),
        ("""roberta-prelayernorm""", """FlaxRobertaPreLayerNormForMaskedLM"""),
        ("""roformer""", """FlaxRoFormerForMaskedLM"""),
        ("""xlm-roberta""", """FlaxXLMRobertaForMaskedLM"""),
    ]
)

_UpperCamelCase					      =  OrderedDict(
    [
        # Model for Seq2Seq Causal LM mapping
        ("""bart""", """FlaxBartForConditionalGeneration"""),
        ("""blenderbot""", """FlaxBlenderbotForConditionalGeneration"""),
        ("""blenderbot-small""", """FlaxBlenderbotSmallForConditionalGeneration"""),
        ("""encoder-decoder""", """FlaxEncoderDecoderModel"""),
        ("""longt5""", """FlaxLongT5ForConditionalGeneration"""),
        ("""marian""", """FlaxMarianMTModel"""),
        ("""mbart""", """FlaxMBartForConditionalGeneration"""),
        ("""mt5""", """FlaxMT5ForConditionalGeneration"""),
        ("""pegasus""", """FlaxPegasusForConditionalGeneration"""),
        ("""t5""", """FlaxT5ForConditionalGeneration"""),
    ]
)

_UpperCamelCase					      =  OrderedDict(
    [
        # Model for Image-classsification
        ("""beit""", """FlaxBeitForImageClassification"""),
        ("""regnet""", """FlaxRegNetForImageClassification"""),
        ("""resnet""", """FlaxResNetForImageClassification"""),
        ("""vit""", """FlaxViTForImageClassification"""),
    ]
)

_UpperCamelCase					      =  OrderedDict(
    [
        ("""vision-encoder-decoder""", """FlaxVisionEncoderDecoderModel"""),
    ]
)

_UpperCamelCase					      =  OrderedDict(
    [
        # Model for Causal LM mapping
        ("""bart""", """FlaxBartForCausalLM"""),
        ("""bert""", """FlaxBertForCausalLM"""),
        ("""big_bird""", """FlaxBigBirdForCausalLM"""),
        ("""electra""", """FlaxElectraForCausalLM"""),
        ("""gpt-sw3""", """FlaxGPT2LMHeadModel"""),
        ("""gpt2""", """FlaxGPT2LMHeadModel"""),
        ("""gpt_neo""", """FlaxGPTNeoForCausalLM"""),
        ("""gptj""", """FlaxGPTJForCausalLM"""),
        ("""opt""", """FlaxOPTForCausalLM"""),
        ("""roberta""", """FlaxRobertaForCausalLM"""),
        ("""roberta-prelayernorm""", """FlaxRobertaPreLayerNormForCausalLM"""),
        ("""xglm""", """FlaxXGLMForCausalLM"""),
        ("""xlm-roberta""", """FlaxXLMRobertaForCausalLM"""),
    ]
)

_UpperCamelCase					      =  OrderedDict(
    [
        # Model for Sequence Classification mapping
        ("""albert""", """FlaxAlbertForSequenceClassification"""),
        ("""bart""", """FlaxBartForSequenceClassification"""),
        ("""bert""", """FlaxBertForSequenceClassification"""),
        ("""big_bird""", """FlaxBigBirdForSequenceClassification"""),
        ("""distilbert""", """FlaxDistilBertForSequenceClassification"""),
        ("""electra""", """FlaxElectraForSequenceClassification"""),
        ("""mbart""", """FlaxMBartForSequenceClassification"""),
        ("""roberta""", """FlaxRobertaForSequenceClassification"""),
        ("""roberta-prelayernorm""", """FlaxRobertaPreLayerNormForSequenceClassification"""),
        ("""roformer""", """FlaxRoFormerForSequenceClassification"""),
        ("""xlm-roberta""", """FlaxXLMRobertaForSequenceClassification"""),
    ]
)

_UpperCamelCase					      =  OrderedDict(
    [
        # Model for Question Answering mapping
        ("""albert""", """FlaxAlbertForQuestionAnswering"""),
        ("""bart""", """FlaxBartForQuestionAnswering"""),
        ("""bert""", """FlaxBertForQuestionAnswering"""),
        ("""big_bird""", """FlaxBigBirdForQuestionAnswering"""),
        ("""distilbert""", """FlaxDistilBertForQuestionAnswering"""),
        ("""electra""", """FlaxElectraForQuestionAnswering"""),
        ("""mbart""", """FlaxMBartForQuestionAnswering"""),
        ("""roberta""", """FlaxRobertaForQuestionAnswering"""),
        ("""roberta-prelayernorm""", """FlaxRobertaPreLayerNormForQuestionAnswering"""),
        ("""roformer""", """FlaxRoFormerForQuestionAnswering"""),
        ("""xlm-roberta""", """FlaxXLMRobertaForQuestionAnswering"""),
    ]
)

_UpperCamelCase					      =  OrderedDict(
    [
        # Model for Token Classification mapping
        ("""albert""", """FlaxAlbertForTokenClassification"""),
        ("""bert""", """FlaxBertForTokenClassification"""),
        ("""big_bird""", """FlaxBigBirdForTokenClassification"""),
        ("""distilbert""", """FlaxDistilBertForTokenClassification"""),
        ("""electra""", """FlaxElectraForTokenClassification"""),
        ("""roberta""", """FlaxRobertaForTokenClassification"""),
        ("""roberta-prelayernorm""", """FlaxRobertaPreLayerNormForTokenClassification"""),
        ("""roformer""", """FlaxRoFormerForTokenClassification"""),
        ("""xlm-roberta""", """FlaxXLMRobertaForTokenClassification"""),
    ]
)

_UpperCamelCase					      =  OrderedDict(
    [
        # Model for Multiple Choice mapping
        ("""albert""", """FlaxAlbertForMultipleChoice"""),
        ("""bert""", """FlaxBertForMultipleChoice"""),
        ("""big_bird""", """FlaxBigBirdForMultipleChoice"""),
        ("""distilbert""", """FlaxDistilBertForMultipleChoice"""),
        ("""electra""", """FlaxElectraForMultipleChoice"""),
        ("""roberta""", """FlaxRobertaForMultipleChoice"""),
        ("""roberta-prelayernorm""", """FlaxRobertaPreLayerNormForMultipleChoice"""),
        ("""roformer""", """FlaxRoFormerForMultipleChoice"""),
        ("""xlm-roberta""", """FlaxXLMRobertaForMultipleChoice"""),
    ]
)

_UpperCamelCase					      =  OrderedDict(
    [
        ("""bert""", """FlaxBertForNextSentencePrediction"""),
    ]
)

_UpperCamelCase					      =  OrderedDict(
    [
        ("""speech-encoder-decoder""", """FlaxSpeechEncoderDecoderModel"""),
        ("""whisper""", """FlaxWhisperForConditionalGeneration"""),
    ]
)

_UpperCamelCase					      =  OrderedDict(
    [
        ("""whisper""", """FlaxWhisperForAudioClassification"""),
    ]
)

_UpperCamelCase					      =  _LazyAutoMapping(CONFIG_MAPPING_NAMES, FLAX_MODEL_MAPPING_NAMES)
_UpperCamelCase					      =  _LazyAutoMapping(CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_PRETRAINING_MAPPING_NAMES)
_UpperCamelCase					      =  _LazyAutoMapping(CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_MASKED_LM_MAPPING_NAMES)
_UpperCamelCase					      =  _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMES
)
_UpperCamelCase					      =  _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING_NAMES
)
_UpperCamelCase					      =  _LazyAutoMapping(CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_VISION_2_SEQ_MAPPING_NAMES)
_UpperCamelCase					      =  _LazyAutoMapping(CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_CAUSAL_LM_MAPPING_NAMES)
_UpperCamelCase					      =  _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING_NAMES
)
_UpperCamelCase					      =  _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_QUESTION_ANSWERING_MAPPING_NAMES
)
_UpperCamelCase					      =  _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING_NAMES
)
_UpperCamelCase					      =  _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_MULTIPLE_CHOICE_MAPPING_NAMES
)
_UpperCamelCase					      =  _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_NEXT_SENTENCE_PREDICTION_MAPPING_NAMES
)
_UpperCamelCase					      =  _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING_NAMES
)
_UpperCamelCase					      =  _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING_NAMES
)







class  lowerCamelCase__ (	_BaseAutoModelClass			):
				SCREAMING_SNAKE_CASE		=      FLAX_MODEL_MAPPING







_UpperCamelCase					      =  auto_class_update(FlaxAutoModel)







class  lowerCamelCase__ (	_BaseAutoModelClass			):
				SCREAMING_SNAKE_CASE		=      FLAX_MODEL_FOR_PRETRAINING_MAPPING







_UpperCamelCase					      =  auto_class_update(FlaxAutoModelForPreTraining, head_doc="""pretraining""")







class  lowerCamelCase__ (	_BaseAutoModelClass			):
				SCREAMING_SNAKE_CASE		=      FLAX_MODEL_FOR_CAUSAL_LM_MAPPING







_UpperCamelCase					      =  auto_class_update(FlaxAutoModelForCausalLM, head_doc="""causal language modeling""")







class  lowerCamelCase__ (	_BaseAutoModelClass			):
				SCREAMING_SNAKE_CASE		=      FLAX_MODEL_FOR_MASKED_LM_MAPPING







_UpperCamelCase					      =  auto_class_update(FlaxAutoModelForMaskedLM, head_doc="""masked language modeling""")







class  lowerCamelCase__ (	_BaseAutoModelClass			):
				SCREAMING_SNAKE_CASE		=      FLAX_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING







_UpperCamelCase					      =  auto_class_update(
    FlaxAutoModelForSeqaSeqLM, head_doc="""sequence-to-sequence language modeling""", checkpoint_for_example="""t5-base"""
)







class  lowerCamelCase__ (	_BaseAutoModelClass			):
				SCREAMING_SNAKE_CASE		=      FLAX_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING







_UpperCamelCase					      =  auto_class_update(
    FlaxAutoModelForSequenceClassification, head_doc="""sequence classification"""
)







class  lowerCamelCase__ (	_BaseAutoModelClass			):
				SCREAMING_SNAKE_CASE		=      FLAX_MODEL_FOR_QUESTION_ANSWERING_MAPPING







_UpperCamelCase					      =  auto_class_update(FlaxAutoModelForQuestionAnswering, head_doc="""question answering""")







class  lowerCamelCase__ (	_BaseAutoModelClass			):
				SCREAMING_SNAKE_CASE		=      FLAX_MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING







_UpperCamelCase					      =  auto_class_update(
    FlaxAutoModelForTokenClassification, head_doc="""token classification"""
)







class  lowerCamelCase__ (	_BaseAutoModelClass			):
				SCREAMING_SNAKE_CASE		=      FLAX_MODEL_FOR_MULTIPLE_CHOICE_MAPPING







_UpperCamelCase					      =  auto_class_update(FlaxAutoModelForMultipleChoice, head_doc="""multiple choice""")







class  lowerCamelCase__ (	_BaseAutoModelClass			):
				SCREAMING_SNAKE_CASE		=      FLAX_MODEL_FOR_NEXT_SENTENCE_PREDICTION_MAPPING







_UpperCamelCase					      =  auto_class_update(
    FlaxAutoModelForNextSentencePrediction, head_doc="""next sentence prediction"""
)







class  lowerCamelCase__ (	_BaseAutoModelClass			):
				SCREAMING_SNAKE_CASE		=      FLAX_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING







_UpperCamelCase					      =  auto_class_update(
    FlaxAutoModelForImageClassification, head_doc="""image classification"""
)







class  lowerCamelCase__ (	_BaseAutoModelClass			):
				SCREAMING_SNAKE_CASE		=      FLAX_MODEL_FOR_VISION_2_SEQ_MAPPING







_UpperCamelCase					      =  auto_class_update(FlaxAutoModelForVisionaSeq, head_doc="""vision-to-text modeling""")







class  lowerCamelCase__ (	_BaseAutoModelClass			):
				SCREAMING_SNAKE_CASE		=      FLAX_MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING







_UpperCamelCase					      =  auto_class_update(
    FlaxAutoModelForSpeechSeqaSeq, head_doc="""sequence-to-sequence speech-to-text modeling"""
)











"""simple docstring"""







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

import sentencepiece as spm

from ...tokenization_utils import AddedToken, PreTrainedTokenizer
from ...utils import logging


_UpperCamelCase					      =  logging.get_logger(__name__)

_UpperCamelCase					      =  """▁"""

_UpperCamelCase					      =  {"""vocab_file""": """sentencepiece.bpe.model""", """monolingual_vocab_file""": """dict.txt"""}

_UpperCamelCase					      =  {
    """vocab_file""": {
        """vinai/bartpho-syllable""": """https://huggingface.co/vinai/bartpho-syllable/resolve/main/sentencepiece.bpe.model""",
    },
    """monolingual_vocab_file""": {
        """vinai/bartpho-syllable""": """https://huggingface.co/vinai/bartpho-syllable/resolve/main/dict.txt""",
    },
}

_UpperCamelCase					      =  {"""vinai/bartpho-syllable""": 1024}







class  lowerCamelCase__ (	snake_case			):
    SCREAMING_SNAKE_CASE		=      VOCAB_FILES_NAMES
    SCREAMING_SNAKE_CASE		=      PRETRAINED_VOCAB_FILES_MAP
    SCREAMING_SNAKE_CASE		=      PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
    SCREAMING_SNAKE_CASE		=      ['''input_ids''', '''attention_mask''']






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

          UpperCAmelCase          =	{} if sp_model_kwargs is None else sp_model_kwargs

          super().__init__(
              bos_token=A     ,eos_token=A     ,unk_token=A     ,sep_token=A     ,cls_token=A     ,pad_token=A     ,mask_token=A     ,sp_model_kwargs=self.sp_model_kwargs     ,**A     ,)

          UpperCAmelCase          =	vocab_file
          UpperCAmelCase          =	monolingual_vocab_file
          UpperCAmelCase          =	spm.SentencePieceProcessor(**self.sp_model_kwargs )
          self.sp_model.Load(str(A ) )

          # Load the reduced vocab

          # Keep order of special tokens for backward compatibility
          UpperCAmelCase          =	{}
          UpperCAmelCase          =	0
          for token in [bos_token, pad_token, eos_token, unk_token, sep_token, cls_token]:
                if str(A ) not in self.fairseq_tokens_to_ids:
                      UpperCAmelCase          =	cnt
                      cnt += 1
          with open(A     ,"""r"""     ,encoding="""utf-8""" ) as f:
                for line in f.readlines():
                      UpperCAmelCase          =	line.strip().split()[0]
                      UpperCAmelCase          =	len(self.fairseq_tokens_to_ids )
          if str(A ) not in self.fairseq_tokens_to_ids:
                UpperCAmelCase          =	len(self.fairseq_tokens_to_ids )

          UpperCAmelCase          =	{v: k for k, v in self.fairseq_tokens_to_ids.items()}






    def __getstate__(			self ):
          UpperCAmelCase          =	self.__dict__.copy()
          UpperCAmelCase          =	None
          UpperCAmelCase          =	self.sp_model.serialized_model_proto()
          return state






    def __setstate__(			self     ,A ):
          UpperCAmelCase          =	d

          # for backward compatibility
          if not hasattr(self     ,"""sp_model_kwargs""" ):
                UpperCAmelCase          =	{}

          UpperCAmelCase          =	spm.SentencePieceProcessor(**self.sp_model_kwargs )
          self.sp_model.LoadFromSerializedProto(self.sp_model_proto )






    def     _UpperCamelCase							(			self     ,A     ,A = None ):

          if token_ids_a is None:
                return [self.cls_token_id] + token_ids_a + [self.sep_token_id]
          UpperCAmelCase          =	[self.cls_token_id]
          UpperCAmelCase          =	[self.sep_token_id]
          return cls + token_ids_a + sep + sep + token_ids_a + sep






    def     _UpperCamelCase							(			self     ,A     ,A = None     ,A = False ):

          if already_has_special_tokens:
                return super().get_special_tokens_mask(
                    token_ids_a=A     ,token_ids_a=A     ,already_has_special_tokens=A )

          if token_ids_a is None:
                return [1] + ([0] * len(A )) + [1]
          return [1] + ([0] * len(A )) + [1, 1] + ([0] * len(A )) + [1]






    def     _UpperCamelCase							(			self     ,A     ,A = None ):
          UpperCAmelCase          =	[self.sep_token_id]
          UpperCAmelCase          =	[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]






    @property
    def     _UpperCamelCase							(			self ):
          return len(self.fairseq_ids_to_tokens )






    def     _UpperCamelCase							(			self ):
          UpperCAmelCase          =	{self.convert_ids_to_tokens(A ): i for i in range(self.vocab_size )}
          vocab.update(self.added_tokens_encoder )
          return vocab






    def     _UpperCamelCase							(			self     ,A ):
          return self.sp_model.encode(A     ,out_type=A )






    def     _UpperCamelCase							(			self     ,A ):
          if token in self.fairseq_tokens_to_ids:
                return self.fairseq_tokens_to_ids[token]
          else:
                return self.unk_token_id






    def     _UpperCamelCase							(			self     ,A ):
          return self.fairseq_ids_to_tokens[index]






    def     _UpperCamelCase							(			self     ,A ):
          UpperCAmelCase          =	"""""".join(A ).replace(A     ,""" """ ).strip()
          return out_string






    def     _UpperCamelCase							(			self     ,A     ,A = None ):
          if not os.path.isdir(A ):
                logger.error(F'''Vocabulary path ({save_directory}) should be a directory''' )
                return
          UpperCAmelCase          =	os.path.join(
              A     ,(filename_prefix + """-""" if filename_prefix else """""") + VOCAB_FILES_NAMES["""vocab_file"""] )
          UpperCAmelCase          =	os.path.join(
              A     ,(filename_prefix + """-""" if filename_prefix else """""") + VOCAB_FILES_NAMES["""monolingual_vocab_file"""]     ,)

          if os.path.abspath(self.vocab_file ) != os.path.abspath(A ) and os.path.isfile(self.vocab_file ):
                copyfile(self.vocab_file     ,A )
          elif not os.path.isfile(self.vocab_file ):
                with open(A     ,"""wb""" ) as fi:
                      UpperCAmelCase          =	self.sp_model.serialized_model_proto()
                      fi.write(A )

          if os.path.abspath(self.monolingual_vocab_file ) != os.path.abspath(
              A ) and os.path.isfile(self.monolingual_vocab_file ):
                copyfile(self.monolingual_vocab_file     ,A )
          elif not os.path.isfile(self.monolingual_vocab_file ):
                with open(A     ,"""w"""     ,encoding="""utf-8""" ) as fp:
                      for token in self.fairseq_tokens_to_ids:
                            if token not in self.all_special_tokens:
                                  fp.write(F'''{str(A )} \n''' )

          return out_vocab_file, out_monolingual_vocab_file



