




'''simple docstring'''


import json
from typing import List, Optional, Tuple

from tokenizers import pre_tokenizers, processors

from ...tokenization_utils_base import AddedToken, BatchEncoding
from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_bart import BartTokenizer


UpperCAmelCase_					=   logging.get_logger(__name__)


UpperCAmelCase_					=   {"vocab_file": "vocab.json", "merges_file": "merges.txt", "tokenizer_file": "tokenizer.json"}

# See all BART models at https://huggingface.co/models?filter=bart
UpperCAmelCase_					=   {
    "vocab_file": {
        "facebook/bart-base": "https://huggingface.co/facebook/bart-base/resolve/main/vocab.json",
        "facebook/bart-large": "https://huggingface.co/facebook/bart-large/resolve/main/vocab.json",
        "facebook/bart-large-mnli": "https://huggingface.co/facebook/bart-large-mnli/resolve/main/vocab.json",
        "facebook/bart-large-cnn": "https://huggingface.co/facebook/bart-large-cnn/resolve/main/vocab.json",
        "facebook/bart-large-xsum": "https://huggingface.co/facebook/bart-large-xsum/resolve/main/vocab.json",
        "yjernite/bart_eli5": "https://huggingface.co/yjernite/bart_eli5/resolve/main/vocab.json",
    },
    "merges_file": {
        "facebook/bart-base": "https://huggingface.co/facebook/bart-base/resolve/main/merges.txt",
        "facebook/bart-large": "https://huggingface.co/facebook/bart-large/resolve/main/merges.txt",
        "facebook/bart-large-mnli": "https://huggingface.co/facebook/bart-large-mnli/resolve/main/merges.txt",
        "facebook/bart-large-cnn": "https://huggingface.co/facebook/bart-large-cnn/resolve/main/merges.txt",
        "facebook/bart-large-xsum": "https://huggingface.co/facebook/bart-large-xsum/resolve/main/merges.txt",
        "yjernite/bart_eli5": "https://huggingface.co/yjernite/bart_eli5/resolve/main/merges.txt",
    },
    "tokenizer_file": {
        "facebook/bart-base": "https://huggingface.co/facebook/bart-base/resolve/main/tokenizer.json",
        "facebook/bart-large": "https://huggingface.co/facebook/bart-large/resolve/main/tokenizer.json",
        "facebook/bart-large-mnli": "https://huggingface.co/facebook/bart-large-mnli/resolve/main/tokenizer.json",
        "facebook/bart-large-cnn": "https://huggingface.co/facebook/bart-large-cnn/resolve/main/tokenizer.json",
        "facebook/bart-large-xsum": "https://huggingface.co/facebook/bart-large-xsum/resolve/main/tokenizer.json",
        "yjernite/bart_eli5": "https://huggingface.co/yjernite/bart_eli5/resolve/main/tokenizer.json",
    },
}

UpperCAmelCase_					=   {
    "facebook/bart-base": 10_24,
    "facebook/bart-large": 10_24,
    "facebook/bart-large-mnli": 10_24,
    "facebook/bart-large-cnn": 10_24,
    "facebook/bart-large-xsum": 10_24,
    "yjernite/bart_eli5": 10_24,
}





class  __lowercase    (	__magic_name__			):
   _a    						=   VOCAB_FILES_NAMES
   _a    						=   PRETRAINED_VOCAB_FILES_MAP
   _a    						=   PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
   _a    						=   ["""input_ids""", """attention_mask"""]
   _a    						=   BartTokenizer







   def __init__(						self   ,				UpperCamelCase=None   ,				UpperCamelCase=None   ,				UpperCamelCase=None   ,				UpperCamelCase="replace"   ,				UpperCamelCase="<s>"   ,				UpperCamelCase="</s>"   ,				UpperCamelCase="</s>"   ,				UpperCamelCase="<s>"   ,				UpperCamelCase="<unk>"   ,				UpperCamelCase="<pad>"   ,				UpperCamelCase="<mask>"   ,				UpperCamelCase=False   ,				UpperCamelCase=True   ,				**UpperCamelCase   ,				)					->     Union[str, Any]:
     super().__init__(
         UpperCamelCase   ,				UpperCamelCase   ,				tokenizer_file=UpperCamelCase   ,				errors=UpperCamelCase   ,				bos_token=UpperCamelCase   ,				eos_token=UpperCamelCase   ,				sep_token=UpperCamelCase   ,				cls_token=UpperCamelCase   ,				unk_token=UpperCamelCase   ,				pad_token=UpperCamelCase   ,				mask_token=UpperCamelCase   ,				add_prefix_space=UpperCamelCase   ,				trim_offsets=UpperCamelCase   ,				**UpperCamelCase   ,				)

     __a								=       json.loads(self.backend_tokenizer.pre_tokenizer.__getstate__()   )
     if pre_tok_state.get('add_prefix_space'   ,				UpperCamelCase   ) != add_prefix_space:
       __a								=       getattr(UpperCamelCase   ,				pre_tok_state.pop('type'   )   )
       __a								=       add_prefix_space
       __a								=       pre_tok_class(**UpperCamelCase   )

     __a								=       add_prefix_space

     # the pre_tokenizer is already updated in the GPT2TokenizerFast `__init__`
     __a								=       'post_processor'
     __a								=       getattr(self.backend_tokenizer   ,				UpperCamelCase   ,				UpperCamelCase   )
     if tokenizer_component_instance:
       __a								=       json.loads(tokenizer_component_instance.__getstate__()   )

       # The lists 'sep' and 'cls' must be cased in tuples for the object `post_processor_class`
       if "sep" in state:
         __a								=       tuple(state['sep']   )
       if "cls" in state:
         __a								=       tuple(state['cls']   )

       __a								=       False

       if state.get('add_prefix_space'   ,				UpperCamelCase   ) != add_prefix_space:
         __a								=       add_prefix_space
         __a								=       True

       if state.get('trim_offsets'   ,				UpperCamelCase   ) != trim_offsets:
         __a								=       trim_offsets
         __a								=       True

       if changes_to_apply:
         __a								=       getattr(UpperCamelCase   ,				state.pop('type'   )   )
         __a								=       component_class(**UpperCamelCase   )
         setattr(self.backend_tokenizer   ,				UpperCamelCase   ,				UpperCamelCase   )







   @property
   def 		UpperCamelCase__      (						self   )					->     str:
     if self._mask_token is None:
       if self.verbose:
         logger.error('Using mask_token, but it is not set yet.'   )
       return None
     return str(self._mask_token   )







   @mask_token.setter
   def 		UpperCamelCase__      (						self   ,				UpperCamelCase   )					->     List[Any]:
     __a								=       AddedToken(UpperCamelCase   ,				lstrip=UpperCamelCase   ,				rstrip=UpperCamelCase   ) if isinstance(UpperCamelCase   ,				UpperCamelCase   ) else value
     __a								=       value







   def 		UpperCamelCase__      (						self   ,				*UpperCamelCase   ,				**UpperCamelCase   )					->     BatchEncoding:
     __a								=       kwargs.get('is_split_into_words'   ,				UpperCamelCase   )

     if is_split_into_words and not self.add_prefix_space:
       raise ValueError(
           f"You need to instantiate {self.__class__.__name__} with add_prefix_space=True "
           'to use it with pretokenized inputs.'   )

     return super()._batch_encode_plus(*UpperCamelCase   ,				**UpperCamelCase   )







   def 		UpperCamelCase__      (						self   ,				*UpperCamelCase   ,				**UpperCamelCase   )					->     BatchEncoding:
     __a								=       kwargs.get('is_split_into_words'   ,				UpperCamelCase   )

     if is_split_into_words and not self.add_prefix_space:
       raise ValueError(
           f"You need to instantiate {self.__class__.__name__} with add_prefix_space=True "
           'to use it with pretokenized inputs.'   )

     return super()._encode_plus(*UpperCamelCase   ,				**UpperCamelCase   )







   def 		UpperCamelCase__      (						self   ,				UpperCamelCase   ,				UpperCamelCase = None   )					->     Tuple[str]:
     __a								=       self._tokenizer.model.save(UpperCamelCase   ,				name=UpperCamelCase   )
     return tuple(UpperCamelCase   )







   def 		UpperCamelCase__      (						self   ,				UpperCamelCase   ,				UpperCamelCase=None   )					->     List[str]:
     __a								=       [self.bos_token_id] + token_ids_a + [self.eos_token_id]
     if token_ids_a is None:
       return output

     return output + [self.eos_token_id] + token_ids_a + [self.eos_token_id]







   def 		UpperCamelCase__      (						self   ,				UpperCamelCase   ,				UpperCamelCase = None   )					->     List[int]:
     __a								=       [self.sep_token_id]
     __a								=       [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]









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


UpperCAmelCase_					=   logging.get_logger(__name__)

UpperCAmelCase_					=   {
    "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    (	__magic_name__			):
   _a    						=   """segformer"""







   def __init__(						self   ,				UpperCamelCase=3   ,				UpperCamelCase=4   ,				UpperCamelCase=[2, 2, 2, 2]   ,				UpperCamelCase=[8, 4, 2, 1]   ,				UpperCamelCase=[32, 64, 160, 256]   ,				UpperCamelCase=[7, 3, 3, 3]   ,				UpperCamelCase=[4, 2, 2, 2]   ,				UpperCamelCase=[1, 2, 5, 8]   ,				UpperCamelCase=[4, 4, 4, 4]   ,				UpperCamelCase="gelu"   ,				UpperCamelCase=0.0   ,				UpperCamelCase=0.0   ,				UpperCamelCase=0.1   ,				UpperCamelCase=0.02   ,				UpperCamelCase=0.1   ,				UpperCamelCase=1e-6   ,				UpperCamelCase=256   ,				UpperCamelCase=255   ,				**UpperCamelCase   ,				)					->     int:
     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   ,				)

     __a								=       num_channels
     __a								=       num_encoder_blocks
     __a								=       depths
     __a								=       sr_ratios
     __a								=       hidden_sizes
     __a								=       patch_sizes
     __a								=       strides
     __a								=       mlp_ratios
     __a								=       num_attention_heads
     __a								=       hidden_act
     __a								=       hidden_dropout_prob
     __a								=       attention_probs_dropout_prob
     __a								=       classifier_dropout_prob
     __a								=       initializer_range
     __a								=       drop_path_rate
     __a								=       layer_norm_eps
     __a								=       decoder_hidden_size
     __a								=       kwargs.get('reshape_last_stage'   ,				UpperCamelCase   )
     __a								=       semantic_loss_ignore_index





class  __lowercase    (	__magic_name__			):
   _a    						=   version.parse("""1.11"""			)







   @property
   def 		UpperCamelCase__      (						self   )					->     Mapping[str, Mapping[int, str]]:
     return OrderedDict(
         [
             ('pixel_values', {0: 'batch', 1: 'num_channels', 2: 'height', 3: 'width'}),
         ]   )







   @property
   def 		UpperCamelCase__      (						self   )					->     float:
     return 1e-4







   @property
   def 		UpperCamelCase__      (						self   )					->     int:
     return 12



