






'''simple docstring'''







import importlib
import shutil
import threading
import warnings
from typing import List

import fsspec
import fsspec.asyn

from . import compression
from .hffilesystem import HfFileSystem


UpperCamelCase    :      int  			=		importlib.util.find_spec('s3fs') is not None

if _has_safs:
							from .safilesystem import SaFileSystem  # noqa: F401

UpperCamelCase    :      List[compression.BaseCompressedFileFileSystem]  			=		[
    compression.BzaFileSystem,
    compression.GzipFileSystem,
    compression.LzaFileSystem,
    compression.XzFileSystem,
    compression.ZstdFileSystem,
]

# Register custom filesystems
for fs_class in COMPRESSION_FILESYSTEMS + [HfFileSystem]:
							if fs_class.protocol in fsspec.registry and fsspec.registry[fs_class.protocol] is not fs_class:
														warnings.warn(F'A filesystem protocol was already set for {fs_class.protocol} and will be overwritten.')
							fsspec.register_implementation(fs_class.protocol, fs_class, clobber=True)
def 						A__			(				__lowerCAmelCase		:			str						):
						if "://" in dataset_path:
												lowerCamelCase__         =  dataset_path.split("""://"""						)[1]
						return dataset_path
def 						A__			(				__lowerCAmelCase		:			fsspec.AbstractFileSystem						):
						if fs is not None and fs.protocol != "file":
												return True
						else:
												return False
def 						A__			(				__lowerCAmelCase		:			fsspec.AbstractFileSystem   ,    __lowerCAmelCase		:			str   ,    __lowerCAmelCase		:			str						):
						lowerCamelCase__         =  not is_remote_filesystem(__lowerCAmelCase						)
						if is_local:
												# LocalFileSystem.mv does copy + rm, it is more efficient to simply move a local directory
												shutil.move(fs._strip_protocol(__lowerCAmelCase						)   ,    fs._strip_protocol(__lowerCAmelCase						)						)
						else:
												fs.mv(__lowerCAmelCase   ,    __lowerCAmelCase   ,    recursive=__lowerCAmelCase						)





def 						A__			(				):
						if hasattr(fsspec.asyn   ,    """reset_lock"""						):
												# for future fsspec>2022.05.0
												fsspec.asyn.reset_lock()
						else:
												lowerCamelCase__         =  None
												lowerCamelCase__         =  None
												lowerCamelCase__         =  threading.Lock()









'''simple docstring'''







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


UpperCamelCase    :      Tuple  			=		logging.get_logger(__name__)

UpperCamelCase    :      List[str]  			=		{
    'naver-clova-ix/donut-base': 'https://huggingface.co/naver-clova-ix/donut-base/resolve/main/config.json',
    # See all Donut models at https://huggingface.co/models?filter=donut-swin
}




class 		UpperCamelCase__    (a			):




		'''simple docstring'''





		_UpperCamelCase				  =					'donut-swin'

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






		def __init__(      self   ,_lowerCAmelCase=2_24   ,_lowerCAmelCase=4   ,_lowerCAmelCase=3   ,_lowerCAmelCase=96   ,_lowerCAmelCase=[2, 2, 6, 2]   ,_lowerCAmelCase=[3, 6, 12, 24]   ,_lowerCAmelCase=7   ,_lowerCAmelCase=4.0   ,_lowerCAmelCase=True   ,_lowerCAmelCase=0.0   ,_lowerCAmelCase=0.0   ,_lowerCAmelCase=0.1   ,_lowerCAmelCase="gelu"   ,_lowerCAmelCase=False   ,_lowerCAmelCase=0.02   ,_lowerCAmelCase=1E-5   ,**_lowerCAmelCase   ,):
								super().__init__(**_lowerCAmelCase       )

								lowerCamelCase__         =  image_size
								lowerCamelCase__         =  patch_size
								lowerCamelCase__         =  num_channels
								lowerCamelCase__         =  embed_dim
								lowerCamelCase__         =  depths
								lowerCamelCase__         =  len(_lowerCAmelCase       )
								lowerCamelCase__         =  num_heads
								lowerCamelCase__         =  window_size
								lowerCamelCase__         =  mlp_ratio
								lowerCamelCase__         =  qkv_bias
								lowerCamelCase__         =  hidden_dropout_prob
								lowerCamelCase__         =  attention_probs_dropout_prob
								lowerCamelCase__         =  drop_path_rate
								lowerCamelCase__         =  hidden_act
								lowerCamelCase__         =  use_absolute_embeddings
								lowerCamelCase__         =  layer_norm_eps
								lowerCamelCase__         =  initializer_range
								# 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
								lowerCamelCase__         =  int(embed_dim * 2 ** (len(_lowerCAmelCase       ) - 1)       )

