For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /max/get-started.md).
Mojo function
eplb_remap_kernel
def eplb_remap_kernel[PhyIdxLayoutType: TensorLayout, RouterIdxLayoutType: TensorLayout, LogcntLayoutType: TensorLayout, Log2phyLayoutType: TensorLayout, LayerIdxLayoutType: TensorLayout, num_log: Int, max_replicas: Int, K: Int, tile_tokens: Int, hash_decorrelate: Bool](phy_idx: TileTensor[DType.int32, PhyIdxLayoutType, MutAnyOrigin], router_idx: TileTensor[DType.int32, RouterIdxLayoutType, ImmutAnyOrigin], logcnt: TileTensor[DType.int32, LogcntLayoutType, ImmutAnyOrigin], log2phy: TileTensor[DType.int32, Log2phyLayoutType, ImmutAnyOrigin], layer_idx: TileTensor[DType.int32, LayerIdxLayoutType, ImmutAnyOrigin])
Fused EPLB per tile_token rows of router idx; one thread per (n,k) element. Each block cooperatively caces the current layer's logcnt and log2phy slices in SMEM, then every thread does: HBM-load logical id -> SMEM-looup cnt -> int mod -> SMEM-Lookup phy id -> HBM-store.
Portable across all hardwares.
Optimality of choosing : hash_decorrelate=True xor-hashes the flat position with a Knuth multiplicative hash of the logical id before the modulo, breaking structured position-vs-cnt alignment without warp ops.
Parameters:
- βPhyIdxLayoutType (
TensorLayout):TensorLayoutof thephy_idxoutput tensor. - βRouterIdxLayoutType (
TensorLayout):TensorLayoutof therouter_idxinput tensor. - βLogcntLayoutType (
TensorLayout):TensorLayoutof thelogcntinput tensor. - βLog2phyLayoutType (
TensorLayout):TensorLayoutof thelog2phyinput tensor. - βLayerIdxLayoutType (
TensorLayout):TensorLayoutof thelayer_idxinput tensor. - βnum_log (
Int): Number of logical experts per MoE layer. - βmax_replicas (
Int): Maximum number of physical replicas per logical expert. - βK (
Int): Number of top-K experts selected per token. Must be a power of two sotid % Kis a bitmask. - βtile_tokens (
Int): Number ofrouter_idxrows processed per block. Block size istile_tokens * Kthreads. - βhash_decorrelate (
Bool): IfTrue, xor-hash the flat position with a Knuth multiplicative hash of the logical id before the modulo to break structured-position bias. IfFalse, use plainpos % cnt.
Args:
- βphy_idx (
TileTensor[DType.int32, PhyIdxLayoutType, MutAnyOrigin]): Output[num_tokens, K]tensor of physical expert IDs after EPLB remap. - βrouter_idx (
TileTensor[DType.int32, RouterIdxLayoutType, ImmutAnyOrigin]): Input[num_tokens, K]tensor of logical expert IDs from the gate. - βlogcnt (
TileTensor[DType.int32, LogcntLayoutType, ImmutAnyOrigin]): Input[num_moe_layers, num_log]tensor of replica counts per (layer, logical expert). - βlog2phy (
TileTensor[DType.int32, Log2phyLayoutType, ImmutAnyOrigin]): Input[num_moe_layers, num_log, max_replicas]tensor of physical-id lookup table entries. - βlayer_idx (
TileTensor[DType.int32, LayerIdxLayoutType, ImmutAnyOrigin]): Input rank-1[1]scalar tensor carrying the current MoE layer index.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!