Skip to content

MoE Extraction

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

MoE Extraction

src/moe/{mod,expert,extract}.rs

Conventions

Stacked

blk.{B}.ffn_gate_exps.weight
blk.{B}.ffn_up_exps.weight
blk.{B}.ffn_down_exps.weight

Shape: expert axis is the last dim (GGML innermost-first). Per-expert chunk is a contiguous byte stride: byte_len / n_experts.

Per-expert

blk.{B}.ffn_gate.{E}.weight   (or ffn_gate_{E}.weight)
blk.{B}.ffn_up.{E}.weight
blk.{B}.ffn_down.{E}.weight

Whole tensor payload cloned; stacked_slice = false.

API

list_experts(layout) -> Vec<(block, expert)>

Reports a pair if any of gate/up/down is discoverable under either naming scheme. Sorted via BTreeSet.

extract_expert(layout, block, expert) -> MoeExpertWeights

Field Type
block, expert indices
gate / up / down Option<RawTensor>
is_complete() all three present

Prefers stacked names first, then per-expert candidates. If none found → MissingTensor. Expert ≥ available → ExpertOutOfRange.

RawTensor

Self-owning: source_name, dims (expert dim stripped for stacked), dtype, ggml_type, bytes, stacked_slice.

Related


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

Clone this wiki locally