




"""simple docstring"""






import pytest

from datasets.utils.sharding import _distribute_shards, _number_of_shards_in_gen_kwargs, _split_gen_kwargs







@pytest.mark.parametrize(
    'kwargs, expected'							,    [
        ({'num_shards': 0, 'max_num_jobs': 1}, []),
        ({'num_shards': 10, 'max_num_jobs': 1}, [range(10		)]),
        ({'num_shards': 10, 'max_num_jobs': 10}, [range(lowercase__							,    i + 1		) for i in range(10		)]),
        ({'num_shards': 1, 'max_num_jobs': 10}, [range(1		)]),
        ({'num_shards': 10, 'max_num_jobs': 3}, [range(0							,    4		), range(4							,    7		), range(7							,    10		)]),
        ({'num_shards': 3, 'max_num_jobs': 10}, [range(0							,    1		), range(1							,    2		), range(2							,    3		)]),
    ]							,    )
def      _snake_case			(				lowercase__							,    lowercase__		):
				_lowerCamelCase     :			int    =    _distribute_shards(**lowercase__		)
				assert out == expected







@pytest.mark.parametrize(
    'gen_kwargs, max_num_jobs, expected'							,    [
        ({'foo': 0}, 10, [{'foo': 0}]),
        ({'shards': [0, 1, 2, 3]}, 1, [{'shards': [0, 1, 2, 3]}]),
        ({'shards': [0, 1, 2, 3]}, 4, [{'shards': [0]}, {'shards': [1]}, {'shards': [2]}, {'shards': [3]}]),
        ({'shards': [0, 1]}, 4, [{'shards': [0]}, {'shards': [1]}]),
        ({'shards': [0, 1, 2, 3]}, 2, [{'shards': [0, 1]}, {'shards': [2, 3]}]),
    ]							,    )
def      _snake_case			(				lowercase__							,    lowercase__							,    lowercase__		):
				_lowerCamelCase     :			int    =    _split_gen_kwargs(lowercase__							,    lowercase__		)
				assert out == expected







@pytest.mark.parametrize(
    'gen_kwargs, expected'							,    [
        ({'foo': 0}, 1),
        ({'shards': [0]}, 1),
        ({'shards': [0, 1, 2, 3]}, 4),
        ({'shards': [0, 1, 2, 3], 'foo': 0}, 4),
        ({'shards': [0, 1, 2, 3], 'other': (0, 1)}, 4),
        ({'shards': [0, 1, 2, 3], 'shards2': [0, 1]}, RuntimeError),
    ]							,    )
def      _snake_case			(				lowercase__							,    lowercase__		):
				if expected is RuntimeError:
								with pytest.raises(lowercase__		):
												_number_of_shards_in_gen_kwargs(lowercase__		)
				else:
								_lowerCamelCase     :			Tuple    =    _number_of_shards_in_gen_kwargs(lowercase__		)
								assert out == expected





"""simple docstring"""






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


lowercase__     						=						logging.get_logger(__name__)

lowercase__     						=						{"""ctrl""": """https://huggingface.co/ctrl/resolve/main/config.json"""}






class lowerCAmelCase__	(     lowercase						):






			'''simple docstring'''



			lowerCamelCase__      =			"""ctrl"""
			lowerCamelCase__      =			["""past_key_values"""]
			lowerCamelCase__      =			{
			    """max_position_embeddings""": """n_positions""",
			    """hidden_size""": """n_embd""",
			    """num_attention_heads""": """n_head""",
			    """num_hidden_layers""": """n_layer""",
			}
			def __init__(  self  ,      lowercase=246534  ,      lowercase=256  ,      lowercase=1280  ,      lowercase=8192  ,      lowercase=48  ,      lowercase=16  ,      lowercase=0.1  ,      lowercase=0.1  ,      lowercase=1E-6  ,      lowercase=0.02  ,      lowercase=True  ,      **lowercase  ,      ):
							_lowerCamelCase     :			Any    =    vocab_size
							_lowerCamelCase     :			Dict    =    n_positions
							_lowerCamelCase     :			Optional[int]    =    n_embd
							_lowerCamelCase     :			str    =    n_layer
							_lowerCamelCase     :			Union[str, Any]    =    n_head
							_lowerCamelCase     :			Any    =    dff
							_lowerCamelCase     :			int    =    resid_pdrop
							_lowerCamelCase     :			Dict    =    embd_pdrop
							_lowerCamelCase     :			Union[str, Any]    =    layer_norm_epsilon
							_lowerCamelCase     :			Tuple    =    initializer_range

							_lowerCamelCase     :			str    =    use_cache

							super().__init__(**lowercase  )