






"""simple docstring"""





from typing import List

import numpy as np



def     __lowercase					(    a :				dict )					->					int:
      __snake_case      :    Tuple  			={key: len(a ) for key, value in gen_kwargs.items() if isinstance(a       ,		a )}
      if len(set(lists_lengths.values() ) ) > 1:
            raise RuntimeError(
                (
                    '''Sharding is ambiguous for this dataset: '''
                    + '''we found several data sources lists of different lengths, and we don\'t know over which list we should parallelize:\n'''
                    + '''\n'''.join(f'''\t- key {key} has length {length}''' for key, length in lists_lengths.items() )
                    + '''\nTo fix this, check the \'gen_kwargs\' and make sure to use lists only for data sources, '''
                    + '''and use tuples otherwise. In the end there should only be one single list, or several lists with the same length.'''
                ) )
      __snake_case      :    int  			=max(lists_lengths.values()       ,		default=0 )
      return max(1       ,		a )



def     __lowercase					(    a :				int       ,		a :				int )					->					List[range]:
      __snake_case      :    str  			=[]
      for group_idx in range(a ):
            __snake_case      :    List[str]  			=num_shards // max_num_jobs + (group_idx < (num_shards % max_num_jobs))
            if num_shards_to_add == 0:
                  break
            __snake_case      :    Tuple  			=shards_indices_per_group[-1].stop if shards_indices_per_group else 0
            __snake_case      :    str  			=range(a       ,		start + num_shards_to_add )
            shards_indices_per_group.append(a )
      return shards_indices_per_group



def     __lowercase					(    a :				dict       ,		a :				int )					->					List[dict]:
      __snake_case      :    str  			=_number_of_shards_in_gen_kwargs(a )
      if num_shards == 1:
            return [dict(a )]
      else:
            __snake_case      :    Any  			=_distribute_shards(num_shards=a       ,		max_num_jobs=a )
            return [
                {
                    key: [value[shard_idx] for shard_idx in shard_indices_per_group[group_idx]]
                    if isinstance(a       ,		a )
                    else value
                    for key, value in gen_kwargs.items()
                }
                for group_idx in range(len(a ) )
            ]



def     __lowercase					(    a :				List[dict] )					->					dict:
      return {
          key: [value for gen_kwargs in gen_kwargs_list for value in gen_kwargs[key]]
          if isinstance(gen_kwargs_list[0][key]       ,		a )
          else gen_kwargs_list[0][key]
          for key in gen_kwargs_list[0]
      }



def     __lowercase					(    a :				np.random.Generator       ,		a :				dict )					->					dict:
      __snake_case      :    Any  			={len(a ) for value in gen_kwargs.values() if isinstance(a       ,		a )}
      __snake_case      :    Optional[int]  			={}
      for size in list_sizes:
            __snake_case      :    Optional[int]  			=list(range(a ) )
            rng.shuffle(indices_per_size[size] )
      # Now let's copy the gen_kwargs and shuffle the lists based on their sizes
      __snake_case      :    Optional[int]  			=dict(a )
      for key, value in shuffled_kwargs.items():
            if isinstance(a       ,		a ):
                  __snake_case      :    Tuple  			=[value[i] for i in indices_per_size[len(a )]]
      return shuffled_kwargs










"""simple docstring"""





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


UpperCamelCase_	:				Optional[int]										= logging.get_logger(__name__)

UpperCamelCase_	:				Union[str, Any]										= {"""ctrl""": """https://huggingface.co/ctrl/resolve/main/config.json"""}


class      _lowercase (     lowerCAmelCase						):
      _a   :     str								=   '''ctrl'''
      _a   :     Optional[int]								=   ['''past_key_values''']
      _a   :     List[Any]								=   {
          '''max_position_embeddings''': '''n_positions''',
          '''hidden_size''': '''n_embd''',
          '''num_attention_heads''': '''n_head''',
          '''num_hidden_layers''': '''n_layer''',
      }


      def __init__(    self				:	str							,   a				:	Optional[int]=2_4_6_5_3_4							,   a				:	Optional[int]=2_5_6							,   a				:	Optional[int]=1_2_8_0							,   a				:	Any=8_1_9_2							,   a				:	int=4_8							,   a				:	Optional[Any]=1_6							,   a				:	str=0.1							,   a				:	str=0.1							,   a				:	Any=1e-6							,   a				:	Optional[int]=0.0_2							,   a				:	int=True							,   **a				:	str							,   ):





            """simple docstring"""







            __snake_case      :    Tuple  			=vocab_size
            __snake_case      :    Optional[Any]  			=n_positions
            __snake_case      :    List[Any]  			=n_embd
            __snake_case      :    Any  			=n_layer
            __snake_case      :    Any  			=n_head
            __snake_case      :    str  			=dff
            __snake_case      :    List[str]  			=resid_pdrop
            __snake_case      :    str  			=embd_pdrop
            __snake_case      :    Union[str, Any]  			=layer_norm_epsilon
            __snake_case      :    List[Any]  			=initializer_range

            __snake_case      :    Any  			=use_cache

            super().__init__(**a						)


