"""simple docstring"""





import copy
import os
from typing import TYPE_CHECKING, List, Union


if TYPE_CHECKING:
				pass

from ...configuration_utils import PretrainedConfig
from ...utils import logging


__A  =				logging.get_logger(__name__)

__A  =				{
    '''kakaobrain/align-base''': '''https://huggingface.co/kakaobrain/align-base/resolve/main/config.json''',
}
class  _snake_case     (					a__		):
						snake_case__			  =			"align_text_model"






						def __init__(       self      :			Union[str, Any]							,					UpperCAmelCase      :			int=30522							,					UpperCAmelCase      :			Union[str, Any]=768							,					UpperCAmelCase      :			Union[str, Any]=12							,					UpperCAmelCase      :			Union[str, Any]=12							,					UpperCAmelCase      :			str=3072							,					UpperCAmelCase      :			int="gelu"							,					UpperCAmelCase      :			Optional[Any]=0.1							,					UpperCAmelCase      :			List[str]=0.1							,					UpperCAmelCase      :			Any=512							,					UpperCAmelCase      :			Tuple=2							,					UpperCAmelCase      :			str=0.0_2							,					UpperCAmelCase      :			List[Any]=1E-12							,					UpperCAmelCase      :			str=0							,					UpperCAmelCase      :			Union[str, Any]="absolute"							,					UpperCAmelCase      :			Any=True							,					**UpperCAmelCase      :			Optional[int]							,					):
													super().__init__(**UpperCAmelCase    )

													__lowerCamelCase					:		Any		   =     vocab_size
													__lowerCamelCase					:		List[str]		   =     hidden_size
													__lowerCamelCase					:		List[str]		   =     num_hidden_layers
													__lowerCamelCase					:		List[str]		   =     num_attention_heads
													__lowerCamelCase					:		List[Any]		   =     hidden_act
													__lowerCamelCase					:		Tuple		   =     intermediate_size
													__lowerCamelCase					:		Optional[int]		   =     hidden_dropout_prob
													__lowerCamelCase					:		str		   =     attention_probs_dropout_prob
													__lowerCamelCase					:		Union[str, Any]		   =     max_position_embeddings
													__lowerCamelCase					:		Union[str, Any]		   =     type_vocab_size
													__lowerCamelCase					:		Optional[int]		   =     initializer_range
													__lowerCamelCase					:		List[Any]		   =     layer_norm_eps
													__lowerCamelCase					:		Tuple		   =     position_embedding_type
													__lowerCamelCase					:		Tuple		   =     use_cache
													__lowerCamelCase					:		Dict		   =     pad_token_id







						@classmethod
						def       lowerCamelCase__     (       cls      :			Optional[Any]							,					UpperCAmelCase      :			Union[str, os.PathLike]							,					**UpperCAmelCase      :			int    ):
													cls._set_token_in_kwargs(UpperCAmelCase    )

													__lowerCamelCase   ,  __lowerCamelCase					:		Any		   =     cls.get_config_dict(UpperCAmelCase							,					**UpperCAmelCase    )

													# get the text config dict if we are loading from AlignConfig
													if config_dict.get("model_type"    ) == "align":
																				__lowerCamelCase					:		List[Any]		   =     config_dict["text_config"]

													if "model_type" in config_dict and hasattr(cls							,					"model_type"    ) and config_dict["model_type"] != cls.model_type:
																				logger.warning(
																				    F"""You are using a model of type {config_dict["model_type"]} to instantiate a model of type """
																				    F"""{cls.model_type}. This is not supported for all configurations of models and can yield errors."""    )

													return cls.from_dict(UpperCAmelCase							,					**UpperCAmelCase    )

class  _snake_case     (					a__		):
						snake_case__			  =			"align_vision_model"






						def __init__(       self      :			str							,					UpperCAmelCase      :			int = 3							,					UpperCAmelCase      :			int = 600							,					UpperCAmelCase      :			float = 2.0							,					UpperCAmelCase      :			float = 3.1							,					UpperCAmelCase      :			int = 8							,					UpperCAmelCase      :			List[int] = [3, 3, 5, 3, 5, 5, 3]							,					UpperCAmelCase      :			List[int] = [32, 16, 24, 40, 80, 112, 192]							,					UpperCAmelCase      :			List[int] = [16, 24, 40, 80, 112, 192, 320]							,					UpperCAmelCase      :			List[int] = []							,					UpperCAmelCase      :			List[int] = [1, 2, 2, 2, 1, 2, 1]							,					UpperCAmelCase      :			List[int] = [1, 2, 2, 3, 3, 4, 1]							,					UpperCAmelCase      :			List[int] = [1, 6, 6, 6, 6, 6, 6]							,					UpperCAmelCase      :			float = 0.2_5							,					UpperCAmelCase      :			str = "swish"							,					UpperCAmelCase      :			int = 2560							,					UpperCAmelCase      :			str = "mean"							,					UpperCAmelCase      :			float = 0.0_2							,					UpperCAmelCase      :			float = 0.0_0_1							,					UpperCAmelCase      :			float = 0.9_9							,					UpperCAmelCase      :			float = 0.2							,					**UpperCAmelCase      :			int							,					):
													super().__init__(**UpperCAmelCase    )

													__lowerCamelCase					:		Tuple		   =     num_channels
													__lowerCamelCase					:		Optional[int]		   =     image_size
													__lowerCamelCase					:		Union[str, Any]		   =     width_coefficient
													__lowerCamelCase					:		Tuple		   =     depth_coefficient
													__lowerCamelCase					:		Tuple		   =     depth_divisor
													__lowerCamelCase					:		Tuple		   =     kernel_sizes
													__lowerCamelCase					:		Union[str, Any]		   =     in_channels
													__lowerCamelCase					:		Union[str, Any]		   =     out_channels
													__lowerCamelCase					:		Union[str, Any]		   =     depthwise_padding
													__lowerCamelCase					:		int		   =     strides
													__lowerCamelCase					:		Union[str, Any]		   =     num_block_repeats
													__lowerCamelCase					:		List[Any]		   =     expand_ratios
													__lowerCamelCase					:		List[Any]		   =     squeeze_expansion_ratio
													__lowerCamelCase					:		List[Any]		   =     hidden_act
													__lowerCamelCase					:		int		   =     hidden_dim
													__lowerCamelCase					:		List[str]		   =     pooling_type
													__lowerCamelCase					:		Optional[Any]		   =     initializer_range
													__lowerCamelCase					:		Union[str, Any]		   =     batch_norm_eps
													__lowerCamelCase					:		Union[str, Any]		   =     batch_norm_momentum
													__lowerCamelCase					:		str		   =     drop_connect_rate
													__lowerCamelCase					:		Tuple		   =     sum(UpperCAmelCase    ) * 4







						@classmethod
						def       lowerCamelCase__     (       cls      :			int							,					UpperCAmelCase      :			Union[str, os.PathLike]							,					**UpperCAmelCase      :			Tuple    ):
													cls._set_token_in_kwargs(UpperCAmelCase    )

													__lowerCamelCase   ,  __lowerCamelCase					:		int		   =     cls.get_config_dict(UpperCAmelCase							,					**UpperCAmelCase    )

													# get the vision config dict if we are loading from AlignConfig
													if config_dict.get("model_type"    ) == "align":
																				__lowerCamelCase					:		Tuple		   =     config_dict["vision_config"]

													if "model_type" in config_dict and hasattr(cls							,					"model_type"    ) and config_dict["model_type"] != cls.model_type:
																				logger.warning(
																				    F"""You are using a model of type {config_dict["model_type"]} to instantiate a model of type """
																				    F"""{cls.model_type}. This is not supported for all configurations of models and can yield errors."""    )

													return cls.from_dict(UpperCAmelCase							,					**UpperCAmelCase    )

class  _snake_case     (					a__		):
						snake_case__			  =			"align"
						snake_case__			  =			True






						def __init__(       self      :			int							,					UpperCAmelCase      :			List[str]=None							,					UpperCAmelCase      :			Optional[Any]=None							,					UpperCAmelCase      :			Any=640							,					UpperCAmelCase      :			int=1.0							,					UpperCAmelCase      :			Any=0.0_2							,					**UpperCAmelCase      :			Dict							,					):
													super().__init__(**UpperCAmelCase    )

													if text_config is None:
																				__lowerCamelCase					:		str		   =     {}
																				logger.info("text_config is None. Initializing the AlignTextConfig with default values."    )

													if vision_config is None:
																				__lowerCamelCase					:		Optional[Any]		   =     {}
																				logger.info("vision_config is None. Initializing the AlignVisionConfig with default values."    )

													__lowerCamelCase					:		Optional[int]		   =     AlignTextConfig(**UpperCAmelCase    )
													__lowerCamelCase					:		List[str]		   =     AlignVisionConfig(**UpperCAmelCase    )

													__lowerCamelCase					:		Optional[int]		   =     projection_dim
													__lowerCamelCase					:		Optional[Any]		   =     temperature_init_value
													__lowerCamelCase					:		Optional[int]		   =     initializer_range






						@classmethod
						def       lowerCamelCase__     (       cls      :			Dict							,					UpperCAmelCase      :			AlignTextConfig							,					UpperCAmelCase      :			AlignVisionConfig							,					**UpperCAmelCase      :			Any    ):
													return cls(text_config=text_config.to_dict()							,					vision_config=vision_config.to_dict()							,					**UpperCAmelCase    )







						def       lowerCamelCase__     (       self      :			Any    ):
													__lowerCamelCase					:		int		   =     copy.deepcopy(self.__dict__    )
													__lowerCamelCase					:		Any		   =     self.text_config.to_dict()
													__lowerCamelCase					:		str		   =     self.vision_config.to_dict()
													__lowerCamelCase					:		List[Any]		   =     self.__class__.model_type
													return output
"""simple docstring"""





import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_funnel import FunnelTokenizer


__A  =				logging.get_logger(__name__)

__A  =				{'''vocab_file''': '''vocab.txt''', '''tokenizer_file''': '''tokenizer.json'''}

__A  =				[
    '''small''',
    '''small-base''',
    '''medium''',
    '''medium-base''',
    '''intermediate''',
    '''intermediate-base''',
    '''large''',
    '''large-base''',
    '''xlarge''',
    '''xlarge-base''',
]

__A  =				{
    '''vocab_file''': {
        '''funnel-transformer/small''': '''https://huggingface.co/funnel-transformer/small/resolve/main/vocab.txt''',
        '''funnel-transformer/small-base''': '''https://huggingface.co/funnel-transformer/small-base/resolve/main/vocab.txt''',
        '''funnel-transformer/medium''': '''https://huggingface.co/funnel-transformer/medium/resolve/main/vocab.txt''',
        '''funnel-transformer/medium-base''': (
            '''https://huggingface.co/funnel-transformer/medium-base/resolve/main/vocab.txt'''
        ),
        '''funnel-transformer/intermediate''': (
            '''https://huggingface.co/funnel-transformer/intermediate/resolve/main/vocab.txt'''
        ),
        '''funnel-transformer/intermediate-base''': (
            '''https://huggingface.co/funnel-transformer/intermediate-base/resolve/main/vocab.txt'''
        ),
        '''funnel-transformer/large''': '''https://huggingface.co/funnel-transformer/large/resolve/main/vocab.txt''',
        '''funnel-transformer/large-base''': '''https://huggingface.co/funnel-transformer/large-base/resolve/main/vocab.txt''',
        '''funnel-transformer/xlarge''': '''https://huggingface.co/funnel-transformer/xlarge/resolve/main/vocab.txt''',
        '''funnel-transformer/xlarge-base''': (
            '''https://huggingface.co/funnel-transformer/xlarge-base/resolve/main/vocab.txt'''
        ),
    },
    '''tokenizer_file''': {
        '''funnel-transformer/small''': '''https://huggingface.co/funnel-transformer/small/resolve/main/tokenizer.json''',
        '''funnel-transformer/small-base''': (
            '''https://huggingface.co/funnel-transformer/small-base/resolve/main/tokenizer.json'''
        ),
        '''funnel-transformer/medium''': '''https://huggingface.co/funnel-transformer/medium/resolve/main/tokenizer.json''',
        '''funnel-transformer/medium-base''': (
            '''https://huggingface.co/funnel-transformer/medium-base/resolve/main/tokenizer.json'''
        ),
        '''funnel-transformer/intermediate''': (
            '''https://huggingface.co/funnel-transformer/intermediate/resolve/main/tokenizer.json'''
        ),
        '''funnel-transformer/intermediate-base''': (
            '''https://huggingface.co/funnel-transformer/intermediate-base/resolve/main/tokenizer.json'''
        ),
        '''funnel-transformer/large''': '''https://huggingface.co/funnel-transformer/large/resolve/main/tokenizer.json''',
        '''funnel-transformer/large-base''': (
            '''https://huggingface.co/funnel-transformer/large-base/resolve/main/tokenizer.json'''
        ),
        '''funnel-transformer/xlarge''': '''https://huggingface.co/funnel-transformer/xlarge/resolve/main/tokenizer.json''',
        '''funnel-transformer/xlarge-base''': (
            '''https://huggingface.co/funnel-transformer/xlarge-base/resolve/main/tokenizer.json'''
        ),
    },
}
__A  =				{F"""funnel-transformer/{name}""": 512 for name in _model_names}
__A  =				{F"""funnel-transformer/{name}""": {'''do_lower_case''': True} for name in _model_names}
class  _snake_case     (					a__		):
						snake_case__			  =			VOCAB_FILES_NAMES
						snake_case__			  =			PRETRAINED_VOCAB_FILES_MAP
						snake_case__			  =			PRETRAINED_INIT_CONFIGURATION
						snake_case__			  =			FunnelTokenizer
						snake_case__			  =			PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
						snake_case__			  =			2






						def __init__(       self      :			List[Any]							,					UpperCAmelCase      :			List[str]=None							,					UpperCAmelCase      :			Optional[int]=None							,					UpperCAmelCase      :			List[Any]=True							,					UpperCAmelCase      :			int="<unk>"							,					UpperCAmelCase      :			List[Any]="<sep>"							,					UpperCAmelCase      :			List[str]="<pad>"							,					UpperCAmelCase      :			Union[str, Any]="<cls>"							,					UpperCAmelCase      :			int="<mask>"							,					UpperCAmelCase      :			List[str]="<s>"							,					UpperCAmelCase      :			Union[str, Any]="</s>"							,					UpperCAmelCase      :			List[Any]=True							,					UpperCAmelCase      :			Tuple=True							,					UpperCAmelCase      :			int=None							,					UpperCAmelCase      :			int="##"							,					**UpperCAmelCase      :			Dict							,					):
													super().__init__(
													    UpperCAmelCase							,					tokenizer_file=UpperCAmelCase							,					do_lower_case=UpperCAmelCase							,					unk_token=UpperCAmelCase							,					sep_token=UpperCAmelCase							,					pad_token=UpperCAmelCase							,					cls_token=UpperCAmelCase							,					mask_token=UpperCAmelCase							,					bos_token=UpperCAmelCase							,					eos_token=UpperCAmelCase							,					clean_text=UpperCAmelCase							,					tokenize_chinese_chars=UpperCAmelCase							,					strip_accents=UpperCAmelCase							,					wordpieces_prefix=UpperCAmelCase							,					**UpperCAmelCase							,					)

													__lowerCamelCase					:		List[Any]		   =     json.loads(self.backend_tokenizer.normalizer.__getstate__()    )
													if (
													    normalizer_state.get("lowercase"							,					UpperCAmelCase    ) != do_lower_case
													    or normalizer_state.get("strip_accents"							,					UpperCAmelCase    ) != strip_accents
													    or normalizer_state.get("handle_chinese_chars"							,					UpperCAmelCase    ) != tokenize_chinese_chars
													):
																				__lowerCamelCase					:		Tuple		   =     getattr(UpperCAmelCase							,					normalizer_state.pop("type"    )    )
																				__lowerCamelCase					:		Optional[int]		   =     do_lower_case
																				__lowerCamelCase					:		Union[str, Any]		   =     strip_accents
																				__lowerCamelCase					:		Optional[Any]		   =     tokenize_chinese_chars
																				__lowerCamelCase					:		Optional[Any]		   =     normalizer_class(**UpperCAmelCase    )

													__lowerCamelCase					:		List[Any]		   =     do_lower_case






						def       lowerCamelCase__     (       self      :			Union[str, Any]							,					UpperCAmelCase      :			Union[str, Any]							,					UpperCAmelCase      :			Tuple=None    ):
													__lowerCamelCase					:		List[Any]		   =     [self.cls_token_id] + token_ids_a + [self.sep_token_id]

													if token_ids_a:
																				output += token_ids_a + [self.sep_token_id]

													return output






						def       lowerCamelCase__     (       self      :			Dict							,					UpperCAmelCase      :			List[int]							,					UpperCAmelCase      :			Optional[List[int]] = None    ):
													__lowerCamelCase					:		Tuple		   =     [self.sep_token_id]
													__lowerCamelCase					:		int		   =     [self.cls_token_id]
													if token_ids_a is None:
																				return len(cls    ) * [self.cls_token_type_id] + len(token_ids_a + sep    ) * [0]
													return len(cls    ) * [self.cls_token_type_id] + len(token_ids_a + sep    ) * [0] + len(token_ids_a + sep    ) * [1]







						def       lowerCamelCase__     (       self      :			Tuple							,					UpperCAmelCase      :			str							,					UpperCAmelCase      :			Optional[str] = None    ):
													__lowerCamelCase					:		List[Any]		   =     self._tokenizer.model.save(UpperCAmelCase							,					name=UpperCAmelCase    )
													return tuple(UpperCAmelCase    )