Repository navigation
ort: load single-subgraph Core ML sessions natively - #30
moltenglue wants to merge 1 commit into
Conversation
The keep-warm thread was busy from a frame's start until a second after the last one, through the engine's own work. With the whole model on the Neural Engine that took time from the frame it was there for. It now rests from the start of the engine's work to its end (run and runAhead) and is busy only in the gaps between frames, which also halves its CPU time. Measured with Cinque Terre V3 at 20 Hz on Neural Engine Only: an M1 Pro went from 30.1 ms mean and 35.0 p99 to 23.9 and 27.2, an iPhone 13 mini from 38.0 and 41.8 to 32.9 and 36.8 over three minutes from cool. The iPhone once hot slid to 48 ms before and holds 34 now. Neural Engine + GPU on the M1 Pro is unchanged (27.9 to 27.8). The idea is moltenglue's, from #30. Co-authored-by: moltenglue <257664494+moltenglue@users.noreply.github.com>
|
Thanks for this and for the detailed numbers. I benchmarked the pieces separately on an M1 Pro and an iPhone 13 mini to see where the gains come from. The latency win is the keep-warm thread resting while a frame runs. On its own it took Neural Engine Only from 30.1 to 23.9 ms on the M1 Pro and from 38.0 to 32.9 ms on the iPhone. That is on main now in d750eed, with you as co-author. The native Core ML session does not change frame time here, but it cuts the memory peak while loading (729 MB to 82 MB on the iPhone), and I would like to take it. Two things first: decide native-or-not at build time and record it in sessions.json, and drop I could not measure a gain from the IOSurface pool, and the MLState rewriter never ran on the shipped models because their state tensors are float32. Would you be up for rebasing this down to the native session? The iOS screens would be easier to review as their own PR. |
b5c95b7 to
d90103d
Compare
|
Rebased onto
Broken the iOS UI changes (OLED Driving Mode, Benchmark Dim Screen, reliable idle timer, and Core ML Placement) out into #31. |
Summary
Loads single-subgraph Core ML
.mlmodelccaches directly throughCoreML.MLModelinstead of ONNX Runtime's C API wrapper, eliminating duplicate runtime memory while preserving full FP16/FP32 precision (allowLowPrecisionAccumulationOnGPU = false):sessions.json): After compiling and verifying the build on ONNX Runtime (OrtBackend.checkCoreML), validates each Core ML cache withCoreMLSession.canRunNatively(...)(single.mlmodelc, 1:1 input/output names, static shapes, and types) and records"native": true/falsedirectly intosessions.json."native"(true→CoreML-Native(...),false→OrtSession, legacy caches without"native"probe once so existingv0.10.4caches still benefit).RequireStaticInputShapes: Keeps ORT'sSessionPlanoptions unchanged frommainso cache directories stay0_dynamic_mlprogramacross--no-native-coremltoggles and existing artifacts.MLMultiArray(dataPointer:...)inputs andMLPredictionOptions.outputBackingsoverEngineCore-owned buffers (skipping output copies when Core ML writes directly into the backing pointer).--no-native-coremlCLI flag: Falls back toOrtSessioncleanly on any model or CLI invocation.v0.10.4pipelining & keep-warm:CoreMLSession/CoreMLBindingconform toEngineSession/EngineBinding, sorunAhead()andCPUKeepWarm.workStarted()/workEnded()work identically.Verification (Apple M5 Max, macOS 26.7.3, Release, 20 Hz,
v0.10.4)With
v0.10.4running all 966 ops (vision502/502 +policy464/464) on the Neural Engine under--device ane-both:--device ane-both)--no-native-coreml)CoreML(CPUAndNeuralEngine)× 2CoreML-Native(CPUAndNeuralEngine)× 2sessions.jsonrecords"native": trueat build time and a subsequent--no-native-coremlrun keeps a singlecompiled_model.mlmodelcper cache (0_dynamic_mlprogram).swift test --package-path JetlinkKit --filter OrtBackendTests: 11/11 passed (covers split-graph rejection,RequireStaticInputShapes == nil, nativeCPUOnlyexecution,"native": false, andnativeCoreML: false).xcrun swift-format lint --strict --configuration macos/.swift-formatpasses acrossJetlinkKit/SourcesandJetlinkKit/Tests.How to Test