





"""simple docstring"""
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      __lowerCamelCase   (							a_     :		Tuple							)			->      str:  # picklable for multiprocessing
      return i + 1



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

      __SCREAMING_SNAKE_CASE   :List[Any]						=  [1, 2, 3]
      with pytest.raises(a_							):
            with parallel_backend('''unsupported backend'''							):
                  map_nested(a_ ,   a_ ,   num_proc=2							)

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







@require_dill_gt_0_3_2
@require_joblibspark
@require_not_windows
@pytest.mark.parametrize('''num_proc''' ,   [2, -1]							)
def      __lowerCamelCase   (							a_     :		int							)			->      List[str]:
      __SCREAMING_SNAKE_CASE   :Optional[int]						=  [1, 2]
      __SCREAMING_SNAKE_CASE   :Optional[int]						=  {'''a''': 1, '''b''': 2}
      __SCREAMING_SNAKE_CASE   :int						=  {'''a''': [1, 2], '''b''': [3, 4]}
      __SCREAMING_SNAKE_CASE   :Union[str, Any]						=  {'''a''': {'''1''': 1}, '''b''': 2}
      __SCREAMING_SNAKE_CASE   :Any						=  {'''a''': 1, '''b''': 2, '''c''': 3, '''d''': 4}
      __SCREAMING_SNAKE_CASE   :int						=  [2, 3]
      __SCREAMING_SNAKE_CASE   :Optional[Any]						=  {'''a''': 2, '''b''': 3}
      __SCREAMING_SNAKE_CASE   :Any						=  {'''a''': [2, 3], '''b''': [4, 5]}
      __SCREAMING_SNAKE_CASE   :Tuple						=  {'''a''': {'''1''': 2}, '''b''': 3}
      __SCREAMING_SNAKE_CASE   :List[Any]						=  {'''a''': 2, '''b''': 3, '''c''': 4, '''d''': 5}

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






"""simple docstring"""
from ...configuration_utils import PretrainedConfig
from ...utils import logging


lowerCamelCase_								=		logging.get_logger(__name__)

lowerCamelCase_								=		{}






class 					_SCREAMING_SNAKE_CASE(   A  ):
       SCREAMING_SNAKE_CASE_   :      List[Any]							=  '''llama'''
       SCREAMING_SNAKE_CASE_   :      Optional[int]							=  ['''past_key_values''']




       def __init__(						self		,SCREAMING_SNAKE_CASE__=3_20_00		,SCREAMING_SNAKE_CASE__=40_96		,SCREAMING_SNAKE_CASE__=1_10_08		,SCREAMING_SNAKE_CASE__=32		,SCREAMING_SNAKE_CASE__=32		,SCREAMING_SNAKE_CASE__=None		,SCREAMING_SNAKE_CASE__="silu"		,SCREAMING_SNAKE_CASE__=20_48		,SCREAMING_SNAKE_CASE__=0.0_2		,SCREAMING_SNAKE_CASE__=1E-6		,SCREAMING_SNAKE_CASE__=True		,SCREAMING_SNAKE_CASE__=0		,SCREAMING_SNAKE_CASE__=1		,SCREAMING_SNAKE_CASE__=2		,SCREAMING_SNAKE_CASE__=1		,SCREAMING_SNAKE_CASE__=False		,SCREAMING_SNAKE_CASE__=None		,**SCREAMING_SNAKE_CASE__		,)			->      Union[str, Any]:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE   :Optional[Any]						=  vocab_size
             __SCREAMING_SNAKE_CASE   :int						=  max_position_embeddings
             __SCREAMING_SNAKE_CASE   :List[str]						=  hidden_size
             __SCREAMING_SNAKE_CASE   :Tuple						=  intermediate_size
             __SCREAMING_SNAKE_CASE   :List[str]						=  num_hidden_layers
             __SCREAMING_SNAKE_CASE   :List[Any]						=  num_attention_heads

             # for backward compatibility
             if num_key_value_heads is None:
                   __SCREAMING_SNAKE_CASE   :Optional[int]						=  num_attention_heads

             __SCREAMING_SNAKE_CASE   :str						=  num_key_value_heads
             __SCREAMING_SNAKE_CASE   :Union[str, Any]						=  hidden_act
             __SCREAMING_SNAKE_CASE   :List[str]						=  initializer_range
             __SCREAMING_SNAKE_CASE   :Union[str, Any]						=  rms_norm_eps
             __SCREAMING_SNAKE_CASE   :Dict						=  pretraining_tp
             __SCREAMING_SNAKE_CASE   :Optional[Any]						=  use_cache
             __SCREAMING_SNAKE_CASE   :Optional[Any]						=  rope_scaling
             self._rope_scaling_validation()

             super().__init__(
                 pad_token_id=SCREAMING_SNAKE_CASE__		,bos_token_id=SCREAMING_SNAKE_CASE__		,eos_token_id=SCREAMING_SNAKE_CASE__		,tie_word_embeddings=SCREAMING_SNAKE_CASE__		,**SCREAMING_SNAKE_CASE__		,)




       def     _UpperCamelCase     (						self							)			->      List[Any]:





             """simple docstring"""






             if self.rope_scaling is None:
                   return

             if not isinstance(self.rope_scaling		,SCREAMING_SNAKE_CASE__							) or len(self.rope_scaling							) != 2:
                   raise ValueError(
                       '''`rope_scaling` must be a dictionary with with two fields, `name` and `factor`, '''
                       f'''got {self.rope_scaling}'''							)
             __SCREAMING_SNAKE_CASE   :Optional[Any]						=  self.rope_scaling.get('''type'''		,SCREAMING_SNAKE_CASE__							)
             __SCREAMING_SNAKE_CASE   :Optional[int]						=  self.rope_scaling.get('''factor'''		,SCREAMING_SNAKE_CASE__							)
             if rope_scaling_type is None or rope_scaling_type not in ["linear", "dynamic"]:
                   raise ValueError(
                       f'''`rope_scaling`\'s name field must be one of [\'linear\', \'dynamic\'], got {rope_scaling_type}'''							)
             if rope_scaling_factor is None or not isinstance(SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							) or rope_scaling_factor <= 1.0:
                   raise ValueError(f'''`rope_scaling`\'s factor field must be an float > 1, got {rope_scaling_factor}'''							)