Minimal but complete inference engines, optimized by coding agents under verified acceptance.
Quick start · Run a model · Demo · How it works · Results · Usage · Docs · Citation · 中文
Production inference frameworks such as vLLM and SGLang serve many models, devices and workloads at once. That breadth leaves a coding agent editing fragments of a large, coupled codebase without a view of the full execution path. EngineTailor gives each target, one model on one device with one workload, its own minimal but complete engine. A Manager Agent turns measured bottlenecks into bounded tasks for fresh Worker Agents, and a protected acceptance plane admits a change only after independent correctness and end-to-end performance checks.
This repository is the code for the DAI '26 paper EngineTailor: Minimal Complete Inference Engines for Agent-Driven Optimization: arXiv:2611.37129 (PDF), accepted at DAI '26, Hong Kong.
- Small enough to read whole. The initial Qwen3-4B target engine is 28 Python files and 3.3K lines, against 416K lines for SGLang's runtime and 684K for the vLLM package under the same counting rule. It still keeps generation, caching, profiling, benchmarking and the correctness gate.
- Agents propose, evidence admits. Workers run in isolated worktrees and cannot touch the gate that judges them. Each candidate passes a guard, the correctness gate, a negative control and an independent rerun before it is merged.
- Knowledge carries over. Every verdict is recorded with the conditions it
held under. 139 recipes ship in
recipes/, 8000 and later targets re-qualify them instead of trusting them. - Multi-agent & Humanize workflows. Campaigns run natively with Codex,
Claude Code, or Antigravity CLI (
agy), support heterogeneous agent pools via--agent-profile, and can dispatch multi-role Humanize (hmz) task packages. - Cloud to edge. The paper evaluates seven targets across autoregressive
LLMs, vision-language-action models and an interactive world model, four of
them on edge devices; two post-paper Apple M5 Ultra (96 GB) case studies
extend this to a pure C/Metal video DiT (
MiniMax-H3) and a 100K-context native MLX/Metal LLM (Inkling-2-Mini).
Headline results from the paper and Apple M5 Ultra case studies. Values are medians over archived samples; the paper's appendix has the full boards.
| Target | Result |
|---|---|
| Pi0.5 on Jetson AGX Orin, strict BF16 | End-to-end action latency 190.3 ms against PhyAI's 333.9 ms: 43.0% lower, 1.75× faster |
| Qwen3-4B on SM100, BF16, same agent configuration | EngineTailor admitted short-prefill gains of 3.1–4.1× after matching token-generation latency. Five direct attempts on SGLang admitted no improvement |
| Qwen3-4B on SM100, concurrency 16 | Throughput 3078.6 → 4654.8 tokens/s (+51.2%) after a graph boundary from a VLA target was re-qualified on Qwen |
| MiniMax-H3 on Apple M5 Ultra, pure C/Metal (case study) | 6-shot video+audio suite 336.41 s → 240.01 s (−28.66%, 1.40×) vs antirez/h3.c, byte-identical frames and PCM on every judged run |
| Inkling-2-Mini on Apple M5 Ultra, native MLX/Metal (case study) | 6-cell 1K–100K long-context suite 703.78 s → 305.30 s (−56.6%, 2.31×) vs oMLX 0.8.2, 88.4% of attainable roofline, token-identical across Stage 4 |
All paper campaigns ran Codex gpt-5.6-sol at xhigh effort under a protocol
registered before dispatch. The Apple M5 Ultra campaigns additionally exercised
heterogeneous codex / claude / agy agent pools and Humanize (hmz) flows.
- Register a campaign. It fixes the target, the gain an admitted change must reach, and the budget.
- Dispatch bounded tasks. The Manager reads the current profile and sends each bottleneck to a fresh Worker with its own worktree and budget.
- Admit serially. Each candidate passes the guard, the correctness gate, and an independent rerun. A correct change that clears the gain bar is admitted as a WIN; a correct, non-regressing change under a predeclared contract is admitted as an ENABLE. A wrong one is rejected. A correct one that merits neither is stopped and the engine stays as it was. After an admission, the remaining candidates are rebased and verified again.
- Keep what was learned. Every verdict goes into the shared substrate as a ledger entry, a runnable variant, or a recipe with its applicability conditions, so the next target starts from it.
| Model | Type | Device | Edge | Source | Launch configuration |
|---|---|---|---|---|---|
| Qwen3-4B | LLM | NVIDIA SM100 | models/qwen3 |
Broker config · Single-GPU local config | |
| Llama-3.1-8B | LLM | NVIDIA SM100 | models/llama |
Source only | |
| Oasis-500M | World model | NVIDIA SM100 | models/oasis |
Source only | |
| Qwen3.5-2B | LLM | RTX 5070 Laptop | ✓ | models/qwen35 |
Source only |
| Pi0.5 | VLA | Jetson AGX Orin | ✓ | models/pi05 |
Source only |
| Wall-OSS-0.5 | VLA | Jetson AGX Thor | ✓ | models/walloss |
Source only |
| Qwen3-0.6B | LLM | Apple M4 | ✓ | models/mlx |
Apple silicon config |
| MiniMax-H3 | Video+Audio DiT | Apple M5 Ultra | ✓ | models/minimax_h3 |
M5 Ultra target · Case study |
| Inkling-2-Mini | LLM (100K ctx) | Apple M5 Ultra | ✓ | models/inkling2 |
M5 Ultra target · Case study |
The CUDA targets are standalone minimal engines written in this repository.
The Apple target is not: it loads Qwen3-0.6B with mlx-lm and patches that
model instance with EngineTailor's candidate code
(runner.py). The paper's Qwen3-0.6B
campaign ran on an Apple M1 Pro. The shipped launch configuration, its
objective and its ecosystem intakes pin an Apple M4, so the table says M4.
The two launchable targets judge candidates with these commands:
| Launch configuration | Gate | Benchmark |
|---|---|---|
| Qwen3-0.6B, Apple M4 | python -m enginetailor.models.mlx.gate_questions --candidate-variant fusion |
The same command; it reports median_ms_per_token |
| Qwen3-4B, SM100 | python -m enginetailor.models.qwen3.gate |
python -m enginetailor.models.qwen3.bench_pp_tg --depths 4096,8192 |
Add --negative-control to a gate to check that it rejects corrupted output.
Each shipped launch configuration pins the exact device name and memory it was
last run on; set your own before launching. Source-only targets ship their model code,
gates and benchmarks; you write the launch configuration as in
Optimize your own target.
PAPER.md maps each part of the paper to its code.
Check the install on any machine. Nothing here downloads weights or needs a GPU.
Python 3.11 or newer is required. On macOS, /usr/bin/python3 is 3.9 and
cannot install torch==2.13.0, whose macOS wheels also need macOS 14 or
newer. There, replace the python3 -m venv .venv line below with
uv venv --seed --python 3.12 .venv (uv), or
run brew install python@3.12 and use python3.12 -m venv .venv.
git clone https://github.com/qhy991/EngineTailor.git
cd EngineTailor
python3 -m venv .venv && source .venv/bin/activate
python -m pip install -r requirements-dev.txt
python -m enginetailor.smoke # imports and the CPU operator harness
python -m enginetailor.substrate # two real Llama layers with synthetic weights
python -m pytest -q # tests that need CUDA, MLX or a device skip themselvessmoke ends with SMOKE PASS and substrate with SUBSTRATE CHECK PASS.
They confirm the code runs; they are not a model qualification or a speed
claim.
On an Apple silicon Mac, build the locked MLX environment once, download the
pinned weights with hf from the Quick start environment, and ask a question:
uv venv --python 3.14 ~/.venvs/enginetailor-mac
uv pip install --python ~/.venvs/enginetailor-mac/bin/python -r environments/requirements-mac.lock
hf download Qwen/Qwen3-0.6B --revision c1899de289a04d12100db370d81485cdf75e47ca
~/.venvs/enginetailor-mac/bin/python -m enginetailor run "What is the capital of France?"The default variant, fusion, is the optimized engine the Mac campaign
works on. --variant public runs the unmodified mlx-lm reference, and
--max-tokens N caps the answer. The lock is the one scripts/optimize.sh
installs for the Apple target, so you can reuse this interpreter there with
ENGINETAILOR_PYTHON=~/.venvs/enginetailor-mac/bin/python.
On an NVIDIA GPU, in the CUDA environment from the
user guide, the same command runs Qwen3-4B
(--variant eager is the unoptimized reference):
hf download Qwen/Qwen3-4B --revision 1cfa9a7208912126459214e8b04321603b3df60c
python -m enginetailor run "What is the capital of France?"The standalone cross-engine showcase lives in the companion repository
qhy991/apxinf-mario-demo.
Mechanisms discovered on EngineTailor were ported into the standalone Metal
runtime qhy991/apxinf-metal
(clef-decide-server), driving Super Mario Bros. World 1-1 locally on Apple
Silicon via three visual yes/no (noul) questions per decision (./run.sh;
no ROM or model weights are distributed). On Apple M1 Pro, per-request latency
drops from 2458 ms (reference) to 1853 ms (auto) and 1446 ms
(gpu-ane-columns, 1.70× faster).
| Goal | You need | Time |
|---|---|---|
| Reproduce a paper target | The target device, its weights, a signed-in agent CLI (codex, claude, or agy), tmux |
Hours |
| Optimize your own target | A correct baseline and a gate you trust, plus the items listed below | Days |
bash scripts/optimize.sh --config targets/qwen3-06b-m4-bf16/optimization-v2.json --check
bash scripts/optimize.sh --config targets/qwen3-06b-m4-bf16/optimization-v2.json --agent codex
bash scripts/optimize.sh --config targets/qwen3-06b-m4-bf16/optimization-v2.json --agent claude
bash scripts/optimize.sh --config targets/qwen3-06b-m4-bf16/optimization-v2.json --agent agy
bash scripts/optimize.sh --config targets/qwen3-06b-m4-bf16/optimization-v2.json --agent-profile ~/.config/enginetailor/agents.json
bash scripts/optimize.sh --config targets/qwen3-06b-m4-bf16/optimization-v2.json --status--check validates the environment, device and weights without starting a
campaign. The launch generates the original answers once, starts the Manager
in tmux, and returns. Prepare the machine first:
Before you launch
-
Install tmux and at least one supported coding-agent CLI:
codex(Codex CLI with Goal mode; default backend, default--model gpt-6.1-sol,--effort xhigh; the paper usedgpt-5.6-sol)claude(Claude Code CLI;--agent claude, default--model claude-opus-5-5[1m])agy(Antigravity CLI;--agent agy, default--model gemini-4-neon-high)- Mixed agent pools & Humanize (
hmz): pass--agent-profile /abs/path/to/agents.json(a private schema-1 pool file outside the repo, with mode-0600env_filecredentials) to assign different backends/models tomanager,worker, and multi-role Humanize (hmz) task packages.
-
Install uv. The launcher builds the target's locked Python environment from the configuration: Python 3.14 for the Apple target, 3.12 for the SM100 target, and
--checkprints the interpreter it used. To use your own environment, such as the one from Run a model, setENGINETAILOR_PYTHON=/path/to/env/bin/python; its Python version and every package must match the lock exactly. -
Download the pinned weights into the Hugging Face cache. The
hfcommand comes withrequirements.txt.hf download Qwen/Qwen3-0.6B --revision c1899de289a04d12100db370d81485cdf75e47ca # Apple target hf download Qwen/Qwen3-4B --revision 1cfa9a7208912126459214e8b04321603b3df60c # SM100 target
-
Run
--check. The launcher compares the device name and memory literally. On a mismatch it names every file in the target directory that pins the device and the exact"hardware"value to set there. -
Commit the edited configuration. A campaign launches only from a clean
maincheckout, so every input it uses is pinned to a commit.--checkwarns when the checkout is not onmain, has uncommitted changes, or has no Codex CLI.
The SM100 target supports two resource modes: experiment.json uses a site GPU
lease broker (resources.mode: broker, configured via ENGINETAILOR_GPU_RUN,
ENGINETAILOR_BROKER_SOCKET, and ENGINETAILOR_BROKER_OWNER), while
experiment-local.json
uses local file locking (resources.mode: lock) for dedicated single-GPU
NVIDIA hosts without gpu-run.
Relaunching resumes the same campaign. Changing --model, --effort or the
budget requires a new --name, and --status then takes the same --name.
EngineTailor does not optimize a model it cannot already run correctly. You supply a working baseline and a way to judge correctness. The agents search for faster implementations, and the acceptance plane checks every candidate against your baseline.
- Bring up the model on a branch of
main. Copytasks/TEMPLATE.bringup.mdand work through it: environment check, oracle, gate, an independent cross-check against the Hugging Face reference, baseline measurement, and profile. You run or closely supervise this stage yourself, because agents may not write the gate that judges them. - Add the launch inputs listed below. Use
"source": {"kind": "existing", "ref": "main"}in the configuration. - Review and merge the change into
main. - Check and launch with
bash scripts/optimize.sh --config targets/<target-id>/<name>.json, first with--check. - Follow it with
--status. Every outcome, including failures, is archived. When the budget runs out, qualify and promote the final source as described in TARGET-LIFECYCLE.md.
What to prepare
| Item | What it is | Where it goes |
|---|---|---|
| Launch configuration | Schema 2: model repo, revision and manifest hash, device name and memory, workload shape, budget, adapter, Python version, resource mode, question suite, intake. Field reference in PORTABLE-EXPERIMENTS.md | targets/<target-id>/<name>.json |
| Objective | The metric, its direction, the gain worth accepting, the gate and benchmark commands, and what agents may change. Start from campaigns/templates/OBJECTIVE.example.md |
targets/<target-id>/OBJECTIVE.md |
| Weights | A complete Hugging Face snapshot at the pinned revision, including the tokenizer | Hugging Face cache, or --snapshot PATH |
| Environment lock | Exact name==version pins for the target's Python |
targets/<target-id>/requirements.lock |
| Baseline model | An unoptimized, correct forward: the frozen oracle every candidate is compared with | enginetailor/models/<family>/model.py |
| Gate | Compares a candidate with the oracle and prints exactly one GATE PASS or GATE FAIL line. With --negative-control it corrupts its own input and must print CONTROL PASS |
enginetailor/models/<family>/gate.py |
| Benchmark | Measures the metric over repeated runs and keeps every sample | enginetailor/models/<family>/bench.py |
| Real questions | Prompts in the languages you serve. Original and optimized answers must mean the same | targets/<target-id>/questions.json |
| Ecosystem intake | A reviewed survey of existing engines and kernels for this model and device. Format in ECOSYSTEM-INTAKE.md | targets/<target-id>/ecosystem/ |
| Launch adapter | Validates the configuration, checks the device, resolves weights | targets/<target-id>/adapter.py, or a reviewed entry in orchestrate/experiment_adapters/ |
| Semantic runtime | Runs the ori 8000 ginal and the candidate on the real questions | A runtime entry in orchestrate/semantic_compare.py |
| Family manifest | One MANIFEST naming the family's gates, frozen oracle functions, protected paths and model loader. The gate registry, guard, change policy, exporter and runtime registry read it; no central table is edited. Copy enginetailor/models/llama/family.py |
enginetailor/models/<family>/family.py |
| Agent access | tmux and a signed-in codex, claude, or agy CLI (or --agent-profile) on the machine with the accelerator |
Your shell |
Copy from the closest existing target instead of starting empty.
enginetailor/models/llama/ is the smallest complete model family, and the
two launchable targets show every other item. Their adapters are mlx_qwen3
and cuda_qwen3.
The minimal substrate (base)
base is a projection of main that keeps the control plane, the acceptance
plane, the shared operators, the recipes and Llama, and drops every other
model family. It shows exactly what a target engine needs. Browse it on the
base branch; its README is
docs/SUBSTRATE.md.
Campaigns do not start from base. The launcher regenerates base locally
on every new launch, but both shipped configurations set
"source": {"kind": "existing", "ref": "main"}, so their campaigns start from
main, which has the model families they need. To regenerate base yourself
and run the CPU rehearsal in a small checkout:
bash scripts/make_base.sh
git worktree add --detach ../enginetailor-base baseKeep --detach: make_base.sh updates base in its own worktree and cannot
while another worktree has the branch checked out.
Terms
| Term | Meaning |
|---|---|
| Target | One model, device, precision and workload. Everything is measured against exactly one |
| Oracle | The frozen, unoptimized forward. Candidates are compared with its outputs |
| Gate | The trusted script that decides whether a candidate is correct. Agents cannot edit it |
| Negative control | A gate run on deliberately corrupted output. It must report CONTROL PASS, showing the gate catches a real error |
| Campaign | One optimization run on one target: a Manager plans, Workers each run one bounded experiment |
| Acceptance plane | Guard, gate, negative control and paired timing, run independently of the Worker that made the change |
| WIN / ENABLE | A WIN is a correct change that clears the predeclared gain bar on an independent rerun. An ENABLE is a correct, non-regressing change admitted under a predeclared contract, such as a step that later gains build on. It changes the engine but never counts as a WIN |
base |
The minimal substrate generated from main. Nobody develops on it |
| Intake | The reviewed survey of prior engines and kernels a campaign starts from |
| Recipe | A recorded optimization mechanism or failure, with the conditions under which it held |
enginetailor/ engine: shared operators, runtime, kernels, quantization, models/<family>/
orchestrate/ control plane: task contracts, campaign loop, guard, verification, archive, promotion
native/ standalone CUDA operators with build provenance
targets/ target definitions: model, device, workload, objective, real questions
tasks/ task templates for bring-up, optimization and quantization
recipes/ reusable mechanisms and recorded failures, indexed in recipes/INDEX.md
skills/ agent skills, mirrored into .agents/ and .claude/
scripts/ launchers, environment probes, base projection
docs/ guides and design records
- Documentation index: every guide and design record, ordered by when you need it
- User guide: install, sanity checks, running and benchmarking the engine
- Humanize executor & agent pools: multi-agent profiles (
codex/claude/agy) and boundedhmztask flows - M5 Ultra case studies: MiniMax-H3 (C/Metal) · Inkling-2-Mini (100K MLX/Metal)
- Portable experiments: launch configuration reference
- Target lifecycle: how
main,base, campaign and target branches relate - AGENTS.md: the rules agents follow. Read it before changing the acceptance plane
- CONTRIBUTING.md and SECURITY.md
If you use EngineTailor, please cite the DAI '26 paper (arXiv:2611.37129):
@inproceedings{qin2026enginetailor,
title = {EngineTailor: Minimal Complete Inference Engines for Agent-Driven Optimization},
author = {Qin, Haiyan and Wan, Rui and Han, Jinchen and Zeng, Shulin and Dai, Guohao and Wang, Yu and Kang, Wang},
booktitle = {Proceedings of the Eighth International Conference on Distributed Artificial Intelligence (DAI '26)},
address = {Hong Kong, China},
year = {2026}
}
@misc{qin2026enginetailorarXiv,
title = {EngineTailor: Minimal Complete Inference Engines for Agent-Driven Optimization},
author = {Qin, Haiyan and Wan, Rui and Han, Jinchen and Zeng, Shulin and Dai, Guohao and Wang, Yu and Kang, Wang},
year = {2026},
eprint = {2611.37129},
archivePrefix = {arXiv},
primaryClass = {cs.AI},
url = {https://arxiv.org/abs/2611.37129}
}Parts of EngineTailor derive from SGLang, DeepGEMM, CUTLASS, LeRobot / openpi, antirez/h3.c, and oMLX. We thank their authors. NOTICE lists each derived file and its license.
EngineTailor is released for non-commercial use only under the
PolyForm Noncommercial License 1.0.0 (PolyForm-Noncommercial-1.0.0).
Commercial use requires separate written permission from the authors.
Derived third-party components keep their upstream licenses; see NOTICE and licenses/.