






from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available, is_vision_available


_a       =    {
    "configuration_donut_swin": ["DONUT_SWIN_PRETRAINED_CONFIG_ARCHIVE_MAP", "DonutSwinConfig"],
    "processing_donut": ["DonutProcessor"],
}

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		_a       =    [
		    "DONUT_SWIN_PRETRAINED_MODEL_ARCHIVE_LIST",
		    "DonutSwinModel",
		    "DonutSwinPreTrainedModel",
		]

try:
		if not is_vision_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		_a       =    ["DonutFeatureExtractor"]
		_a       =    ["DonutImageProcessor"]


if TYPE_CHECKING:
		from .configuration_donut_swin import DONUT_SWIN_PRETRAINED_CONFIG_ARCHIVE_MAP, DonutSwinConfig
		from .processing_donut import DonutProcessor

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_donut_swin import (
				    DONUT_SWIN_PRETRAINED_MODEL_ARCHIVE_LIST,
				    DonutSwinModel,
				    DonutSwinPreTrainedModel,
				)

		try:
				if not is_vision_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .feature_extraction_donut import DonutFeatureExtractor
				from .image_processing_donut import DonutImageProcessor

else:
		import sys

		_a       =    _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)







'''simple docstring'''

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

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


if is_sentencepiece_available():
			from .tokenization_xglm import XGLMTokenizer
else:
			lowerCAmelCase__      :   List[str]      	=			None


lowerCAmelCase__      :   Union[str, Any]      	=			logging.get_logger(__name__)

lowerCAmelCase__      :   Tuple      	=			{"vocab_file": "sentencepiece.bpe.model", "tokenizer_file": "tokenizer.json"}

lowerCAmelCase__      :   List[str]      	=			{
    "vocab_file": {
        "facebook/xglm-564M": "https://huggingface.co/facebook/xglm-564M/resolve/main/sentencepiece.bpe.model",
    },
    "tokenizer_file": {
        "facebook/xglm-564M": "https://huggingface.co/facebook/xglm-564M/resolve/main/tokenizer.json",
    },
}

lowerCAmelCase__      :   int      	=			{
    "facebook/xglm-564M": 20_48,
}


class      SCREAMING_SNAKE_CASE__      (   snake_case__		):







					"""simple docstring"""






					SCREAMING_SNAKE_CASE							=	VOCAB_FILES_NAMES
					SCREAMING_SNAKE_CASE							=	PRETRAINED_VOCAB_FILES_MAP
					SCREAMING_SNAKE_CASE							=	PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
					SCREAMING_SNAKE_CASE							=	['''input_ids''', '''attention_mask''']
					SCREAMING_SNAKE_CASE							=	XGLMTokenizer
					def __init__(   self       :      Optional[int]		,	UpperCAmelCase_       :      List[Any]=None		,	UpperCAmelCase_       :      str=None		,	UpperCAmelCase_       :      str="<s>"		,	UpperCAmelCase_       :      List[Any]="</s>"		,	UpperCAmelCase_       :      Dict="</s>"		,	UpperCAmelCase_       :      Optional[Any]="<s>"		,	UpperCAmelCase_       :      List[str]="<unk>"		,	UpperCAmelCase_       :      Union[str, Any]="<pad>"		,	**UpperCAmelCase_       :      List[Any]		,	):







							"""simple docstring"""
							# Compatibility with the original tokenizer
							__UpperCAmelCase	:							Union[str, Any]     =     7
							__UpperCAmelCase	:							Tuple     =     [f"<madeupword{i}>" for i in range(self.num_madeup_words		)]

							__UpperCAmelCase	:							List[Any]     =     kwargs.get("additional_special_tokens"		,	[]		)
							kwargs["additional_special_tokens"] += [
							    word for word in madeup_words if word not in kwargs["additional_special_tokens"]
							]

							super().__init__(
							    UpperCAmelCase_		,	tokenizer_file=UpperCAmelCase_		,	bos_token=UpperCAmelCase_		,	eos_token=UpperCAmelCase_		,	sep_token=UpperCAmelCase_		,	cls_token=UpperCAmelCase_		,	unk_token=UpperCAmelCase_		,	pad_token=UpperCAmelCase_		,	**UpperCAmelCase_		,	)

							__UpperCAmelCase	:							Dict     =     vocab_file
							__UpperCAmelCase	:							Optional[int]     =     False if not self.vocab_file else True
					def 		lowerCamelCase_   (   self       :      int		,	UpperCAmelCase_       :      List[int]		,	UpperCAmelCase_       :      Optional[List[int]] = None		):







							"""simple docstring"""

							if token_ids_a is None:
									return [self.sep_token_id] + token_ids_a
							__UpperCAmelCase	:							Any     =     [self.sep_token_id]
							return sep + token_ids_a + sep + sep + token_ids_a
					def 		lowerCamelCase_   (   self       :      Optional[Any]		,	UpperCAmelCase_       :      List[int]		,	UpperCAmelCase_       :      Optional[List[int]] = None		):







							"""simple docstring"""
							__UpperCAmelCase	:							List[Any]     =     [self.sep_token_id]

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






					def 		lowerCamelCase_   (   self       :      List[Any]		,	UpperCAmelCase_       :      str		,	UpperCAmelCase_       :      Optional[str] = None		):







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

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

							return (out_vocab_file,)




