



"""simple docstring"""





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

from ...tokenization_utils import AddedToken
from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import is_sentencepiece_available, logging


if is_sentencepiece_available():
					from .tokenization_xlnet import XLNetTokenizer
else:
					__lowerCAmelCase       :					List[Any]             =					None


__lowerCAmelCase       :					Dict             =					logging.get_logger(__name__)

__lowerCAmelCase       :					Dict             =					{"vocab_file": "spiece.model", "tokenizer_file": "tokenizer.json"}

__lowerCAmelCase       :					List[str]             =					{
    "vocab_file": {
        "xlnet-base-cased": "https://huggingface.co/xlnet-base-cased/resolve/main/spiece.model",
        "xlnet-large-cased": "https://huggingface.co/xlnet-large-cased/resolve/main/spiece.model",
    },
    "tokenizer_file": {
        "xlnet-base-cased": "https://huggingface.co/xlnet-base-cased/resolve/main/tokenizer.json",
        "xlnet-large-cased": "https://huggingface.co/xlnet-large-cased/resolve/main/tokenizer.json",
    },
}

__lowerCAmelCase       :					Optional[Any]             =					{
    "xlnet-base-cased": None,
    "xlnet-large-cased": None,
}

__lowerCAmelCase       :					str             =					"▁"

# Segments (not really needed)
__lowerCAmelCase       :					str             =					0
__lowerCAmelCase       :					Any             =					1
__lowerCAmelCase       :					Union[str, Any]             =					2
__lowerCAmelCase       :					str             =					3
__lowerCAmelCase       :					List[str]             =					4



class    _lowerCAmelCase    (				UpperCAmelCase_		):





		"""simple docstring"""






		_lowerCamelCase			  =       VOCAB_FILES_NAMES
		_lowerCamelCase			  =       PRETRAINED_VOCAB_FILES_MAP
		_lowerCamelCase			  =       PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
		_lowerCamelCase			  =       'left'
		_lowerCamelCase			  =       XLNetTokenizer





		def __init__(					self							,    _lowercase=None							,    _lowercase=None							,    _lowercase=False							,    _lowercase=True							,    _lowercase=False							,    _lowercase="<s>"							,    _lowercase="</s>"							,    _lowercase="<unk>"							,    _lowercase="<sep>"							,    _lowercase="<pad>"							,    _lowercase="<cls>"							,    _lowercase="<mask>"							,    _lowercase=["<eop>", "<eod>"]							,    **_lowercase							,    ) ->						int:







								'''simple docstring'''

								snake_case_   : Dict						=			AddedToken(_lowercase							,    lstrip=_lowercase							,    rstrip=_lowercase   ) if isinstance(_lowercase							,    _lowercase   ) else mask_token

								super().__init__(
								    vocab_file=_lowercase							,    tokenizer_file=_lowercase							,    do_lower_case=_lowercase							,    remove_space=_lowercase							,    keep_accents=_lowercase							,    bos_token=_lowercase							,    eos_token=_lowercase							,    unk_token=_lowercase							,    sep_token=_lowercase							,    pad_token=_lowercase							,    cls_token=_lowercase							,    mask_token=_lowercase							,    additional_special_tokens=_lowercase							,    **_lowercase							,    )

								snake_case_   : Optional[int]						=			3
								snake_case_   : List[str]						=			do_lower_case
								snake_case_   : Tuple						=			remove_space
								snake_case_   : List[Any]						=			keep_accents
								snake_case_   : int						=			vocab_file
								snake_case_   : List[Any]						=			False if not self.vocab_file else True





		def    UpperCAmelCase__							(					self							,    _lowercase							,    _lowercase = None   ) ->						List[int]:







								'''simple docstring'''

								snake_case_   : str						=			[self.sep_token_id]
								snake_case_   : Optional[Any]						=			[self.cls_token_id]
								if token_ids_a is None:
														return token_ids_a + sep + cls
								return token_ids_a + sep + token_ids_a + sep + cls





		def    UpperCAmelCase__							(					self							,    _lowercase							,    _lowercase = None   ) ->						List[int]:







								'''simple docstring'''

								snake_case_   : int						=			[self.sep_token_id]
								snake_case_   : str						=			[2]

								if token_ids_a is None:
														return len(token_ids_a + sep   ) * [0] + cls_segment_id
								return len(token_ids_a + sep   ) * [0] + len(token_ids_a + sep   ) * [1] + cls_segment_id





		def    UpperCAmelCase__							(					self							,    _lowercase							,    _lowercase = None   ) ->						Tuple[str]:







								'''simple docstring'''

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

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

								return (out_vocab_file,)






"""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
from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices


__lowerCAmelCase       :					Tuple      					=					logging.get_logger(__name__)

__lowerCAmelCase       :					Dict      					=					{
    '''microsoft/swin-tiny-patch4-window7-224''': (
        '''https://huggingface.co/microsoft/swin-tiny-patch4-window7-224/resolve/main/config.json'''
    ),
    # See all Swin models at https://huggingface.co/models?filter=swin
}



class    _lowerCAmelCase    (				SCREAMING_SNAKE_CASE__  ,				SCREAMING_SNAKE_CASE__		):





		"""simple docstring"""






		_lowerCamelCase			  =       '''swin'''

		_lowerCamelCase			  =       {
		    '''num_attention_heads''': '''num_heads''',
		    '''num_hidden_layers''': '''num_layers''',
		}





		def __init__(					self							,    _lowercase=2_2_4							,    _lowercase=4							,    _lowercase=3							,    _lowercase=9_6							,    _lowercase=[2, 2, 6, 2]							,    _lowercase=[3, 6, 1_2, 2_4]							,    _lowercase=7							,    _lowercase=4.0							,    _lowercase=True							,    _lowercase=0.0							,    _lowercase=0.0							,    _lowercase=0.1							,    _lowercase="gelu"							,    _lowercase=False							,    _lowercase=0.02							,    _lowercase=1E-5							,    _lowercase=3_2							,    _lowercase=None							,    _lowercase=None							,    **_lowercase							,    ) ->						Union[str, Any]:







								'''simple docstring'''

								super().__init__(**_lowercase   )

								snake_case_   : str						=			image_size
								snake_case_   : int						=			patch_size
								snake_case_   : Optional[int]						=			num_channels
								snake_case_   : Union[str, Any]						=			embed_dim
								snake_case_   : Optional[int]						=			depths
								snake_case_   : Optional[int]						=			len(_lowercase   )
								snake_case_   : Optional[Any]						=			num_heads
								snake_case_   : Optional[Any]						=			window_size
								snake_case_   : Optional[Any]						=			mlp_ratio
								snake_case_   : Optional[Any]						=			qkv_bias
								snake_case_   : Optional[Any]						=			hidden_dropout_prob
								snake_case_   : Tuple						=			attention_probs_dropout_prob
								snake_case_   : Union[str, Any]						=			drop_path_rate
								snake_case_   : List[Any]						=			hidden_act
								snake_case_   : str						=			use_absolute_embeddings
								snake_case_   : str						=			layer_norm_eps
								snake_case_   : Optional[Any]						=			initializer_range
								snake_case_   : Any						=			encoder_stride
								# we set the hidden_size attribute in order to make Swin work with VisionEncoderDecoderModel
								# this indicates the channel dimension after the last stage of the model
								snake_case_   : Tuple						=			int(embed_dim * 2 ** (len(_lowercase   ) - 1)   )
								snake_case_   : Tuple						=			["""stem"""] + [f'stage{idx}' for idx in range(1							,    len(_lowercase   ) + 1   )]
								snake_case_			,		snake_case_   : Any						=			get_aligned_output_features_output_indices(
								    out_features=_lowercase							,    out_indices=_lowercase							,    stage_names=self.stage_names   )




class    _lowerCAmelCase    (				SCREAMING_SNAKE_CASE__		):





		"""simple docstring"""






		_lowerCamelCase			  =       version.parse('''1.11'''		)





		@property
		def    UpperCAmelCase__							(					self   ) ->						Mapping[str, Mapping[int, str]]:







								'''simple docstring'''

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





		@property
		def    UpperCAmelCase__							(					self   ) ->						float:







								'''simple docstring'''

								return 1E-4

