



'''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_longformer import LongformerTokenizer


A_				:					Any							=      logging.get_logger(__name__)

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

A_				:					Optional[Any]							=      {
    """vocab_file""": {
        """allenai/longformer-base-4096""": """https://huggingface.co/allenai/longformer-base-4096/resolve/main/vocab.json""",
        """allenai/longformer-large-4096""": (
            """https://huggingface.co/allenai/longformer-large-4096/resolve/main/vocab.json"""
        ),
        """allenai/longformer-large-4096-finetuned-triviaqa""": (
            """https://huggingface.co/allenai/longformer-large-4096-finetuned-triviaqa/resolve/main/vocab.json"""
        ),
        """allenai/longformer-base-4096-extra.pos.embd.only""": (
            """https://huggingface.co/allenai/longformer-base-4096-extra.pos.embd.only/resolve/main/vocab.json"""
        ),
        """allenai/longformer-large-4096-extra.pos.embd.only""": (
            """https://huggingface.co/allenai/longformer-large-4096-extra.pos.embd.only/resolve/main/vocab.json"""
        ),
    },
    """merges_file""": {
        """allenai/longformer-base-4096""": """https://huggingface.co/allenai/longformer-base-4096/resolve/main/merges.txt""",
        """allenai/longformer-large-4096""": (
            """https://huggingface.co/allenai/longformer-large-4096/resolve/main/merges.txt"""
        ),
        """allenai/longformer-large-4096-finetuned-triviaqa""": (
            """https://huggingface.co/allenai/longformer-large-4096-finetuned-triviaqa/resolve/main/merges.txt"""
        ),
        """allenai/longformer-base-4096-extra.pos.embd.only""": (
            """https://huggingface.co/allenai/longformer-base-4096-extra.pos.embd.only/resolve/main/merges.txt"""
        ),
        """allenai/longformer-large-4096-extra.pos.embd.only""": (
            """https://huggingface.co/allenai/longformer-large-4096-extra.pos.embd.only/resolve/main/merges.txt"""
        ),
    },
    """tokenizer_file""": {
        """allenai/longformer-base-4096""": (
            """https://huggingface.co/allenai/longformer-base-4096/resolve/main/tokenizer.json"""
        ),
        """allenai/longformer-large-4096""": (
            """https://huggingface.co/allenai/longformer-large-4096/resolve/main/tokenizer.json"""
        ),
        """allenai/longformer-large-4096-finetuned-triviaqa""": (
            """https://huggingface.co/allenai/longformer-large-4096-finetuned-triviaqa/resolve/main/tokenizer.json"""
        ),
        """allenai/longformer-base-4096-extra.pos.embd.only""": (
            """https://huggingface.co/allenai/longformer-base-4096-extra.pos.embd.only/resolve/main/tokenizer.json"""
        ),
        """allenai/longformer-large-4096-extra.pos.embd.only""": (
            """https://huggingface.co/allenai/longformer-large-4096-extra.pos.embd.only/resolve/main/tokenizer.json"""
        ),
    },
}

A_				:					int							=      {
    """allenai/longformer-base-4096""": 4_0_9_6,
    """allenai/longformer-large-4096""": 4_0_9_6,
    """allenai/longformer-large-4096-finetuned-triviaqa""": 4_0_9_6,
    """allenai/longformer-base-4096-extra.pos.embd.only""": 4_0_9_6,
    """allenai/longformer-large-4096-extra.pos.embd.only""": 4_0_9_6,
}



class 				lowercase			(    _lowerCamelCase							):


 """simple docstring"""


 UpperCAmelCase		      =    VOCAB_FILES_NAMES
 UpperCAmelCase		      =    PRETRAINED_VOCAB_FILES_MAP
 UpperCAmelCase		      =    PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
 UpperCAmelCase		      =    ["""input_ids""", """attention_mask"""]
 UpperCAmelCase		      =    LongformerTokenizer







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

        _UpperCAmelCase    :		Any     	=					json.loads(self.backend_tokenizer.pre_tokenizer.__getstate__()				)
        if pre_tok_state.get("""add_prefix_space"""    ,a_				) != add_prefix_space:
               _UpperCAmelCase    :		List[str]     	=					getattr(a_    ,pre_tok_state.pop("""type"""				)				)
               _UpperCAmelCase    :		List[str]     	=					add_prefix_space
               _UpperCAmelCase    :		int     	=					pre_tok_class(**a_				)

        _UpperCAmelCase    :		Union[str, Any]     	=					add_prefix_space

        _UpperCAmelCase    :		Union[str, Any]     	=					"""post_processor"""
        _UpperCAmelCase    :		Optional[Any]     	=					getattr(self.backend_tokenizer    ,a_    ,a_				)
        if tokenizer_component_instance:
               _UpperCAmelCase    :		Tuple     	=					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:
                      _UpperCAmelCase    :		str     	=					tuple(state["""sep"""]				)
               if "cls" in state:
                      _UpperCAmelCase    :		str     	=					tuple(state["""cls"""]				)

               _UpperCAmelCase    :		int     	=					False

               if state.get("""add_prefix_space"""    ,a_				) != add_prefix_space:
                      _UpperCAmelCase    :		Dict     	=					add_prefix_space
                      _UpperCAmelCase    :		Optional[int]     	=					True

               if state.get("""trim_offsets"""    ,a_				) != trim_offsets:
                      _UpperCAmelCase    :		Optional[Any]     	=					trim_offsets
                      _UpperCAmelCase    :		str     	=					True

               if changes_to_apply:
                      _UpperCAmelCase    :		Dict     	=					getattr(a_    ,state.pop("""type"""				)				)
                      _UpperCAmelCase    :		Dict     	=					component_class(**a_				)
                      setattr(self.backend_tokenizer    ,a_    ,a_				)







 @property
 def _snake_case					(				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 _snake_case					(				self    ,a_				)						->  List[str]:
        _UpperCAmelCase    :		Tuple     	=					AddedToken(a_    ,lstrip=a_    ,rstrip=a_				) if isinstance(a_    ,a_				) else value
        _UpperCAmelCase    :		List[Any]     	=					value







 def _snake_case					(				self    ,*a_    ,**a_				)						->  BatchEncoding:
        _UpperCAmelCase    :		int     	=					kwargs.get("""is_split_into_words"""    ,a_				)
        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(*a_    ,**a_				)







 def _snake_case					(				self    ,*a_    ,**a_				)						->  BatchEncoding:
        _UpperCAmelCase    :		int     	=					kwargs.get("""is_split_into_words"""    ,a_				)

        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(*a_    ,**a_				)







 def _snake_case					(				self    ,a_    ,a_ = None				)						->  Tuple[str]:
        _UpperCAmelCase    :		Any     	=					self._tokenizer.model.save(a_    ,name=a_				)
        return tuple(a_				)







 def _snake_case					(				self    ,a_    ,a_=None				)						->  Optional[int]:
        _UpperCAmelCase    :		str     	=					[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 _snake_case					(				self    ,a_    ,a_ = None				)						->  List[int]:
        _UpperCAmelCase    :		Dict     	=					[self.sep_token_id]
        _UpperCAmelCase    :		Dict     	=					[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'''







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				:		Optional[Any]				      =    {
    'MBZUAI/swiftformer-xs': 'https://huggingface.co/MBZUAI/swiftformer-xs/resolve/main/config.json',
}





class 	lowerCamelCase_				(			UpperCAmelCase_				):




					'''simple docstring'''






					lowercase__       =					"""swiftformer"""






					def __init__(       self,    __UpperCamelCase=3,    __UpperCamelCase=[3, 3, 6, 4],    __UpperCamelCase=[48, 56, 112, 220],    __UpperCamelCase=4,    __UpperCamelCase=[True, True, True, True],    __UpperCamelCase="gelu",    __UpperCamelCase=3,    __UpperCamelCase=2,    __UpperCamelCase=1,    __UpperCamelCase=0.0,    __UpperCamelCase=True,    __UpperCamelCase=1E-5,    __UpperCamelCase=1E-5,    **__UpperCamelCase,    ):
							super().__init__(**__UpperCamelCase					)
							_snake_case      			=			num_channels
							_snake_case      			=			depths
							_snake_case      			=			embed_dims
							_snake_case      			=			mlp_ratio
							_snake_case      			=			downsamples
							_snake_case      			=			hidden_act
							_snake_case      			=			down_patch_size
							_snake_case      			=			down_stride
							_snake_case      			=			down_pad
							_snake_case      			=			drop_path_rate
							_snake_case      			=			use_layer_scale
							_snake_case      			=			layer_scale_init_value
							_snake_case      			=			batch_norm_eps





class 	lowerCamelCase_				(			UpperCAmelCase_				):




					'''simple docstring'''






					lowercase__       =					version.parse("""1.11"""				)






					@property
					def 							__SCREAMING_SNAKE_CASE      (       self					):
							return OrderedDict(
							    [
							        ("pixel_values", {0: "batch", 1: "num_channels", 2: "height", 3: "width"}),
							    ]					)






					@property
					def 							__SCREAMING_SNAKE_CASE      (       self					):
							return 1E-4





