Expand description
2026-09-25: Launchers for the device-side MoE expert LoRA folds:
moe_lora_grouped_down over the expert-sorted prefill rows and
moe_lora_gather_bgmv over the slot-major decode rows, plus the host packing
of their per-expert tables.
Both read the expert routing (expert_offsets or indices) on the device.
The host loop crate::lora::expert_apply::apply_expert_lora_sorted needs a
host copy of expert_offsets and one launch per adapted expert, which a CUDA
graph cannot capture.
Owner: model-layers ops. Invariants:
- An expert whose
a_tableorb_tablecell is0, or whose id is at or above the table length, folds nothing (moe_lora_grouped_down.cu,moe_lora_gather_bgmv.cu).
Structs§
- Expert
Tables - 2026-09-25: Host-side tables from
pack_expert_tables, before upload. - MoeExpert
Route - 2026-09-25: Device tables for one projection’s expert LoRA pairs, indexed by
expert id: the expert-keyed counterpart of the slot-keyed
super::lora_delta::LoraRoute.MoeLayer::build_expert_routebuilds one per projection (down, gate, up) at adapter install, and the router fold builds a one-entry route whose expert 0 is the router pair.
Constants§
- MLG_
M_ TILE - 2026-09-25: Rows per grouped-fold tile. It must equal the
MLG_M_TILE#defineinmoe_lora_grouped_down.cu, or the host grid and the kernel’s tiles cover different rows.
Functions§
- gather_
bgmv_ grids - 2026-09-25:
(shrink, expand)grids of the gather fold:[ceil(out/4), n_slots, 1], whereoutismax_rankfor the shrink andn_outfor the expand. Each 256-thread block computes 4 outputs, 64 threads per output (GBGMV_N_PER_BLOCKinmoe_lora_gather_bgmv.cu). - gather_
row_ token - 2026-09-25: The token that owns flat
(token, slot)rowrow: the gather kernels’row / top_k. - grouped_
down_ wc - 2026-09-25:
grid.yof both grouped-fold kernels for the window[row_offset, row_end):ceil((row_end - row_offset) / MLG_M_TILE), at least 1. It is the same expression as the launcher’swc, kept separate so tests can check the window math without a GPU. - grouped_
down_ windows - 2026-09-25: Contiguous
[start, end)windows of at mostcaprows covering0..total_rows. Panics whencapis 0. - moe_
lora_ gather_ bgmv - 2026-09-25: Fold
base_out[row] += scale_e * (x[x_row] @ A_e^T) @ B_e^Tfor every flat(token, slot)row in[0, n_slots), wheree = indices[row]. This is the unsorted counterpart ofmoe_lora_grouped_down: the expert comes fromindicesinstead of anexpert_offsetsspan. - moe_
lora_ grouped_ down - 2026-09-25: Fold
base_out[r] += scale_e * (x[row(r)] @ A_e^T) @ B_e^Tfor the sorted rowsrin the window[row_offset, row_end), whereeis the expert whoseexpert_offsetsspan holdsr. - pack_
expert_ tables - 2026-09-25: Pack
(expert_id, a_addr, b_addr, scale)entries into dense tables indexed by expert id, with0/0.0at every unadapted id andn_experts = max expert_id + 1. ReturnsNonewhenentriesis empty. A duplicate expert id keeps its last entry.