Skip to content

🚨 Introduce a standalone MoE engine with independent placement and cache policies - #1334

Merged
0xShug0 merged 6 commits into
mainfrom
feature/moe-optimization-policies-attempt2
Nov 19, 2026
Merged

0xShug0 merged 6 commits into
mainfrom
feature/moe-optimization-policies-attempt2

Conversation

@0xShug0

@0xShug0 0xShug0 commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Replace duplicated expert storage and execution machinery with a standalone MoE engine, and migrate Drama3, Ming3 Audio, Nemotron Transcribe, Zonos2 and Zonos3. Model code retains routing mathematics, shared experts, residuals and generation; the engine owns expert resources, staging, placement and eviction.

  • Add MoE-specific prepared graph ownership, execution leases, bounded expert caches and explicit policy lifecycle contracts. Remove MoE state from generic execution/session components rather than extending their responsibilities.
  • Select placement and eviction independently through --moe-policy / session options, with scoped parameters. Include CPU-share, cost-aware placement and frequency-aware eviction; preserve legacy controls and model defaults.
  • Preserve native expert slot ordering, assignment-count ranking, per-program fractional carry, CPU-only staging and whole-layer CPU precedence.
  • Add independent mathematical, quantized execution, allocation-failure, callback, concurrency and lifecycle coverage. Document configuration and policy behavior.

Validation

Matched main-versus-branch CUDA A→B→B→A measurements, eight threads, unrelated warmup and repeated X→Y→X requests. RTF uses session wall time; VRAM is process peak.

Disk-expert staging with fractional CPU share omitted:

Model / task Main RTF Branch RTF Peak VRAM MiB, main → branch
Drama3 offline 1.39696 1.39432 8,194 → 8,196
Drama3 streaming 1.38987 1.38722 7,950 → 7,852
Ming3 ASR 0.03642 0.03615 4,146 → 4,146
Ming3 speech response 0.30826 0.31164 4,640 → 4,640
Nemotron Transcribe 0.26806 0.26498 6,432 → 6,432

Drama3 uses Q4_K_S experts, context 4096, five text chunks, 32 cache slots, one CPU expert layer and unpinned staging. Its streaming TTFA is 4,164 → 4,191 ms. Ming3 uses Q4_K, eight slots, zero CPU expert layers and pinned staging. Nemotron uses Q4_K_S experts, eight slots, one CPU expert layer and unpinned staging. ASR inputs are 80 seconds. These are matched staging profiles, not full-GPU performance figures.

All 100 corresponding request results match: audio PCM is byte-identical; ASR structured outputs, including Nemotron timestamps, speaker labels and confidence, match after excluding timing telemetry. Six additional staged Zonos2/3 cases also produce byte-identical PCM versus main.

CPU-share 0.5, eight cache slots, zero whole-layer CPU expert layers and unpinned staging:

Model / input Main RTF Branch RTF Peak VRAM MiB, main → branch
Ming3 ASR, English 0.05644 0.05270 4,152 → 4,152
Ming3 ASR, Mandarin 0.04390 0.04032 4,284 → 4,288
Zonos3, chunked passage 0.05025 0.04764 1,550 → 1,550
Zonos3, single long chunk 0.04433 0.04464 1,564 → 1,564

All 80 corresponding requests match main: Zonos3 PCM is byte-identical and Ming3 structured transcripts match. CPU assignment counts also match, including across request/shape reuse. An independently controlled skewed-routing case confirms the legacy 44 CPU assignments and 64-row bucket, rather than 124 assignments and a 128-row bucket.

The engine suite passes on CUDA and CPU with F32 and Q4_K fixtures; policy and Drama3 allocation/recovery fixtures pass. Explicit retirement/reprepare and failure recovery are covered by fixtures. The focused final staging/CPU-share measurements above are CUDA-only; they do not establish universal performance gains or benchmark the new cost-aware/frequency policies.

Move expert resources, prepared execution and independent placement/cache policies into a self-contained engine. Compose MoE graph scheduling and execution scopes through MoePreparedGraph, and migrate Drama3, Ming3 Audio, Nemotron Transcribe, Zonos2 and Zonos3.

Remove superseded MoE interfaces and generic context/session coupling. Reuse prepared graph plans, routing workspaces and native single-token expert graphs; retain existing model controls and add the moe-policy session shortcut.

Validation: Debug C++17 builds of CLI, server, C API and affected fixture binaries. No tests or inference executed.
Separate completed-work observations from phase timing and supply cache context and lifecycle notifications to eviction policies. Reject evaluation callbacks consistently for shared graph allocation.

Add graph ownership, overlap, concurrent-session, scheduler callback and failed-upload recovery assertions, including native Q4_K lifecycle cases.

Validation: Debug builds of CLI, server, C API and affected fixture binaries. Tests and inference were not run.
Determine placement applicability from each layer's backend. CPU-only and whole-layer CPU execution bypass fractional placement while retaining policy observations and the native top-k single-token path.

Add F32 and Q4_K regression assertions for cache misses with nonzero CPU share, executed row counts and independent expert outputs.

Validation: Debug builds passed. Tests and inference were not run.
Keep eligible staged single-token expert operations in the parent graph and map cache IDs through scheduler evaluation while preserving caller callbacks and execution leases. Retain explicit regions for shared graph allocation and preserve phased expert bucket layouts.

Align prepared slot-ID views to backend requirements, enable Drama3 shared-gate broadcasting, and migrate the Zonos2 parity caller to engine configuration.

Extend independent F32/Q4_K references, exact expert-row boundaries, eviction/reload, stale-handle, synchronization and lifecycle coverage without relaxing numerical tolerances.
@0xShug0 0xShug0 changed the title Introduce a standalone MoE engine with independent placement and cache policies 🚨 Introduce a standalone MoE engine with independent placement and cache policies Nov 19, 2026
@0xShug0
0xShug0 merged commit ced4b4b into main Nov 19, 2026
7 checks passed
@0xShug0
0xShug0 deleted the feature/moe-optimization-policies-attempt2 branch November 19, 2026 01:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant