Skip to content

epic: OpenXLA backend architecture-coverage parity with the MLX engine #493

Closed

Description

@inureyes

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: XlaBatchEngine plus 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: BatchEngine trait, 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:

  1. Config::from_json arch detection and fields (emitter/config.rs).
  2. weight_names per-layer order (iree.rs).
  3. The emitter forward (emitter/model.rs).
  4. 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:

  1. Dequant a 4bit/8bit checkpoint offline to f32 (or use a bf16 checkpoint directly).
  2. Run HF fp32 as the oracle.
  3. Run XLA on the quantized/bf16 model.
  4. 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)

Phase 2: Window B (Dense decoder-only families)

Phase 3: Window C (Mixture-of-Experts)

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=xla path and serves via mlxcel-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

Activity

  1. inureyes commented on Jul 1, 2026

    @inureyes
    MemberAuthor

    Epic implementation complete

    All 10 sub-issues are implemented, merged, and closed with status:done, across 4 execution waves. main is 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

    • Waves executed: 4 (Wave 0: 3 units, Wave 1: 4 units, Wave 2: 1 unit, Wave 3: 1 chain of 2). Max parallelism 10.
    • Worktrees created and cleaned: 9 (one per unit, all removed; build caches pre-warmed for incremental-only builds).
    • Cross-unit conflicts on the shared emitter files (config.rs, model.rs, rope.rs, weight naming, validation.rs) were resolved into one coherent structure: emit_attention returns (hn, attn_out) with residual owned by emit_transformer_layer (sequential vs parallel blocks), an emit_ffn_body that dispatches dense (emit_mlp_body) vs MoE (moe.rs), and a single weight-ordering authority (weights::weight_specs sourcing names from weight_names). Llama/Qwen2/Gemma2 stayed byte-identical throughout.

    Validation

    Follow-up epics

  2. added and removed on Jul 1, 2026
  3. inureyes commented on Jul 1, 2026

    @inureyes
    MemberAuthor

    GPU validation sweep (xla-iree, CUDA / GB10)

    Ran the OpenXLA CUDA path end to end (rust xla-iree build 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)

    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.

  4. inureyes commented on Jul 1, 2026

    @inureyes
    MemberAuthor

    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.

  5. self-assigned this
    on Jul 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions