Repository navigation
Description
Problem / Background
PR #446 landed a provisional ComputeBackend seam at the model-load boundary, returning the concrete MLX LoadedModel from select_backend. That seam is at the wrong level for the real targets. ADR 0004 (docs/adr/0004-compute-backend-session-seam-and-stablehlo-family.md, Proposed in PR #447) reframes the seam to the inference-session / engine level, because the actual backends we want (FuriosaAI, Tenstorrent, OpenXLA) are graph-compiler backends and the current LanguageModel::forward is itself MLX-coupled: it takes &mut [KVCache] and returns UniquePtr<MlxArray>. A load-boundary seam that hands back an MLX object cannot host a compiler backend that never produces an MlxArray.
This issue redraws the contract at the token level and moves the existing MLX path behind it as a behavior-preserving refactor. Because MLX is the only backend we have today, the redraw is fully validatable on the MLX path: it must be byte-identical, with no behavior or throughput change. This supersedes the provisional load-boundary contract introduced in #446. Follow-on from issue #338 and PR #446.
Proposed Solution
Define an inference-session / engine trait at the token level rather than at the load boundary. The session, not the caller, owns per-sequence KV state. The hot path exchanges token ids plus optional logprobs, with sampling done on-device, so a compiler backend can keep KV and sampling inside its compiled graph. The contract exposes prefill plus decode-step primitives, and the session advertises its capabilities (batching, paged KV, speculative decode, multimodal) so callers can gate on what a given backend supports.
Move the MLX path behind this contract. CxxGenerator becomes the MLX session implementation and must cover both the CLI single-sequence generate path and the server batch-scheduler path. Keep the select_backend selection skeleton and the default-off experimental-backend feature gate from PR #446, and keep the non-MLX scaffold compiling; only the contract shape changes, replacing the provisional load-boundary contract with the session/engine contract.
Design deliverables to resolve in this issue
These are open and to be decided as part of the work, not pre-decided here.
- Whether the session owns the decode loop, or exposes step primitives that the existing server batch scheduler drives. The current leaning is step primitives, so cross-sequence batching survives and the backend keeps ownership of KV; confirm or revise during the work.
- Synchronous vs asynchronous session API.
- Where the trait lives:
mlxcel-corevs a rootsrc/backendmodule. - How capabilities are advertised and gated (batching, paged KV, speculative decode, multimodal).
Acceptance Criteria
- The MLX path runs entirely behind the new session contract with no behavior change.
- Byte-identical temp-0 greedy parity verified on a real checkpoint on the CLI
generatepath. - Byte-identical temp-0 greedy parity verified on a real checkpoint on the server path.
- No measurable throughput regression on MLX decode.
- With only MLX compiled (default features), the generated code adds no runtime dispatch on the hot path.
- The server batch scheduler still drives batched decode correctly through the new contract.
- The
experimental-backendscaffold still compiles (default-off).
Technical Considerations
This supersedes the provisional contract from #446. The experimental-backend non-MLX scaffold stays default-off, so default Apple-Silicon and CUDA builds are unaffected. The session/engine seam is the contract that Track B (OpenXLA reference backend) will exercise and validate; expect reconciliation between the two tracks as the second backend reveals MLX-shaped assumptions in the trait.
Activity
feat: scaffold the OpenXLA backend crate and seam (#449 Phase 3 M1) (#…
feat: scaffold the OpenXLA backend crate and seam (lablup#449 Phase 3…