





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


__lowerCamelCase       :     Union[str, Any]   =     logging.get_logger(__name__)

__lowerCamelCase       :     Dict   =     {
    '''google/realm-cc-news-pretrained-embedder''': (
        '''https://huggingface.co/google/realm-cc-news-pretrained-embedder/resolve/main/config.json'''
    ),
    '''google/realm-cc-news-pretrained-encoder''': (
        '''https://huggingface.co/google/realm-cc-news-pretrained-encoder/resolve/main/config.json'''
    ),
    '''google/realm-cc-news-pretrained-scorer''': (
        '''https://huggingface.co/google/realm-cc-news-pretrained-scorer/resolve/main/config.json'''
    ),
    '''google/realm-cc-news-pretrained-openqa''': (
        '''https://huggingface.co/google/realm-cc-news-pretrained-openqa/aresolve/main/config.json'''
    ),
    '''google/realm-orqa-nq-openqa''': '''https://huggingface.co/google/realm-orqa-nq-openqa/resolve/main/config.json''',
    '''google/realm-orqa-nq-reader''': '''https://huggingface.co/google/realm-orqa-nq-reader/resolve/main/config.json''',
    '''google/realm-orqa-wq-openqa''': '''https://huggingface.co/google/realm-orqa-wq-openqa/resolve/main/config.json''',
    '''google/realm-orqa-wq-reader''': '''https://huggingface.co/google/realm-orqa-wq-reader/resolve/main/config.json''',
    # See all REALM models at https://huggingface.co/models?filter=realm
}



class 					A__   (       UpperCAmelCase__			):
      _UpperCAmelCase	:Tuple						    =   "realm"





      def __init__( self       ,							A_=3_0522       ,							A_=768       ,							A_=128       ,							A_=12       ,							A_=12       ,							A_=8       ,							A_=3072       ,							A_="gelu_new"       ,							A_=0.1       ,							A_=0.1       ,							A_=512       ,							A_=2       ,							A_=0.02       ,							A_=1e-12       ,							A_=256       ,							A_=10       ,							A_=1e-3       ,							A_=5       ,							A_=320       ,							A_=1335_3718       ,							A_=5000       ,							A_=1       ,							A_=0       ,							A_=2       ,							**A_       ,							):
       '''simple docstring'''




       super().__init__(pad_token_id=A_       ,							bos_token_id=A_       ,							eos_token_id=A_       ,							**A_   )

       # Common config
       UpperCamelCase	:					Tuple       	=   vocab_size
       UpperCamelCase	:					List[Any]       	=   max_position_embeddings
       UpperCamelCase	:					List[Any]       	=   hidden_size
       UpperCamelCase	:					Any       	=   retriever_proj_size
       UpperCamelCase	:					List[Any]       	=   num_hidden_layers
       UpperCamelCase	:					int       	=   num_attention_heads
       UpperCamelCase	:					Optional[Any]       	=   num_candidates
       UpperCamelCase	:					Optional[Any]       	=   intermediate_size
       UpperCamelCase	:					Tuple       	=   hidden_act
       UpperCamelCase	:					Optional[Any]       	=   hidden_dropout_prob
       UpperCamelCase	:					Any       	=   attention_probs_dropout_prob
       UpperCamelCase	:					Optional[Any]       	=   initializer_range
       UpperCamelCase	:					List[str]       	=   type_vocab_size
       UpperCamelCase	:					str       	=   layer_norm_eps

       # Reader config
       UpperCamelCase	:					Tuple       	=   span_hidden_size
       UpperCamelCase	:					List[Any]       	=   max_span_width
       UpperCamelCase	:					Optional[Any]       	=   reader_layer_norm_eps
       UpperCamelCase	:					int       	=   reader_beam_size
       UpperCamelCase	:					Tuple       	=   reader_seq_len

       # Retrieval config
       UpperCamelCase	:					Optional[Any]       	=   num_block_records
       UpperCamelCase	:					Any       	=   searcher_beam_size




'''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(_UpperCAmelCase    ,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 	SCREAMING_SNAKE_CASE_					(  _UpperCAmelCase	:	Union[str, Any]    ,_UpperCAmelCase	:	Dict  )  ->			Optional[Any]:
       _a    : Tuple     					=_distribute_shards(**_UpperCAmelCase  )
       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 	SCREAMING_SNAKE_CASE_					(  _UpperCAmelCase	:	Tuple    ,_UpperCAmelCase	:	List[Any]    ,_UpperCAmelCase	:	Union[str, Any]  )  ->			List[str]:
       _a    : List[str]     					=_split_gen_kwargs(_UpperCAmelCase    ,_UpperCAmelCase  )
       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 	SCREAMING_SNAKE_CASE_					(  _UpperCAmelCase	:	Optional[Any]    ,_UpperCAmelCase	:	List[Any]  )  ->			Union[str, Any]:
       if expected is RuntimeError:
              with pytest.raises(_UpperCAmelCase  ):
                     _number_of_shards_in_gen_kwargs(_UpperCAmelCase  )
       else:
              _a    : Dict     					=_number_of_shards_in_gen_kwargs(_UpperCAmelCase  )
              assert out == expected


