


'''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     :  List[str]											=    logging.get_logger(__name__)

lowerCAmelCase     :  Tuple											=    {
    """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 						UpperCamelCase__       (			SCREAMING_SNAKE_CASE_						):



     """simple docstring"""






     __magic_name__           =     "segformer"







     def __init__(			self   ,						snake_case__=3   ,						snake_case__=4   ,						snake_case__=[2, 2, 2, 2]   ,						snake_case__=[8, 4, 2, 1]   ,						snake_case__=[32, 64, 160, 256]   ,						snake_case__=[7, 3, 3, 3]   ,						snake_case__=[4, 2, 2, 2]   ,						snake_case__=[1, 2, 5, 8]   ,						snake_case__=[4, 4, 4, 4]   ,						snake_case__="gelu"   ,						snake_case__=0.0   ,						snake_case__=0.0   ,						snake_case__=0.1   ,						snake_case__=0.02   ,						snake_case__=0.1   ,						snake_case__=1E-6   ,						snake_case__=256   ,						snake_case__=255   ,						**snake_case__   ,						):

            '''simple docstring'''

            super().__init__(**snake_case__ )

            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.'   ,						snake_case__   ,						)

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



     """simple docstring"""






     __magic_name__           =     version.parse("1.11"						)







     @property
     def a						(			self ):

            '''simple docstring'''

            return OrderedDict(
                [
                    ('pixel_values', {0: 'batch', 1: 'num_channels', 2: 'height', 3: 'width'}),
                ] )







     @property
     def a						(			self ):

            '''simple docstring'''

            return 1E-4







     @property
     def a						(			self ):

            '''simple docstring'''

            return 12





'''simple docstring'''







import json
import re
from typing import TYPE_CHECKING, List, Optional, Tuple, Union

import numpy as np

from ...utils import is_tf_available, is_torch_available, logging


if TYPE_CHECKING:
       if is_torch_available():
              import torch
       if is_tf_available():
              import tensorflow as tf

from tokenizers import pre_tokenizers

from ...tokenization_utils_base import BatchEncoding
from ...tokenization_utils_fast import PreTrainedTokenizerFast
from .tokenization_codegen import CodeGenTokenizer


lowerCAmelCase     :  Optional[int]											=    logging.get_logger(__name__)

lowerCAmelCase     :  Union[str, Any]											=    {"""vocab_file""": """vocab.json""", """merges_file""": """merges.txt""", """tokenizer_file""": """tokenizer.json"""}

lowerCAmelCase     :  Optional[Any]											=    {
    """vocab_file""": {
        """Salesforce/codegen-350M-mono""": """https://huggingface.co/Salesforce/codegen-350M-mono/resolve/main/vocab.json""",
    },
    """merges_file""": {
        """Salesforce/codegen-350M-mono""": """https://huggingface.co/Salesforce/codegen-350M-mono/resolve/main/merges.txt""",
    },
    """tokenizer_file""": {
        """Salesforce/codegen-350M-mono""": (
            """https://huggingface.co/Salesforce/codegen-350M-mono/resolve/main/tokenizer.json"""
        ),
    },
}

lowerCAmelCase     :  List[str]											=    {
    """Salesforce/codegen-350M-mono""": 20_48,
}
class 						UpperCamelCase__       (			SCREAMING_SNAKE_CASE_						):



     """simple docstring"""






     __magic_name__           =     VOCAB_FILES_NAMES
     __magic_name__           =     PRETRAINED_VOCAB_FILES_MAP
     __magic_name__           =     PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
     __magic_name__           =     ["input_ids", "attention_mask"]
     __magic_name__           =     CodeGenTokenizer







     def __init__(			self   ,						snake_case__=None   ,						snake_case__=None   ,						snake_case__=None   ,						snake_case__="<|endoftext|>"   ,						snake_case__="<|endoftext|>"   ,						snake_case__="<|endoftext|>"   ,						snake_case__=False   ,						**snake_case__   ,						):

            '''simple docstring'''

            super().__init__(
                snake_case__   ,						snake_case__   ,						tokenizer_file=snake_case__   ,						unk_token=snake_case__   ,						bos_token=snake_case__   ,						eos_token=snake_case__   ,						add_prefix_space=snake_case__   ,						**snake_case__   ,						)

            if kwargs.pop('add_bos_token'   ,						snake_case__ ):
                   _lowerCAmelCase     :				Tuple       =							kwargs.pop('name_or_path'   ,						'' )
                   raise ValueError(
                       'Currenty GPT2\'s fast tokenizer does NOT support adding a BOS token.'
                       'Instead you should use GPT2\'s slow tokenizer class `CodeGenTokenizer` as follows: \n'
                       F'`CodeGenTokenizer.from_pretrained(\'{model_id}\')`\nor\n'
                       F'`AutoTokenizer.from_pretrained(\'{model_id}\', use_fast=False)`\n'
                       'This issue will be fixed soon, see: https://github.com/huggingface/tokenizers/pull/1005.'
                       ' so that the fast tokenizer works correctly.' )

            _lowerCAmelCase     :				List[str]       =							json.loads(self.backend_tokenizer.pre_tokenizer.__getstate__() )
            if pre_tok_state.get('add_prefix_space'   ,						snake_case__ ) != add_prefix_space:
                   _lowerCAmelCase     :				List[Any]       =							getattr(snake_case__   ,						pre_tok_state.pop('type' ) )
                   _lowerCAmelCase     :				Dict       =							add_prefix_space
                   _lowerCAmelCase     :				List[Any]       =							pre_tok_class(**snake_case__ )

            _lowerCAmelCase     :				Tuple       =							add_prefix_space







     def a						(			self   ,						*snake_case__   ,						**snake_case__ ):

            '''simple docstring'''

            _lowerCAmelCase     :				Union[str, Any]       =							kwargs.get('is_split_into_words'   ,						snake_case__ )
            assert self.add_prefix_space or not is_split_into_words, (
                F'You need to instantiate {self.__class__.__name__} with add_prefix_space=True '
                "to use it with pretokenized inputs."
            )

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







     def a						(			self   ,						*snake_case__   ,						**snake_case__ ):

            '''simple docstring'''

            _lowerCAmelCase     :				List[str]       =							kwargs.get('is_split_into_words'   ,						snake_case__ )

            assert self.add_prefix_space or not is_split_into_words, (
                F'You need to instantiate {self.__class__.__name__} with add_prefix_space=True '
                "to use it with pretokenized inputs."
            )

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







     def a						(			self   ,						snake_case__   ,						snake_case__ = None ):

            '''simple docstring'''

            _lowerCAmelCase     :				List[str]       =							self._tokenizer.model.save(snake_case__   ,						name=snake_case__ )
            return tuple(snake_case__ )







     def a						(			self   ,						snake_case__   ,						snake_case__ = False   ,						snake_case__ = None   ,						snake_case__ = None   ,						**snake_case__   ,						):

            '''simple docstring'''

            _lowerCAmelCase     :				Dict       =							super().decode(
                token_ids=snake_case__   ,						skip_special_tokens=snake_case__   ,						clean_up_tokenization_spaces=snake_case__   ,						**snake_case__   ,						)

            if truncate_before_pattern is not None and len(snake_case__ ) > 0:
                   _lowerCAmelCase     :				Optional[int]       =							self.truncate(snake_case__   ,						snake_case__ )

            return decoded_text







     def a						(			self   ,						snake_case__   ,						snake_case__ ):

            '''simple docstring'''

            def find_re(snake_case__   ,						snake_case__   ,						snake_case__ ):
                   _lowerCAmelCase     :				List[Any]       =							pattern.search(snake_case__   ,						snake_case__ )
                   return m.start() if m else -1

            _lowerCAmelCase     :				Any       =							[re.compile(snake_case__   ,						re.MULTILINE ) for pattern in truncate_before_pattern]

            _lowerCAmelCase     :				Dict       =							list(re.finditer('^print'   ,						snake_case__   ,						re.MULTILINE ) )

            if len(snake_case__ ) > 1:
                   _lowerCAmelCase     :				Optional[int]       =							completion[: prints[1].start()]

            _lowerCAmelCase     :				Optional[int]       =							list(re.finditer('^def'   ,						snake_case__   ,						re.MULTILINE ) )

            if len(snake_case__ ) > 1:
                   _lowerCAmelCase     :				Optional[Any]       =							completion[: defs[1].start()]

            _lowerCAmelCase     :				int       =							0

            _lowerCAmelCase     :				Tuple       =							[
                pos for pos in [find_re(snake_case__   ,						snake_case__   ,						snake_case__ ) for terminal in terminals] if pos != -1
            ]

            if len(snake_case__ ) > 0:
                   return completion[: min(snake_case__ )]
            else:
                   return completion

