"""simple docstring"""






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


lowerCAmelCase__  :  List[Any]						     =	logging.get_logger(__name__)

lowerCAmelCase__  :  Tuple						     =	{
    'facebook/nllb-moe-54B': 'https://huggingface.co/facebook/nllb-moe-54b/resolve/main/config.json',
}
class 				snake_case       ( __UpperCAmelCase				):




					"""simple docstring"""

					snake_case__				    = "nllb-moe"
					snake_case__				    = ["past_key_values"]
					snake_case__				    = {"num_attention_heads": "encoder_attention_heads", "hidden_size": "d_model"}







					def __init__(				self   :	Tuple    ,lowerCamelCase__   :	Optional[Any]=128_112    ,lowerCamelCase__   :	List[str]=1_024    ,lowerCamelCase__   :	Any=12    ,lowerCamelCase__   :	Any=4_096    ,lowerCamelCase__   :	Dict=16    ,lowerCamelCase__   :	str=12    ,lowerCamelCase__   :	Any=4_096    ,lowerCamelCase__   :	str=16    ,lowerCamelCase__   :	str=0.0_5    ,lowerCamelCase__   :	Dict=0.0_5    ,lowerCamelCase__   :	Union[str, Any]=True    ,lowerCamelCase__   :	List[Any]=True    ,lowerCamelCase__   :	Dict="relu"    ,lowerCamelCase__   :	Any=1_024    ,lowerCamelCase__   :	List[str]=0.1    ,lowerCamelCase__   :	Optional[int]=0.1    ,lowerCamelCase__   :	Tuple=0.0    ,lowerCamelCase__   :	str=0.0_2    ,lowerCamelCase__   :	Any=2    ,lowerCamelCase__   :	Optional[Any]=True    ,lowerCamelCase__   :	str=False    ,lowerCamelCase__   :	Optional[int]="float32"    ,lowerCamelCase__   :	Dict=False    ,lowerCamelCase__   :	Dict=128    ,lowerCamelCase__   :	int=64    ,lowerCamelCase__   :	Tuple=4    ,lowerCamelCase__   :	Any=4    ,lowerCamelCase__   :	Dict=0.0_0_1    ,lowerCamelCase__   :	List[str]=0.0_0_1    ,lowerCamelCase__   :	Optional[Any]="all"    ,lowerCamelCase__   :	List[Any]=False    ,lowerCamelCase__   :	str=False    ,lowerCamelCase__   :	Optional[int]=1.0    ,lowerCamelCase__   :	Union[str, Any]=0.2    ,lowerCamelCase__   :	int=1    ,lowerCamelCase__   :	List[Any]=0    ,lowerCamelCase__   :	Optional[int]=2    ,lowerCamelCase__   :	Optional[Any]=False    ,**lowerCamelCase__   :	List[Any]    ,):
									UpperCAmelCase__             =							vocab_size
									UpperCAmelCase__             =							max_position_embeddings
									UpperCAmelCase__             =							d_model
									UpperCAmelCase__             =							encoder_ffn_dim
									UpperCAmelCase__             =							encoder_layers
									UpperCAmelCase__             =							encoder_attention_heads
									UpperCAmelCase__             =							decoder_ffn_dim
									UpperCAmelCase__             =							decoder_layers
									UpperCAmelCase__             =							decoder_attention_heads
									UpperCAmelCase__             =							dropout
									UpperCAmelCase__             =							attention_dropout
									UpperCAmelCase__             =							activation_dropout
									UpperCAmelCase__             =							activation_function
									UpperCAmelCase__             =							init_std
									UpperCAmelCase__             =							encoder_layerdrop
									UpperCAmelCase__             =							decoder_layerdrop
									UpperCAmelCase__             =							use_cache
									UpperCAmelCase__             =							encoder_layers
									UpperCAmelCase__             =							scale_embedding  # scale factor will be sqrt(d_model) if True
									UpperCAmelCase__             =							router_z_loss_coef
									UpperCAmelCase__             =							router_aux_loss_coef
									UpperCAmelCase__             =							decoder_sparse_step
									UpperCAmelCase__             =							encoder_sparse_step
									UpperCAmelCase__             =							num_experts
									UpperCAmelCase__             =							expert_capacity
									UpperCAmelCase__             =							router_bias
									if router_dtype not in ["float32", "float16", "bfloat16"]:
													raise ValueError(f'''`router_dtype` must be one of \'float32\', \'float16\' or \'bfloat16\', got {router_dtype}'''			)
									UpperCAmelCase__             =							router_dtype

									UpperCAmelCase__             =							router_ignore_padding_tokens
									UpperCAmelCase__             =							batch_prioritized_routing
									UpperCAmelCase__             =							second_expert_policy
									UpperCAmelCase__             =							normalize_router_prob_before_dropping
									UpperCAmelCase__             =							moe_eval_capacity_token_fraction
									UpperCAmelCase__             =							moe_token_dropout
									UpperCAmelCase__             =							output_router_logits
									super().__init__(
									    pad_token_id=lowerCamelCase__    ,bos_token_id=lowerCamelCase__    ,eos_token_id=lowerCamelCase__    ,is_encoder_decoder=lowerCamelCase__    ,decoder_start_token_id=lowerCamelCase__    ,**lowerCamelCase__    ,)







_A		       =						{0: [2, 3], 1: [0], 2: [1], 3: [4], 4: []}

_A		       =						{0: [1, 2, 3], 1: [2], 2: [0], 3: [4], 4: [5], 5: [3]}

def 						_UpperCAmelCase				(			SCREAMING_SNAKE_CASE__			:					dict[int, list[int]]			,     SCREAMING_SNAKE_CASE__			:					int			,     SCREAMING_SNAKE_CASE__			:					list[bool]				):
     __UpperCamelCase    							=True
     __UpperCamelCase    							=[]

     for neighbour in graph[vert]:
          if not visited[neighbour]:
               order += topology_sort(SCREAMING_SNAKE_CASE__			,     SCREAMING_SNAKE_CASE__			,     SCREAMING_SNAKE_CASE__				)

     order.append(SCREAMING_SNAKE_CASE__				)

     return order

def 						_UpperCAmelCase				(			SCREAMING_SNAKE_CASE__			:					dict[int, list[int]]			,     SCREAMING_SNAKE_CASE__			:					int			,     SCREAMING_SNAKE_CASE__			:					list[bool]				):
     __UpperCamelCase    							=True
     __UpperCamelCase    							=[vert]

     for neighbour in reversed_graph[vert]:
          if not visited[neighbour]:
               component += find_components(SCREAMING_SNAKE_CASE__			,     SCREAMING_SNAKE_CASE__			,     SCREAMING_SNAKE_CASE__				)

     return component





def 						_UpperCAmelCase				(			SCREAMING_SNAKE_CASE__			:					dict[int, list[int]]				):
     __UpperCamelCase    							=len(SCREAMING_SNAKE_CASE__				) * [False]
     __UpperCamelCase    							={vert: [] for vert in range(len(SCREAMING_SNAKE_CASE__				)				)}

     for vert, neighbours in graph.items():
          for neighbour in neighbours:
               reversed_graph[neighbour].append(SCREAMING_SNAKE_CASE__				)

     __UpperCamelCase    							=[]
     for i, was_visited in enumerate(SCREAMING_SNAKE_CASE__				):
          if not was_visited:
               order += topology_sort(SCREAMING_SNAKE_CASE__			,     SCREAMING_SNAKE_CASE__			,     SCREAMING_SNAKE_CASE__				)

     __UpperCamelCase    							=[]
     __UpperCamelCase    							=len(SCREAMING_SNAKE_CASE__				) * [False]

     for i in range(len(SCREAMING_SNAKE_CASE__				)				):
          __UpperCamelCase    							=order[len(SCREAMING_SNAKE_CASE__				) - i - 1]
          if not visited[vert]:
               __UpperCamelCase    							=find_components(SCREAMING_SNAKE_CASE__			,     SCREAMING_SNAKE_CASE__			,     SCREAMING_SNAKE_CASE__				)
               components_list.append(SCREAMING_SNAKE_CASE__				)

     return components_list





