bridge.models.ernie.ernie_router#
ERNIE 4.5 MoE router: softmax gate with an expert-bias selection correction.
Module Contents#
Classes#
Router that reproduces ERNIE 4.5 softmax routing with |
|
ERNIE softmax gating with Megatron-Core’s optimized inference router. |
Functions#
Convert router logits to the log-odds of their softmax probabilities. |
|
Replace the MCore router while retaining its inference or training path. |
|
Build a GPT block spec that honors |
Data#
API#
- bridge.models.ernie.ernie_router._MAX_PROB#
None
- bridge.models.ernie.ernie_router._ernie45_log_odds(logits: torch.Tensor) torch.Tensor#
Convert router logits to the log-odds of their softmax probabilities.
- class bridge.models.ernie.ernie_router.Ernie45TopKRouter#
Bases:
megatron.core.transformer.moe.router.TopKRouterRouter that reproduces ERNIE 4.5 softmax routing with
e_score_correction_bias.ERNIE 4.5 (Hugging Face
Ernie4_5_MoeTopKRouter, Paddlemoe_gate_act="softmax") computesp = softmax(logits), selects experts bytopk(p + e_score_correction_bias), and weights them byprenormalized over the selected experts. Megatron Core appliesexpert_biasonly on its sigmoid score path, sogatingreturns the log-odds ofp:sigmoid(log p - log(1 - p)) == p. Withmoe_router_score_function="sigmoid"the existing biased top-k and renormalization then match ERNIE exactly. Auxiliary losses see the softmax probabilities, as in ERNIE; a router z-loss would act on the log-odds, but ERNIE does not use one.- gating(input: torch.Tensor) torch.Tensor#
Return the log-odds of the softmax gate probabilities.
- class bridge.models.ernie.ernie_router.Ernie45InferenceTopKRouter#
Bases:
megatron.core.transformer.moe.router.InferenceTopKRouterERNIE softmax gating with Megatron-Core’s optimized inference router.
- gating(input: torch.Tensor) torch.Tensor#
Return the log-odds of the softmax gate probabilities.
- bridge.models.ernie.ernie_router._ernie45_moe_submodules(
- submodules: megatron.core.transformer.moe.moe_layer.MoESubmodules,
Replace the MCore router while retaining its inference or training path.
- bridge.models.ernie.ernie_router.ernie45_decoder_block_spec(
- config: megatron.core.transformer.transformer_config.TransformerConfig | megatron.training.models.gpt.GPTModelConfig,
- use_transformer_engine: bool | None = None,
- normalization: str | None = None,
- qk_l2_norm: bool | None = False,
- vp_stage: int | None = None,
- pp_rank: int | None = None,
- **kwargs: object,
Build a GPT block spec that honors
moe_layer_freqand uses the ERNIE router.A builder passes its model config; the spec is then built from the nested transformer config.