



from typing import Optional, Union

import torch
from torch import nn
from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss

from ...activations import ACTaFN
from ...modeling_outputs import BaseModelOutputWithPoolingAndNoAttention, ImageClassifierOutputWithNoAttention
from ...modeling_utils import PreTrainedModel
from ...utils import add_code_sample_docstrings, add_start_docstrings, add_start_docstrings_to_model_forward, logging
from .configuration_mobilenet_va import MobileNetVaConfig


__A   			=logging.get_logger(__name__)


# General docstring
__A   			="MobileNetV1Config"

# Base docstring
__A   			="google/mobilenet_v1_1.0_224"
__A   			=[1, 1_0_2_4, 7, 7]

# Image classification docstring
__A   			="google/mobilenet_v1_1.0_224"
__A   			="tabby, tabby cat"


__A   			=[
    "google/mobilenet_v1_1.0_224",
    "google/mobilenet_v1_0.75_192",
    # See all MobileNetV1 models at https://huggingface.co/models?filter=mobilenet_v1
]

def        a						(      _UpperCAmelCase							:					str ,   _UpperCAmelCase							:					Optional[int] ,   _UpperCAmelCase							:					str=None						):







		'''simple docstring'''





		__UpperCAmelCase    :     Union[str, Any]													=	{}

		if isinstance(_UpperCAmelCase ,   _UpperCAmelCase						):
				__UpperCAmelCase    :     Dict													=	model.mobilenet_va
		else:
				__UpperCAmelCase    :     Dict													=	model

		__UpperCAmelCase    :     Any													=	'''MobilenetV1/Conv2d_0/'''
		__UpperCAmelCase    :     Union[str, Any]													=	backbone.conv_stem.convolution.weight
		__UpperCAmelCase    :     Optional[int]													=	backbone.conv_stem.normalization.bias
		__UpperCAmelCase    :     Optional[Any]													=	backbone.conv_stem.normalization.weight
		__UpperCAmelCase    :     Union[str, Any]													=	backbone.conv_stem.normalization.running_mean
		__UpperCAmelCase    :     str													=	backbone.conv_stem.normalization.running_var

		for i in range(13						):
				__UpperCAmelCase    :     str													=	i + 1
				__UpperCAmelCase    :     Dict													=	i * 2

				__UpperCAmelCase    :     int													=	backbone.layer[pt_index]
				__UpperCAmelCase    :     Union[str, Any]													=	f'MobilenetV1/Conv2d_{tf_index}_depthwise/'
				__UpperCAmelCase    :     Any													=	pointer.convolution.weight
				__UpperCAmelCase    :     Union[str, Any]													=	pointer.normalization.bias
				__UpperCAmelCase    :     Optional[Any]													=	pointer.normalization.weight
				__UpperCAmelCase    :     Any													=	pointer.normalization.running_mean
				__UpperCAmelCase    :     Union[str, Any]													=	pointer.normalization.running_var

				__UpperCAmelCase    :     Dict													=	backbone.layer[pt_index + 1]
				__UpperCAmelCase    :     List[Any]													=	f'MobilenetV1/Conv2d_{tf_index}_pointwise/'
				__UpperCAmelCase    :     List[Any]													=	pointer.convolution.weight
				__UpperCAmelCase    :     Union[str, Any]													=	pointer.normalization.bias
				__UpperCAmelCase    :     Any													=	pointer.normalization.weight
				__UpperCAmelCase    :     Tuple													=	pointer.normalization.running_mean
				__UpperCAmelCase    :     str													=	pointer.normalization.running_var

		if isinstance(_UpperCAmelCase ,   _UpperCAmelCase						):
				__UpperCAmelCase    :     Dict													=	'''MobilenetV1/Logits/Conv2d_1c_1x1/'''
				__UpperCAmelCase    :     Tuple													=	model.classifier.weight
				__UpperCAmelCase    :     List[str]													=	model.classifier.bias

		return tf_to_pt_map

def        a						(      _UpperCAmelCase							:					Any ,   _UpperCAmelCase							:					str ,   _UpperCAmelCase							:					str						):







		'''simple docstring'''





		try:
				import numpy as np
				import tensorflow as tf
		except ImportError:
				logger.error(
				    '''Loading a TensorFlow models in PyTorch, requires TensorFlow to be installed. Please see '''
				    '''https://www.tensorflow.org/install/ for installation instructions.'''						)
				raise

		# Load weights from TF model
		__UpperCAmelCase    :     Dict													=	tf.train.list_variables(_UpperCAmelCase						)
		__UpperCAmelCase    :     int													=	{}
		for name, shape in init_vars:
				logger.info(f'Loading TF weight {name} with shape {shape}'						)
				__UpperCAmelCase    :     Optional[Any]													=	tf.train.load_variable(_UpperCAmelCase ,   _UpperCAmelCase						)
				__UpperCAmelCase    :     str													=	array

		# Build TF to PyTorch weights loading map
		__UpperCAmelCase    :     Any													=	_build_tf_to_pytorch_map(_UpperCAmelCase ,   _UpperCAmelCase ,   _UpperCAmelCase						)

		for name, pointer in tf_to_pt_map.items():
				logger.info(f'Importing {name}'						)
				if name not in tf_weights:
						logger.info(f'{name} not in tf pre-trained weights, skipping'						)
						continue

				__UpperCAmelCase    :     Any													=	tf_weights[name]

				if "depthwise_weights" in name:
						logger.info('''Transposing depthwise'''						)
						__UpperCAmelCase    :     List[str]													=	np.transpose(_UpperCAmelCase ,   (2, 3, 0, 1)						)
				elif "weights" in name:
						logger.info('''Transposing'''						)
						if len(pointer.shape						) == 2:  # copying into linear layer
								__UpperCAmelCase    :     str													=	array.squeeze().transpose()
						else:
								__UpperCAmelCase    :     Tuple													=	np.transpose(_UpperCAmelCase ,   (3, 2, 0, 1)						)

				if pointer.shape != array.shape:
						raise ValueError(f'Pointer shape {pointer.shape} and array shape {array.shape} mismatched'						)

				logger.info(f'Initialize PyTorch weight {name} {array.shape}'						)
				__UpperCAmelCase    :     Union[str, Any]													=	torch.from_numpy(_UpperCAmelCase						)

				tf_weights.pop(_UpperCAmelCase ,   _UpperCAmelCase						)
				tf_weights.pop(name + '''/RMSProp''' ,   _UpperCAmelCase						)
				tf_weights.pop(name + '''/RMSProp_1''' ,   _UpperCAmelCase						)
				tf_weights.pop(name + '''/ExponentialMovingAverage''' ,   _UpperCAmelCase						)

		logger.info(f'Weights not copied to PyTorch model: {", ".join(tf_weights.keys()						)}'						)
		return model

def        a						(      _UpperCAmelCase							:					torch.Tensor ,   _UpperCAmelCase							:					nn.Convad						):







		'''simple docstring'''





		__UpperCAmelCase							,					__UpperCAmelCase    :     Union[str, Any]													=	features.shape[-2:]
		__UpperCAmelCase							,					__UpperCAmelCase    :     int													=	conv_layer.stride
		__UpperCAmelCase							,					__UpperCAmelCase    :     Dict													=	conv_layer.kernel_size

		if in_height % stride_height == 0:
				__UpperCAmelCase    :     List[Any]													=	max(kernel_height - stride_height ,   0						)
		else:
				__UpperCAmelCase    :     Tuple													=	max(kernel_height - (in_height % stride_height) ,   0						)

		if in_width % stride_width == 0:
				__UpperCAmelCase    :     Optional[int]													=	max(kernel_width - stride_width ,   0						)
		else:
				__UpperCAmelCase    :     List[str]													=	max(kernel_width - (in_width % stride_width) ,   0						)

		__UpperCAmelCase    :     List[Any]													=	pad_along_width // 2
		__UpperCAmelCase    :     Union[str, Any]													=	pad_along_width - pad_left
		__UpperCAmelCase    :     Dict													=	pad_along_height // 2
		__UpperCAmelCase    :     int													=	pad_along_height - pad_top

		__UpperCAmelCase    :     Optional[Any]													=	(pad_left, pad_right, pad_top, pad_bottom)
		return nn.functional.pad(_UpperCAmelCase ,   _UpperCAmelCase ,   '''constant''' ,   0.0						)

class 		UpperCAmelCase__			(			nn.Module   ):




			'''simple docstring'''






			def __init__(   self							: Optional[int]       ,       a_							: MobileNetVaConfig       ,       a_							: int       ,       a_							: int       ,       a_							: int       ,       a_							: Optional[int] = 1       ,       a_							: Optional[int] = 1       ,       a_							: bool = False       ,       a_							: Optional[bool] = True       ,       a_							: Optional[bool or str] = True       ,       ):
					'''simple docstring'''





					super().__init__()
					__UpperCAmelCase    :     Optional[int]													=	config

					if in_channels % groups != 0:
							raise ValueError(F'Input channels ({in_channels}) are not divisible by {groups} groups.' )
					if out_channels % groups != 0:
							raise ValueError(F'Output channels ({out_channels}) are not divisible by {groups} groups.' )

					__UpperCAmelCase    :     int													=	0 if config.tf_padding else int((kernel_size - 1) / 2 )

					__UpperCAmelCase    :     str													=	nn.Convad(
					    in_channels=a_       ,       out_channels=a_       ,       kernel_size=a_       ,       stride=a_       ,       padding=a_       ,       groups=a_       ,       bias=a_       ,       padding_mode='''zeros'''       ,       )

					if use_normalization:
							__UpperCAmelCase    :     Dict													=	nn.BatchNormad(
							    num_features=a_       ,       eps=config.layer_norm_eps       ,       momentum=0.9_9_9_7       ,       affine=a_       ,       track_running_stats=a_       ,       )
					else:
							__UpperCAmelCase    :     Union[str, Any]													=	None

					if use_activation:
							if isinstance(a_       ,       a_ ):
									__UpperCAmelCase    :     List[Any]													=	ACTaFN[use_activation]
							elif isinstance(config.hidden_act       ,       a_ ):
									__UpperCAmelCase    :     Any													=	ACTaFN[config.hidden_act]
							else:
									__UpperCAmelCase    :     str													=	config.hidden_act
					else:
							__UpperCAmelCase    :     str													=	None




			def  snake_case__     (   self							: Tuple       ,       a_							: torch.Tensor ):
					'''simple docstring'''





					if self.config.tf_padding:
							__UpperCAmelCase    :     str													=	apply_tf_padding(a_       ,       self.convolution )
					__UpperCAmelCase    :     Tuple													=	self.convolution(a_ )
					if self.normalization is not None:
							__UpperCAmelCase    :     Optional[int]													=	self.normalization(a_ )
					if self.activation is not None:
							__UpperCAmelCase    :     Tuple													=	self.activation(a_ )
					return features

class 		UpperCAmelCase__			(			__UpperCamelCase   ):




			'''simple docstring'''






			UpperCamelCase									=       MobileNetVaConfig
			UpperCamelCase									=       load_tf_weights_in_mobilenet_va
			UpperCamelCase									=       """mobilenet_v1"""
			UpperCamelCase									=       """pixel_values"""
			UpperCamelCase									=       False




			def  snake_case__     (   self							: Optional[Any]       ,       a_							: Union[nn.Linear, nn.Convad] ):
					'''simple docstring'''





					if isinstance(a_       ,       (nn.Linear, nn.Convad) ):
							module.weight.data.normal_(mean=0.0       ,       std=self.config.initializer_range )
							if module.bias is not None:
									module.bias.data.zero_()
					elif isinstance(a_       ,       nn.BatchNormad ):
							module.bias.data.zero_()
							module.weight.data.fill_(1.0 )
__A   			=R"\n    This model is a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass. Use it\n    as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and\n    behavior.\n\n    Parameters:\n        config ([`MobileNetV1Config`]): Model configuration class with all the parameters of the model.\n            Initializing with a config file does not load the weights associated with the model, only the\n            configuration. Check out the [`~PreTrainedModel.from_pretrained`] method to load the model weights.\n"

__A   			=R"\n    Args:\n        pixel_values (`torch.FloatTensor` of shape `(batch_size, num_channels, height, width)`):\n            Pixel values. Pixel values can be obtained using [`AutoImageProcessor`]. See\n            [`MobileNetV1ImageProcessor.__call__`] for details.\n        output_hidden_states (`bool`, *optional*):\n            Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for\n            more detail.\n        return_dict (`bool`, *optional*):\n            Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.\n"

@add_start_docstrings(
    """The bare MobileNetV1 model outputting raw hidden-states without any specific head on top."""						,__UpperCamelCase						,)
class 		UpperCAmelCase__			(			__UpperCamelCase   ):




			'''simple docstring'''






			def __init__(   self							: Any       ,       a_							: MobileNetVaConfig       ,       a_							: bool = True ):
					'''simple docstring'''





					super().__init__(a_ )
					__UpperCAmelCase    :     int													=	config

					__UpperCAmelCase    :     List[Any]													=	32
					__UpperCAmelCase    :     int													=	max(int(depth * config.depth_multiplier )       ,       config.min_depth )

					__UpperCAmelCase    :     Optional[Any]													=	MobileNetVaConvLayer(
					    a_       ,       in_channels=config.num_channels       ,       out_channels=a_       ,       kernel_size=3       ,       stride=2       ,       )

					__UpperCAmelCase    :     str													=	[1, 2, 1, 2, 1, 2, 1, 1, 1, 1, 1, 2, 1]

					__UpperCAmelCase    :     List[Any]													=	nn.ModuleList()
					for i in range(13 ):
							__UpperCAmelCase    :     int													=	out_channels

							if strides[i] == 2 or i == 0:
									depth *= 2
									__UpperCAmelCase    :     List[Any]													=	max(int(depth * config.depth_multiplier )       ,       config.min_depth )

							self.layer.append(
							    MobileNetVaConvLayer(
							        a_       ,       in_channels=a_       ,       out_channels=a_       ,       kernel_size=3       ,       stride=strides[i]       ,       groups=a_       ,       ) )

							self.layer.append(
							    MobileNetVaConvLayer(
							        a_       ,       in_channels=a_       ,       out_channels=a_       ,       kernel_size=1       ,       ) )

					__UpperCAmelCase    :     Tuple													=	nn.AdaptiveAvgPoolad((1, 1) ) if add_pooling_layer else None

					# Initialize weights and apply final processing
					self.post_init()




			def  snake_case__     (   self							: List[Any]       ,       a_							: List[Any] ):
					'''simple docstring'''





					raise NotImplementedError




			@add_start_docstrings_to_model_forward(a_ )
			@add_code_sample_docstrings(
			    checkpoint=_CHECKPOINT_FOR_DOC       ,       output_type=a_       ,       config_class=_CONFIG_FOR_DOC       ,       modality='''vision'''       ,       expected_output=_EXPECTED_OUTPUT_SHAPE       ,       )
			def  snake_case__     (   self							: List[str]       ,       a_							: Optional[torch.Tensor] = None       ,       a_							: Optional[bool] = None       ,       a_							: Optional[bool] = None       ,       ):
					'''simple docstring'''





					__UpperCAmelCase    :     List[Any]													=	(
					    output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
					)
					__UpperCAmelCase    :     Any													=	return_dict if return_dict is not None else self.config.use_return_dict

					if pixel_values is None:
							raise ValueError('''You have to specify pixel_values''' )

					__UpperCAmelCase    :     Any													=	self.conv_stem(a_ )

					__UpperCAmelCase    :     List[str]													=	() if output_hidden_states else None

					for i, layer_module in enumerate(self.layer ):
							__UpperCAmelCase    :     Dict													=	layer_module(a_ )

							if output_hidden_states:
									__UpperCAmelCase    :     int													=	all_hidden_states + (hidden_states,)

					__UpperCAmelCase    :     Tuple													=	hidden_states

					if self.pooler is not None:
							__UpperCAmelCase    :     Tuple													=	torch.flatten(self.pooler(a_ )       ,       start_dim=1 )
					else:
							__UpperCAmelCase    :     Tuple													=	None

					if not return_dict:
							return tuple(v for v in [last_hidden_state, pooled_output, all_hidden_states] if v is not None )

					return BaseModelOutputWithPoolingAndNoAttention(
					    last_hidden_state=a_       ,       pooler_output=a_       ,       hidden_states=a_       ,       )

@add_start_docstrings(
    """
    MobileNetV1 model with an image classification head on top (a linear layer on top of the pooled features), e.g. for
    ImageNet.
    """						,__UpperCamelCase						,)
class 		UpperCAmelCase__			(			__UpperCamelCase   ):




			'''simple docstring'''






			def __init__(   self							: Optional[Any]       ,       a_							: MobileNetVaConfig ):
					'''simple docstring'''





					super().__init__(a_ )

					__UpperCAmelCase    :     Union[str, Any]													=	config.num_labels
					__UpperCAmelCase    :     Optional[Any]													=	MobileNetVaModel(a_ )

					__UpperCAmelCase    :     str													=	self.mobilenet_va.layer[-1].convolution.out_channels

					# Classifier head
					__UpperCAmelCase    :     int													=	nn.Dropout(config.classifier_dropout_prob       ,       inplace=a_ )
					__UpperCAmelCase    :     List[Any]													=	nn.Linear(a_       ,       config.num_labels ) if config.num_labels > 0 else nn.Identity()

					# Initialize weights and apply final processing
					self.post_init()




			@add_start_docstrings_to_model_forward(a_ )
			@add_code_sample_docstrings(
			    checkpoint=_IMAGE_CLASS_CHECKPOINT       ,       output_type=a_       ,       config_class=_CONFIG_FOR_DOC       ,       expected_output=_IMAGE_CLASS_EXPECTED_OUTPUT       ,       )
			def  snake_case__     (   self							: List[str]       ,       a_							: Optional[torch.Tensor] = None       ,       a_							: Optional[bool] = None       ,       a_							: Optional[torch.Tensor] = None       ,       a_							: Optional[bool] = None       ,       ):
					'''simple docstring'''





					__UpperCAmelCase    :     Tuple													=	return_dict if return_dict is not None else self.config.use_return_dict

					__UpperCAmelCase    :     Optional[int]													=	self.mobilenet_va(a_       ,       output_hidden_states=a_       ,       return_dict=a_ )

					__UpperCAmelCase    :     Any													=	outputs.pooler_output if return_dict else outputs[1]

					__UpperCAmelCase    :     List[Any]													=	self.classifier(self.dropout(a_ ) )

					__UpperCAmelCase    :     int													=	None
					if labels is not None:
							if self.config.problem_type is None:
									if self.num_labels == 1:
											__UpperCAmelCase    :     List[Any]													=	'''regression'''
									elif self.num_labels > 1 and (labels.dtype == torch.long or labels.dtype == torch.int):
											__UpperCAmelCase    :     Dict													=	'''single_label_classification'''
									else:
											__UpperCAmelCase    :     Any													=	'''multi_label_classification'''

							if self.config.problem_type == "regression":
									__UpperCAmelCase    :     Any													=	MSELoss()
									if self.num_labels == 1:
											__UpperCAmelCase    :     Optional[int]													=	loss_fct(logits.squeeze()       ,       labels.squeeze() )
									else:
											__UpperCAmelCase    :     Any													=	loss_fct(a_       ,       a_ )
							elif self.config.problem_type == "single_label_classification":
									__UpperCAmelCase    :     Optional[Any]													=	CrossEntropyLoss()
									__UpperCAmelCase    :     Optional[Any]													=	loss_fct(logits.view(-1       ,       self.num_labels )       ,       labels.view(-1 ) )
							elif self.config.problem_type == "multi_label_classification":
									__UpperCAmelCase    :     Dict													=	BCEWithLogitsLoss()
									__UpperCAmelCase    :     Dict													=	loss_fct(a_       ,       a_ )

					if not return_dict:
							__UpperCAmelCase    :     List[Any]													=	(logits,) + outputs[2:]
							return ((loss,) + output) if loss is not None else output

					return ImageClassifierOutputWithNoAttention(
					    loss=a_       ,       logits=a_       ,       hidden_states=outputs.hidden_states       ,       )










import warnings
from typing import Dict, List, Optional, Tuple

from ...tokenization_utils import AddedToken, PreTrainedTokenizer
from ...utils import logging


__A   			=logging.get_logger(__name__)

class 		UpperCAmelCase__			(			__UpperCamelCase   ):




			'''simple docstring'''






			UpperCamelCase									=       ["""input_ids""", """attention_mask"""]




			def __init__(   self							: List[str]       ,       a_							: List[Any]="</s>"       ,       a_							: str="<unk>"       ,       a_							: Tuple="<pad>"       ,       a_							: List[Any]=1_25       ,       a_							: Any=None       ,       **a_							: Tuple       ,       ):
					'''simple docstring'''





					if extra_ids > 0 and additional_special_tokens is None:
							__UpperCAmelCase    :     Optional[Any]													=	[F'<extra_id_{i}>' for i in range(a_ )]
					elif extra_ids > 0 and additional_special_tokens is not None:
							# Check that we have the right number of extra_id special tokens
							__UpperCAmelCase    :     Optional[Any]													=	len(set(filter(lambda a_ : bool('''extra_id''' in str(a_ ) )       ,       a_ ) ) )
							if extra_tokens != extra_ids:
									raise ValueError(
									    F'Both extra_ids ({extra_ids}) and additional_special_tokens ({additional_special_tokens}) are'
									    ''' provided to ByT5Tokenizer. In this case the additional_special_tokens must include the'''
									    ''' extra_ids tokens''' )

					__UpperCAmelCase    :     str													=	AddedToken(a_       ,       lstrip=a_       ,       rstrip=a_ ) if isinstance(a_       ,       a_ ) else pad_token
					__UpperCAmelCase    :     str													=	AddedToken(a_       ,       lstrip=a_       ,       rstrip=a_ ) if isinstance(a_       ,       a_ ) else eos_token
					__UpperCAmelCase    :     int													=	AddedToken(a_       ,       lstrip=a_       ,       rstrip=a_ ) if isinstance(a_       ,       a_ ) else unk_token

					super().__init__(
					    eos_token=a_       ,       unk_token=a_       ,       pad_token=a_       ,       extra_ids=a_       ,       additional_special_tokens=a_       ,       **a_       ,       )

					__UpperCAmelCase    :     Dict													=	extra_ids

					__UpperCAmelCase    :     Any													=	2**8  # utf is 8 bits

					# define special tokens dict
					__UpperCAmelCase    :     Dict[int, str]													=	{
					    self.pad_token: 0,
					    self.eos_token: 1,
					    self.unk_token: 2,
					}
					__UpperCAmelCase    :     Optional[int]													=	len(self.special_tokens_encoder )
					__UpperCAmelCase    :     Union[str, Any]													=	len(a_ )
					for i, token in enumerate(a_ ):
							__UpperCAmelCase    :     Union[str, Any]													=	self.vocab_size + i - n
					__UpperCAmelCase    :     Dict[str, int]													=	{v: k for k, v in self.special_tokens_encoder.items()}




			@property
			def  snake_case__     (   self							: Tuple ):
					'''simple docstring'''





					return self._utf_vocab_size + self._num_special_tokens + self._extra_ids




			def  snake_case__     (   self							: Any       ,       a_							: List[int]       ,       a_							: Optional[List[int]] = None       ,       a_							: bool = False ):
					'''simple docstring'''





					if already_has_special_tokens:
							return super().get_special_tokens_mask(
							    token_ids_a=a_       ,       token_ids_a=a_       ,       already_has_special_tokens=a_ )

					# normal case: some special tokens
					if token_ids_a is None:
							return ([0] * len(a_ )) + [1]
					return ([0] * len(a_ )) + [1] + ([0] * len(a_ )) + [1]




			def  snake_case__     (   self							: Any       ,       a_							: List[int] ):
					'''simple docstring'''





					if len(a_ ) > 0 and token_ids[-1] == self.eos_token_id:
							warnings.warn(
							    F'This sequence already has {self.eos_token}. In future versions this behavior may lead to duplicated'
							    ''' eos tokens being added.''' )
							return token_ids
					else:
							return token_ids + [self.eos_token_id]




			def  snake_case__     (   self							: Union[str, Any]       ,       a_							: List[int]       ,       a_							: Optional[List[int]] = None ):
					'''simple docstring'''





					__UpperCAmelCase    :     str													=	[self.eos_token_id]

					if token_ids_a is None:
							return len(token_ids_a + eos ) * [0]
					return len(token_ids_a + eos + token_ids_a + eos ) * [0]




			def  snake_case__     (   self							: Optional[Any]       ,       a_							: List[int]       ,       a_							: Optional[List[int]] = None ):
					'''simple docstring'''





					__UpperCAmelCase    :     Union[str, Any]													=	self._add_eos_if_not_present(a_ )
					if token_ids_a is None:
							return token_ids_a
					else:
							__UpperCAmelCase    :     List[str]													=	self._add_eos_if_not_present(a_ )
							return token_ids_a + token_ids_a




			def  snake_case__     (   self							: List[Any]       ,       a_							: str ):
					'''simple docstring'''





					__UpperCAmelCase    :     str													=	[chr(a_ ) for i in text.encode('''utf-8''' )]
					return tokens




			def  snake_case__     (   self							: Optional[Any]       ,       a_							: int ):
					'''simple docstring'''





					if token in self.special_tokens_encoder:
							__UpperCAmelCase    :     Union[str, Any]													=	self.special_tokens_encoder[token]
					elif token in self.added_tokens_encoder:
							__UpperCAmelCase    :     Optional[Any]													=	self.added_tokens_encoder[token]
					elif len(a_ ) != 1:
							__UpperCAmelCase    :     int													=	self.unk_token_id
					else:
							__UpperCAmelCase    :     List[str]													=	ord(a_ ) + self._num_special_tokens
					return token_id




			def  snake_case__     (   self							: Union[str, Any]       ,       a_							: Optional[int] ):
					'''simple docstring'''





					if index in self.special_tokens_decoder:
							__UpperCAmelCase    :     Dict													=	self.special_tokens_decoder[index]
					else:
							__UpperCAmelCase    :     List[Any]													=	chr(index - self._num_special_tokens )
					return token




			def  snake_case__     (   self							: int       ,       a_							: Dict ):
					'''simple docstring'''





					__UpperCAmelCase    :     List[Any]													=	b''''''
					for token in tokens:
							if token in self.special_tokens_decoder:
									__UpperCAmelCase    :     Optional[int]													=	self.special_tokens_decoder[token].encode('''utf-8''' )
							elif token in self.added_tokens_decoder:
									__UpperCAmelCase    :     List[str]													=	self.special_tokens_decoder[token].encode('''utf-8''' )
							elif token in self.special_tokens_encoder:
									__UpperCAmelCase    :     Tuple													=	token.encode('''utf-8''' )
							elif token in self.added_tokens_encoder:
									__UpperCAmelCase    :     int													=	token.encode('''utf-8''' )
							else:
									__UpperCAmelCase    :     Any													=	bytes([ord(a_ )] )
							bstring += tok_string
					__UpperCAmelCase    :     Dict													=	bstring.decode('''utf-8'''       ,       errors='''ignore''' )
					return string




			def  snake_case__     (   self							: Tuple       ,       a_							: str       ,       a_							: Optional[str] = None ):
					'''simple docstring'''





					return ()





