vllm.models.beam.nvidia.moe_finalize
¶
Finalize live MegaMoE tokens with Beam's post normalization.
Functions:
-
beam_moe_finalize–Reduce only output rows, preserving BF16 casts before scale and RMSNorm.
-
beam_moe_finalize_gather_norm_residual_norm–Finalize MegaMoE output and restore the replicated token boundary.
-
beam_moe_finalize_norm_residual_norm–Finalize local MegaMoE tokens through the next normalization boundary.
beam_moe_finalize(expert_outputs, expert_weights, output, routed_scale=1.0, post_weight=None, post_eps=None)
¶
Reduce only output rows, preserving BF16 casts before scale and RMSNorm.
Parameters:
-
(expert_outputs¶Tensor) –Contiguous BF16 expert results [capacity, top_k, hidden].
-
(expert_weights¶Tensor) –Contiguous FP32 routing weights [capacity, top_k].
-
(output¶Tensor) –Contiguous BF16 destination [live_tokens, hidden].
-
(routed_scale¶float, default:1.0) –Multiplier applied after rounding the expert reduction.
-
(post_weight¶Tensor | None, default:None) –Optional BF16 RMSNorm affine weight [hidden].
-
(post_eps¶float | None, default:None) –RMSNorm epsilon, or None to omit normalization.
Source code in vllm/models/beam/nvidia/moe_finalize.py
beam_moe_finalize_gather_norm_residual_norm(x, residual, post_weight, post_eps, next_weight, next_eps, scales, workspace, routed_scale=1.0, *, strategy=None)
¶
Finalize MegaMoE output and restore the replicated token boundary.
FlashInfer's forward_unfinalized guarantees token-major expert rows and
an identity route map, so a view recovers its [tokens, top_k, hidden] layout.
This consumer requires that producer contract.
Each rank owns ceil(global_tokens / TP) consecutive tokens. Capacity rows
and the final rank's token padding do not contribute to the returned tensors.
strategy overrides the token-count heuristic for validation and benchmarking.
Source code in vllm/models/beam/nvidia/moe_finalize.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | |
beam_moe_finalize_norm_residual_norm(x, residual, post_weight, post_eps, next_weight, next_eps, scales, routed_scale=1.0, *, strategy=None)
¶
Finalize local MegaMoE tokens through the next normalization boundary.
Requires FlashInfer's token-major expert rows and identity route map.
Only the live rows in residual are read from the workspace capacity.
strategy can force the unfused reference for validation and benchmarking.