






'''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_mbart import MBartTokenizer
else:
		lowerCAmelCase__          =						None


lowerCAmelCase__          =						logging.get_logger(__name__)


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

lowerCAmelCase__          =						{
    'vocab_file': {
        'facebook/mbart-large-en-ro': (
            'https://huggingface.co/facebook/mbart-large-en-ro/resolve/main/sentencepiece.bpe.model'
        ),
        'facebook/mbart-large-cc25': (
            'https://huggingface.co/facebook/mbart-large-cc25/resolve/main/sentencepiece.bpe.model'
        ),
    },
    'tokenizer_file': {
        'facebook/mbart-large-en-ro': 'https://huggingface.co/facebook/mbart-large-en-ro/resolve/main/tokenizer.json',
        'facebook/mbart-large-cc25': 'https://huggingface.co/facebook/mbart-large-cc25/resolve/main/tokenizer.json',
    },
}

lowerCAmelCase__          =						{
    'facebook/mbart-large-en-ro': 1024,
    'facebook/mbart-large-cc25': 1024,
}

# 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']







class       __lowercase					(__lowerCamelCase    ):
	_lowerCamelCase              =  VOCAB_FILES_NAMES
	_lowerCamelCase              =  PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
	_lowerCamelCase              =  PRETRAINED_VOCAB_FILES_MAP
	_lowerCamelCase              =  ['''input_ids''', '''attention_mask''']
	_lowerCamelCase              =  MBartTokenizer

	_lowerCamelCase              =  []
	_lowerCamelCase              =  []

	def __init__(      self   :						int  ,					UpperCAmelCase_   :						List[Any]=None  ,					UpperCAmelCase_   :						int=None  ,					UpperCAmelCase_   :						List[str]="<s>"  ,					UpperCAmelCase_   :						Union[str, Any]="</s>"  ,					UpperCAmelCase_   :						Any="</s>"  ,					UpperCAmelCase_   :						Tuple="<s>"  ,					UpperCAmelCase_   :						Tuple="<unk>"  ,					UpperCAmelCase_   :						Dict="<pad>"  ,					UpperCAmelCase_   :						Any="<mask>"  ,					UpperCAmelCase_   :						Any=None  ,					UpperCAmelCase_   :						str=None  ,					UpperCAmelCase_   :						Union[str, Any]=None  ,					**UpperCAmelCase_   :						List[Any]  ,					):
			# Mask token behave like a normal word, i.e. include the space before it
			UpperCamelCase__				:					Union[str, Any]					=					AddedToken(UpperCAmelCase_  ,					lstrip=UpperCAmelCase_  ,					rstrip=UpperCAmelCase_) if isinstance(UpperCAmelCase_  ,					UpperCAmelCase_) else mask_token

			super().__init__(
			    vocab_file=UpperCAmelCase_  ,					tokenizer_file=UpperCAmelCase_  ,					bos_token=UpperCAmelCase_  ,					eos_token=UpperCAmelCase_  ,					sep_token=UpperCAmelCase_  ,					cls_token=UpperCAmelCase_  ,					unk_token=UpperCAmelCase_  ,					pad_token=UpperCAmelCase_  ,					mask_token=UpperCAmelCase_  ,					src_lang=UpperCAmelCase_  ,					tgt_lang=UpperCAmelCase_  ,					additional_special_tokens=UpperCAmelCase_  ,					**UpperCAmelCase_  ,					)

			UpperCamelCase__				:					Union[str, Any]					=					vocab_file
			UpperCamelCase__				:					Dict					=					False if not self.vocab_file else True

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

			UpperCamelCase__				:					Tuple					=					src_lang if src_lang is not None else 'en_XX'
			UpperCamelCase__				:					Dict					=					self.convert_tokens_to_ids(self._src_lang)
			UpperCamelCase__				:					str					=					tgt_lang
			self.set_src_lang_special_tokens(self._src_lang)

	@property
	def      __UpperCamelCase							(      self   :						Any):
			return self._src_lang

	@src_lang.setter
	def      __UpperCamelCase							(      self   :						Optional[int]  ,					UpperCAmelCase_   :						str):
			UpperCamelCase__				:					List[str]					=					new_src_lang
			self.set_src_lang_special_tokens(self._src_lang)

	def      __UpperCamelCase							(      self   :						List[Any]  ,					UpperCAmelCase_   :						List[int]  ,					UpperCAmelCase_   :						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      __UpperCamelCase							(      self   :						int  ,					UpperCAmelCase_   :						List[int]  ,					UpperCAmelCase_   :						Optional[List[int]] = None):
			UpperCamelCase__				:					Any					=					[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   :						str  ,					UpperCAmelCase_   :						Tuple  ,					UpperCAmelCase_   :						str  ,					UpperCAmelCase_   :						Optional[str]  ,					UpperCAmelCase_   :						Optional[str]  ,					**UpperCAmelCase_   :						Optional[int]):
			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__				:					int					=					src_lang
			UpperCamelCase__				:					Tuple					=					self(UpperCAmelCase_  ,					add_special_tokens=UpperCAmelCase_  ,					return_tensors=UpperCAmelCase_  ,					**UpperCAmelCase_)
			UpperCamelCase__				:					Dict					=					self.convert_tokens_to_ids(UpperCAmelCase_)
			UpperCamelCase__				:					Optional[Any]					=					tgt_lang_id
			return inputs

	def      __UpperCamelCase							(      self   :						List[str]  ,					UpperCAmelCase_   :						List[str]  ,					UpperCAmelCase_   :						str = "en_XX"  ,					UpperCAmelCase_   :						Optional[List[str]] = None  ,					UpperCAmelCase_   :						str = "ro_RO"  ,					**UpperCAmelCase_   :						Dict  ,					):
			UpperCamelCase__				:					List[Any]					=					src_lang
			UpperCamelCase__				:					Tuple					=					tgt_lang
			return super().prepare_seqaseq_batch(UpperCAmelCase_  ,					UpperCAmelCase_  ,					**UpperCAmelCase_)

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

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

	def      __UpperCamelCase							(      self   :						Tuple  ,					UpperCAmelCase_   :						Any):
			UpperCamelCase__				:					Any					=					self.convert_tokens_to_ids(UpperCAmelCase_)
			UpperCamelCase__				:					Optional[int]					=					[]
			UpperCamelCase__				:					str					=					[self.eos_token_id, self.cur_lang_code]

			UpperCamelCase__				:					Union[str, Any]					=					self.convert_ids_to_tokens(self.prefix_tokens)
			UpperCamelCase__				:					List[Any]					=					self.convert_ids_to_tokens(self.suffix_tokens)

			UpperCamelCase__				:					List[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   :						Union[str, Any]  ,					UpperCAmelCase_   :						str):
			UpperCamelCase__				:					Tuple					=					self.convert_tokens_to_ids(UpperCAmelCase_)
			UpperCamelCase__				:					Optional[Any]					=					[]
			UpperCamelCase__				:					Optional[Any]					=					[self.eos_token_id, self.cur_lang_code]

			UpperCamelCase__				:					List[str]					=					self.convert_ids_to_tokens(self.prefix_tokens)
			UpperCamelCase__				:					Tuple					=					self.convert_ids_to_tokens(self.suffix_tokens)

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

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

			return (out_vocab_file,)












'''simple docstring'''




import warnings
from collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


lowerCAmelCase__          =						logging.get_logger(__name__)

lowerCAmelCase__          =						{
    'nvidia/segformer-b0-finetuned-ade-512-512': (
        'https://huggingface.co/nvidia/segformer-b0-finetuned-ade-512-512/resolve/main/config.json'
    ),
    # See all SegFormer models at https://huggingface.co/models?filter=segformer
}







class       __lowercase					(__lowerCamelCase    ):
	_lowerCamelCase              =  '''segformer'''

	def __init__(      self   :						Tuple  ,					UpperCAmelCase_   :						Optional[Any]=3  ,					UpperCAmelCase_   :						Optional[int]=4  ,					UpperCAmelCase_   :						Tuple=[2, 2, 2, 2]  ,					UpperCAmelCase_   :						List[str]=[8, 4, 2, 1]  ,					UpperCAmelCase_   :						Union[str, Any]=[32, 64, 160, 256]  ,					UpperCAmelCase_   :						Any=[7, 3, 3, 3]  ,					UpperCAmelCase_   :						Any=[4, 2, 2, 2]  ,					UpperCAmelCase_   :						Union[str, Any]=[1, 2, 5, 8]  ,					UpperCAmelCase_   :						Tuple=[4, 4, 4, 4]  ,					UpperCAmelCase_   :						str="gelu"  ,					UpperCAmelCase_   :						List[Any]=0.0  ,					UpperCAmelCase_   :						int=0.0  ,					UpperCAmelCase_   :						int=0.1  ,					UpperCAmelCase_   :						List[str]=0.02  ,					UpperCAmelCase_   :						Dict=0.1  ,					UpperCAmelCase_   :						Dict=1e-6  ,					UpperCAmelCase_   :						int=256  ,					UpperCAmelCase_   :						Optional[int]=255  ,					**UpperCAmelCase_   :						Tuple  ,					):
			super().__init__(**UpperCAmelCase_)

			if "reshape_last_stage" in kwargs and kwargs["reshape_last_stage"] is False:
					warnings.warn(
					    'Reshape_last_stage is set to False in this config. This argument is deprecated and will soon be'
					    ' removed, as the behaviour will default to that of reshape_last_stage = True.'  ,					UpperCAmelCase_  ,					)

			UpperCamelCase__				:					List[Any]					=					num_channels
			UpperCamelCase__				:					Any					=					num_encoder_blocks
			UpperCamelCase__				:					Dict					=					depths
			UpperCamelCase__				:					int					=					sr_ratios
			UpperCamelCase__				:					str					=					hidden_sizes
			UpperCamelCase__				:					List[str]					=					patch_sizes
			UpperCamelCase__				:					Optional[int]					=					strides
			UpperCamelCase__				:					Dict					=					mlp_ratios
			UpperCamelCase__				:					List[str]					=					num_attention_heads
			UpperCamelCase__				:					int					=					hidden_act
			UpperCamelCase__				:					Any					=					hidden_dropout_prob
			UpperCamelCase__				:					str					=					attention_probs_dropout_prob
			UpperCamelCase__				:					List[str]					=					classifier_dropout_prob
			UpperCamelCase__				:					List[Any]					=					initializer_range
			UpperCamelCase__				:					Union[str, Any]					=					drop_path_rate
			UpperCamelCase__				:					int					=					layer_norm_eps
			UpperCamelCase__				:					Dict					=					decoder_hidden_size
			UpperCamelCase__				:					List[Any]					=					kwargs.get('reshape_last_stage'  ,					UpperCAmelCase_)
			UpperCamelCase__				:					List[str]					=					semantic_loss_ignore_index







class       __lowercase					(__lowerCamelCase    ):
	_lowerCamelCase              =  version.parse('''1.11'''    )

	@property
	def      __UpperCamelCase							(      self   :						Optional[Any]):
			return OrderedDict(
			    [
			        ('pixel_values', {0: 'batch', 1: 'num_channels', 2: 'height', 3: 'width'}),
			    ])

	@property
	def      __UpperCamelCase							(      self   :						Optional[Any]):
			return 1e-4





	@property
	def      __UpperCamelCase							(      self   :						Any):
			return 12




