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 / ROADMAP.md

285 lines · 21121 bytes Raw Blame History Source

MojoLlama Roadmap

Vision: One-stop CPU-first LLM platform β€” quantize, train, evaluate, benchmark, and serve any model on HuggingFace. The Unsloth+LLaMA-Factory alternative built on Modular MAX, with a full Studio experience.

Current: v0.5.0 β€” CPU inference engine, 50+ arch detection, 2 custom forward passes, C batched engine, 14-panel Studio dashboard, Docker, 2.26Γ— vs llama.cpp (GPT-OSS).

Codebase: ~39K Python, ~12K C, ~5.6K HTML across 60+ Python files, 7 C kernels, 1 comprehensive web UI.


🎯 Strategic Pillars

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                       MojoLlama Platform                          β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  INFERENCE  β”‚   STUDIO     β”‚   ENGINE    β”‚   GPU         β”‚ DEPLOY β”‚
β”‚  Engine     β”‚   One-stop   β”‚   Full HF   β”‚   MAX +       β”‚ Docker β”‚
β”‚  + Serving  β”‚   ML App     β”‚   Coverage  β”‚   Tuning      β”‚ + App  β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ C engine    β”‚ Quantization β”‚ 60+ arch    β”‚ CUDA/ROCm    β”‚ pip    β”‚
β”‚ Batch inf   β”‚ Training     β”‚ forward     β”‚ Metal backend β”‚ Desktopβ”‚
β”‚ PagedAttn   β”‚ Dataset      β”‚ passes      β”‚ GPU tuning    β”‚ CLI    β”‚
β”‚ Concurrent  β”‚ Benchmark    β”‚ Auto-tune   β”‚ Multi-GPU     β”‚ CI/CD  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Phase 0: Foundation (current β€” shipped)

AreaWhat existsLines
C enginecengine_batch_instr.c β€” AVX2+OMP quant matmul, batch_forward, SSM decode, PagedAttention~1000
Python engineturbo_engine_v7_moe.py β€” zero-allocation MoE, C-accelerated quant matmul1177
Custom forward passesforward/gemma4.py (445), forward/zaya.py (187)632
Studio web UI14 panels: Chat, Train, Dataset, Export, Benchmark, Auto-Tune, Evaluate, Quantize, Merge, Checkpoints, Templates, HF Hub, Experiments, Model Cards4121
Studio CLIstudio.py β€” 25+ commands: train, export, merge, dataset, chat, serve, benchmark, evaluate, quantize, imatrix, dynamic_quant, hub, checkpoint1929
Trainingtrainer.py β€” 9 methods (LoRA, QLoRA, DoRA, GaLore, DPO, ORPO, KTO, SimPO, GRPO), all subprocess wrappers1505
Datasetdataset.py β€” 5 format readers, streaming, auto-labeling, splits, stats1221
Quantizerquantizer.py — 35 quant types, HF→GGUF converter, benchmark, validate1389
Serverserver.py β€” OpenAI-compatible, SSE streaming, tool calling, 12 API endpoints965
Auto-tuneautotune.py β€” 7-phase hardware sweep (threads, batch, flash attn, parallel, mlock, engine, concurrency)867
Backendsbackends.py β€” Auto-backend selector (llama.cpp > MAX(stub) > numpy)631
Arch detectionmodel/architectures.py β€” 60+ archs mapped to 9 forward types918
DockerDockerfile, docker-compose.yml (6 profiles), entrypoint with auto-tune + HF downloadβ€”
Web sitewww/ β€” index.html, studio.html, docs/, studio.html5624

Phase 1: Engine β€” Full HF Model Coverage (ongoing β€” 4 weeks)

The biggest gap: only 2 of 60+ detected architectures have custom forward passes. Everything else uses generic fallback paths that may produce incorrect output.

#TaskEst.Impact
1.1Profile generic fallback vs custom β€” measure correctness (perplexity diff) on 10 archs using generic path3dFoundation
1.2Falcon forward pass β€” parallel attention+FFN, fused QKV, inherent norm fusion4dUnlocks Falcon-7B/40B/180B
1.3Phi-3/4 forward pass β€” fused QKV, long RoPE (128K), dense MoE variants (Phi-3 MoE)4dUnlocks Phi-3/4 family
1.4DeepSeek V2/V3 forward pass β€” Multi-head Latent Attention, DeepSeekMoE, KV compression7dUnlocks DeepSeek family
1.5Qwen2-VL forward pass β€” vision encoder + language decoder interop5dUnlocks vision models
1.6Command-R / Cohere2 forward pass β€” Tanh-gated RoPE, logit softcapping3dUnlocks Cohere family
1.7BTLM / GLM forward pass β€” bidirectional + autoregressive hybrid4dUnlocks GLM family
1.8StableLM / OLMo forward pass β€” grouped-query attention variants, ALiBi3dUnlocks OLMo family
1.9Automated forward pass generator β€” template-based from GGUF metadata (infer n_head, n_kv_head, n_ff, act_fn, norm_type)5dRapid-fire remaining 40 archs
1.10Regression benchmark β€” compare output tokens vs llama.cpp reference per arch3dQuality gate

Success metric: All 60+ architectures produce correct output (perplexity within 1% of llama.cpp reference).


Phase 2: Studio β€” One-Stop ML App (4-8 weeks)

The Studio has 14 panels but many delegate to external tools. The vision: everything in one app, no external binaries required.

2A. Quantization Pipeline (2 weeks)

#TaskEst.Description
2A.1Pure-Python quantizer β€” full Q4_K, Q5_K, Q6_K, Q8_0 in Python (no llama.cpp binary)5dRemove external dependency
2A.2MXFP4 quantizer β€” fast C-based conversion from Q8_0 (replace 600s Python timeout)3dEnable MXFP4 without Python loop
2A.3Imatrix computation in Python β€” importance matrix from calibration data4dNo llama-imatrix binary needed
2A.4Dynamic 2-bit quantization — per-tensor quant assignment (Q6_K→Q2_K) guided by imatrix5dMax compression with min quality loss
2A.5NF4 quantizer β€” 4-bit NormalFloat for QLoRA training3dIn-house NF4, no external tool
2A.6Studio quant wizard β€” pick model β†’ pick quants β†’ pick calibration data β†’ preview size/speed β†’ run4d7.7 from previous roadmap

2B. Training Pipeline (4 weeks)

#TaskEst.Description
2B.1LoRA in Python β€” actual gradient computation in Python using MojoLlama engine (no subprocess)7dFirst in-house training
2B.2QLoRA in Python β€” NF4 base + LoRA adapters, fused forward/backward5dTrain 70B on consumer hardware
2B.3Training loop UI β€” live loss charts, step counter, ETA, learning rate schedule4dStudio panel enhancement
2B.4Dataset import from HF β€” load datasets from HuggingFace Hub directly3dNo local file needed
2B.5DPO/ORPO training β€” preference optimization with Python gradient5dAlignment training
2B.6Checkpoint management UI β€” save/load/resume, compare checkpoints, export LoRA3dStudio panel enhancement
2B.7Multi-LoRA serving β€” load multiple adapters, switch at runtime, merge on-the-fly4dProduction LoRA

2C. Benchmarking (2 weeks)

#TaskEst.Description
2C.1Capability benchmarks β€” MMLU, GSM8K, HumanEval, HellaSwag, ARC, BBH in-studio (no external server)5dMeasure quality, not just speed
2C.2Benchmark comparison view β€” side-by-side tok/s + accuracy across engines/quant3dStudio panel enhancement
2C.3Perplexity evaluation β€” cross-entropy loss on held-out text, compare to llama.cpp reference2dRegression detection
2C.4Benchmark history β€” track changes over time, plot regression charts2dTrack progress
2C.5Auto-generated benchmark report β€” export as HTML/Markdown for sharing2dShare results

2D. Dataset Management (1 week)

#TaskEst.Description
2D.1HF dataset integration β€” search, browse, download datasets from HuggingFace Hub3dNo local files
2D.2Dataset preview UI β€” view samples, filter, search within dataset3dStudio panel enhancement
2D.3Quality filters β€” perplexity-based filtering, near-dedup, length filters3dClean training data
2D.4Preference pair generator β€” create DPO/RLHF pairs from completions3dAlignment data

Phase 3: Inference Engine β€” Performance + GPU (4-8 weeks)

3A. CPU Engine Maturation (3 weeks)

#TaskEst.Description
3A.1Q8_0 input C quant β€” quantize activations to Q8_0 before matmul in C engine (2-4Γ— improvement)3dCritical bottleneck fix
3A.2MXFP4 C kernel β€” native C MXFP4 matmul (replace Python fallback, 10Γ— speedup expected)4dUnlocks Qwen3.6 C engine
3A.3Fused Q+K projection β€” single matmul for Q+K instead of 3 calls2d2-5% end-to-end
3A.4True continuous batching β€” merge multiple users' MoE routing into single batched matmuls5dLinear scaling with users
3A.5PagedAttention production β€” page table with KV block reclamation, defrag, swap4dLong-context serving
3A.6Fix Qwen3.6 MXFP4 cleanup crash β€” heap corruption on exit1dStability

3B. GPU via MAX β€” Full GPU Pipeline (6 weeks)

The MAX backend is currently a stub. This phase builds end-to-end GPU support: loading models, dispatching layers, tuning performance, and handling multi-GPU.

3B.1 GPU Integration (2 weeks)

#TaskEst.Description
3B.1.1MAX GGUF reader β€” load GGUF tensors into MAX-compatible buffers, map quantized types to MAX types5dFoundation for all GPU work
3B.1.2MAX CPU inference β€” run full LLM forward pass via MAX engine on CPU as baseline3dValidate MAX engine works
3B.1.3MAX GPU pipeline β€” model load β†’ transfer to GPU β†’ generate tokens β†’ return logits5dFirst GPU inference
3B.1.4Layer-by-layer GPU dispatch — per-layer offloading decision (attn→GPU, FFN→CPU, or all→GPU)4dHybrid inference control

3B.2 GPU Acceleration (2 weeks)

#TaskEst.Description
3B.2.1GPU attention β€” offload Q, K, V projections + softmax attention to GPU4dBiggest speedup per layer
3B.2.2GPU MoE dispatch β€” expert routing + top-k selection + expert matmuls on GPU5dMoE models on GPU
3B.2.3GPU KV cache β€” KV cache blocks on GPU memory, PagedAttention with GPU page table4dLong-context on GPU
3B.2.4CUDA graphs β€” capture repeated forward pass structure as CUDA graph for <10ΞΌs kernel launch3dMinimize GPU overhead
3B.2.5Flash Attention β€” use MAX's FlashAttention-2 integration for O(1) memory attention3d32K+ context on GPU

3B.3 Multi-GPU (2 weeks)

#TaskEst.Description
3B.3.1Tensor parallelism β€” split weight matrices across GPUs, all-reduce during forward5dModel sharding
3B.3.2Pipeline parallelism β€” assign layer groups to different GPUs4dDeeper models on multi-GPU
3B.3.3GPU memory management β€” dynamic offloading, swap KV cache between GPU↔CPU, memory budget tracking4dFit larger models
3B.3.4Multi-GPU benchmark suite β€” speedup curves (1/2/4/8 GPUs), memory scaling, batch scaling2dKnow your hardware

3B.4 GPU Formats & Quantization (2 weeks)

#TaskEst.Description
3B.4.1GPU-native quant types β€” FP16, FP8 (E4M3/E5M2), INT8, INT4 on GPU natively (no dequant)5dGPU memory efficiency
3B.4.2On-the-fly quant conversion β€” convert GGUF Q4_K/Q8_0 to GPU-native FP8/INT8 at load time3dNo re-quantizing needed
3B.4.3GPU imatrix β€” importance matrix computed via GPU (10Γ— faster than CPU)3dFast calibration
3B.4.4Mixed-precision GPU inference β€” FP16 attn + INT8 FFN + FP32 embeddings automatically3dMax throughput per layer type

3B.5 GPU Auto-Tune (2 weeks)

#TaskEst.Description
3B.5.1GPU layer sweep β€” sweep n_gpu_layers 0β†’all, measure tok/s, find knee3dOptimal GPU/CPU split
3B.5.2GPU batch size sweep β€” test batch sizes 1β†’64 with GPU, find throughput plateau2dMax concurrency
3B.5.3GPU memory tuning β€” measure peak memory per model/size/quant, auto-pick batch to fit3dNo OOM crashes
3B.5.4GPU concurrent tuning β€” sweep concurrent users 1β†’N, find latency knee (p50/p95/p99)3dProduction config
3B.5.5Multi-GPU tuning β€” sweep GPU count (1/2/4/8), parallelism strategy, interconnect type4dMulti-GPU optimization
3B.5.6Metal/ROCm tuning β€” Apple Silicon GPU and AMD GPU specific parameter sweeps3dCross-platform GPU

3B.6 GPU Support Matrix

BackendHardwareStatusTarget tok/s (7B Q4_K_M)
MAX CUDANVIDIA Tesla/RTX/A100/H100/B300⬜ Not started100+ (A100)
MAX ROCmAMD MI250/MI300X/RX 7000⬜ Not started80+ (MI250)
MAX MetalApple M1/M2/M3/M4 (Pro/Max/Ultra)⬜ Not started40+ (M2 Ultra)
MAX CPUAny x86_64/ARM with AVX2/SVE⬜ Not started20+ (Threadripper)
MojoLlama CPUx86_64 AVX2+OMPβœ… Working13-63 (Threadripper)

3B.7 GPU Production (1 week)

#TaskEst.Description
3B.7.1GPU server β€” serve models from GPU via /v1/chat/completions, SSE streaming3dProduction GPU serving
3B.7.2GPU health monitoring β€” GPU utilization, memory, temperature, power in Studio metrics2dOps visibility
3B.7.3Automatic fallback β€” GPU OOM β†’ auto-offload to CPU β†’ continue with degraded throughput2dReliability
3B.7.4GPU model hot-swap β€” unload model from GPU, load new model, without restart2dMulti-model serving

3C. Auto-Tune Improvement (2 weeks)

#TaskEst.Description
3C.1Self-contained auto-tune β€” no external llama-bench binary required4dPure MojoLlama sweeps
3C.2Per-model auto-tune cache β€” store per-model-hash configs, share with community2dInstant optimal config
3C.3GPU auto-tune β€” sweep GPU layers, batch size, concurrency with MAX backend3dGPU optimization
3C.4Auto-tune recommendation engine β€” suggest optimal config from hardware fingerprint3dZero-click tuning
3C.5Auto-tune Studio UI β€” guided wizard with progress, charts, one-click apply3dStudio panel

Phase 4: Platform β€” Ship It (4-6 weeks)

#TaskEst.Description
4.1pip package β€” pip install mojollama with pre-built wheels (manylinux x86_64, aarch64)5dZero-install
4.2Desktop app β€” Tauri/Electron wrapper for Studio, bundled Python runtime + model downloader7dDesktop experience
4.3CI/CD pipeline β€” GitHub Actions: test every PR, benchmark regression checks, build wheels3dQuality gates
4.4Comprehensive test suite β€” unit tests for each module, integration tests for forward passes5dRegression prevention
4.5API hardening β€” API keys, rate limiting, model hot-swap, token usage tracking4dProduction-ready server
4.6Model registry β€” local + HF Hub model browser, one-click download, version management4dModel management
4.7Release automation β€” semantic versioning, changelog, automated release notes2dClean releases

Timeline

Month 1                Month 2                Month 3                Month 4                Month 5+        
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Ί
β”‚ Phase 1: HF Coverage                       β”‚ Phase 2: Studio Pipeline                    β”‚ Phase 4
β”‚ 1.1-1.5 Custom forward passes              β”‚ 2A. Quant Pipeline                          β”‚ Ship
β”‚ 1.6-1.10 Broader arch + auto-gen           β”‚ 2B. Training                                β”‚ pip
β”‚                                             β”‚ 2C. Benchmarking                            β”‚ Desktop
β”‚ Phase 3A: CPU Engine                       β”‚ 2D. Dataset                                 β”‚ CI/CD
β”‚ 3A.1-3.3 C kernel improvements             β”‚                                             β”‚
β”‚ 3A.4-3.6 Batching + stability              β”‚ Phase 3B: GPU via MAX (Full Pipeline)       β”‚
β”‚                                             β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Phase 3C: Auto-Tune (CPU)                  β”‚ 3B.1 GPU Integration                         β”‚
β”‚ 3C.1-3.3 Self-contained                    β”‚ 3B.2 GPU Acceleration                        β”‚
β”‚ 3C.4-3.5 Studio wizard                     β”‚ 3B.3 Multi-GPU                               β”‚
β”‚                                             β”‚ 3B.4 GPU Formats & Quant                    β”‚
β”‚                                             β”‚ 3B.5 GPU Auto-Tune                          β”‚
β”‚                                             β”‚ 3B.6 Support Matrix                         β”‚
β”‚                                             β”‚ 3B.7 GPU Production                         β”‚
└──────────────────────┴──────────────────────┴──────────────────────┴──────────────────────┴──────────────►

Architecture Coverage Roadmap

Current (2 custom passes):      Target (60+ passes):
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ βœ… Gemma 4         β”‚         β”‚ βœ… Llama 2/3/4           β”‚
β”‚ βœ… ZAYA1           β”‚         β”‚ βœ… Mistral               β”‚
β”‚ ⬜ Falcon          β”‚         β”‚ βœ… Qwen2/3               β”‚
β”‚ ⬜ Phi-3/4         β”‚         β”‚ βœ… Gemma 2/3/4           β”‚
β”‚ ⬜ DeepSeek V2/V3  β”‚         β”‚ βœ… GPT-OSS               β”‚
β”‚ ⬜ 50+ more...     β”‚         β”‚ βœ… ZAYA1                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β”‚ βœ… Falcon                β”‚
                               β”‚ βœ… Phi-3/4               β”‚
Auto-generated template        β”‚ βœ… DeepSeek V2/V3        β”‚
for remaining archs:           β”‚ βœ… Command-R / Cohere    β”‚
  GGUF metadata β†’ forward      β”‚ βœ… DBRX / Mixtral        β”‚
  pass skeleton β†’ manual        β”‚ βœ… 50+ more (generated)  β”‚
  tuning                       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Risk Factors

RiskImpactMitigation
MAX engine GGUF compatibility gapsPhase 3B.1 blockedMaintain llama.cpp fallback; upstream patches to MAX
GPU memory insufficient for model sizePhase 3B.4/3B.7 failsLayer-by-layer CPU offload; quantize to FP8/INT4 for GPU
Custom forward passes diverge from upstreamPerplexity regressionsAutomated perplexity CI per arch
Training on CPU is slowPhase 2B perceived as uselessFocus on QLoRA (small adapters); leverage MAX GPU
Multi-GPU scaling sublinear (<1.5Γ— per GPU)Phase 3B.3 underwhelmingOptimize all-reduce; use tensor parallelism with async comms
CUDA graphs fragile to model changesPhase 3B.2.4 breaksRegenerate graphs on model load; fallback to eager mode
Apple Metal GPU limited memory (unified)Phase 3B.6 Apple perf lowOptimize for unified memory; use small models (7B max)
Dataset format fragmentationPhase 2D scope creepSupport top 5 HF formats only
MXFP4 in C engine complexPhase 3A.2 delayedShip Q8_0 input quant first (biggest win)