interplane.Get Omega
Read in your language

MojoLlama

Archived Mojo/MAX quantizer and serving research repository (read-only history)

Brought by drakestapleton

branch main Branches Tags History

MojoLlama / BENCHMARK_ZIG_VS_C.md

25 lines · 1457 bytes Raw Blame History Source

MojoLlama Engine Benchmark — Zig vs C vs Python+C

MXFP4 Kernel Performance (GPT-OSS expert, 2880×2880)

Enginerows/svs C OMPNotes
C OMP batch2,425,8431.0x (baseline)moe_forward_omp with full parallel
Zig scalar341,2927.1x slowerPer-row via ctypes; faster than C per-row!
C per-row251,4269.6x slowerNo OMP, per-row dispatch

Finding: Zig scalar fallback beats C scalar per-row dispatch by 36%. This is because Zig compiles a tight scalar loop without the overhead of _mm256_* setup. With AVX2 intrinsics (same as C), Zig would match or beat C's OMP batch.

Full Engine Throughput (Python+C layer loop)

Modeltok/sMemoryArchitecture
GPT-OSS-20B23.611 GB24L MoE, MXFP4 experts
Qwen3.6-35B21.821 GB40L hybrid SSM+Attn
ZAYA-8B18.95 GB80L Python-only forward

Zig Verdict

Zig is viable as a C replacement for the MXFP4 kernel paths. The scalar fallback is already competitive with C's per-row dispatch. With AVX2 intrinsics and manual threading (or OMP interop via @cImport), Zig can match C's OMP batch performance.

Recommended integration: Phase 1 (Zig wraps C) is working now. Phase 2 (port MXFP4 row dot to Zig with AVX2) would restore performance while adding memory safety. Phase 3 (full engine) is blocked by the OpenMP gap.