




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_				( __UpperCAmelCase		:      str				)   ->					Tuple:  # picklable for multiprocessing
      return i + 1

@require_dill_gt_0_3_2
@require_joblibspark
@require_not_windows
def    UpperCAmelCase_				( )   ->					str:
      with parallel_backend('spark'				):
            assert ParallelBackendConfig.backend_name == "spark"

      SCREAMING_SNAKE_CASE_      		=     [1, 2, 3]
      with pytest.raises(__UpperCAmelCase				):
            with parallel_backend('unsupported backend'				):
                  map_nested(__UpperCAmelCase     ,     __UpperCAmelCase     ,     num_proc=2				)

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





@require_dill_gt_0_3_2
@require_joblibspark
@require_not_windows
@pytest.mark.parametrize('num_proc'     ,     [2, -1]				)
def    UpperCAmelCase_				( __UpperCAmelCase		:      Tuple				)   ->					List[Any]:
      SCREAMING_SNAKE_CASE_      		=     [1, 2]
      SCREAMING_SNAKE_CASE_      		=     {'a': 1, 'b': 2}
      SCREAMING_SNAKE_CASE_      		=     {'a': [1, 2], 'b': [3, 4]}
      SCREAMING_SNAKE_CASE_      		=     {'a': {'1': 1}, 'b': 2}
      SCREAMING_SNAKE_CASE_      		=     {'a': 1, 'b': 2, 'c': 3, 'd': 4}
      SCREAMING_SNAKE_CASE_      		=     [2, 3]
      SCREAMING_SNAKE_CASE_      		=     {'a': 2, 'b': 3}
      SCREAMING_SNAKE_CASE_      		=     {'a': [2, 3], 'b': [4, 5]}
      SCREAMING_SNAKE_CASE_      		=     {'a': {'1': 2}, 'b': 3}
      SCREAMING_SNAKE_CASE_      		=     {'a': 2, 'b': 3, 'c': 4, 'd': 5}

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


from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


_UpperCAmelCase						:  int									=			{
    """configuration_lilt""": ["""LILT_PRETRAINED_CONFIG_ARCHIVE_MAP""", """LiltConfig"""],
}

try:
					if not is_torch_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					_UpperCAmelCase						:  str									=			[
					    """LILT_PRETRAINED_MODEL_ARCHIVE_LIST""",
					    """LiltForQuestionAnswering""",
					    """LiltForSequenceClassification""",
					    """LiltForTokenClassification""",
					    """LiltModel""",
					    """LiltPreTrainedModel""",
					]

if TYPE_CHECKING:
					from .configuration_lilt import LILT_PRETRAINED_CONFIG_ARCHIVE_MAP, LiltConfig

					try:
										if not is_torch_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_lilt import (
										    LILT_PRETRAINED_MODEL_ARCHIVE_LIST,
										    LiltForQuestionAnswering,
										    LiltForSequenceClassification,
										    LiltForTokenClassification,
										    LiltModel,
										    LiltPreTrainedModel,
										)

else:
					import sys

					_UpperCAmelCase						:  Dict									=			_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)




