import pytest

from datasets.parallel import ParallelBackendConfig, parallel_backend
from datasets.utils.py_utils import map_nested

from .utils import require_dill_gt_0_3_2, require_joblibspark, require_not_windows




def 							UpperCamelCase		(			__lowercase		:					Tuple      ):  # picklable for multiprocessing
		'''simple docstring'''




		return i + 1




@require_dill_gt_0_3_2
@require_joblibspark
@require_not_windows
def 							UpperCamelCase		(			):
		'''simple docstring'''




		with parallel_backend('spark'      ):
				assert ParallelBackendConfig.backend_name == "spark"

		A_						:							Optional[int]      = [1, 2, 3]
		with pytest.raises(__lowercase      ):
				with parallel_backend('unsupported backend'      ):
						map_nested(__lowercase		,__lowercase		,num_proc=2      )

		with pytest.raises(__lowercase      ):
				with parallel_backend('unsupported backend'      ):
						map_nested(__lowercase		,__lowercase		,num_proc=-1      )




@require_dill_gt_0_3_2
@require_joblibspark
@require_not_windows
@pytest.mark.parametrize('num_proc'		,[2, -1]      )
def 							UpperCamelCase		(			__lowercase		:					List[Any]      ):
		'''simple docstring'''




		A_						:							Tuple      = [1, 2]
		A_						:							List[Any]      = {'a': 1, 'b': 2}
		A_						:							Dict      = {'a': [1, 2], 'b': [3, 4]}
		A_						:							List[str]      = {'a': {'1': 1}, 'b': 2}
		A_						:							List[str]      = {'a': 1, 'b': 2, 'c': 3, 'd': 4}
		A_						:							Union[str, Any]      = [2, 3]
		A_						:							List[str]      = {'a': 2, 'b': 3}
		A_						:							Any      = {'a': [2, 3], 'b': [4, 5]}
		A_						:							Optional[int]      = {'a': {'1': 2}, 'b': 3}
		A_						:							str      = {'a': 2, 'b': 3, 'c': 4, 'd': 5}

		with parallel_backend('spark'      ):
				assert map_nested(__lowercase		,__lowercase		,num_proc=__lowercase      ) == expected_map_nested_sa
				assert map_nested(__lowercase		,__lowercase		,num_proc=__lowercase      ) == expected_map_nested_sa
				assert map_nested(__lowercase		,__lowercase		,num_proc=__lowercase      ) == expected_map_nested_sa
				assert map_nested(__lowercase		,__lowercase		,num_proc=__lowercase      ) == expected_map_nested_sa
				assert map_nested(__lowercase		,__lowercase		,num_proc=__lowercase      ) == expected_map_nested_sa







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


_UpperCAmelCase          =						logging.get_logger(__name__)

_UpperCAmelCase          =						{
    """facebook/deit-base-distilled-patch16-224""": (
        """https://huggingface.co/facebook/deit-base-patch16-224/resolve/main/config.json"""
    ),
    # See all DeiT models at https://huggingface.co/models?filter=deit
}





class UpperCAmelCase		(   __A    ):


				'''simple docstring'''






				lowerCamelCase_        =   '''deit'''
				def __init__(		self						,      lowercase=7_6_8						,      lowercase=1_2						,      lowercase=1_2						,      lowercase=3_0_7_2						,      lowercase="gelu"						,      lowercase=0.0						,      lowercase=0.0						,      lowercase=0.02						,      lowercase=1E-12						,      lowercase=2_2_4						,      lowercase=1_6						,      lowercase=3						,      lowercase=True						,      lowercase=1_6						,      **lowercase						,      ):



						"""simple docstring"""





						super().__init__(**lowercase   )

						A_						:							Dict      = hidden_size
						A_						:							List[Any]      = num_hidden_layers
						A_						:							Optional[int]      = num_attention_heads
						A_						:							List[str]      = intermediate_size
						A_						:							int      = hidden_act
						A_						:							Optional[int]      = hidden_dropout_prob
						A_						:							str      = attention_probs_dropout_prob
						A_						:							List[str]      = initializer_range
						A_						:							List[Any]      = layer_norm_eps
						A_						:							List[str]      = image_size
						A_						:							str      = patch_size
						A_						:							str      = num_channels
						A_						:							Dict      = qkv_bias
						A_						:							Optional[Any]      = encoder_stride





class UpperCAmelCase		(   __A    ):


				'''simple docstring'''






				lowerCamelCase_        =   version.parse('''1.11'''    )
				@property
				def     lowerCAmelCase_  (		self   ):



						"""simple docstring"""





						return OrderedDict(
						    [
						        ('pixel_values', {0: 'batch', 1: 'num_channels', 2: 'height', 3: 'width'}),
						    ]   )







				@property
				def     lowerCAmelCase_  (		self   ):



						"""simple docstring"""





						return 1E-4






