



from random import randint, random






def 					__lowerCAmelCase		(  __lowerCamelCase	:    int				,   __lowerCamelCase	:    int				,   __lowerCamelCase	:    int				,   __lowerCamelCase	:    bool = False				,   __lowerCamelCase	:    bool = False				,   __lowerCamelCase	:    int = 5				,   )  ->						list:
     __lowerCAmelCase	   =[[-1] * number_of_cells]  # Create a highway without any car
     __lowerCAmelCase	   =0
     __lowerCAmelCase	   =max(__lowerCamelCase				,   0	)
     while i < number_of_cells:
          __lowerCAmelCase	   =(
              randint(0				,   __lowerCamelCase	) if random_speed else initial_speed
          )  # Place the cars
          i += (
              randint(1				,   max_speed * 2	) if random_frequency else frequency
          )  # Arbitrary number, may need tuning
     return highway






def 					__lowerCAmelCase		(  __lowerCamelCase	:    list				,   __lowerCamelCase	:    int	)  ->						int:
     __lowerCAmelCase	   =0
     __lowerCAmelCase	   =highway_now[car_index + 1 :]
     for cell in range(len(__lowerCamelCase	)	):  # May need a better name for this
          if cells[cell] != -1:  # If the cell is not empty then
               return distance  # we have the distance we wanted
          distance += 1
     # Here if the car is near the end of the highway
     return distance + get_distance(__lowerCamelCase				,   -1	)






def 					__lowerCAmelCase		(  __lowerCamelCase	:    list				,   __lowerCamelCase	:    float				,   __lowerCamelCase	:    int	)  ->						list:
     __lowerCAmelCase	   =len(__lowerCamelCase	)
     # Beforce calculations, the highway is empty
     __lowerCAmelCase	   =[-1] * number_of_cells

     for car_index in range(__lowerCamelCase	):
          if highway_now[car_index] != -1:
               # Add 1 to the current speed of the car and cap the speed
               __lowerCAmelCase	   =min(highway_now[car_index] + 1				,   __lowerCamelCase	)
               # Number of empty cell before the next car
               __lowerCAmelCase	   =get_distance(__lowerCamelCase				,   __lowerCamelCase	) - 1
               # We can't have the car causing an accident
               __lowerCAmelCase	   =min(next_highway[car_index]				,   __lowerCamelCase	)
               if random() < probability:
                    # Randomly, a driver will slow down
                    __lowerCAmelCase	   =max(next_highway[car_index] - 1				,   0	)
     return next_highway






def 					__lowerCAmelCase		(  __lowerCamelCase	:    list				,   __lowerCamelCase	:    int				,   __lowerCamelCase	:    float				,   __lowerCamelCase	:    int	)  ->						list:
     __lowerCAmelCase	   =len(highway[0]	)

     for i in range(__lowerCamelCase	):
          __lowerCAmelCase	   =update(highway[i]				,   __lowerCamelCase				,   __lowerCamelCase	)
          __lowerCAmelCase	   =[-1] * number_of_cells

          for car_index in range(__lowerCamelCase	):
               __lowerCAmelCase	   =next_speeds_calculated[car_index]
               if speed != -1:
                    # Change the position based on the speed (with % to create the loop)
                    __lowerCAmelCase	   =(car_index + speed) % number_of_cells
                    # Commit the change of position
                    __lowerCAmelCase	   =speed
          highway.append(__lowerCamelCase	)

     return highway


if __name__ == "__main__":
    import doctest

    doctest.testmod()









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


lowercase_	       =			logging.get_logger(__name__)

lowercase_	       =			{
    '''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 (     SCREAMING_SNAKE_CASE				):
	SCREAMING_SNAKE_CASE       =       "realm"



	def __init__(						self							:    Tuple				,	snake_case_							:    Tuple=3_05_22				,	snake_case_							:    List[Any]=7_68				,	snake_case_							:    Any=1_28				,	snake_case_							:    Union[str, Any]=12				,	snake_case_							:    List[str]=12				,	snake_case_							:    Any=8				,	snake_case_							:    Any=30_72				,	snake_case_							:    int="gelu_new"				,	snake_case_							:    Optional[int]=0.1				,	snake_case_							:    Tuple=0.1				,	snake_case_							:    List[Any]=5_12				,	snake_case_							:    List[Any]=2				,	snake_case_							:    Any=0.0_2				,	snake_case_							:    List[str]=1e-12				,	snake_case_							:    Optional[Any]=2_56				,	snake_case_							:    Dict=10				,	snake_case_							:    str=1e-3				,	snake_case_							:    List[str]=5				,	snake_case_							:    Optional[Any]=3_20				,	snake_case_							:    Optional[Any]=13_35_37_18				,	snake_case_							:    Tuple=50_00				,	snake_case_							:    Union[str, Any]=1				,	snake_case_							:    Union[str, Any]=0				,	snake_case_							:    List[str]=2				,	**snake_case_							:    List[str]				,	)->							str:
						super().__init__(pad_token_id=snake_case_				,	bos_token_id=snake_case_				,	eos_token_id=snake_case_				,	**snake_case_)

						# Common config
						__lowerCAmelCase	   =vocab_size
						__lowerCAmelCase	   =max_position_embeddings
						__lowerCAmelCase	   =hidden_size
						__lowerCAmelCase	   =retriever_proj_size
						__lowerCAmelCase	   =num_hidden_layers
						__lowerCAmelCase	   =num_attention_heads
						__lowerCAmelCase	   =num_candidates
						__lowerCAmelCase	   =intermediate_size
						__lowerCAmelCase	   =hidden_act
						__lowerCAmelCase	   =hidden_dropout_prob
						__lowerCAmelCase	   =attention_probs_dropout_prob
						__lowerCAmelCase	   =initializer_range
						__lowerCAmelCase	   =type_vocab_size
						__lowerCAmelCase	   =layer_norm_eps

						# Reader config
						__lowerCAmelCase	   =span_hidden_size
						__lowerCAmelCase	   =max_span_width
						__lowerCAmelCase	   =reader_layer_norm_eps
						__lowerCAmelCase	   =reader_beam_size
						__lowerCAmelCase	   =reader_seq_len

						# Retrieval config
						__lowerCAmelCase	   =num_block_records
						__lowerCAmelCase	   =searcher_beam_size




