Loomcore

C++17 · ONNX Runtime · Python bindings · MIT

Run several ONNX models as one scheduled graph

Loomcore is a C++ runtime for multi-model inference. Each job flows through a dependency graph of models. Before every node a router decides whether to skip it, which precision to run and which lane to use. Calls are batched across jobs, deadlines are enforced, and the whole graph can be swapped under load without losing a job.

Load test · recorded 2 Oct 202648 jobs, 12 at a time, on the live runtime (Modal container, x86-64). Each bar is one ONNX Runtime call, placed where the scheduler ran it.
FP32INT8router decisionskipreject / cancelDAG edge
342 ms

Ctrl + wheel zooms, drag pans, ← → step through events.Tap a bar or marker for details; + and − zoom, then drag to pan. Open in Perfetto: copy the trace, save it as trace.json, drop it on ui.perfetto.dev.

All 155 events in time order
mstrackwhatdetail
0.000Jobsjob-13completed after 87.0 ms
1.70Jobsjob-14completed after 85.5 ms
6.25Jobsjob-15completed after 81.1 ms
8.12Jobsjob-16completed after 88.7 ms
9.23RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=2 gpu_sim_queue=0; routing to the shallower lane
9.35RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=2 gpu_sim_queue=0; routing to the shallower lane
10.7Jobsjob-17completed after 86.3 ms
12.2CPU mobilenet FP32 ×228.3 ms · job-13 job-14
15.2RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=2 gpu_sim_queue=0; routing to the shallower lane
18.3Jobsjob-18completed after 65.6 ms
19.3RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=0 gpu_sim_queue=3; routing to the shallower lane
20.5Jobsjob-19completed after 63.5 ms
21.2GPU_SIM mobilenet FP32 ×355.0 ms · job-15 job-16 job-17
22.9RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=0 gpu_sim_queue=3; routing to the shallower lane
24.5Jobsjob-20completed after 71.8 ms
27.4RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=1 gpu_sim_queue=0; routing to the shallower lane
28.8Jobsjob-21completed after 68.1 ms
30.9CPU mobilenet FP32 ×237.0 ms · job-18 job-19
31.4RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=2 gpu_sim_queue=0; routing to the shallower lane
35.4Jobsjob-22completed after 48.6 ms
35.8RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=0 gpu_sim_queue=2; routing to the shallower lane
36.9Jobsjob-23completed after 50.3 ms
39.3RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=0 gpu_sim_queue=2; routing to the shallower lane
39.7GPU_SIM mobilenet FP32 ×237.2 ms · job-20 job-21
43.3Jobsjob-24completed after 81.6 ms
44.1RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=2 gpu_sim_queue=0; routing to the shallower lane
44.7RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=1 gpu_sim_queue=0; routing to the shallower lane
49.4CPU mobilenet FP32 ×225.1 ms · job-22 job-23
69.2RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=0 gpu_sim_queue=3; routing to the shallower lane
70.6RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=1 gpu_sim_queue=3; routing to the shallower lane
75.5RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=2 gpu_sim_queue=3; routing to the shallower lane
81.5RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=3 gpu_sim_queue=5; routing to the shallower lane
81.8RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=3 gpu_sim_queue=6; routing to the shallower lane
81.9CPU bert_tiny FP32 ×31.92 ms · job-18 job-19 job-22
82.8GPU_SIM bert_tiny FP32 ×44.03 ms · job-13 job-14 job-23 job-15
83.3RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=1 gpu_sim_queue=6; routing to the shallower lane
84.0GPU_SIM mobilenet FP3218.8 ms · job-24
84.1Jobsjob-25completed after 78.2 ms
84.4Jobsjob-26completed after 77.7 ms
84.6Jobsjob-27completed after 77.8 ms
84.6RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=3 gpu_sim_queue=1; routing to the shallower lane
84.6RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=3 gpu_sim_queue=1; routing to the shallower lane
86.9RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=3 gpu_sim_queue=1; routing to the shallower lane
88.7Jobsjob-28completed after 73.7 ms
89.0Jobsjob-29completed after 73.3 ms
89.2Jobsjob-30completed after 87.8 ms
89.4Jobsjob-31completed after 86.8 ms
89.5RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=3 gpu_sim_queue=4; routing to the shallower lane
89.6RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=3 gpu_sim_queue=4; routing to the shallower lane
89.7RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=3 gpu_sim_queue=4; routing to the shallower lane
90.2RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=3 gpu_sim_queue=4; routing to the shallower lane
92.9GPU_SIM bert_tiny FP323.22 ms · job-20
93.1CPU mobilenet FP32 ×459.2 ms · job-29 job-28 job-30 job-31
95.0CPU bert_tiny FP32 ×31.68 ms · job-16 job-21 job-17
96.3GPU_SIM mobilenet FP32 ×350.5 ms · job-26 job-27 job-25
96.5Jobsjob-32completed after 65.9 ms
98.7Jobsjob-33completed after 78.7 ms
99.0Jobsjob-34completed after 77.3 ms
99.2Jobsjob-35completed after 78.3 ms
99.3RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=1 gpu_sim_queue=0; routing to the shallower lane
99.4RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=1 gpu_sim_queue=0; routing to the shallower lane
99.5RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=1 gpu_sim_queue=0; routing to the shallower lane
104RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=1 gpu_sim_queue=2; routing to the shallower lane
107CPU mobilenet FP3214.3 ms · job-32
110GPU_SIM mobilenet FP32 ×352.6 ms · job-34 job-33 job-35
123RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=1 gpu_sim_queue=0; routing to the shallower lane
124CPU bert_tiny FP320.905 ms · job-24
125Jobsjob-36completed after 37.3 ms
125RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=0 gpu_sim_queue=1; routing to the shallower lane
136CPU mobilenet FP3214.8 ms · job-36
149RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=0 gpu_sim_queue=1; routing to the shallower lane
155RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=1 gpu_sim_queue=2; routing to the shallower lane
158RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=1 gpu_sim_queue=2; routing to the shallower lane
159GPU_SIM bert_tiny FP32 ×33.29 ms · job-32 job-27 job-36
159RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=2 gpu_sim_queue=3; routing to the shallower lane
160CPU bert_tiny FP32 ×42.08 ms · job-26 job-29 job-25 job-28
161RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=4 gpu_sim_queue=0; routing to the shallower lane
162RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=0 gpu_sim_queue=1; routing to the shallower lane
162Jobsjob-37completed after 82.9 ms
163Jobsjob-38completed after 78.2 ms
164Jobsjob-39completed after 47.6 ms
164Jobsjob-40completed after 81.8 ms
164Jobsjob-41completed after 46.8 ms
165Jobsjob-42completed after 81.5 ms
165Jobsjob-43completed after 45.4 ms
165RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=2 gpu_sim_queue=1; routing to the shallower lane
167CPU mobilenet FP32 ×455.9 ms · job-37 job-40 job-42 job-38
168RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=0 gpu_sim_queue=1; routing to the shallower lane
170RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=4 gpu_sim_queue=2; routing to the shallower lane
172RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=4 gpu_sim_queue=3; routing to the shallower lane
173GPU_SIM bert_tiny FP32 ×33.65 ms · job-30 job-33 job-35
175CPU bert_tiny FP32 ×21.43 ms · job-31 job-34
176GPU_SIM mobilenet FP3217.0 ms · job-43
176CPU mobilenet FP32 ×223.4 ms · job-41 job-39
177Jobsjob-44completed after 69.5 ms
177Jobsjob-45completed after 64.7 ms
178Jobsjob-46completed after 64.1 ms
178Jobsjob-47completed after 78.7 ms
178Jobsjob-48completed after 63.5 ms
179RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=2 gpu_sim_queue=0; routing to the shallower lane
179RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=2 gpu_sim_queue=0; routing to the shallower lane
179RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=2 gpu_sim_queue=0; routing to the shallower lane
188GPU_SIM mobilenet FP32 ×343.6 ms · job-46 job-48 job-47
194RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=2 gpu_sim_queue=0; routing to the shallower lane
201RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=2 gpu_sim_queue=1; routing to the shallower lane
203CPU mobilenet FP32 ×225.2 ms · job-44 job-45
207GPU_SIM bert_tiny FP32 ×33.36 ms · job-43 job-41 job-39
211Jobsjob-49completed after 108 ms
212Jobsjob-50completed after 108 ms
212Jobsjob-51completed after 44.4 ms
213RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=1 gpu_sim_queue=0; routing to the shallower lane
222GPU_SIM mobilenet FP3217.9 ms · job-51
225RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=2 gpu_sim_queue=0; routing to the shallower lane
226RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=2 gpu_sim_queue=1; routing to the shallower lane
231RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=2 gpu_sim_queue=3; routing to the shallower lane
233CPU mobilenet FP32 ×224.4 ms · job-49 job-50
234RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=2 gpu_sim_queue=4; routing to the shallower lane
236RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=2 gpu_sim_queue=3; routing to the shallower lane
239RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=3 gpu_sim_queue=4; routing to the shallower lane
239CPU bert_tiny FP32 ×41.56 ms · job-38 job-45 job-46 job-48
240RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=0 gpu_sim_queue=4; routing to the shallower lane
242GPU_SIM bert_tiny FP32 ×43.40 ms · job-37 job-40 job-42 job-44
242Jobsjob-52completed after 75.3 ms
242Jobsjob-53completed after 75.2 ms
243RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=0 gpu_sim_queue=4; routing to the shallower lane
243Jobsjob-54completed after 74.9 ms
243Jobsjob-55completed after 76.2 ms
243RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=1 gpu_sim_queue=0; routing to the shallower lane
243RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=1 gpu_sim_queue=0; routing to the shallower lane
244RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=1 gpu_sim_queue=0; routing to the shallower lane
245RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=1 gpu_sim_queue=0; routing to the shallower lane
246GPU_SIM mobilenet FP32 ×460.8 ms · job-52 job-53 job-55 job-54
246Jobsjob-56completed after 71.3 ms
247Jobsjob-57completed after 85.0 ms
247Jobsjob-58completed after 83.5 ms
248Jobsjob-59completed after 83.8 ms
248RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=2 gpu_sim_queue=0; routing to the shallower lane
248RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=2 gpu_sim_queue=0; routing to the shallower lane
248RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=2 gpu_sim_queue=0; routing to the shallower lane
248RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=2 gpu_sim_queue=0; routing to the shallower lane
250GPU_SIM mobilenet FP32 ×460.1 ms · job-56 job-57 job-58 job-59
254CPU bert_tiny FP32 ×21.93 ms · job-47 job-51
257Jobsjob-60completed after 39.9 ms
268CPU mobilenet FP3213.0 ms · job-60
283RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=0 gpu_sim_queue=2; routing to the shallower lane
296CPU bert_tiny FP321.03 ms · job-60
309RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=0 gpu_sim_queue=2; routing to the shallower lane
310RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=1 gpu_sim_queue=2; routing to the shallower lane
313RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=1 gpu_sim_queue=2; routing to the shallower lane
315RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=2 gpu_sim_queue=3; routing to the shallower lane
316GPU_SIM bert_tiny FP32 ×33.34 ms · job-49 job-50 job-55
316CPU bert_tiny FP32 ×41.76 ms · job-52 job-53 job-56 job-54
317RouterRouter decisionCompositeRouter: LoadAwareBackendPolicy: cpu_queue=0 gpu_sim_queue=1; routing to the shallower lane
328GPU_SIM bert_tiny FP32 ×23.34 ms · job-57 job-59
330CPU bert_tiny FP320.847 ms · job-58

Try it in the console

The console opens on the recorded run above and connects to the live runtime in the background. The runtime sleeps when nobody is using it, so the first request can take up to half a minute while it starts.

  1. Step 1

    Run one job

    Pick a sample photo, or drop in your own JPEG or PNG (up to 2 MB), and press Run. MobileNetV2 labels it; unless it is already 85% sure, bert_tiny turns the label into a 128-number text embedding.

    Look for: The router’s decisions sit above the lanes with their reasons. Hover any bar for the node, precision, batch and time.

    Recorded: red fox, 77.5% sure, so bert_tiny ran. The job took 38.9 ms.

    The console’s Controls panel for “Run one job”, with the settings used for the recorded run
  2. Step 2

    Run a load test

    Fire up to 64 jobs, up to 16 at a time, with an optional time budget per job. Toggle router policies on the graph panel to see what each one changes.

    Look for: Calls stack into batches of up to 4 per model, split between the CPU and GPU_SIM lanes by queue depth. Rejected and cancelled jobs are drawn in red.

    Recorded: 48 of 48 jobs done, 12 at a time, job p50 77.9 ms and p95 91.3 ms; MobileNetV2 ran 23 times on CPU and 25 on GPU_SIM.

    The console’s Controls panel for “Run a load test”, with the settings used for the recorded run
  3. Step 3

    Hot-swap the graph under load

    Rebuild the whole graph, models and scheduler up to 6 times while jobs keep arriving. Each swap loads fresh ONNX Runtime sessions beside the old ones.

    Look for: The swap markers cut across the lanes; jobs that started before a swap finish on the graph they started with. The count to check is “lost”.

    Recorded: 4 swaps during 48 jobs, 48 completed, 0 lost. The slowest swap took 157 ms to build.

    The console’s Controls panel for “Hot-swap the graph under load”, with the settings used for the recorded run
Open the console

Use it from code

Call the live runtime over HTTP, or build the library and drive it from C++ or Python.

curl -X POST https://loomcore-api.amittal.dev/run \
  -H 'content-type: application/json' \
  -d '{"sample": "retriever"}'

# {"label": "Golden Retriever", "confidence": 0.9141,
#  "skipped": ["bert_tiny"], "totalMs": 31.2,
#  "decisions": [...], "nodes": [...], "trace": [...]}

The live runtime behind the console. /health, /graph, /run, /load, /reload and /bench; 20 POSTs a minute per address.

How a job runs

jobimagerouter: skip? precision? lane? (asked before every node)MobileNetV2CPU lane · FP32 | INT8bert_tinyGPU_SIM lane · FP32 | INT8label +embeddingbert_tiny is skipped when MobileNetV2 is ≥ 85% sureeach lane batches same-model calls from concurrent jobs (up to 4, within 8–12 ms)

The router, in order

  1. circuit-breakerskips a node whose error rate reached 50% over at least 4 runs; lets one probe through after 2 s
  2. bulkheadsheds (skips) a request once 6 are already in flight for that nodeoff by default in the console
  3. confidence-gateskips bert_tiny once mobilenet is at least 85% sure; there is nothing left to describe
  4. precision-plannersolves a 0/1 knapsack over the critical path for which nodes to run INT8 so the job fits
  5. latency-budgetdrops a node to INT8 once less than 30 ms of the budget is left
  6. load-awaresends the node to whichever lane has the shallower queue

Deadlines that bind

Give a job a time budget and the planner solves a 0/1 knapsack over the critical path to choose which nodes run INT8. A job it judges undeliverable is rejected before anything runs; one that runs out of time is cancelled inside the ONNX Runtime call.

Hot-swap without a lost job

A reload builds a new graph, models and scheduler as one snapshot and swaps a pointer to it atomically. Jobs in flight keep the snapshot they started with; new jobs get the new one. No locks on the hot path, nothing torn.

Two lanes, one of them simulated

CPU and GPU_SIM are two worker pools. There is no GPU here: GPU_SIM adds a modelled transfer cost, so the load-aware policy has a real trade-off to make.

Numbers

FP32 against INT8, 20 warm-up runs then 100 timed, measured by loomcore_bench on the live runtime (Modal container, x86-64) when it started.

ModelFP32 p50INT8 p50INT8 speed-up
MobileNetV211.4 ms11.5 ms0.99x
bert_tiny0.323 ms0.259 ms1.25x

This CPU has AVX2 but no VNNI, so INT8 convolutions have no fast path and MobileNetV2 gains nothing from quantizing; bert_tiny’s matrix multiplies still do. On a CPU with VNNI the gap opens up. The console’s benchmark panel shows the same run, live from whichever machine the runtime is on.

What it is not

  • Not a model: MobileNetV2 and bert_tiny are untrained, off-the-shelf exports chosen for their different shapes. The work is the scheduling around them.
  • Not a GPU server: everything runs on CPU, and GPU_SIM is simulated.
  • The live runtime is small: Modal’s free tier, 2 cores, one job-running request at a time, started on demand. For real numbers, build it on your own machine.