



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


__lowerCAmelCase       :					Dict      					=					logging.get_logger(__name__)


__lowerCAmelCase       :					Optional[int]      					=					{'''vocab_file''': '''vocab.json''', '''merges_file''': '''merges.txt''', '''tokenizer_file''': '''tokenizer.json'''}

# See all BART models at https://huggingface.co/models?filter=bart
__lowerCAmelCase       :					List[Any]      					=					{
    '''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''',
    },
}

__lowerCAmelCase       :					Dict      					=					{
    '''facebook/bart-base''': 1024,
    '''facebook/bart-large''': 1024,
    '''facebook/bart-large-mnli''': 1024,
    '''facebook/bart-large-cnn''': 1024,
    '''facebook/bart-large-xsum''': 1024,
    '''yjernite/bart_eli5''': 1024,
}



class    _lowerCAmelCase    (				SCREAMING_SNAKE_CASE__		):





		"""simple docstring"""






		_lowerCamelCase			  =       VOCAB_FILES_NAMES
		_lowerCamelCase			  =       PRETRAINED_VOCAB_FILES_MAP
		_lowerCamelCase			  =       PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
		_lowerCamelCase			  =       ['''input_ids''', '''attention_mask''']
		_lowerCamelCase			  =       BartTokenizer





		def __init__(					self							,    _lowercase=None							,    _lowercase=None							,    _lowercase=None							,    _lowercase="replace"							,    _lowercase="<s>"							,    _lowercase="</s>"							,    _lowercase="</s>"							,    _lowercase="<s>"							,    _lowercase="<unk>"							,    _lowercase="<pad>"							,    _lowercase="<mask>"							,    _lowercase=False							,    _lowercase=True							,    **_lowercase							,    ) ->						Union[str, Any]:







								'''simple docstring'''

								super().__init__(
								    _lowercase							,    _lowercase							,    tokenizer_file=_lowercase							,    errors=_lowercase							,    bos_token=_lowercase							,    eos_token=_lowercase							,    sep_token=_lowercase							,    cls_token=_lowercase							,    unk_token=_lowercase							,    pad_token=_lowercase							,    mask_token=_lowercase							,    add_prefix_space=_lowercase							,    trim_offsets=_lowercase							,    **_lowercase							,    )

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

								snake_case_   : List[Any]						=			add_prefix_space

								# the pre_tokenizer is already updated in the GPT2TokenizerFast `__init__`
								snake_case_   : Dict						=			"""post_processor"""
								snake_case_   : List[Any]						=			getattr(self.backend_tokenizer							,    _lowercase							,    _lowercase   )
								if tokenizer_component_instance:
														snake_case_   : str						=			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:
																				snake_case_   : Dict						=			tuple(state["""sep"""]   )
														if "cls" in state:
																				snake_case_   : Union[str, Any]						=			tuple(state["""cls"""]   )

														snake_case_   : List[Any]						=			False

														if state.get("""add_prefix_space"""							,    _lowercase   ) != add_prefix_space:
																				snake_case_   : Union[str, Any]						=			add_prefix_space
																				snake_case_   : List[Any]						=			True

														if state.get("""trim_offsets"""							,    _lowercase   ) != trim_offsets:
																				snake_case_   : List[Any]						=			trim_offsets
																				snake_case_   : Dict						=			True

														if changes_to_apply:
																				snake_case_   : Tuple						=			getattr(_lowercase							,    state.pop("""type"""   )   )
																				snake_case_   : Any						=			component_class(**_lowercase   )
																				setattr(self.backend_tokenizer							,    _lowercase							,    _lowercase   )





		@property
		def    UpperCAmelCase__							(					self   ) ->						str:







								'''simple docstring'''

								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							,    _lowercase   ) ->						Optional[int]:







								'''simple docstring'''

								snake_case_   : Union[str, Any]						=			AddedToken(_lowercase							,    lstrip=_lowercase							,    rstrip=_lowercase   ) if isinstance(_lowercase							,    _lowercase   ) else value
								snake_case_   : str						=			value





		def    UpperCAmelCase__							(					self							,    *_lowercase							,    **_lowercase   ) ->						BatchEncoding:







								'''simple docstring'''

								snake_case_   : Tuple						=			kwargs.get("""is_split_into_words"""							,    _lowercase   )

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





		def    UpperCAmelCase__							(					self							,    *_lowercase							,    **_lowercase   ) ->						BatchEncoding:







								'''simple docstring'''

								snake_case_   : Tuple						=			kwargs.get("""is_split_into_words"""							,    _lowercase   )

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





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







								'''simple docstring'''

								snake_case_   : str						=			self._tokenizer.model.save(_lowercase							,    name=_lowercase   )
								return tuple(_lowercase   )





		def    UpperCAmelCase__							(					self							,    _lowercase							,    _lowercase=None   ) ->						Dict:







								'''simple docstring'''

								snake_case_   : Tuple						=			[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							,    _lowercase							,    _lowercase = None   ) ->						List[int]:







								'''simple docstring'''

								snake_case_   : Tuple						=			[self.sep_token_id]
								snake_case_   : Optional[int]						=			[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
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

