epic: OpenXLA backend architecture-coverage parity with the MLX engine #493
Description
Problem / Background
The MLX engine supports roughly 90 model_type values (see src/models/detection.rs). The OpenXLA/IREE backend (#449 M3 Stage 2d) currently serves only three text, dense architectures: Llama, Qwen2, and Gemma2, on both the single-sequence CLI path (MLXCEL_BACKEND=xla) and the continuous-batching serve path (mlxcel-server).
The gap is no longer infrastructure. The shared, architecture-agnostic base is already done and must not be re-created:
- Weight loading: single-file and sharded (
index.json), bf16/f16/f32 widening, MLX 4bit/8bit affine dequant. - IREE runtime, KV cache, and compile pipeline.
- Continuous-batching engine:
XlaBatchEngineplus the ragged scheduler. - Host-side sampling: temperature, top-k, top-p, min-p, seed.
- History penalties: repetition, frequency, presence, DRY.
- Streaming-safe stop strings.
- Server seam:
BatchEnginetrait,XlaServeWorker,/v1/completions,/metrics.
Goal
Bring the OpenXLA backend toward MLX-engine architecture coverage, planned in release windows. Because the common base is fixed, adding a new family needs only four per-family pieces:
Config::from_jsonarch detection and fields (emitter/config.rs).weight_namesper-layer order (iree.rs).- The emitter forward (
emitter/model.rs). - Token-exact (or reference-exact) validation against an HF oracle on a real checkpoint.
The only exceptions are families that need a new shared graph primitive (MoE FFN, SSM/recurrent mixing); those are scoped as their own foundation issues so the per-family work stays cheap.
Validation pattern
The established gate for every architecture:
- Dequant a 4bit/8bit checkpoint offline to f32 (or use a bf16 checkpoint directly).
- Run HF fp32 as the oracle.
- Run XLA on the quantized/bf16 model.
- Compare: single-sequence path token-exact vs the HF fp32 oracle; serve path reference-exact via
xla_batch_bench.
tanh-based architectures (soft-capping, GeGLU) may differ only at sub-0.01 logit near-ties; that is acceptable.
Sub-issues
Phase 1: Window A (Foundation)
- refactor: share the full per-layer attention core across all emitter graph kinds #494
- feat: implement Gemma2 sliding-window attention (local/global alternation) #495
- test: add a reusable per-architecture token-exact validation harness #496
Phase 2: Window B (Dense decoder-only families)
- feat: dense arch pack for qk-norm and Gemma family (Qwen3, Gemma1, Gemma3, SmolLM3, OLMo2/OLMo3) #497 (depends on refactor: share the full per-layer attention core across all emitter graph kinds #494)
- feat: dense arch pack for parallel-block and norm-variant families (Cohere/Cohere2, Phi3, StableLM, StarCoder2, Granite, MiniCPM/MiniCPM3) #498 (depends on refactor: share the full per-layer attention core across all emitter graph kinds #494)
- feat: dense arch pack for remaining Llama-family architectures (Mistral/Ministral, ExaOne, InternLM, Baichuan, GLM4, and more) #499 (depends on refactor: share the full per-layer attention core across all emitter graph kinds #494)
Phase 3: Window C (Mixture-of-Experts)
- feat: add the MoE FFN graph primitive (router + top-k expert dispatch) #500 (depends on refactor: share the full per-layer attention core across all emitter graph kinds #494)
- feat: MoE family coverage on the shared FFN primitive (Mixtral, Qwen2/Qwen3-MoE, OLMoE, DeepSeek-V2/V3, gpt-oss, and more) #501 (depends on feat: add the MoE FFN graph primitive (router + top-k expert dispatch) #500)
Phase 4: Window D (SSM / hybrid / recurrent)
Phase 5: Window E (Multimodal / VLM)
Acceptance Criteria
- All sub-issues completed and merged.
- Each new family loads and generates via the CLI
MLXCEL_BACKEND=xlapath and serves viamlxcel-server. - Each new family passes the validation gate: token-exact single-seq vs HF fp32 oracle, reference-exact serve via
xla_batch_bench. - Windows D and E either land a first reference architecture or record an explicit deferral into a dedicated follow-up epic.
Technical Considerations
- Parent milestone: feat: OpenXLA reference backend - export-route spike through 4-bit quantized decode #449 (OpenXLA reference backend, M3 Stage 2d).
- The shared attention-core refactor (refactor: share the full per-layer attention core across all emitter graph kinds #494, Window A) and the MoE FFN primitive (feat: add the MoE FFN graph primitive (router + top-k expert dispatch) #500, Window C) are prerequisites that unblock the cheap per-family work; explicit dependency edges are recorded in the sub-issue list above.
- Windows D (SSM/hybrid/recurrent) and E (multimodal/VLM) are separate tracks that introduce non-attention graph primitives or vision/audio encoders; each is expected to spin out into its own follow-up epic after its design issue lands.
Activity
feat: dense arch pack for qk-norm and Gemma family in mlxcel-xla (#558)
feat: dense arch pack (Seed-OSS, MiMo, InternLM3, ExaOne) in mlxcel-x…
feat: dense arch pack for parallel-block and norm-variant families (#561
docs: scope the OpenXLA SSM / hybrid / recurrent track (#502) (#565)
docs: scope the OpenXLA multimodal / VLM track (#503) (#567)
inureyes commentedon Jul 1, 2026
Epic implementation complete
All 10 sub-issues are implemented, merged, and closed with
status:done, across 4 execution waves.mainis at the merged head and the mlxcel-xla arch-coverage suite is green (111 passed, 0 failed).Sub-issues (issue -> PR)
Wave 0, foundation:
Wave 1, dense packs + MoE primitive:
Wave 2, MoE families:
Wave 3, design/scoping (serial chain):
Execution
emit_attentionreturns(hn, attn_out)with residual owned byemit_transformer_layer(sequential vs parallel blocks), anemit_ffn_bodythat dispatches dense (emit_mlp_body) vs MoE (moe.rs), and a single weight-ordering authority (weights::weight_specssourcing names fromweight_names). Llama/Qwen2/Gemma2 stayed byte-identical throughout.Validation
MLXCEL_BACKEND=xlaplusmlxcel-serverserve, token-exact plusxla_batch_benchreference-exact). The rust xla-iree feature was intentionally not built inside the sub-agents to respect the build watchdog; the shared GPU runtime path is unchanged from the already-proven Llama/Qwen2/Gemma2 baseline.Follow-up epics
fix(xla): load bf16 affine quant scales in the OpenXLA weight loader (#…
inureyes commentedon Jul 1, 2026
GPU validation sweep (xla-iree, CUDA / GB10)
Ran the OpenXLA CUDA path end to end (rust
xla-ireebuild against IREE-CUDA plus the HF fp32 oracle) for representative families from each dense wave. This exercises the real GPU execution path, beyond the IREE-CPU synthetic-model token-exact checks the sub-issues used during implementation.Results (device=cuda)
trust_remote_codeand the pinned transformers errors on its config. That is an oracle-side environment limitation, not an XLA-path issue; arch correctness is covered by feat: dense arch pack for remaining Llama-family architectures (Mistral/Ministral, ExaOne, InternLM, Baichuan, GLM4, and more) #499's own synthetic-model check.Fix landed during the sweep
PR #569 (fix(xla): load bf16 affine quant scales): the 4bit/8bit dequant loader hardcoded f16 scales/biases and could not load any Qwen3 / Gemma3-27B / Qwen3-MoE checkpoint (they store bf16 scales; the pre-existing Llama/Qwen2 baselines happened to be f16, so it went unnoticed). Threading a dtype flag through the dequantizer and widening bf16 to f32 unblocks them, completing the "loads and generates via CLI" acceptance for those families. Verified: qwen3-0.6b-4bit went from unloadable to token-exact single-seq on GPU.
Net
The epic's new architectures run correctly on the real GPU path: dense families (#497 Gemma3, #498 StableLM) pass both gates at f16; the qk-norm path (#497 Qwen3) is exact (f16 single-seq, f32 both gates), with only an accepted f16 batched near-tie on serve; the MoE math is block-exact and now loadable. The remaining gaps are environmental (ExaOne oracle needs trust_remote_code) or resource-bound (30B MoE full-model), not correctness.
inureyes commentedon Jul 1, 2026
Epic complete: all 10 sub-issues implemented, merged, and closed with status:done across 4 waves; the arch-coverage suite is green; the GPU (xla-iree/CUDA) validation sweep passed for representative families; the bf16-scales loader gap surfaced by the sweep was fixed in #569; and the SSM/hybrid and multimodal tracks are carried by follow-up epics #564 and #566.
feat: dense arch pack for qk-norm and Gemma family in mlxcel-xla (lab…
feat: dense arch pack (Seed-OSS, MiMo, InternLM3, ExaOne) in mlxcel-x…
feat: dense arch pack for parallel-block and norm-variant families (l…
docs: scope the OpenXLA SSM / hybrid / recurrent track (lablup#502) (l…
docs: scope the OpenXLA multimodal / VLM track (lablup#503) (lablup#567)
fix(xla): load bf16 affine quant scales in the OpenXLA weight loader (l…