Skip to content

MoE Router

Raul Montoya Cardenas edited this page Jul 29, 2026 · 2 revisions

MoE Router (OlmoeRouter)

Public API in src/moe/mod.rs. Family-aware GGUF-backed router for top-k expert selection.

Types

RoutingMode

Mode Behavior
StubUniform Uniform expert weights; no checkpoint needed
DenseSim Gate scores → softmax → top-k (dense simulation)
SpikingSim Membrane-style expert/hidden dynamics (CPU sim only; not GPU SNN dispatch)

Default in types.rs is SpikingSim; empty-path load historically defaults to StubUniform via load_with_family_and_mode.

OlmoeOutput

pub struct OlmoeOutput {
    pub expert_weights: Vec<f32>,
    pub selected_experts: Vec<usize>,
    pub hidden: Vec<f32>,
}

RouterMetadata

Family, architecture, sizes, quantization, routing tensor name, preferred GPU synapse tensor name, synapse_source label.

Load constructors

Method Notes
load(path, num_experts, top_k) Mode = StubUniform path
load_with_mode(path, n, k, mode) Common entry
load_with_family_and_mode(..., family_override, mode) Full control
Empty path Builds stub router (loaded=false, quant "stub")
num_experts == 0 Use checkpoint expert count
top_k == 0 Use expert_used_count clamped

Forward path

embedding [EMBEDDING_DIM=2048]
    │
    ├─ StubUniform → equal weights
    ├─ DenseSim    → gate scores → softmax → top-k → hidden = emb * selected_mass
    └─ SpikingSim  → membrane update + spikes → softmax → hidden spikes

Gate scores: if checkpoint+adapter present → checkpoint_gate_scores on F32 routing tensor (after resample to hidden_size + L2); else synthetic chunk sums.

Other API

Method Role
probe_model(path, family?) Metadata without keeping full runtime state long-term
extract_token_embedding(token_id) Dequant row → normalize to 2048
reset_state Clear membranes (SpikingSim)
Accessors is_loaded, family, routing_tensor_name, synapse_source, preferred_gpu_synapse_tensor_name, real_gpu_synapse_tensor_name, …

Related


Last updated: July 29, 2026 Updated by: Grok Build: Grok 4.5 Package tip reference: 37c5a21 (main)

Clone this wiki locally