interplane.Get Omega
Read in your language

aien-sovereign-core-mv

AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.

Brought by drakestapleton

branch main Branches Tags History

aien-sovereign-core-mv / docs / inference / evidence / mojo-kernels-20260923 / qwen3_moe

e10a8b5 fix: review items for the Modular removal aien committed 2026-10-15
..
README.md6104
gb10_qwen3_a3b_layer0_fp8_curve_2026-09-23.json7582
gb10_qwen3_a3b_layer0_mojo_fp8_curve_2026-09-23.json7130

README.md

Record only. Moved here on 2026-10-15 from crates/aien-inference-abi/mojo/qwen3_moe/ when Modular MAX and Mojo were removed from the project. The Mojo sources, build scripts and tests it describes no longer exist in this tree; the receipts beside it are the 2026-09-23 runs.

Qwen3-Coder-30B-A3B routed expert layer on GB10

One routed MoE layer of Qwen/Qwen3-Coder-30B-A3B-Instruct-FP8, executed entirely in Mojo on the GB10 with packed FP8 expert weights. Rust loads the checkpoint, owns the tensor contract, and calls the layer through a C ABI. There is no Python and no MAX graph API anywhere in the path.

official sharded safetensors
      -> load_qwen3_fp8_moe_layer (Rust): index + header + byte-range validation
      -> ModelCapsule: typed FP8/BF16 tensor views, capsule digest
      -> libaien_qwen3_moe.so (Mojo), per call:
           router logits (FP32 accumulate)
           top-8 routing, non-finite logits fail closed
           stable counting sort by expert (MoeBatchPlan contract)
           gather, FP8 E4M3 activation quantization (per row, 128 channels)
           grouped FP8 gate/up GEMM (mma.sync m16n8k32 e4m3)
           SwiGLU, FP8 quantization, grouped FP8 down GEMM
           weighted inverse reduction to token order, BF16 output

Build and test

crates/aien-inference-abi/mojo/qwen3_moe/build.sh

# Kernel, routing, fail-closed and synthetic-layer parity (seconds).
AIEN_REQUIRE_GPU_TESTS=1 cargo test -p aien-inference-abi --test qwen3_moe_gpu

# Official checkpoint parity; needs the index plus the shards holding the layers.
AIEN_REQUIRE_GPU_TESTS=1 AIEN_QWEN3_FP8_CHECKPOINT=/path/to/Qwen3-Coder-30B-A3B-Instruct-FP8 \
  AIEN_QWEN3_LAYERS=0,1,23,24,47 AIEN_QWEN3_SEEDS=1,2,3 \
  cargo test -p aien-inference-abi --test qwen3_moe_gpu official -- --nocapture

# Batch-size curve with a reproducible receipt.
cargo run --release -p aien-inference-abi --example qwen3_moe_bench -- \
  /path/to/Qwen3-Coder-30B-A3B-Instruct-FP8 --layer 0 --out receipt.json

Without the built library the GPU tests skip with a message. AIEN_REQUIRE_GPU_TESTS=1 turns a missing library into a failure.

What the tests prove

TestClaim
grouped_fp8_gemm_matches_block_scaled_referenceMMA fragment mapping, ragged groups, expert remapping and both scale axes against an exact reference.
grouped_fp8_gemm_rejects_out_of_range_groupsOut-of-range expert IDs and bad offsets are refused before launch.
device_routing_matches_moe_batch_plan_exactlyRust router == Mojo router == device permutation == inverse map, over 1024 tokens including full ties and ties across the 64-expert mask split.
device_router_fails_closed_on_non_finite_logitsNaN and +/-Inf logits return status 2; no output is produced.
layer_rejects_non_finite_input_without_outputThe same through the full layer.
synthetic_layer_with_distinct_experts_matches_fp32_oracleDistinct random experts and router, 1/37/130 tokens: device matches an oracle that quantizes activations the same way.
official_checkpoint_layers_match_fp32_oracleOfficial layers against both oracles, tolerances below.

Two oracles are used. OracleActivations::Fp8Block128 quantizes activations exactly as the device does, so only accumulation order separates it from the device: any indexing, scaling or routing defect shows up there. Fp32 keeps activations in FP32 and measures the real cost of FP8 activation quantization. Both oracles route with the device's own logits, because FP32 summation order can reorder experts separated by a few ULPs; the logits themselves are checked against the CPU separately (observed error under 3e-6).

Official checkpoint tolerances

Frozen from layers 0, 1, 23, 24 and 47, seeds 1 to 3, 16 tokens each, with limits at about 1.5x to 2x the worst observed error:

OracleMetricWorst observedLimit
FP8-emulatedcosine0.999998430.99999
FP8-emulatedmax abs / max|expected|0.33%1%
FP32cosine0.99910 (layer 23)0.9985
FP32p95 relative error1.73% (layer 47)2.5%
FP32max abs / max|expected|3.2% (layer 24)5%
bothnon-finite outputs00
bothdevice top-8 vs MoeBatchPlan on device logitsidenticalidentical

The FP32 gap is the cost of FP8 E4M3 activations in 128-channel blocks, the W8A8 block scheme this checkpoint is published for. It is larger on middle layers (cosine about 0.9991) than on layer 0 (about 0.9998).

Performance

Official layer 0, seed 42, two warmups and five timed runs per point, median milliseconds for the whole routed layer (routing, grouping, both FP8 GEMMs, SwiGLU, quantization and reduction). Receipt: gb10_qwen3_a3b_layer0_mojo_fp8_curve_2026-09-23.json.

TokensThis libraryEarlier MAX graph, FP8Earlier MAX graph, BF16
10.5651.0861.131
82.5065.4514.626
163.8168.6827.986
325.52311.58112.011
647.77413.32822.336
12810.78015.96943.875
25618.19324.99286.080
50032.17043.529165.718
102462.91677.416338.866

The timing methods are close but not identical: this library times enqueue to device synchronize with input resident; the earlier driver also copied the BF16 output back to the host. Read the comparison as indicative. Tokens per second here is one layer only; the model has 48 plus attention.

The receipt in gb10_qwen3_a3b_layer0_fp8_curve_2026-09-23.json is the earlier MAX-graph measurement, kept for its BF16 grouped-GEMM baseline. That baseline depended on the Python MAX graph API and is no longer built.

Boundaries

This is one MoE layer. Attention, norms, embeddings, sampling, scheduler wiring and full-model residency are not implemented here. Each call creates its device context and uploads weights; a resident-weight handle is the next step before scheduler integration. Test inputs are seeded random hidden states, not hidden states from real prompts.