π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
delete old reports
laurenspriem3c9ee2cb76a0
diff --git a/infra/ml/playground/optimizations/benchmark_reports/20260714_IOS_COREML_BENCHMARK_REPORT.md b/infra/ml/playground/optimizations/benchmark_reports/20260714_IOS_COREML_BENCHMARK_REPORT.mddeleted file mode 100644index da38349988..0000000000--- a/infra/ml/playground/optimizations/benchmark_reports/20260714_IOS_COREML_BENCHMARK_REPORT.md+++ /dev/null@@ -1,751 +0,0 @@-# iOS CoreML Benchmark and Execution-Plan Investigation--- **Initial investigation:** 13 July 2026-- **Two-device follow-up:** 14 July 2026-- **Devices:** iPhone 15 Pro (`iPhone16,1`, A17 Pro) and iPhone 11 Pro (`iPhone12,3`, A13), both on iOS 26.5 (`23F77`)-- **Build mode:** Flutter profile build with release-mode Rust-- **Follow-up base revision:** `68bd5ded13`, plus the benchmark-only instrumentation and model-transformation work listed below-- **Original evidence:** [`infra/ml/test/out/ios_coreml_benchmark_artifacts_2026-07-13/`](infra/ml/test/out/ios_coreml_benchmark_artifacts_2026-07-13/)-- **Follow-up evidence:** [`infra/ml/test/out/ios_coreml_strategy_2026-07-14/`](infra/ml/test/out/ios_coreml_strategy_2026-07-14/)--## Final outcome after the two-device follow-up--The requested architecture is viable and is now the recommended target:--> Use the MLProgram format and the `ALL` compute policy for every model, allowing CoreML to choose CPU, GPU, or ANE per operation.--The important qualification is that `ALL` is permission, not a hardware guarantee. On the A17 Pro, CoreML assigned every profiled operation in all three final graphs to the GPU. On the A13, it assigned MobileCLIP and MobileFaceNet to the GPU, but used a 219-GPU/109-CPU split for YOLO. No profiled operation was assigned to the ANE in these runs. That device-dependent choice is exactly why `ALL` is preferable to forcing CPU+GPU or CPU+ANE.--All six requested experiments were completed:--1. MLProgram `Default` and `FastPrediction` specialization were compared on both phones.-2. The ORT-generated MobileCLIP MLProgram package was extracted, inspected, and compiled as a native-package delivery pilot.-3. YOLO was rewritten to static batch 1 and constant-folded.-4. MobileFaceNet's decomposed activations were replaced with native `PRelu` nodes and fixed B1, B4, B8, and B16 variants were produced.-5. Cold conversion, warm loading, first inference, steady inference, storage, memory, power impact, thermal state, and parity were measured.-6. The final candidates were exercised on both an iPhone 11 Pro and an iPhone 15 Pro.--The final production candidate is:--| Model | Recommended model | Format and policy | Specialization | Batch policy |-|---|---|---|---|---|-| YOLO face detector | Static `[1, 3, 640, 640]`, constant-folded ONNX | MLProgram + `ALL` | `Default` | B1 |-| MobileCLIP | Existing fixed `[1, 3, 256, 256]` ONNX | MLProgram + `ALL` | `Default` | B1 |-| MobileFaceNet | PReLU-rewritten, explicit-padding, static ONNX | MLProgram + `ALL` | `Default` | B1 with chunking; consider B4/B8 buckets only if production telemetry justifies them |--This supersedes the initial recommendation below to keep MobileFaceNet on CPU or use a NeuralNetwork/MLProgram hybrid. The graph rewrite changed the result materially: final MobileFaceNet B1 inference is about 1.9 ms on A17 Pro and 4β5 ms on A13, and all 101 operations are assigned to the GPU on both devices.--## Final model transformations--### Static YOLO--The original detector declared a dynamic batch and contained 587 nodes. The final candidate:--- Declares input `[1, 3, 640, 640]` and output `[1, 25200, 16]`.-- Uses ONNX Runtime basic graph optimization to constant-fold the shape graph.-- Contains 328 nodes, with the dynamic `Shape`, `Gather`, and related batch-shape work removed.-- Is 32,355,091 bytes, versus 30,762,872 bytes for the original. The slight size increase is acceptable and comes with a much simpler runtime graph.-- Forms one CoreML Execution Provider partition on both phones.--The old phone still assigns 109 operations to CPU. Static export makes the graph supported and predictable, but it does not make βall GPUβ a portable invariant.--### PReLU MobileFaceNet--The original MobileFaceNet graph contained 267 nodes and represented each PReLU as an arithmetic decomposition involving `Relu`, `Abs`, `Sub`, `Mul`, and `Add`. The final graph contains 101 nodes:--| Operator | Count |-|---|---:|-| `Conv` | 52 |-| `PRelu` | 33 |-| `Add` | 12 |-| `Reshape` | 3 |-| `Transpose` | 1 |--Two details were necessary for a clean CoreML compilation:--- PReLU slopes use CoreML-compatible `[channels, 1, 1]` broadcasting. A `[1, channels, 1, 1]` slope only produced partial CoreML coverage.-- Two valid-padding convolutions that omitted an explicit ONNX `pads` attribute were rewritten with explicit zero pads. The earlier CoreML compiler failureβ`Required param 'pad' is missing`βcame from those convolutions, not from PReLU.--The final redundant `LpNormalization` was removed because the Rust caller already L2-normalizes each returned embedding. CPU equivalence after caller normalization had a maximum absolute difference of `5.96e-8`; the largest observed cosine distance through B16 was approximately `2.98e-7`.--Fixed B1, B4, B8, and B16 models were produced. Each is 5,238,749 bytes and forms one CoreML partition.--## Final compute plans on both phones--`ProfileComputePlan` was enabled only for placement analysis and disabled for the timing runs.--| Model | A17 Pro placement | A13 placement | CoreML-supported ONNX nodes |-|---|---:|---:|---:|-| Static YOLO | 328 GPU | 219 GPU, 109 CPU | 328/328 on both |-| MobileCLIP | 658 GPU | 655 printed GPU plan entries[^clip-plan] | 658/658 on both |-| PReLU MobileFaceNet B1 | 101 GPU | 101 GPU | 101/101 on both |--[^clip-plan]: ORT reported all 658 MobileCLIP nodes in the CoreML partition on A13, while Apple's printed compute plan contained 655 explicit operation-placement lines. The missing three lines appear to be fused or omitted from the textual plan; there was no CPU or ANE placement line for them.--The result supports a uniform provider policy, not a uniform hardware claim. On A17 Pro, the final graphs happen to be fully GPU-placed. On A13, CoreML deliberately keeps part of YOLO on CPU. Neither device selected ANE for these graphs.--## Final timing results--All timings below come from real devices running the profile app, with Rust built in release mode. The timers surround only synchronous ONNX Runtime inference or session creation. Decoding, resize, preprocessing, detector postprocessing, face alignment, and caller-side embedding normalization are excluded.--### Cold conversion and warm session loading--βColdβ uses a new model cache and therefore includes ONNX-to-MLProgram conversion and device compilation. βWarmβ is a relaunch of the same installed app using the existing compiled cache.--| Device | Model | Cold session | Warm session 1 | Warm session 2 |-|---|---|---:|---:|---:|-| A17 Pro | Static YOLO | 372.4 ms | 58.8 ms | 57.8 ms |-| A17 Pro | MobileCLIP | 3,609.0 ms | 560.1 ms | 565.8 ms |-| A17 Pro | MobileFaceNet B1 | 165.5 ms | 26.5 ms | 27.6 ms |-| A13 | Static YOLO | 1,065.1 ms | 257.2 ms | 256.7 ms |-| A13 | MobileCLIP | 5,042.2 ms | 1,400.7 ms | 1,382.0 ms |-| A13 | MobileFaceNet B1 | 410.5 ms | 117.3 ms | 96.8 ms |--Persistent caching is effective. It removes most conversion/compilation work, especially for MobileCLIP, but does not eliminate normal CoreML/session construction or the first hardware-use warm-up.--### First and steady pure inference--| Device | Model | First inference per app launch | Steady result |-|---|---|---:|---:|-| A17 Pro | Static YOLO B1 | 49.7β51.1 ms | 18.8β19.1 ms median across the suite |-| A17 Pro | MobileCLIP B1 | 64.0β66.0 ms | 18.24β18.30 ms median |-| A17 Pro | MobileFaceNet physical B1 | 17.7β19.8 ms | 1.7β2.0 ms per face |-| A17 Pro | MobileFaceNet logical B7 | β | 10.5β10.8 ms total |-| A17 Pro | MobileFaceNet logical B10 | β | 15.0β15.2 ms total |-| A13 | Static YOLO B1 | 161β171 ms | 97.6β99.4 ms median |-| A13 | MobileCLIP B1 | 211β216 ms | 74.7β76.1 ms median |-| A13 | MobileFaceNet physical B1 | 36β43 ms | 4.0β5.3 ms per face |-| A13 | MobileFaceNet logical B7 | β | 27.6β29.8 ms total |-| A13 | MobileFaceNet logical B10 | β | 50.5β51.0 ms total |--The A13 was in the iOS `Fair` thermal state during the Instruments runs and remained `Fair` after an idle recheck; the A17 Pro stayed `Nominal`. The placement result and large MobileFaceNet improvement are robust, but the A13 absolute latency and cross-device ratios should not be treated as a thermally controlled chipset comparison.--### Profiling overhead--`ProfileComputePlan` is extremely intrusive for first inference. With it enabled, MobileFaceNet first inference appeared to take about 1.0 seconds on A17 Pro and 1.56 seconds on A13. With it disabled, the corresponding production-like values were about 18β20 ms and 36β43 ms. Placement evidence must therefore come from profiled runs, while performance evidence must come from unprofiled runs.--## Default versus `FastPrediction`--The missing MLProgram specialization experiment was run in both orders across the two phones. In the controlled A17 warm comparison on the pre-rewrite models:--| Model session | `Default` | `FastPrediction` |-|---|---:|---:|-| YOLO | 421 ms | 409 ms |-| MobileCLIP | 562 ms | 560 ms |-| MobileFaceNet | 1,679 ms | 1,684 ms |--Inference values and outputs were likewise indistinguishable within run noise. An apparent A13 cold-start difference disappeared when execution order was reversed, identifying device-wide warm-up/order effects rather than a specialization benefit.--Recommendation: use `Default`. `FastPrediction` has not demonstrated a repeatable advantage and would add another conversion/cache dimension.--## Bounded MobileFaceNet batch experiment--The B1, B4, B8, and B16 variants were tested by padding a logical input to the model's physical batch and, when necessary, invoking multiple chunks. The table shows representative logical-call latency.--| Device | Physical variant | One face after warm-up | Logical B7 | Logical B10 |-|---|---:|---:|---:|---:|-| A17 Pro | B1 | 1.7β2.0 ms | 10.8 ms | 15.0 ms |-| A17 Pro | B4 | 3.6β3.9 ms | 7.1 ms | **10.3 ms** |-| A17 Pro | B8 | 5.8β6.3 ms | **5.9 ms** | 12.0 ms |-| A17 Pro | B16 | 11.3β12.2 ms | 11.5 ms | 11.4 ms |-| A13 | B1 | 4.0β5.3 ms | 29.8 ms | 51.0 ms |-| A13 | B4 | 10.3β13.4 ms | 23.4 ms | **44.3 ms** |-| A13 | B8 | 18.5β26.2 ms | **20.8 ms** | 49.2 ms |-| A13 | B16 | 34.6β59.3 ms | 41.0 ms | 43.2 ms |--B8 is best for the observed seven-face case and B4 is best for the ten-face case on both devices. B16 is never the best choice. B1 is clearly best for the common one-face case and has the simplest loading, cache, and routing behavior.--One A17 B4 run showed an 874 ms first-use outlier and one A13 B4 run showed a 1.38 second first-use outlier. The A17 outlier did not reproduce on an immediate clean rerun, whose first inference was 21.8 ms. The A13 outlier was not repeated, so no production startup claim should rely on its single value.--Recommendation: ship B1 with chunking first. Add B4 and/or B8 buckets only if production telemetry shows enough multi-face images to justify another model, compiled cache, session, and routing policy. Do not ship B16.--## Output parity--Parity was checked at three levels:--- The final V3 models versus the previous iOS models: 14/14 fixtures passed on both phones. Maximum face-embedding cosine distance was approximately `3.60e-7` on A13 and `6.71e-13` on A17.-- Every B4/B8/B16 candidate versus the B1 iOS reference: all six device/variant candidates passed all 14 fixtures. Across the reported comparisons, maximum CLIP cosine distance was about `9.02e-12`, face-embedding cosine distance about `3.61e-7`, and score/landmark changes remained far below thresholds.-- Final iOS results versus the Python reference: 13/14 fixtures passed on each phone. The only failure was MobileCLIP for `IMG_8905.CR2`; face detection and face embedding passed for that fixture. This is the pre-existing iOS-versus-Python RAW decode difference, not a model-format, graph-rewrite, or cross-device regression.--The two iPhones agree extremely closely with each other. The transformed models therefore preserve the application-visible results within the existing test tolerances.--## Native MobileCLIP delivery/loading pilot--ORT's generated A17 MLProgram cache was extracted into a portable package and compiled on the Mac with `coremlcompiler`:--| Artifact | Size |-|---|---:|-| Existing MobileCLIP ONNX | 143,061,211 bytes |-| Extracted `MobileCLIP-S2.mlpackage` data | 143,308,974 bytes, about 137 MiB |-| Device-compiled `.mlmodelc` | 162,223,783 bytes, about 155 MiB |-| Host `coremlcompiler` compile time | 0.57 s |--This proves the generated package is a valid MLProgram asset and that a package-delivery pilot is technically possible. It also exposes an important architectural boundary:--- ONNX Runtime's CoreML Execution Provider takes ONNX as its model input.-- `ModelCacheDirectory` is an internal cache of the generated `.mlpackage` and device-compiled `.mlmodelc`.-- ORT does not provide a public API to load a CDN-delivered `.mlpackage` as an ORT model.--Therefore βnative MLProgram in ONNX Runtimeβ cannot currently mean one CDN-delivered `.mlpackage` passed to ORT. There are two real choices:--1. Keep the uniform ORT path: deliver ONNX and use ORT's persistent CoreML cache.-2. Deliver a native `.mlpackage` and add a direct CoreML backend on iOS, which is no longer the same ORT loading path.--A portable `.mlpackage` may be distributed and compiled on the phone. A compiled `.mlmodelc` should not be distributed from the CDN because it is tied to CoreML/runtime/device details. The ORT-generated A13 and A17 package hashes also differed, so the runtime-generated packages should not be assumed byte-identical or deterministic even though their outputs were equivalent.--The package is almost the same size as the ONNX file, so native delivery does not materially reduce download size. Its main benefit would be eliminating ORT's ONNX-to-CoreML conversion step. It would still incur device compilation and would require a separate iOS loader.--## Cache and storage findings--The final ORT cache contains both generated package data and compiled model data:--| Model | Generated package data | Compiled data | Total ORT cache |-|---|---:|---:|---:|-| MobileFaceNet B1 | 5.31 MB | 5.40 MB | 10.70 MB |-| Static YOLO | 32.49 MB | 32.50 MB | 65.00 MB |-| MobileCLIP | 143.31 MB | 162.22 MB | 305.53 MB |-| **Total** | **181.11 MB** | **200.12 MB** | **381.23 MB / 363.5 MiB** |--The three ONNX source assets total about 180.7 MB. Keeping those sources plus the full persistent cache therefore consumes about 562 MB after first use. MobileCLIP dominates both conversion time and storage.--Recommendation for the ORT architecture:--- Keep a versioned `ModelCacheDirectory`; warm session loading is materially faster than cold conversion.-- Put it in an evictable, non-backed-up cache location.-- Key it by model SHA, ORT version, model format, compute policy, and specialization policy.-- Establish a storage budget and cleanup policy before rollout.-- Consider caching all three initially: YOLO and MobileFaceNet add only about 72 MB together, while their warm-load reductions are useful. If the total budget is unacceptable, MobileCLIP is both the most valuable cache and the dominant cost, so selective caching cannot make the problem small.--The βoptimizationβ is not a model mutation that can simply be generated once and served as `.mlmodelc`. The portable part can be generated up front as `.mlpackage`, but using it directly requires the separate CoreML backend described above.--## Memory, power, and thermal observations--Instruments captured the whole Flutter parity process while the three models and the complete fixture suite were active:--| Device | Peak physical footprint | Peak resident memory | Thermal state |-|---|---:|---:|---|-| A17 Pro | 974 MiB | 1,004 MiB | Nominal |-| A13 | 563 MiB | 604 MiB | Fair |--These are whole-process peaks, not incremental per-model memory. They include Flutter, decoding, fixtures, preprocessing, ORT, CoreML, all loaded sessions, and Instruments overhead. Without a matched CPU/no-CoreML baseline they are upper-bound characterization, not a CoreML memory delta.--The Power Profiler showed CPU and GPU activity on both phones. Its duration-weighted normalized impact values were approximately:--| Device | CPU impact | GPU impact | Sample window |-|---|---:|---:|---:|-| A17 Pro | 10.00 | 1.20 | about 14 s |-| A13 | 17.96 | 2.12 | about 25 s |--These values are Instruments impact units, not joules. The phones were USB-connected/charging, the windows differed, the A13 was already in `Fair` thermal state, and there is no matched CPU baseline. They confirm GPU use but do not establish an energy saving or permit a fair energy comparison between devices.--A production energy claim requires a separate battery-powered experiment with fixed brightness/radios, cooled devices, isolated repeated inference loops, equal-duration windows, and a CPU baseline. The current latency, placement, storage, and parity evidence is sufficient for the architectural decision; the energy numbers are not.--## Final recommendation and rollout plan--Proceed with one production-facing iOS policy: MLProgram + `ALL` + `Default` specialization for all three models. Use the static YOLO and PReLU/static MobileFaceNet transformations, and leave MobileCLIP's graph as-is.--The rollout should be staged:--1. Land the model-transformation script and reproducibly build the three production ONNX assets.-2. Ship static MobileFaceNet B1 with chunking. Do not add B4/B8 until real face-count telemetry demonstrates a worthwhile end-to-end benefit.-3. Enable MLProgram + `ALL` + `Default` for iOS and enable a versioned, evictable cache.-4. Repeat the 14-fixture parity suite in CI for the final CDN assets and model hashes.-5. Add production telemetry for session creation, first inference, steady inference, cache size/eviction, face-count distribution, and CoreML fallback/errors.-6. Decide separately whether avoiding MobileCLIP's 3.6β5.0 second first-install conversion is worth a native CoreML backend. Do not conflate that decision with enabling the ORT CoreML EP.-7. Before claiming an energy improvement, run the controlled battery-powered test described above on the minimum supported iPhone and an A17-class device.--The architecture should not depend on all operations running on GPU. Its contract should be that CoreML owns the supported model partition and may schedule its operations on CPU, GPU, or ANE. This keeps the configuration uniform while remaining correct across hardware generations.--## Follow-up raw artifact map--The follow-up evidence is stored in the gitignored [`infra/ml/test/out/ios_coreml_strategy_2026-07-14/`](infra/ml/test/out/ios_coreml_strategy_2026-07-14/) directory. The concise aggregate is [`final_findings.json`](infra/ml/test/out/ios_coreml_strategy_2026-07-14/final_findings.json); [`strategy_summary.json`](infra/ml/test/out/ios_coreml_strategy_2026-07-14/strategy_summary.json) retains the detailed per-call timing data.--Key locations:--- Final transformed models and graph inventory: [`model_variants_v3/`](infra/ml/test/out/ios_coreml_strategy_2026-07-14/model_variants_v3/)-- Final B1 two-device cold/warm logs, result JSON, compute plans, cache inventory, and Instruments data: [`final_b1_v3/`](infra/ml/test/out/ios_coreml_strategy_2026-07-14/final_b1_v3/)-- B4/B8/B16 device runs and parity: [`bounded_v3/`](infra/ml/test/out/ios_coreml_strategy_2026-07-14/bounded_v3/)-- MLProgram Default/FastPrediction runs: [`fastprediction/`](infra/ml/test/out/ios_coreml_strategy_2026-07-14/fastprediction/)-- PReLU/padding compiler diagnosis: [`face_compile_diagnostics/`](infra/ml/test/out/ios_coreml_strategy_2026-07-14/face_compile_diagnostics/)-- Native MobileCLIP pilot and compiler logs: [`mobileclip_native_pilot/`](infra/ml/test/out/ios_coreml_strategy_2026-07-14/mobileclip_native_pilot/)--The artifact directory is approximately 281 MiB. It was pruned from approximately 1.6 GiB after analysis: duplicate pulled device caches, superseded model generations, and the reproducible host-compiled `.mlmodelc` copy were removed after their sizes and hashes were recorded. The retained bulk data is the final ONNX variants, the portable MobileCLIP `.mlpackage`, and the raw Instruments traces; logs and result JSON remain intact.--The transformation can be reproduced with [`build_coreml_model_variants.py`](infra/ml/test/tools/build_coreml_model_variants.py). Benchmark-only application/Rust instrumentation remains in the working tree for review; it is not represented as a proposed production change.-------## Original 13 July technical summary--The remainder of this document records the first investigation. Its measurements remain useful historical evidence, but its hybrid recommendation and its statements about the old dynamic MobileFaceNet graph are superseded by the completed follow-up above.--The original expectation that CoreML should be substantially faster is correct, but it depends strongly on the CoreML model format and on choosing an execution policy per model.--- **MLProgram is the major performance unlock for MobileCLIP.** It reduced steady CLIP inference from 225.4 ms on CPU and 94.2 ms with the NeuralNetwork format to 18.6 ms. Its compute plan placed all 658 profiled CLIP operations on the A17 Pro GPU.-- **The NeuralNetwork format remains best for the YOLO face detector.** NeuralNetwork with `ALL` reduced steady detector inference from 171.7 ms on CPU to 11.4 ms. MLProgram was still fast at 20.6 ms, but not as fast as NeuralNetwork for this model.-- **MobileFaceNet should remain on CPU until its model is rewritten.** CPU already completes batch-1 inference in about 7.9 ms. NeuralNetwork CoreML made it slower and caused 1.1β1.5 second dynamic-shape specialization spikes. MLProgram restored stable CPU-like timing, but still incurred substantial session setup and generated unbounded-shape warnings.-- **`CPUAndNeuralEngine` did not use the Neural Engine for the MLProgram graphs on this device.** Every profiled operation was assigned to the CPU. `ALL` and `CPUAndGPU` instead used the GPU and were substantially faster.-- **Persistent model caching fixes much of the compilation cost, especially for CLIP, but costs roughly 300β353 MiB per configuration.** It does not fully solve MobileFaceNet's dynamic specialization cost.-- **`FastPrediction` did not produce a meaningful improvement in the controlled NeuralNetwork comparison.** It neither changed steady timings nor eliminated dynamic-batch spikes.-- **Numerical parity was excellent for every tested MLProgram policy.** NeuralNetwork `CPUAndGPU`, however, generated severely incorrect embeddings on multi-face inputs and failed two of fourteen fixtures.--The strongest measured uniform configuration is **MLProgram + `ALL` + cache + `FastPrediction`**, which reduced the sum of all timed inference calls from 5.85 seconds on CPU to 0.87 seconds, a 6.7Γ speedup, while passing all parity checks.--The likely best production configuration is a **per-model hybrid**:--- YOLO face detector: NeuralNetwork + `ALL` + persistent cache.-- MobileCLIP: MLProgram + `ALL` + persistent cache.-- MobileFaceNet: CPU until the model is rewritten with bounded shapes and CoreML-friendly operators.--That hybrid is an evidence-backed recommendation inferred from the isolated per-model measurements; it has not yet been run as one combined application configuration.--## The main result: MLProgram delivers the expected CoreML speedup--The table below reports warm-run pure-inference measurements. The detector and CLIP columns are medians after excluding each model's first inference. Face batch 7 and batch 10 are their observed calls. βAll callsβ sums every timed inference in the 14-fixture suite, including first-use calls and dynamic batches.--| Configuration | Detector B1 | CLIP B1 | Face B1 | Face B7 | Face B10 | All inference calls |-|---|---:|---:|---:|---:|---:|---:|-| CPU | 171.7 ms | 225.4 ms | 7.9 ms | 55.7 ms | 78.9 ms | 5,847 ms |-| NeuralNetwork `ALL` | **11.4 ms** | 94.2 ms | 19.6 ms | 1,416 ms | 319 ms | 4,471 ms |-| NeuralNetwork `CPUAndNeuralEngine` | 11.5 ms | 93.8 ms | 19.9 ms | 1,443 ms | 321 ms | 4,514 ms |-| NeuralNetwork `CPUAndGPU` | 33.7 ms | 194.5 ms | 16.3 ms | 164 ms | 223 ms | 3,906 ms[^invalid-nn-gpu] |-| MLProgram `ALL` | 20.6 ms | **18.6 ms** | **7.9 ms** | **55.2 ms** | **80.9 ms** | **871 ms** |-| MLProgram `CPUAndNeuralEngine` | 43.0 ms | 42.0 ms | 8.1 ms | 62.9 ms | 90.9 ms | 1,431 ms |-| MLProgram `CPUAndGPU` | 22.7 ms | 18.7 ms | 7.9 ms | 55.8 ms | 82.6 ms | 894 ms |-| MLProgram `ALL`, static-input restriction | 182.3 ms | 25.1 ms | 8.0 ms | 58.4 ms | 82.9 ms | 3,142 ms |--[^invalid-nn-gpu]: NeuralNetwork `CPUAndGPU` is not a valid production option despite its timing. It produced incorrect multi-face embeddings and failed parity for `people.jpeg` and `ui_app.webp`.--### Per-model interpretation--#### YOLO face detection--- CPU: 171.7 ms.-- NeuralNetwork `ALL`: 11.4 ms, approximately 15.1Γ faster than CPU.-- MLProgram `ALL`: 20.6 ms, approximately 8.3Γ faster than CPU.-- MLProgram `CPUAndNeuralEngine`: 43.0 ms because the profiled graph ran on CPU rather than ANE.-- Static-input restriction without changing the actual ONNX input declaration: 182.3 ms, effectively CPU performance.--The current YOLO ONNX input is declared as `[batch, 3, 640, 640]`, although the application always supplies batch 1. The graph contains dynamic shape work including `Shape`, `Gather`, `Reshape`, `Concat`, and related operations. Fixing the exported input to `[1, 3, 640, 640]` and constant-folding the resulting shape graph should reduce CPU-side shape work and make the model easier to compile.--#### MobileCLIP--- CPU: 225.4 ms.-- NeuralNetwork `ALL`: 94.2 ms, only about 2.4Γ faster than CPU.-- MLProgram `ALL`: 18.6 ms, approximately 12.2Γ faster than CPU.-- MLProgram `CPUAndGPU`: 18.7 ms, effectively identical to `ALL`.-- MLProgram `CPUAndNeuralEngine`: 42.0 ms because the whole profiled graph was assigned to CPU.--The model has a fixed `[1, 3, 256, 256]` input. Its 879-node ONNX graph includes 54 `Erf` operations and three `ReduceMean` operations. These operations fragmented or limited the NeuralNetwork-format path. With MLProgram, all 658 profiled runtime operations, including all `erf` and `reduce_mean` operations, were assigned to the GPU.--This is the clearest reason the earlier global CoreML experiment was less impressive than expected: the default NeuralNetwork format did not accelerate CLIP nearly as effectively as MLProgram.--#### MobileFaceNet--- CPU batch 1: 7.9 ms.-- NeuralNetwork `ALL` batch 1: 19.6 ms.-- NeuralNetwork dynamic batch 7: approximately 1.42 seconds in the warm run.-- MLProgram `ALL` batch 1: 7.9 ms.-- MLProgram `ALL` batch 7: 55.2 ms.-- MLProgram `ALL` batch 10: 80.9 ms.--MobileFaceNet's input is `[dynamic batch, 112, 112, 3]`. The NeuralNetwork format repeatedly specialized or compiled when the face count changed, causing the dominant 1.1β1.5 second latency spikes. MLProgram avoided those spikes, but its resulting performance was essentially the same as CPU, while its session still produced unbounded-dimension and shape-propagation warnings.--Because the CPU path is already fast and numerically stable, routing this model through CoreML currently adds complexity and startup cost without a meaningful inference benefit.--### Full parity-runner duration is directionally consistent but secondary--The integration-test timer includes lazy session creation, decoding, preprocessing, postprocessing, and other application work, so it is not used as the primary inference metric. It nevertheless shows the same broad outcome:--| Cold test configuration | Flutter test duration |-|---|---:|-| CPU | 26 s |-| NeuralNetwork `ALL`, no cache/default specialization | 29 s |-| NeuralNetwork `ALL`, cache/default specialization | 34 s |-| NeuralNetwork `ALL`, cache/`FastPrediction` | 21 s |-| NeuralNetwork `CPUAndNeuralEngine` | 21 s |-| NeuralNetwork `CPUAndGPU` | 14 s[^invalid-nn-gpu] |-| MLProgram `ALL`, profiling enabled | 27 s |-| MLProgram `CPUAndNeuralEngine`, profiling enabled | 22 s |-| MLProgram `CPUAndGPU`, profiling enabled | 22 s |-| MLProgram static-input restriction, profiling enabled | 18 s |-| MLProgram `ALL`, profiling disabled | **15 s** |--These one-pass end-to-end values are more sensitive to cache state, fixture staging, decoding, thermal state, and profiler overhead than the model-only timers. In particular, the 14-second NeuralNetwork GPU result is invalidated by its output-parity failure.--## Compute-plan profiling explains the hardware behavior--`ProfileComputePlan` was enabled for the format and compute-unit matrix. MLProgram emitted an operation-placement plan for each CoreML-compiled partition in the device console.--| Model | MLProgram `ALL` / `CPUAndGPU` | MLProgram `CPUAndNeuralEngine` |-|---|---:|---:|-| YOLO face detector | 211 GPU, 50 CPU | 261 CPU, 0 ANE |-| MobileCLIP | 658 GPU | 658 CPU, 0 ANE |-| MobileFaceNet | 160 GPU, 63 CPU | 223 CPU, 0 ANE |--### What the plan means--- `ALL` and `CPUAndGPU` produced the same operation assignment for these MLProgram graphs.-- `CPUAndNeuralEngine` assigned no profiled operation to ANE on this A17 Pro.-- MobileCLIP is an unusually clean GPU workload in MLProgram: all 658 profiled runtime operations ran on the GPU.-- YOLO kept shape-oriented operations on CPU while convolution, activation, pooling, and most arithmetic ran on GPU.-- MobileFaceNet alternated between CPU and GPU within the converted graph, while some ONNX operations were not represented in the CoreML plan.--For YOLO under MLProgram `ALL`, GPU placement comprised 62 convolution operations, 61 sigmoid operations, 61 multiplications, four max-pools, fourteen concatenations, seven additions, and two nearest-neighbor upsampling operations. CPU placement comprised shape, reshape, gather, squeeze, concat, and two convolution operations.--For MobileCLIP, the plan placed 189 convolutions, 54 divisions, 54 `erf` operations, 102 additions, 163 multiplications, all reductions, matrix operations, softmax operations, and the remaining runtime graph on GPU.--For MobileFaceNet, the plan placed 160 operations on GPU and 63 on CPU. The device also reported numerous unbounded-dimension errors around the dynamic input and tensors associated with the decomposed `Abs` activation sequences, plus an invalid-rank shape-propagation warning involving `squeeze`.--The NeuralNetwork format did not emit per-operation placement lines on this runtime even when `ProfileComputePlan` was enabled. Its `ALL` and `CPUAndNeuralEngine` timings were nearly identical, but the absence of a plan means the exact NeuralNetwork hardware assignment was not directly observed.--The underlying provider options and dynamic-shape caveats are documented by the [ONNX Runtime CoreML Execution Provider](https://onnxruntime.ai/docs/execution-providers/CoreML-ExecutionProvider.html). Apple's corresponding profiling workflow is described in [Optimize your Core ML usage](https://developer.apple.com/videos/play/wwdc2022/10027/).--## Compilation can be improved, but caching has a storage cost--`ModelCacheDirectory` stored actual converted models and compiled `.mlmodelc` packages. A true same-install relaunch confirmed that these artifacts were reused.--Session creation was timed separately from inference. The MLProgram values below come from the final no-profile run so that compute-plan enumeration and console output do not contaminate the result.--| Model | NeuralNetwork cold | NeuralNetwork warm | Reduction | MLProgram cold | MLProgram warm | Reduction |-|---|---:|---:|---:|---:|---:|---:|-| YOLO detector | 1,496 ms | 133 ms | 91% | 595 ms | 408 ms | 31% |-| MobileCLIP | 4,103 ms | 595 ms | 86% | 3,576 ms | 555 ms | 84% |-| MobileFaceNet | 1,352 ms | 1,124 ms | 17% | 2,467 ms | 1,709 ms | 31% |--### Cache findings--- Caching is highly effective for CLIP in both formats.-- Caching is highly effective for NeuralNetwork YOLO.-- Caching only modestly improves MobileFaceNet because dynamic shape handling and specialization remain.-- A cache does not remove the first hardware-use warm-up. In the no-profile MLProgram run, the first detector and CLIP inferences were about 66β69 ms before settling near 18β25 ms.-- The cache must be versioned or invalidated when a model changes. A production cache key should include the model SHA and all conversion options that affect the generated package.--### Cache storage--The on-device file inventory showed the following total cache sizes for one complete three-model configuration:--| Cache configuration | Size |-|---|---:|-| NeuralNetwork variants | approximately 300.4 MiB each |-| MLProgram variants | approximately 353.1 MiB each |-| MLProgram static-input restriction | approximately 291.4 MiB |--The MLProgram cache contained both generated model/weight data and compiled model/weight data. For example, the CLIP partitions included a roughly 129.9 MiB weight file in both the generated and compiled representation.--A production implementation should therefore:--- Cache selectively per model rather than automatically caching every session.-- Use an evictable, non-backed-up directory.-- Version the cache by model SHA and provider configuration.-- Measure the storage impact on a normal installation before enabling it globally.-- Consider replacing the iOS ONNX asset with a native CoreML asset rather than retaining both formats indefinitely.--## `FastPrediction` was not a solution--The NeuralNetwork `ALL` cache-default and cache-`FastPrediction` configurations were compared on same-install warm runs:--| Measurement | Default specialization | `FastPrediction` |-|---|---:|---:|-| Detector batch 1 | 11.42 ms | 11.36 ms |-| CLIP batch 1 | 93.81 ms | 94.20 ms |-| Face batch 1 | 19.77 ms | 19.62 ms |-| Face batch 7 | 1,414.61 ms | 1,416.03 ms |-| Sum of inference calls | 4,467.3 ms | 4,471.1 ms |--These differences are negligible and within run-to-run noise. Most importantly, `FastPrediction` did not eliminate MobileFaceNet's dynamic-shape spike.--`FastPrediction` remained enabled for the MLProgram matrix, but a separate MLProgram default-versus-fast experiment was not run. Nothing in the current evidence establishes an MLProgram benefit from this option.--## Static shapes require re-exporting the models--The `RequireStaticInputShapes` diagnostic did not make the current dynamic models static. It instead prevented CoreML from taking most or all of those graphs:--- YOLO detector inference regressed to approximately 182 ms, effectively CPU performance.-- MobileFaceNet remained at CPU-like timing, and it emitted no CoreML operation plan.-- MobileCLIP remained accelerated because it already has a static input, although its steady timing was approximately 25 ms rather than the 18.6 ms observed without the restriction.-- The static-only compute plan showed all 658 CLIP operations on GPU, only a small CPU shape subgraph for YOLO, and no MobileFaceNet CoreML plan.--The useful static-shape experiment is therefore not another provider flag. It is a new model export:--- Export YOLO with a fixed batch of 1.-- Export MobileFaceNet as fixed batch 1, bounded flexible shapes, or a small set of fixed batch buckets.-- Re-run the operation plan and parity suite on those exported models.--For MobileFaceNet, fixed buckets such as 1, 2, 4, 8, and 16 with padding are likely more CoreML-friendly than an unbounded batch. A native CoreML package could alternatively use bounded or enumerated input shapes.--## Unsupported operators have practical graph-level workarounds--### MobileCLIP: use MLProgram--The current CLIP blockers do not need manual graph rewriting. MLProgram successfully represented and assigned all profiled runtime operations, including `Erf` and `ReduceMean`, to GPU. This is already a working whole-model CoreML route.--### MobileFaceNet: replace the decomposed activation with `PRelu`--The MobileFaceNet graph contains 33 repetitions of this activation sequence:--```text-Relu(x) + alpha * (x - Abs(x)) * 0.5-```--Because `(x - |x|) / 2` is `min(x, 0)`, the sequence is mathematically:--```text-max(x, 0) + alpha * min(x, 0)-```--That is PReLU. The model should be re-exported with PReLU preserved or mechanically rewritten to a single ONNX `PRelu` operation. This removes all 33 `Abs` operations and gives the CoreML converter a direct activation operator rather than an unsupported or poorly specialized decomposition.--The rewrite is mathematically exact subject to the same alpha broadcasting. It still requires end-to-end parity validation because converter numerics, broadcasting, and floating-point ordering may differ.--### MobileFaceNet: remove redundant in-model normalization--The final ONNX operation is `LpNormalization`. Rust subsequently L2-normalizes every embedding again in `run_face_embedding`. Removing the in-model normalization and retaining the Rust normalization should preserve ordinary outputs while removing another CoreML boundary.--This change needs explicit testing for zero and near-zero embeddings because ONNX and Rust may use different epsilon behavior. It should not be accepted solely on the algebraic argument.--### What βthe whole model on CoreMLβ means--These rewrites should make it possible for the functional graph to be represented by CoreML. They do not guarantee that every operation runs on GPU or ANE. CoreML may legitimately schedule operations on CPU, GPU, or ANE inside one model.--Moving a final normalization step into Rust still preserves the full application pipeline, but it means the literal normalization operation is no longer inside the CoreML model. If the strict requirement is a single native CoreML package containing every operation, the package must express an equivalent supported normalization.--## MLProgram preserved output parity; NeuralNetwork GPU did not--All candidates were compared against the CPU results generated on the same iPhone. The standard parity tool checked fourteen fixtures, including single-face, multi-face, orientation, HEIC, RAW, panorama, text, and no-face cases.--| Candidate | Files passed | Max CLIP cosine distance | Max face-embedding cosine distance | Result |-|---|---:|---:|---:|---|-| MLProgram `ALL` | 14/14 | `1.58e-12` | `1.01e-6` | Pass |-| MLProgram `CPUAndNeuralEngine` | 14/14 | `1.38e-11` | `5.14e-7` | Pass |-| MLProgram `CPUAndGPU` | 14/14 | `1.58e-12` | `1.01e-6` | Pass |-| MLProgram static-input restriction | 14/14 | `1.58e-12` | `2.22e-16` | Pass |-| NeuralNetwork `ALL` | 14/14 | `1.09e-4` | `2.60e-4` | Pass |-| NeuralNetwork `CPUAndNeuralEngine` | 14/14 | `1.09e-4` | `2.60e-4` | Pass |-| NeuralNetwork `CPUAndGPU` | 12/14 | `9.08e-5` | **`1.094`** | **Fail** |--MLProgram was not merely within tolerance; its CLIP outputs were essentially identical to CPU, and its face embeddings differed only at a very small floating-point level.--NeuralNetwork `CPUAndGPU` retained acceptable detector boxes, landmarks, scores, and CLIP output, but generated unusably different face embeddings for the multi-face fixtures:--- `people.jpeg`-- `ui_app.webp`--The maximum face-embedding cosine distance was 1.094, with many matched faces showing distances around 0.74β1.05. The failure correlates with dynamic multi-face batches, but the benchmark does not establish whether the root cause is an ONNX Runtime CoreML bug, CoreML specialization behavior, or a model-specific GPU issue. This configuration must not be shipped without a separately diagnosed fix.--The complete comparison is available in [`parity_comparison.json`](infra/ml/test/out/ios_coreml_benchmark_artifacts_2026-07-13/parity_comparison.json).--## Why the original CoreML result was not dramatically faster--The earlier result was the combination of one large win, one partial win, and one regression:--1. YOLO became approximately 15Γ faster with NeuralNetwork CoreML.-2. CLIP became only approximately 2.4Γ faster because the NeuralNetwork format did not handle its graph nearly as effectively as MLProgram.-3. MobileFaceNet became slower for batch 1 and introduced second-scale specialization spikes when the batch changed.-4. Session conversion and compilation added several seconds on a cold start.--Those MobileFaceNet spikes almost completely cancelled the detector acceleration in the aggregate NeuralNetwork timing. Once CLIP moved to MLProgram and MobileFaceNet returned to stable CPU-like execution, the aggregate improvement became the expected 6.7Γ.--This was not a simulator or debug-build artifact. The measurements were obtained from a real A17 Pro device in a profile build with release-mode Rust.--## Native CoreML packages are promising, especially for CLIP--The repository currently contains ONNX assets, not ready native CoreML packages for these three models, and the application does not have a native CoreML package loader for this path. A direct native-package device benchmark would therefore have required new implementation code, which was outside the no-code-change constraint of this investigation.--The ONNX Runtime cache nevertheless demonstrated that converted MLProgram packages compile and run successfully on the device. It also exposed reasons to consider a native package:--- ORT creates multiple partition artifacts rather than one intentionally exported model.-- Generated and compiled weights are both stored, producing a 353 MiB three-model cache.-- Runtime conversion still costs several seconds on a cold install.-- A native package can express bounded or enumerated shapes more deliberately.-- A direct export from the original PyTorch model may preserve high-level operations better than converting an already lowered ONNX graph.--MobileCLIP is the best native-package pilot because:--- It already has a fixed input shape.-- MLProgram shows a clear 12Γ inference win.-- Its entire profiled runtime graph runs on GPU.-- Its runtime conversion and duplicated weights dominate the cache cost.--A native package should replace the iOS ONNX asset for that model rather than coexist permanently, otherwise the installation pays for both large representations.--## Original recommended implementation direction (superseded)--### Option A: measured uniform configuration--Use MLProgram + `ALL` + persistent cache for all three models.--Advantages:--- Measured 6.7Γ aggregate pure-inference speedup over CPU.-- Excellent parity across all fourteen fixtures.-- One uniform CoreML policy.-- Stable MobileFaceNet batch behavior.--Disadvantages:--- YOLO is roughly 9 ms slower per inference than with NeuralNetwork.-- MobileFaceNet gains no meaningful inference speed but retains about 1.7 seconds of warm session setup.-- Approximately 353 MiB of cache storage.-- MobileFaceNet continues to produce dynamic-shape warnings.--### Option B: recommended per-model hybrid--Use:--- NeuralNetwork + `ALL` + cache for YOLO.-- MLProgram + `ALL` + cache for MobileCLIP.-- CPU for MobileFaceNet.--Advantages:--- Selects the fastest valid measured path for each model.-- Avoids MobileFaceNet's CoreML session and dynamic-shape complexity.-- Retains the detector's 11.4 ms timing and CLIP's 18.6 ms timing.-- Avoids the invalid NeuralNetwork GPU embedding path.--Disadvantages:--- More policy and cache-management code.-- The combined hybrid has not yet been benchmarked as one build.-- Caching both YOLO and CLIP may still consume significant storage.--This is the recommended direction, but it should be validated as a combined build before being merged.--### Options that should not be selected--- Do not use NeuralNetwork `CPUAndGPU`; it failed face-embedding parity.-- Do not force `CPUAndNeuralEngine` for these models; the MLProgram compute plan assigned zero operations to ANE and performance was worse.-- Do not expect `FastPrediction` to fix dynamic batches.-- Do not enable `RequireStaticInputShapes` until the dynamic models themselves have been re-exported with fixed or bounded shapes.--## Original proposed next experiments (completed above)--Before making the production change, the following sequence gives the highest information value:--1. **Build and benchmark the per-model hybrid.** Confirm the combined pure-inference total, cold/warm session cost, parity, and cache size.-2. **Rewrite MobileFaceNet's decomposed PReLU sequences and remove redundant `LpNormalization`.** Run ONNX CPU parity before any CoreML test.-3. **Export fixed-shape MobileFaceNet variants.** Compare batch 1, a fixed maximum padded batch, and bucketed batches.-4. **Export YOLO with batch 1 fixed.** Re-run MLProgram and NeuralNetwork compute plans to see whether the 50 CPU operations shrink.-5. **Prototype native MLProgram MobileCLIP.** Measure package size, load time, first inference, steady inference, memory, power, and parity.-6. **Repeat the winning candidates in randomized order.** Use at least 5β10 runs per configuration and record thermal state to separate small differences from run-order noise.-7. **Measure energy and memory.** This investigation measured latency and output parity, not sustained power, thermal throttling, or peak memory.--## Scope and methodology--### Test corpus--The existing iOS ML parity runner processed fourteen fixtures spanning:--- JPEG, PNG, WebP, HEIC, and CR2 inputs.-- Rotation and mirroring metadata.-- Panorama and normal aspect ratios.-- No-face, single-face, and multi-face cases.-- Images containing text and app UI.--### Models--| Role | Asset | SHA-256 |-|---|---|---|-| Face detection | `yolov5s_face_640_640_dynamic.onnx` | `71a008707283b03db4881449a24f4da197f9dbd9ddaca5c91fcdb363fbf7e06f` |-| Face embedding | `mobilefacenet_opset15.onnx` | `472a0f7e24d0b070cbbdc031b085bc2a06c70655b3bdefb87dbd69bc98662f45` |-| CLIP image embedding | `mobileclip_s2_image.onnx` | `ef54ec66c687603eb4dd303e20d9b67e81069d3133b1c69a70028c76718b7752` |--### Configuration matrix--The investigation built and ran:--- CPU baseline.-- NeuralNetwork `ALL`, no cache, default specialization.-- NeuralNetwork `ALL`, cache, default specialization.-- NeuralNetwork `ALL`, cache, `FastPrediction`.-- NeuralNetwork `CPUAndNeuralEngine`, cache, `FastPrediction`.-- NeuralNetwork `CPUAndGPU`, cache, `FastPrediction`.-- MLProgram `ALL`, cache, `FastPrediction`, with compute-plan profiling.-- MLProgram `CPUAndNeuralEngine`, cache, `FastPrediction`, with compute-plan profiling.-- MLProgram `CPUAndGPU`, cache, `FastPrediction`, with compute-plan profiling.-- MLProgram `ALL`, cache, `FastPrediction`, static-input restriction, with profiling.-- MLProgram `ALL`, cache, `FastPrediction`, without profiling for uncontaminated startup and inference timing.--### Timing boundaries--Timers were placed immediately around the synchronous ONNX Runtime inference calls in Rust:--- Face detection: `onnx::run_f32_data`.-- Face embedding: `onnx::run_f32`.-- CLIP image embedding: `onnx::run_f32`.--The reported inference measurements therefore exclude:--- File I/O and fixture download.-- Image decoding and color-profile conversion.-- Resize, normalization, crop, and alignment preprocessing.-- Face detector postprocessing and non-max suppression.-- Embedding normalization performed after model output.-- ONNX Runtime session creation.--Session creation was timed and reported separately.--The logs also contain two expected non-model warnings: an embedded ICC profile could not be converted for one fixture, and CR2 decoding fell back from the general image decoder to the TIFF fallback because of an unsupported photometric interpretation. Both paths completed successfully, every relevant fixture was processed, and neither decode path is included in the pure-inference timers.--The report uses exact tables rather than charts because the experiment has one primary cold and warm suite per configuration, not a repeated distribution or time series. A chart would make the precision look stronger than the sampling design supports; the tables retain the auditable measured values.--### Cold and warm definition--- A cold configuration used a unique cache subdirectory and performed its first model conversion/compilation.-- A warm configuration relaunched the same installed app with the same data container and cache.-- Flutter-drive reruns that reinstalled or failed to expose the VM service were not used to claim cache effectiveness.-- The final MLProgram timing run disabled compute-plan profiling because profiling generated extensive per-operation output and distorted startup behavior.--### Profiling overhead--The MLProgram profile-enabled run took substantially longer during model load and, in one cold run, showed first detector and CLIP inferences near 934 ms and 2.07 seconds. The corresponding no-profile run showed first inferences near 68β71 ms and a complete test duration of approximately 15 seconds rather than 27 seconds.--Those profile-enabled startup values are treated as instrumented diagnostic behavior, not production latency. Operation placement comes from the profile-enabled runs; timing recommendations use the no-profile run where available.--## Limitations and robustness--- Each configuration received one primary cold suite and one same-install warm suite rather than many randomized repetitions.-- Medians across fixtures reduce individual-image noise, but configurations were executed sequentially, so thermal state and run order may affect small differences.-- The large differencesβsuch as CLIP at 225 ms versus 18.6 ms, or NeuralNetwork face batch 7 at 1.4 seconds versus MLProgram at 55 msβare far larger than plausible run noise.-- The benchmark measures latency and output parity, not energy, sustained thermal behavior, peak memory, or application responsiveness under concurrent work.-- `ProfileComputePlan` did not expose NeuralNetwork-format operation placement, so NeuralNetwork hardware assignment is inferred only from controlled compute-unit behavior, not directly observed.-- The direct native CoreML package path was assessed but not benchmarked because no native packages or loader existed in scope.-- The recommended hybrid combines independently measured best paths; its integrated performance, cache behavior, and parity still need direct validation.-- The operator rewrites are algebraically motivated but have not yet been applied or parity-tested.--## Raw artifact map--All retained raw output is under the gitignored [`infra/ml/test/out/ios_coreml_benchmark_artifacts_2026-07-13/`](infra/ml/test/out/ios_coreml_benchmark_artifacts_2026-07-13/) directory. It contains 35 logs and 14 JSON files, 49 files in total, occupying approximately 12 MiB. It is a byte-for-byte copy of the original benchmark output; the aggregate source and destination manifest SHA-256 was:--```text-7f7b90e0953b7948f1b9d73b6292e76584a533557bf67a3d9b625d7d06f7efb9-```--Key evidence files:--- CPU baseline: [`cpu/run.log`](infra/ml/test/out/ios_coreml_benchmark_artifacts_2026-07-13/cpu/run.log) and [`cpu/results.json`](infra/ml/test/out/ios_coreml_benchmark_artifacts_2026-07-13/cpu/results.json).-- NeuralNetwork default/no-cache: [`nn_all_nocache_default/run.log`](infra/ml/test/out/ios_coreml_benchmark_artifacts_2026-07-13/nn_all_nocache_default/run.log).-- NeuralNetwork cache/default cold and true warm: [`nn_all_cache_default/cold.log`](infra/ml/test/out/ios_coreml_benchmark_artifacts_2026-07-13/nn_all_cache_default/cold.log) and [`manual_warm.log`](infra/ml/test/out/ios_coreml_benchmark_artifacts_2026-07-13/nn_all_cache_default/manual_warm.log).-- NeuralNetwork `ALL` + fast: [`nn_all_cache_fast/`](infra/ml/test/out/ios_coreml_benchmark_artifacts_2026-07-13/nn_all_cache_fast/).-- NeuralNetwork CPU+ANE: [`nn_ane_cache_fast/`](infra/ml/test/out/ios_coreml_benchmark_artifacts_2026-07-13/nn_ane_cache_fast/).-- NeuralNetwork CPU+GPU: [`nn_gpu_cache_fast/`](infra/ml/test/out/ios_coreml_benchmark_artifacts_2026-07-13/nn_gpu_cache_fast/).-- MLProgram `ALL` compute plan: [`mlp_all_cache_fast/warm.log`](infra/ml/test/out/ios_coreml_benchmark_artifacts_2026-07-13/mlp_all_cache_fast/warm.log).-- MLProgram CPU+ANE compute plan: [`mlp_ane_cache_fast/warm.log`](infra/ml/test/out/ios_coreml_benchmark_artifacts_2026-07-13/mlp_ane_cache_fast/warm.log).-- MLProgram CPU+GPU compute plan: [`mlp_gpu_cache_fast/warm.log`](infra/ml/test/out/ios_coreml_benchmark_artifacts_2026-07-13/mlp_gpu_cache_fast/warm.log).-- MLProgram static-input diagnostic: [`mlp_all_cache_fast_static/`](infra/ml/test/out/ios_coreml_benchmark_artifacts_2026-07-13/mlp_all_cache_fast_static/).-- MLProgram `ALL` uncontaminated timing: [`mlp_all_cache_fast_noprofile/`](infra/ml/test/out/ios_coreml_benchmark_artifacts_2026-07-13/mlp_all_cache_fast_noprofile/).-- Parity comparison: [`parity_comparison.json`](infra/ml/test/out/ios_coreml_benchmark_artifacts_2026-07-13/parity_comparison.json).-- On-device cache file inventory: [`device_files.json`](infra/ml/test/out/ios_coreml_benchmark_artifacts_2026-07-13/device_files.json).--## Original decision questions (answered by the follow-up)--The evidence supports discussing these concrete choices:--1. Should the first production change be the measured uniform MLProgram configuration, or the faster but not-yet-integrated per-model hybrid?-2. Is a 300β353 MiB CoreML cache acceptable, or should caching be selective and/or capped?-3. Should MobileFaceNet stay on CPU for the first release while its graph and batch model are rewritten?-4. Is a native MobileCLIP package worth a separate implementation phase to reduce conversion time and duplicate storage?-5. What minimum iOS version should the MLProgram route support, and does the app need a fallback policy for older devices?--The original run removed its temporary instrumentation. The two-device follow-up instrumentation and reproducible model-transformation script remain in the working tree for review, as documented in the current artifact map above.diff --git a/infra/ml/playground/optimizations/benchmark_reports/20260715_ANDROID_ONNX_RUNTIME_BENCHMARK_REPORT.md b/infra/ml/playground/optimizations/benchmark_reports/20260715_ANDROID_ONNX_RUNTIME_BENCHMARK_REPORT.mddeleted file mode 100644index 1ffb80abc7..0000000000--- a/infra/ml/playground/optimizations/benchmark_reports/20260715_ANDROID_ONNX_RUNTIME_BENCHMARK_REPORT.md+++ /dev/null@@ -1,213 +0,0 @@-# Android ONNX Runtime Execution Provider Benchmark--- **Date:** 15 July 2026-- **Device:** Pixel 8 (`shiba`), Google Tensor G3, Android 16 / API 36-- **Build:** Flutter profile build with release-mode Rust-- **ONNX Runtime:** 1.27.0, `ort` revision `31c8f1443b`-- **Models:** the final iOS-optimized ONNX models plus unchanged MobileCLIP-- **Raw evidence:** [`infra/ml/test/out/android_ort_benchmark_2026-07-15/`](../../../test/out/android_ort_benchmark_2026-07-15/)-- **Machine-readable focused summaries:** [`focused_strategy_summary.csv`](../../../test/out/android_ort_benchmark_2026-07-15/focused_strategy_summary.csv) and [`focused_strategy_summary.json`](../../../test/out/android_ort_benchmark_2026-07-15/focused_strategy_summary.json)--## Outcome--On this Pixel 8, changing the Android provider chain from the current-`NNAPI -> XNNPACK -> CPU` strategy to `XNNPACK (4 threads) -> CPU` preserves-the application-visible results and reduces the measured model-loading plus-inference workload by approximately **36%** against the exact production-configuration. A deliberately conservative controlled comparison, in which-spinning was also disabled for the current strategy's final CPU session, still-improved by approximately **31%**.--The result is not uniform across the three models:--| Model | Current steady p50 | XNNPACK4 steady p50 | Change |-|---|---:|---:|---:|-| YOLO face detector B1 | 350.6 ms | 204.4 ms | **41.7% faster** |-| MobileCLIP B1 | 428.5 ms | 301.6 ms | **29.6% faster** |-| MobileFaceNet B1 | 13.8 ms | 19.4 ms | **40.3% slower** |--For a single simple Android policy, `XNNPACK4 -> CPU` is the better choice on-the Pixel 8 because YOLO and MobileCLIP dominate total inference time. For the-lowest possible latency, use XNNPACK4 for YOLO and MobileCLIP but use the CPU EP-directly for MobileFaceNet. The latter avoids both XNNPACK's MobileFaceNet-regression and the current strategy's failed NNAPI setup attempts.--## Scope--The focused decision compares only:--1. Current: `NNAPI(disable_cpu=true) -> XNNPACK -> CPU`.-2. Candidate: `XNNPACK(intra_op_num_threads=4) -> CPU`, with ORT intra-op- threads fixed at one and intra-op spinning disabled as recommended for the- XNNPACK provider.--QNN, WebGPU, and other providers were deliberately excluded. QNN would not be-applicable to the Google Tensor G3 in any case.--The candidate's four-thread setting was selected from the completed XNNPACK-thread sweep. Four threads was the best balanced point: larger pools improved-YOLO slightly but regressed MobileCLIP and MobileFaceNet.--## Models under test--| Model | Path | SHA-256 | Input |-|---|---|---|---|-| YOLO face detector | `infra/ml/playground/optimizations/models/yolov5s_face_640_640_static_b1.onnx` | `e047647409403d52696035ecd445792173e50d7fbdcccac97b958a585db9aa3d` | `[1,3,640,640]` |-| MobileFaceNet | `infra/ml/playground/optimizations/models/mobilefacenet_prelu_static_b1.onnx` | `f525daf3089ec41c938a66c47cd8278c2a443f31ee2bd2dac987db531c58ccfd` | `[1,112,112,3]` |-| MobileCLIP | existing `mobileclip_s2_image.onnx` | `ef54ec66c687603eb4dd303e20d9b67e81069d3133b1c69a70028c76718b7752` | `[1,3,256,256]` |--The optimized models are therefore the exact proposed cross-platform CDN-artifacts, not the old dynamic YOLO and MobileFaceNet exports.--## Why the current chain does not behave as intended--The Pixel advertises its Google Edge TPU to NNAPI as `google-edgetpu`. During-session creation, that driver rejected all three models with:--> The model cannot run using the current set of target devices, [Name: [google-edgetpu], Type [4]]--This is a session-creation failure, rather than unsupported nodes being handed-to the next EP inside a successfully created session. The current fallback-logic tries these session configurations:--1. `NNAPI -> XNNPACK -> CPU`-2. `NNAPI -> CPU`-3. `CPU`--Consequently, an NNAPI compilation failure prevents XNNPACK from ever getting-a standalone attempt. The session eventually succeeds as CPU-only. Merely-placing XNNPACK after NNAPI does not provide the intended fallback for this-failure mode.--This behavior is also why the candidate improves model loading: it avoids two-failed NNAPI compilation attempts before constructing a usable session.--## Pure inference results--Timers surround synchronous ONNX Runtime tensor creation, `session.run`, and-output extraction/copy. Image decode, resize, preprocessing, detector-postprocessing, face alignment, and embedding normalization are excluded.-Steady values exclude the first call. Current values are from the exact-production configuration in `current_perf`; XNNPACK values pool the two valid-controlled repeats. The additional `current_controlled` run disabled intra-op-spinning for the final CPU fallback and was slightly faster than production,-so it is retained as a conservative corroboration rather than the primary-baseline.--| Model | Strategy | First B1 | Steady p50 | Steady p90 |-|---|---|---:|---:|---:|-| YOLO | Current | 358.0 ms | 350.6 ms | 385.7 ms |-| YOLO | XNNPACK4 | 168.1β231.2 ms | 204.4 ms | 231.9 ms |-| MobileCLIP | Current | 426.1 ms | 428.5 ms | 437.1 ms |-| MobileCLIP | XNNPACK4 | 263.5β289.2 ms | 301.6 ms | 341.4 ms |-| MobileFaceNet B1 | Current | 28.9 ms | 13.8 ms | 20.7 ms |-| MobileFaceNet B1 | XNNPACK4 | 14.9β15.4 ms | 19.4 ms | 23.3 ms |--Static MobileFaceNet B1 executes once per face. The multi-face measurements-therefore show the same regression accumulating across calls:--| Logical request | Current | XNNPACK4 | Change |-|---|---:|---:|---:|-| Seven faces | 98.2 ms | 127.6 ms average | 29.9% slower |-| Ten faces | 118.1 ms | 168.4 ms average | 42.6% slower |--Across the full fixture suite, summing only instrumented model inference gives-11.316 seconds for the exact current strategy and 7.631/7.499 seconds for the-two XNNPACK4 repeats.--## Session creation--βLoad wallβ is the application's complete lazy model-load time. For the current-strategy it includes the failed NNAPI attempts; βsuccessful attemptβ is only-the final CPU session construction.--| Model | Current load wall | Current final CPU attempt | XNNPACK4 load wall |-|---|---:|---:|---:|-| YOLO | 428.4 ms | 58.8 ms | 183.3β209.7 ms |-| MobileCLIP | 1,072.7 ms | 250.7 ms | 448.1β454.7 ms |-| MobileFaceNet | 82.5 ms | 11.5 ms | 25.5β29.5 ms |-| **Total** | **1,583.6 ms** | β | **660.9β689.9 ms** |--Adding load wall and all instrumented inference, the complete measured ML work-is 12.899 seconds for the exact current configuration versus 8.292 and 8.189-seconds for XNNPACK4βa 35.7β36.5% reduction. The conservative-`current_controlled` comparison is 11.961 seconds and therefore still shows a-30.7β31.5% reduction.--The Flutter suite's coarse whole-image clock is not suitable for attributing EP-performance because it includes decoding, I/O, preprocessing, postprocessing,-isolate work, and scheduling. The focused conclusion therefore uses the-instrumented load and inference timers.--## Correctness--Both strategies produced 13/14 Python-golden passes. In both cases, the only-failure was the known MobileCLIP difference for `IMG_8905.CR2`, with a cosine-distance of approximately 0.196 against Python. This is the existing Android-RAW decode difference and is independent of the execution-provider strategy.--All face detection and embedding checks passed against Python:--- Maximum face-embedding cosine distance: current `0.0099064`, XNNPACK4- `0.0099149`, both below the `0.015` threshold.-- Boxes, landmarks, scores, and face counts passed their existing thresholds.--A direct current-versus-XNNPACK4 Android comparison is much tighter:--| Metric | Maximum difference |-|---|---:|-| Face count | Exactly equal; 25 faces total |-| CLIP cosine distance | `2.990e-11` |-| Face-embedding cosine distance | `1.454e-6` |-| Bounding-box absolute delta | `3.576e-7` |-| Landmark absolute delta | `1.192e-7` |-| Detection-score absolute delta | `8.345e-7` |--The two controlled XNNPACK4 repeats were effectively identical to each other:-boxes, landmarks, and scores matched exactly, while embedding cosine distance-was at most `2.22e-16`.--## Recommendation--For a uniform, simple Android configuration, switch the three indexing models-to `XNNPACK4 -> CPU`. It is output-equivalent for application purposes and cuts-the dominant YOLO and MobileCLIP latency enough to reduce total measured ML-work by about 36%, despite MobileFaceNet becoming slower.--For the fastest model-specific configuration:--- YOLO: `XNNPACK4 -> CPU`.-- MobileCLIP: `XNNPACK4 -> CPU`.-- MobileFaceNet B1: direct CPU EP with one ORT intra-op thread.--Whichever policy is selected, fix the fallback sequence. If NNAPI remains in-front, a failed NNAPI session must be followed by an explicit-`XNNPACK -> CPU` session attempt before CPU-only. The current-`NNAPI+XNNPACK+CPU -> NNAPI+CPU -> CPU` sequence silently skips the useful-XNNPACK fallback observed in this benchmark.--The result is device-specific. NNAPI was deprecated in Android 15, and Google-notes that accelerator behavior is device-dependent. Keep CPU fallback and-validate on additional supported Android chipsets before turning this Pixel 8-result into a universal Android policy. See the official-[NNAPI documentation](https://onnxruntime.ai/docs/execution-providers/NNAPI-ExecutionProvider.html),-[XNNPACK documentation](https://onnxruntime.ai/docs/execution-providers/Xnnpack-ExecutionProvider.html),-and [Android NNAPI guidance](https://developer.android.com/ndk/guides/neuralnetworks).--## Raw artifact map--The evidence is intentionally kept under the gitignored `infra/ml/test/out/`-tree:--- `current_controlled/`: primary current-strategy run.-- `xnn4_controlled/` and `xnn4_controlled2/`: primary XNNPACK4 repeats.-- `current_perf/` and `xnn4/`: complete supporting runs.-- `focused_strategy_summary.csv` and `focused_strategy_summary.json`: parsed- focused results and direct parity comparison.-- Each run contains `android/results.json`, Python golden results,- `comparison_report.json`, and the Android platform log with raw session and- inference timers.--Benchmark-only provider-selection and timing instrumentation was removed after-capturing the evidence; no production execution-provider code was changed as-part of this investigation.diff --git a/infra/ml/playground/optimizations/benchmark_reports/20260716_IOS_RUST_ML_PIPELINE_BENCHMARK_REPORT.md b/infra/ml/playground/optimizations/benchmark_reports/20260716_IOS_RUST_ML_PIPELINE_BENCHMARK_REPORT.mddeleted file mode 100644index fce67ec28f..0000000000--- a/infra/ml/playground/optimizations/benchmark_reports/20260716_IOS_RUST_ML_PIPELINE_BENCHMARK_REPORT.md+++ /dev/null@@ -1,261 +0,0 @@-# iOS Rust ML indexing and HEIC decoder benchmark--Date: 2026-07-16--Code revision: `7571009d6e` plus temporary, uncommitted benchmark instrumentation and decoder prototypes--Device: iPhone 15 Pro (A17 Pro), iOS 26.5, wired device ID `00008130-00067DD02212001C`--Build: Flutter profile mode with the Rust release library--Workload: all 14 Rust ML indexing parity fixtures, faces + CLIP enabled, pets disabled--## Executive summary--The four implemented pure-Rust decoder improvements cut the five-fixture HEIC-decode sum from 3,021.6 ms to 1,918.4 ms (**36.5% less time, 1.58Γ as fast**)-and cut the full-corpus Rust total from 3,868.8 ms to 2,776.7 ms (**28.2% less-time**). The largest gains are on the grid-heavy fixtures: pano decode is 53.1%-faster and the text/grid fixture is 50.0% faster. All five HEICs retain face and-CLIP parity.--In an optimized device build, the current decoder spends 3,256 ms of a 3,869 ms representative corpus pass decoding (84.2%). The five HEIC files account for 3,022 ms of decode time. The earlier debug-build measurements overstated absolute latency by roughly an order of magnitude; all results and recommendations in this report use fresh profile/Rust-release runs.--Four alternatives were benchmarked on the same phone:--| Decoder | HEIC decode sum | HEIC speedup | Full-corpus Rust total | Corpus reduction | HEIC parity |-|---|---:|---:|---:|---:|---|-| Current `heic-decoder` | 3,021.6 ms | 1.00Γ | 3,868.8 ms | β | 5/5 pass |-| `speed_improvements` (four cumulative changes) | **1,918.4 ms** | **1.58Γ** | **2,776.7 ms** | **28.2%** | 5/5 pass |-| ImageIO + current-decoder fallback | 1,846.9 ms | 1.64Γ | 2,695.1 ms | 30.3% | 5/5 pass |-| `heic` 0.1.6 | 1,875.5 ms | 1.61Γ | 2,721.7 ms | 29.7% | 5/5 pass |-| `libheif-rs` 2.7.0 + libde265 | **1,625.3 ms** | **1.86Γ** | **2,492.8 ms** | **35.6%** | 5/5 pass |--`libheif-rs` is the fastest complete decoder in this corpus. ImageIO is much faster on the three HEICs it accepts (4.1β7.2Γ), but rejects the two deliberately problematic/grid fixtures. An ImageIO-first path with the current decoder as fallback is therefore nearly as fast as the pure-Rust `heic` crate across the whole corpus, preserves parity, and avoids adding a third-party decoder to the iOS application.--The `heic` crate is particularly strong on the two problematic fixtures, but its `AGPL-3.0-only OR commercial` license is a shipping blocker without an appropriate commercial license. `libheif-rs` itself is MIT, while the native libheif/libde265 stack and its static-linking implications require a separate license and distribution review.--## Method and important correction--Each run used one full warm-up pass followed by five measured passes per fixture. Tables report the median of those five passes. `Rust total` starts immediately before decoding and ends after face and CLIP analysis, so it measures exactly the interval requested. `Decode` includes file access, container/codec work, RGB output, color handling, and orientation. Model session creation is excluded by the warm-up.--The first version of this report mistakenly described the iOS run as profile mode because the test harness printed its Android build-mode setting. The actual iOS command defaulted to debug, and Rust was unoptimized. I discarded those absolute measurements and reran the current decoder and all alternatives with `flutter drive --profile` and the Rust release library. The release results below are internally comparable.--Runs were sequential rather than randomized. Medians limit transient noise, but thermal state and background phone activity can still move results by a few percent. The large differences are robust; close differences such as ImageIO hybrid versus `heic` should be treated as a tie until an uninstrumented randomized A/B run.--The instrumentation logs synchronously, so it adds a small common overhead. Final production validation should remove logging and compare wall-clock throughput.--## Current decoder baseline--Times are milliseconds. File size is compressed on-disk size; megapixels are final oriented dimensions. `Rest` is all warmed preprocessing, inference, alignment, postprocessing, and small unassigned overhead after subtracting decode from Rust total.--| Fixture | File size | Resolution | MP | Rust total | Decode | Rest | Decode share |-|---|---:|---:|---:|---:|---:|---:|---:|-| `1343_rotate_90_cw.jpg` | 2.75 MiB | 2835Γ2200 | 6.24 | 76.8 | 39.1 | 37.7 | 50.9% |-| `1718_rotate_90_cw.HEIC` | 4.75 MiB | 3504Γ2439 | 8.55 | 600.4 | 555.8 | 44.6 | 92.6% |-| `7765_horizontal_normal.HEIC` | 4.67 MiB | 3250Γ4333 | 14.08 | 760.0 | 715.3 | 44.7 | 94.1% |-| `7949_mirror_horizontal_rotate_270_cw.HEIC` | 0.63 MiB | 1547Γ1209 | 1.87 | 145.4 | 100.5 | 44.9 | 69.1% |-| `IMG_0682_pano.HEIC` | 7.52 MiB | 14604Γ3826 | 55.87 | 1,365.6 | 1,316.4 | 49.2 | 96.4% |-| `IMG_8606_rotate_90_cw_contains_text.HEIC` | 1.34 MiB | 3024Γ4032 | 12.19 | 380.8 | 333.7 | 47.2 | 87.6% |-| `IMG_8905.CR2` | 25.14 MiB | 5184Γ3456 | 17.92 | 135.2 | 85.6 | 49.6 | 63.3% |-| `IMG_pano.jpg` | 5.93 MiB | 7872Γ1280 | 10.08 | 107.9 | 66.2 | 41.8 | 61.3% |-| `astronaut.png` | 0.40 MiB | 512Γ512 | 0.26 | 40.1 | 2.6 | 37.6 | 6.4% |-| `man.jpeg` | 0.004 MiB | 275Γ183 | 0.05 | 37.7 | 0.3 | 37.4 | 0.7% |-| `people.jpeg` | 0.009 MiB | 275Γ183 | 0.05 | 50.5 | 0.4 | 50.1 | 0.9% |-| `singapore.jpg` | 0.59 MiB | 1920Γ1200 | 2.30 | 47.4 | 11.1 | 36.2 | 23.5% |-| `starwatchers.jpg` | 0.08 MiB | 500Γ724 | 0.36 | 42.0 | 4.5 | 37.5 | 10.7% |-| `ui_app.webp` | 0.11 MiB | 1070Γ1974 | 2.11 | 79.0 | 25.1 | 53.9 | 31.7% |-| **Corpus total** | β | β | β | **3,868.8** | **3,256.4** | **612.4** | **84.2%** |--Among only the five HEIC fixtures, compressed file size and pixel count are both strongly associated with current decode time (Pearson `r=0.958` and `r=0.931`, respectively), but five deliberately varied samples are too few for a predictive model. File size alone is not sufficient because compression structure and grid/tile layout matter.--The pano should not be treated as a pathological per-pixel result. It is 55.9 MPβroughly four to seven times the ordinary HEICsβand takes 23.6 ms/MP, versus 50.8β65.0 ms/MP for the first three HEICs. Its absolute time is large because the output is enormous, not because it decodes unusually poorly per pixel.--## Detailed current-decoder pipeline breakdown--This is the release-mode equivalent of the original detailed table. Times are milliseconds. `Preprocess` combines YOLO and CLIP preprocessing. `Inference` combines face detection, all face embeddings, and CLIP image inference. `Align + postprocess` combines face alignment and all measured detection/embedding postprocessing.--`End-to-end Dart` is the five-run average recorded by the parity runner. Each Rust stage is the median of its five measured samples, so component columns may differ slightly from the Rust total because medians are calculated independently. The CR2 Rust row represents the successful JPEG retry; its Dart time also includes the failed direct Rust attempt and Dart RAW decode/JPEG conversion.--| Fixture | File size | Resolution | MP | End-to-end Dart | Rust total median (range) | Decode | Preprocess | Inference | Align + postprocess |-|---|---:|---:|---:|---:|---:|---:|---:|---:|---:|-| `1343_rotate_90_cw.jpg` | 2.75 MiB | 2835Γ2200 | 6.24 | 78 | 76.8 (76.1β84.9) | 39.1 | 3.8 | 33.4 | 0.0 |-| `1718_rotate_90_cw.HEIC` | 4.75 MiB | 3504Γ2439 | 8.55 | 603 | 600.4 (598.8β607.6) | 555.8 | 4.4 | 41.4 | 0.4 |-| `7765_horizontal_normal.HEIC` | 4.67 MiB | 3250Γ4333 | 14.08 | 762 | 760.0 (756.9β767.1) | 715.3 | 5.5 | 41.6 | 0.5 |-| `7949_mirror_horizontal_rotate_270_cw.HEIC` | 0.63 MiB | 1547Γ1209 | 1.87 | 146 | 145.4 (143.0β148.0) | 100.5 | 2.7 | 41.8 | 0.4 |-| `IMG_0682_pano.HEIC` | 7.52 MiB | 14604Γ3826 | 55.87 | 1,360 | 1,365.6 (1,343.0β1,368.0) | 1,316.4 | 6.1 | 43.0 | 0.4 |-| `IMG_8606_rotate_90_cw_contains_text.HEIC` | 1.34 MiB | 3024Γ4032 | 12.19 | 380 | 380.8 (375.0β382.8) | 333.7 | 5.3 | 39.1 | 0.0 |-| `IMG_8905.CR2` | 25.14 MiB | 5184Γ3456 | 17.92 | 3,666 | 135.2 (132.9β136.9) | 85.6 | 6.5 | 42.0 | 0.0 |-| `IMG_pano.jpg` | 5.93 MiB | 7872Γ1280 | 10.08 | 109 | 107.9 (107.5β113.0) | 66.2 | 1.8 | 40.0 | 0.3 |-| `astronaut.png` | 0.40 MiB | 512Γ512 | 0.26 | 40 | 40.1 (39.6β40.4) | 2.6 | 2.3 | 34.8 | 0.4 |-| `man.jpeg` | 0.004 MiB | 275Γ183 | 0.05 | 38 | 37.7 (37.5β38.4) | 0.3 | 2.0 | 34.9 | 0.4 |-| `people.jpeg` | 0.009 MiB | 275Γ183 | 0.05 | 52 | 50.5 (50.0β51.1) | 0.4 | 2.1 | 44.7 | 2.9 |-| `singapore.jpg` | 0.59 MiB | 1920Γ1200 | 2.30 | 48 | 47.4 (46.7β48.9) | 11.1 | 2.4 | 33.9 | 0.0 |-| `starwatchers.jpg` | 0.08 MiB | 500Γ724 | 0.36 | 43 | 42.0 (41.8β42.4) | 4.5 | 2.0 | 35.2 | 0.4 |-| `ui_app.webp` | 0.11 MiB | 1070Γ1974 | 2.11 | 81 | 79.0 (77.7β85.8) | 25.1 | 2.0 | 48.9 | 2.9 |-| **Corpus total** | β | β | β | **7,406** | **3,868.8** | **3,256.4** | **49.1** | **554.6** | **9.0** |--The summed Rust stage medians account for 3,869.1 ms versus the 3,868.8 ms sum of per-image Rust total medians; the 0.3 ms difference is the expected independent-median and rounding effect. Excluding the CR2 Dart fallback, Dart and Rust totals track closely. The release data confirms that warmed inference is comparatively stable at roughly 34β49 ms per fixture, while HEIC decode varies from 100 ms to 1.32 seconds with image size and structure.--## Cumulative `speed_improvements` benchmark--This run uses the local `speed_improvements` decoder through a temporary path-dependency at revision `1ac5834` and exercises all four committed changes:--1. production builds compile out diagnostic counters and CTU tracking;-2. grid tiles decode in bounded deterministic parallel batches;-3. the Ente path consumes the decoder's direct RGB8 output before applying the- existing ICC and orientation steps; and-4. exact ARM NEON kernels accelerate dequantization and residual addition.--Unlike the older baseline, this validation is a genuine Flutter release build:-Xcode built `Release-iphoneos`, Dart reported `dart.vm.product=true` and-`dart.vm.profile=false`, and both Rust bridge pods used Cargo `--release` for-`aarch64-apple-ios`. The physical device was the same wired iPhone 15 Pro. Each-row discards one fixture-local warmup and reports the median and range of five-measured native Rust calls. The transcript contains exactly 84 structured-samples (14 fixtures Γ 6 calls).--The old baseline used Flutter profile with the same Rust release optimization.-The table therefore compares timings recorded wholly inside the optimized Rust-call, not Dart wall time. Non-HEIC rows act as a control and are mostly within a-few milliseconds; small percentage changes on sub-millisecond decode rows are-not meaningful.--| Fixture | New Rust total median (range) | Baseline | Change | New decode median (range) | Baseline | Change |-|---|---:|---:|---:|---:|---:|---:|-| `1343_rotate_90_cw.jpg` | 77.4 (75.0β85.6) | 76.8 | +0.8% | 40.0 (38.3β41.7) | 39.1 | +2.4% |-| `1718_rotate_90_cw.HEIC` | 516.2 (515.6β521.9) | 600.4 | **β14.0%** | 473.5 (471.8β473.8) | 555.8 | **β14.8%** |-| `7765_horizontal_normal.HEIC` | 624.3 (622.7β625.6) | 760.0 | **β17.9%** | 576.2 (574.1β579.2) | 715.3 | **β19.5%** |-| `7949_mirror_horizontal_rotate_270_cw.HEIC` | 130.3 (126.3β130.5) | 145.4 | **β10.4%** | 84.8 (84.8β84.8) | 100.5 | **β15.6%** |-| `IMG_0682_pano.HEIC` | 665.5 (660.0β667.0) | 1,365.6 | **β51.3%** | 617.0 (613.3β620.4) | 1,316.4 | **β53.1%** |-| `IMG_8606_rotate_90_cw_contains_text.HEIC` | 214.5 (208.8β215.5) | 380.8 | **β43.7%** | 166.9 (164.7β168.5) | 333.7 | **β50.0%** |-| `IMG_8905.CR2` | 129.7 (124.7β130.3) | 135.2 | β4.1% | 79.9 (79.2β80.1) | 85.6 | β6.7% |-| `IMG_pano.jpg` | 115.1 (110.3β116.0) | 107.9 | +6.7% | 69.6 (69.4β70.0) | 66.2 | +5.1% |-| `astronaut.png` | 40.0 (39.6β40.9) | 40.1 | β0.2% | 2.7 (2.4β3.2) | 2.6 | +2.4% |-| `man.jpeg` | 39.4 (37.9β42.9) | 37.7 | +4.4% | 0.3 (0.3β0.6) | 0.3 | +12.7% |-| `people.jpeg` | 56.0 (55.5β56.8) | 50.5 | +11.0% | 0.7 (0.6β0.7) | 0.4 | +62.5% |-| `singapore.jpg` | 47.6 (47.0β49.3) | 47.4 | +0.4% | 11.6 (11.1β12.9) | 11.1 | +4.3% |-| `starwatchers.jpg` | 42.3 (41.9β43.2) | 42.0 | +0.8% | 5.0 (4.5β5.3) | 4.5 | +10.4% |-| `ui_app.webp` | 78.2 (78.1β80.5) | 79.0 | β1.0% | 24.7 (24.6β26.8) | 25.1 | β1.8% |-| **HEIC total** | **2,150.9** | **3,252.2** | **β33.9%** | **1,918.4** | **3,021.6** | **β36.5%** |-| **Corpus total** | **2,776.7** | **3,868.8** | **β28.2%** | **2,152.7** | **3,256.4** | **β33.9%** |--The result strongly validates bounded grid parallelism: the two grid-heavy-fixtures account for most of the absolute saving and are roughly twice as fast-to decode. The 14.8β19.5% decode reductions on the two large ordinary HEICs,-plus 15.6% on the smaller transformed HEIC, show that direct RGB8 output and the-profile-guided NEON kernels also matter outside grids. This cumulative run does-not independently attribute those ordinary-file gains between RGB8 and NEON;-the decoder repository's sequential A/B notes provide that attribution.--The optimized pure-Rust path is now close to the ImageIO hybrid: its HEIC decode-sum is 71.5 ms (3.9%) slower and its full-corpus Rust total is 81.6 ms (3.0%)-slower in these sequential runs. It remains 293.1 ms slower than the-libheif/libde265 HEIC sum, but avoids that native dependency and license-review-surface. Decode still represents about 77.5% of the new corpus Rust total, so-there is useful headroom, but the four changes remove over one third of the-original HEIC decode cost without changing parity.--## ImageIO hybrid benchmark--The final ImageIO prototype uses full-resolution `CGImageSourceCreateImageAtIndex`, draws into an RGB buffer, and then applies the same explicit Rust orientation handling as the other paths. The earlier thumbnail-based prototype was discarded because it changed pixels/orientation and failed parity.--Full-resolution ImageIO preserves face and CLIP parity for every HEIC it can decode. It rejects `IMG_0682_pano.HEIC` and `IMG_8606...HEIC`; the benchmark below retries those with the current Rust decoder so every fixture completes.--| HEIC fixture | File size | Resolution | Rust total | Decode | Decode speedup | Path | Parity |-|---|---:|---:|---:|---:|---:|---|---|-| `1718_rotate_90_cw.HEIC` | 4.75 MiB | 3504Γ2439 | 157.8 | 114.0 | 4.88Γ | ImageIO | Pass |-| `7765_horizontal_normal.HEIC` | 4.67 MiB | 3250Γ4333 | 148.8 | 98.8 | 7.24Γ | ImageIO | Pass |-| `7949_mirror_horizontal_rotate_270_cw.HEIC` | 0.63 MiB | 1547Γ1209 | 62.6 | 24.5 | 4.09Γ | ImageIO | Pass |-| `IMG_0682_pano.HEIC` | 7.52 MiB | 14604Γ3826 | 1,331.7 | 1,280.8 | 1.03Γ | Current fallback | Pass |-| `IMG_8606_rotate_90_cw_contains_text.HEIC` | 1.34 MiB | 3024Γ4032 | 374.0 | 328.7 | 1.02Γ | Current fallback | Pass |-| **HEIC total** | β | β | **2,075.0** | **1,846.9** | **1.64Γ** | 3 ImageIO / 2 fallback | **5/5 pass** |--The fallback errors occur before meaningful decoding work (under 1 ms), so they do not materially inflate the two fallback rows. This hybrid reduces the full-corpus Rust total by 30.3%.--## `heic` crate benchmark--The [`heic` 0.1.6 crate](https://docs.rs/heic/latest/heic/) was built with its `parallel` feature, decoded directly to RGB8, and used the device's available parallelism. It completed every fixture and preserved parity.--| HEIC fixture | File size | Resolution | Rust total | Decode | Decode speedup | Parity |-|---|---:|---:|---:|---:|---:|---|-| `1718_rotate_90_cw.HEIC` | 4.75 MiB | 3504Γ2439 | 630.8 | 584.6 | 0.95Γ | Pass |-| `7765_horizontal_normal.HEIC` | 4.67 MiB | 3250Γ4333 | 702.0 | 654.0 | 1.09Γ | Pass |-| `7949_mirror_horizontal_rotate_270_cw.HEIC` | 0.63 MiB | 1547Γ1209 | 140.5 | 95.3 | 1.05Γ | Pass |-| `IMG_0682_pano.HEIC` | 7.52 MiB | 14604Γ3826 | 463.5 | 416.7 | 3.16Γ | Pass |-| `IMG_8606_rotate_90_cw_contains_text.HEIC` | 1.34 MiB | 3024Γ4032 | 169.8 | 124.9 | 2.67Γ | Pass |-| **HEIC total** | β | β | **2,106.5** | **1,875.5** | **1.61Γ** | **5/5 pass** |--This decoder is roughly even with the current implementation on the three ordinary HEICs, but dramatically better on the two grid/problem fixtures. It reduces the full-corpus Rust total by 29.7%. Its crate metadata declares `AGPL-3.0-only OR LicenseRef-Imazen-Commercial`, so it should not be adopted without an explicit licensing decision.--## `libheif-rs` benchmark--[`libheif-rs` 2.7.0](https://docs.rs/libheif-rs/latest/libheif_rs/) was benchmarked with a minimal release-built native libheif, libde265 1.0.16 as its HEVC codec, direct RGB output, and maximum decoding threads set to device parallelism. Every HEIC completed and preserved parity.--| HEIC fixture | File size | Resolution | Rust total | Decode | Decode speedup | Parity |-|---|---:|---:|---:|---:|---:|---|-| `1718_rotate_90_cw.HEIC` | 4.75 MiB | 3504Γ2439 | 473.3 | 427.5 | 1.30Γ | Pass |-| `7765_horizontal_normal.HEIC` | 4.67 MiB | 3250Γ4333 | 566.7 | 519.5 | 1.38Γ | Pass |-| `7949_mirror_horizontal_rotate_270_cw.HEIC` | 0.63 MiB | 1547Γ1209 | 123.6 | 78.8 | 1.27Γ | Pass |-| `IMG_0682_pano.HEIC` | 7.52 MiB | 14604Γ3826 | 524.6 | 475.4 | 2.77Γ | Pass |-| `IMG_8606_rotate_90_cw_contains_text.HEIC` | 1.34 MiB | 3024Γ4032 | 167.2 | 124.0 | 2.69Γ | Pass |-| **HEIC total** | β | β | **1,855.3** | **1,625.3** | **1.86Γ** | **5/5 pass** |--This is the fastest complete option and reduces the full-corpus Rust total by 35.6%. The cost is integration complexity: `libheif-rs` wraps a C++ native library, the HEVC codec is a separate native dependency, and the initial embedded build pulled in unnecessary codecs until it was configured as a minimal HEIC-decode-only archive. The [libheif project](https://github.com/strukturag/libheif) documents libde265 as its default HEIC decoder and supports parallel tile decoding.--## Correctness--The current, ImageIO-hybrid, `heic`, and `libheif-rs` runs all produced the same parity result:--- all five HEIC fixtures pass face and CLIP thresholds;-- all non-RAW fixtures pass;-- the sole failure is the pre-existing `IMG_8905.CR2` fallback, whose JPEG re-encode has CLIP cosine distance 0.196097 from the Python RAW ground truth.--The temporary decoder work did not change that CR2 path. The ImageIO-only run without fallback also confirmed that the three supported ImageIO HEICs pass before the hybrid was measured.--The cumulative `speed_improvements` release run has the same correctness-result: all five HEICs and all other non-RAW fixtures pass. The only finding is-the same pre-existing `IMG_8905.CR2` CLIP cosine distance of `0.196097`; there-are no new errors or HEIC threshold regressions.--## Recommendations--### 1. Prefer an ImageIO-first iOS path with the current decoder as fallback--This is the best practical first implementation for iOS. It removes 30.3% of measured corpus time, is 4.1β7.2Γ faster for supported HEICs, preserves parity, adds no decoder licensing burden, and keeps the unusual files on the already-tested Rust path. The fallback boundary is small and readable: one iOS-specific decoder returning the same `DecodedImage` type.--Before shipping, package the ImageIO bridge cleanly (preferably behind the image crate's decoder abstraction), add explicit tests for all EXIF orientations and the two fallback fixtures, and run a larger real-library sample to establish ImageIO's fallback rate. Do not use the thumbnail API; the full-image API plus explicit orientation is required for parity.--### 2. Keep `libheif-rs` as the performance-maximizing alternative--If the additional 202 ms per test corpus versus ImageIO hybrid is valuable, `libheif-rs` is the fastest complete option and handles every problematic fixture. A production integration should build a minimal release-only libheif + libde265 artifact, measure binary-size impact, document native update ownership, and complete an LGPL/static-linking compliance review. The wrapper's MIT license does not remove the native libraries' obligations.--The 7.5% corpus advantage over ImageIO hybrid is real in this run but modest relative to the added build and maintenance surface. It becomes more compelling if a larger photo sample shows frequent ImageIO fallback.--### 3. Do not adopt `heic` without resolving its license--Technically, `heic` is attractive: pure Rust integration, direct RGB8 output, full parity, and the best pano result. Its overall performance is essentially tied with ImageIO hybrid. Legally, the published AGPL/commercial license requires either a compatible product decision or a commercial license; it is not a drop-in dependency decision.--### 4. Use the problem-fixture results to guide the current decoder--Both alternative complete decoders improve the pano/text fixtures far more than the ordinary files. The highest-value work in the current `heic-decoder` is therefore grid/tile scheduling and direct RGB output, not generic container parsing. The `heic` result shows that parallel grid decode can cut the 55.9 MP pano from 1,316 ms to 417 ms while preserving embeddings.--### 5. Make release-mode enforcement part of future benchmarks--The debug/profile mismatch changed absolute decode times by about 10Γ and would have produced misleading prioritization. The runner should print and assert the actual iOS Flutter mode and Rust Cargo profile, and benchmark artifact paths should include both. Future decoder A/B runs should be uninstrumented, randomized by decoder or fixture, and repeated enough to report confidence intervals.--## Artifacts--- Current release: `infra/ml/test/out/rust_pipeline_ios_current_release_2026-07-16/`-- ImageIO full-image validation: `infra/ml/test/out/rust_pipeline_ios_imageio_full_release_2026-07-16/`-- ImageIO hybrid: `infra/ml/test/out/rust_pipeline_ios_imageio_hybrid_release_2026-07-16/`-- `heic` release: `infra/ml/test/out/rust_pipeline_ios_heic_crate_release_2026-07-16/`-- `libheif-rs` release: `infra/ml/test/out/rust_pipeline_ios_libheif_rs_release_2026-07-16/`-- Four cumulative decoder improvements, true Flutter/Rust release:- `infra/ml/test/out/rust_pipeline_ios_speed_improvements_release_2026-07-16/`--The local path override, direct-RGB caller shim, timing instrumentation, and-standalone release runner were removed after the run. The four decoder changes-are committed on `speed_improvements`; the pre-existing experimental artifacts-described elsewhere in this report retain their original status.diff --git a/infra/ml/playground/optimizations/benchmark_reports/20260717_ANDROID_WEBGPU_BENCHMARK_REPORT.md b/infra/ml/playground/optimizations/benchmark_reports/20260717_ANDROID_WEBGPU_BENCHMARK_REPORT.mddeleted file mode 100644index 7d48f64e0c..0000000000--- a/infra/ml/playground/optimizations/benchmark_reports/20260717_ANDROID_WEBGPU_BENCHMARK_REPORT.md+++ /dev/null@@ -1,789 +0,0 @@-# Android WebGPU Release Smoke Test, MobileFaceNet Rewrite, and Tuning Benchmark--- **Date:** 17 July 2026-- **Device:** Pixel 8 (`shiba`), Google Tensor G3, Mali-G715, Android 17 / API 37-- **Base revision:** `6a74a6aba6`, plus temporary benchmark-only instrumentation-- **Build:** Flutter AOT release and release-mode Rust, `independent` flavor-- **ONNX Runtime:** custom 1.27.0 Android AAR, release `ort-1.27.0-webgpu-pilot.5`-- **WebGPU configuration:** forced `true` in the parity runner for this investigation-- **Raw evidence:** [`infra/ml/test/out/android_webgpu_release_2026-07-17/`](../../../test/out/android_webgpu_release_2026-07-17/)-- **Machine-readable summary:** [`benchmark_summary.json`](../../../test/out/android_webgpu_release_2026-07-17/benchmark_summary.json)-- **Follow-up revision:** `18e246ff6432`, plus the model rewrite and temporary tuning instrumentation described below-- **Follow-up evidence:** [`infra/ml/test/out/android_webgpu_tuning_2026-07-17/`](../../../test/out/android_webgpu_tuning_2026-07-17/)-- **Follow-up summary:** [`benchmark_summary.json`](../../../test/out/android_webgpu_tuning_2026-07-17/benchmark_summary.json)-- **Fusion follow-up revision:** `0ee9992b7a0c`, plus temporary release benchmark instrumentation-- **Fusion follow-up evidence:** [`infra/ml/test/out/android_webgpu_fusions_2026-07-17/`](../../../test/out/android_webgpu_fusions_2026-07-17/)-- **Fusion follow-up summary:** [`benchmark_summary.json`](../../../test/out/android_webgpu_fusions_2026-07-17/benchmark_summary.json)--## Fusion follow-up outcome: exact GELU and native PReLU are real wins--Two further FP32 experiments improved the model hot paths without changing-application-level output on the 14-fixture corpus:--- Replacing MobileCLIP's 54 expanded exact-GELU expressions with the standard- ONNX `Gelu(approximate="none")` operator reduced median MobileCLIP inference- from **135.505 ms to 127.103 ms**, a **6.20% improvement**. Its p95 improved- by 5.13%. YOLO was unchanged, confirming that this was a CLIP-local gain.-- Adding native WebGPU `PRelu` support and a WebGPU YOLO SiLU fusion to the- custom ONNX Runtime reduced MobileFaceNet from **14.369 ms to 10.772 ms per- face**, a **25.03% improvement**. YOLO improved from **107.844 ms to- 106.271 ms**, or 1.46%.--The GELU result is large and isolated enough to recommend adopting after an-iOS/CoreML device check. Native WebGPU PReLU is also compelling, but requires-an Android-specific MobileFaceNet artifact or retaining separate Android and-iOS graphs: the portable arithmetic rewrite remains necessary for the shared-CoreML-compatible model. The YOLO SiLU change is directionally positive but-small enough that it should be repeated across run order and more Android-devices before being credited as a stable 1.46% gain.--### FP32 exact GELU fusion--The benchmark-only generator, retained with the-[raw evidence](../../../test/out/android_webgpu_fusions_2026-07-17/optimize_clip_model.py),-recognizes the exact expression:--```text-0.5 * x * (1 + Erf(x / sqrt(2)))-```--and replaces it with the standard opset-20 `Gelu` operator using-`approximate="none"`. This is not a tanh or QuickGELU approximation. The-operator is implemented by both the WebGPU and CoreML execution providers in-the ONNX Runtime source used for this investigation.--| Property | Original MobileCLIP | Exact-GELU MobileCLIP |-|---|---:|---:|-| ONNX opset | 16 | 20 |-| Serialized nodes | 879 | 504 |-| Exact GELU sites | 54 expanded expressions | 54 `Gelu` nodes |-| `Erf` / `Div` nodes | 54 / 54 | 0 / 0 |-| Model bytes | 143,061,211 | 143,057,352 |-| SHA-256 | `ef54ec66β¦7752` | `205a430aβ¦ce7e` |-| MobileCLIP inference p50 | 135.505 ms | **127.103 ms** |-| MobileCLIP inference p95 | 144.448 ms | **137.039 ms** |--The output model passes `onnx.checker.check_model(..., full_check=True)`. Five-deterministic random CPU inputs had minimum raw-output cosine-`0.999999999492`; the maximum absolute difference was `0.0733948`, caused by-the different floating-point evaluation path. More importantly for the app,-all 14 normalized Android CLIP embeddings were byte-for-byte equal to the FP32-baseline. Face counts, detections, and all 25 face embeddings were also exact.--The timing controls support a model-local interpretation: YOLO changed by--0.01%, while MobileFaceNet changed by +0.66%. At this corpus frequency, 14-CLIP calls save approximately **117.6 ms of aggregate model inference**.--### WebGPU-local PReLU and YOLO SiLU fusion--The custom release AAR added three WebGPU capabilities:--1. A broadcast-capable PReLU binary elementwise kernel.-2. WebGPU execution-provider registrations for ONNX `PRelu`.-3. Recognition of `x * Sigmoid(x)` as QuickGELU with alpha `1.0`, which is- exactly SiLU, followed by `ConvActivationFusion` support for that activation.--This allowed Android to use the compact canonical MobileFaceNet graph with 33-PReLU nodes instead of the five-operator portable expression at every site.-The YOLO model itself was unchanged; only the custom runtime could fuse its-SiLU pattern.--| Model/control | Portable FP32 baseline p50 | Custom WebGPU runtime p50 | Change | Baseline p95 | Custom p95 | Corpus parity |-|---|---:|---:|---:|---:|---:|---|-| YOLO, SiLU fusion target | 107.844 ms | **106.271 ms** | **-1.46%** | 112.334 ms | 110.977 ms | Exact |-| MobileFaceNet, native PReLU | 14.369 ms | **10.772 ms** | **-25.03%** | 17.740 ms | 13.755 ms | Exact |-| MobileCLIP, unchanged control | 135.505 ms | 136.892 ms | +1.02% | 144.448 ms | 143.465 ms | Exact |--The 25 face calls in this corpus save approximately **89.9 ms** from native-PReLU alone. Including YOLO, the two targeted models save about **111.9 ms**-of aggregate inference per corpus. The unchanged CLIP control moved in the-opposite direction by 1.02%, which is why the smaller YOLO result is treated-as provisional rather than conclusive.--All 14 fixture IDs and face counts matched. Detection boxes, landmarks, and-scores had maximum absolute difference `0.0`; the 25 face embeddings and all-CLIP embeddings were byte-for-byte equal to baseline.--The custom ONNX Runtime AAR was built in release mode with SHA-256-`fa99ac56β¦9468`. Its `libonnxruntime.so` build ID was-`765ed4f44a9e67c8d4246e3a59420eab6c084279`, and the same build ID was present-inside the benchmark APK. Dawn initialized its Vulkan backend in the app-process, all three sessions loaded with the forced platform-default WebGPU-policy, and no provider-construction fallback was logged. Unlike the earlier-placement audit, this follow-up did not enable verbose per-node assignment-logging; the evidence proves the patched WebGPU runtime executed successfully-but does not provide a second node-by-node placement count.--### Fusion benchmark method and recommendation--Both timing experiments used a non-debuggable `independentRelease` APK,-Flutter AOT product mode (`dart.vm.product == true`, profile false), and Rust-release builds. WebGPU was temporarily forced on. Each full timing run covered-one warm-up plus five measured passes for every fixture: 84 raw YOLO calls, 84-raw MobileCLIP calls, and 150 raw MobileFaceNet calls, leaving 70, 70, and 125-measured calls after warm-up removal. Timers covered input tensor creation,-synchronous `Session::run`, output access/copy, and their complete total.-Android thermal status was `0` before and after each retained run.--The exact-GELU timing run completed the full five-pass protocol. Because its-first result-file transport was removed by Gradle together with the test APK,-its correctness JSON was recaptured in a separate full-corpus run with one-warm-up and one measured pass; the preserved five-pass native timing log is-the source of the latency values above. The custom PReLU/SiLU run retained both-five-pass timings and correctness output in one run. The baseline latency log-was also newly captured with the five-pass protocol; its correctness reference-was reused from the immediately preceding same-device FP32 run, whose model-hashes, runtime, and provider configuration were identical.--Recommended next steps:--1. **Adopt the exact-GELU MobileCLIP graph** after running the same generated- model on the iOS/CoreML benchmark corpus. It is FP32, parity-safe at the app- boundary, and produced the clearest new CLIP gain.-2. **Upstream or carry the WebGPU PReLU kernel**, and ship a compact- Android-specific PReLU MobileFaceNet model if maintaining per-platform- artifacts is acceptable. Keep the portable arithmetic graph for CoreML.-3. **Keep the YOLO SiLU fusion in the candidate runtime**, but repeat it in- randomized A/B/A order and on at least one additional Mali or Adreno device- before treating the 1.46% result as a production forecast.-4. Keep the production precision policy at **FP32**, as requested. No FP16- result is needed to obtain either of these gains.--## Follow-up outcome: MobileFaceNet fixed; provider tuning is effectively neutral--The follow-up changes the most important conclusion from the initial smoke-test. MobileFaceNet no longer needs a CPU-specific provider policy. Rewriting-its 33 unsupported `PRelu` nodes as an exact, portable arithmetic expression-makes the entire optimized graph execute on WebGPU and reduces median FP32-MobileFaceNet inference from **99.5 ms to 14.4 ms per face**. That is an 85.5%-latency reduction, or a **6.91x speedup**, with output-identical full-corpus-results.--Verbose ONNX Runtime placement diagnostics reported:--| Model | Optimized nodes placed on WebGPU | CPU nodes | Result |-|---|---:|---:|---|-| Static YOLO | 277 | 0 | Fully WebGPU |-| MobileCLIP | 660 | 0 | Fully WebGPU |-| Portable MobileFaceNet | 231 | 0 | **Fully WebGPU** |--The complete release suite then compared graph capture, preferred layout,-FP16, all four bucket buffer caches, and preallocated GPU I/O. Each variant ran-the full 14-fixture corpus with one warm-up and five measured passes per-fixture. All runs began and ended at Android thermal status `0`.--The actionable result is:--- Keep **FP32**, following the requested accuracy-first final policy. FP16 was- much faster, but two very small faces in a screenshot produced face-embedding- cosines near `0.959` relative to FP32.-- Keep **NCHW**. NHWC made every model's median inference 0.36β0.41% slower.-- Keep normal ONNX Runtime-managed input/output. Explicit GPU I/O- preallocation merely moved synchronization from `Session::run` into the- device-to-host copy and did not improve total latency.-- Graph capture and bucket caches produced small, parity-exact isolated gains,- so they were selected for the requested final combination. The combination- itself was effectively neutral: 0.38% faster end to end without CR2, while- YOLO and CLIP total-inference medians were 0.77% and 0.50% slower.-- Do **not** enable graph capture or bucket caches in production based on this- single-device result. Their isolated changes are within run-to-run noise and- did not add up in the final controlled configuration.--The recommended Android policy after this follow-up is therefore the simple-one: **portable FP32 models, NCHW, WebGPU -> XNNPACK -> CPU fallback, default-buffer caches, and normal I/O**. The model rewrite is a clear win; the tested-provider knobs are not.--The reproducible generator and manifest now describe-`mobilefacenet_portable_static_b1.onnx`. The app's production model URL/SHA was-not changed because this run did not upload a new CDN artifact. Deployment-requires uploading the generated file and then updating `FaceEmbeddingModel`-to its final remote filename and SHA-256.--## Portable MobileFaceNet operator rewrite--Replacing PReLU with one plain `Relu` would be incorrect whenever the learned-slope is nonzero. The exact identity is:--```text-PReLU(x, alpha) = Relu(x) - alpha * Relu(x * -1)-```--The rewrite deliberately uses `Mul(x, -1)` instead of `Neg(x)`. `Relu`, `Mul`,-and `Sub` are all listed by both the-[CoreML MLProgram operator table](https://onnxruntime.ai/docs/execution-providers/CoreML-ExecutionProvider.html#mlprogram)-and the-[WebGPU operator table](https://github.com/microsoft/onnxruntime/blob/main/js/web/docs/webgpu-operators.md),-whereas `Neg` is not listed for CoreML MLProgram. A scalar `LeakyRelu` is not-equivalent because MobileFaceNet has learned per-channel slopes. `Where` also-lacks documented CoreML MLProgram coverage. The selected five-node expression-is therefore the smallest exact common representation found in the two-published support lists.--Each original six-node `Relu`/`Abs`/`Sub`/`Mul`/`Mul`/`Add` activation becomes-five nodes: positive `Relu`, multiply by `-1`, negative `Relu`, slope `Mul`, and-`Sub`. The `[1, C, 1, 1]` slope tensors are preserved exactly.--| Property | Previous WebGPU model | Portable model |-|---|---:|---:|-| Serialized ONNX nodes | 101 | 233 |-| `PRelu` nodes | 33 | 0 |-| Portable activation nodes per channel block | 1 unsupported `PRelu` | 5 supported arithmetic nodes |-| Model bytes | 5,238,749 | 5,278,803 |-| SHA-256 | `f525daf3β¦ccfd` | `0763fc33β¦a36` |-| ORT execution placement | 132 WebGPU / 33 CPU | **231 WebGPU / 0 CPU** |-| FP32 steady total-inference p50 | 99.5 ms | **14.4 ms** |--Serialized node counts and ORT optimized-plan node counts are different-quantities. The placement result is the relevant runtime comparison: 33 CPU-nodes before the rewrite and zero after it.--Validation was performed at three levels:--1. `onnx.checker.check_model(..., full_check=True)` passes.-2. Twenty deterministic random inputs compared against the prior optimized- PReLU model had maximum absolute difference `0.0`; minimum cosine was within- floating-point rounding of 1 (maximum cosine distance `5.960e-8`).-3. The 14-fixture Android corpus produced identical face counts, CLIP outputs,- and all 25 face embeddings relative to the earlier FP32 Android result. The- minimum reported cosine was `0.9999999999999998`.--CoreML compatibility in this follow-up is based on the published MLProgram-operator list and ONNX validation. The new graph was benchmarked and its full-GPU placement proven on Android WebGPU; it was not re-profiled on an iPhone in-this run.--## Follow-up benchmark method--All tuning APKs were Flutter AOT release builds with release Rust. The runner-asserted `dart.vm.product == true` and `dart.vm.profile == false`; the final APK-was non-debuggable according to `apkanalyzer`. The final FP32-winners APK was-243,478,077 bytes with SHA-256-`e2a805408ccf71e2d48822117cd2a54feaccabdde699c41cb16a100b8974b5af`.--For every variant:--- WebGPU was temporarily forced on in the integration runner.-- App data was cleared, giving process-cold sessions and model loads.-- All 14 fixtures ran six times: one unmeasured warm-up and five measured- passes.-- Exact native timers covered input tensor preparation, synchronous inference,- output access/copy, and their combined total for every model call.-- The measured corpus contains 70 YOLO calls, 70 MobileCLIP calls, and 125- MobileFaceNet calls after warm-up removal.-- Results, complete logcat, and before/after thermal snapshots were retained- for each run.--The end-to-end column below sums one like-numbered measured pass for every-fixture and reports the median of the five corpus rounds. CR2 is excluded from-that column because the failed native RAW path contributes a variable external-timeout of roughly 6β16 seconds before the successful JPEG fallback. All model-inference values and correctness checks still include the CR2 fallback.--## Isolated tuning results--βInferenceβ is the complete native inference timer, not `Session::run` alone.-Percentages are versus the portable FP32/NCHW/default-cache/normal-I/O baseline.--| Variant | YOLO p50 | Change | MobileCLIP p50 | Change | MobileFaceNet p50 | Change | Corpus p50, no CR2 | Change | Output parity vs FP32 baseline |-|---|---:|---:|---:|---:|---:|---:|---:|---:|---|-| **FP32 baseline** | 108.111 ms | β | 136.637 ms | β | 14.397 ms | β | 9,676.216 ms | β | Exact |-| Graph capture | 108.161 ms | +0.05% | **134.893 ms** | **-1.28%** | 14.373 ms | -0.16% | **9,597.319 ms** | **-0.82%** | Exact |-| Preferred NHWC | 108.540 ms | +0.40% | 137.198 ms | +0.41% | 14.449 ms | +0.36% | 9,704.058 ms | +0.29% | Exact |-| All four bucket caches | 108.166 ms | +0.05% | 137.276 ms | +0.47% | **13.738 ms** | **-4.58%** | 9,613.981 ms | -0.64% | Exact |-| Preallocated GPU I/O | 108.465 ms | +0.33% | 137.751 ms | +0.81% | 13.838 ms | -3.88% | 9,655.368 ms | -0.22% | Exact |-| Full FP16 models | **78.299 ms** | **-27.58%** | **102.451 ms** | **-25.02%** | **12.427 ms** | **-13.68%** | **8,727.863 ms** | **-9.80%** | Face accuracy concern |-| **Final FP32 combination**: graph capture + bucket caches + NCHW + normal I/O | 108.946 ms | +0.77% | 137.317 ms | +0.50% | 14.373 ms | -0.17% | 9,638.985 ms | -0.38% | Exact |--The baseline's per-model p95 total-inference values were 114.050 ms for YOLO,-145.308 ms for MobileCLIP, and 19.474 ms for MobileFaceNet. The final FP32-combination's corresponding values were 114.048, 146.538, and 18.956 ms. There-is no hidden tail-latency win large enough to change the recommendation.--Using the median model totals and this corpus's 14 YOLO, 14 CLIP, and 25 face-calls, the portable FP32 baseline needs about **3.786 seconds** of model-inference per corpus. The initial split-MobileFaceNet run needed 5.862 seconds.-The operator rewrite therefore reduces aggregate model time by approximately-35.4% on this face distribution.--### Graph capture--Graph capture was parity-exact. It improved MobileCLIP by 1.28% and the-no-CR2 corpus by 0.82%, while YOLO and MobileFaceNet were flat. Those changes-were small enough to be run-order noise, and the final combination did not-retain the CLIP improvement. It should remain off until repeated across devices-or supported by production telemetry.--### NCHW versus NHWC--NCHW won every pure-inference comparison. NHWC increased median total-inference by 0.40% for YOLO, 0.41% for MobileCLIP, and 0.36% for MobileFaceNet.-The Pixel 8's WebGPU/Vulkan implementation should keep NCHW for these exported-graphs.--### Bucket buffer caches--Setting storage, uniform, query-resolve, and default buffer caches to `bucket`-was parity-exact. MobileFaceNet improved 4.58% in isolation, but YOLO was flat-and CLIP regressed 0.47%. The improvement did not survive the final combined-run, where MobileFaceNet was only 0.17% faster than baseline. The added cache-policy is not justified by this evidence.--### Preallocated WebGPU I/O--The preallocation experiment used persistent CPU and `WebGPU_Buffer` tensors,-`IoBinding`, and synchronous `CopyTensors` calls around each inference. It-worked and was output-identical, but the timing boundary exposed why it did not-help:--| Model | Policy | Input p50 | `Session::run` p50 | Output/sync p50 | Complete inference p50 |-|---|---|---:|---:|---:|---:|-| YOLO | Normal ORT I/O | 0.031 ms | 107.385 ms | 0.800 ms | **108.111 ms** |-| YOLO | Preallocated GPU I/O | 2.212 ms | 13.610 ms | 92.544 ms | 108.465 ms |-| MobileCLIP | Normal ORT I/O | 0.024 ms | 136.603 ms | 0.008 ms | **136.637 ms** |-| MobileCLIP | Preallocated GPU I/O | 0.679 ms | 30.162 ms | 105.752 ms | 137.751 ms |-| MobileFaceNet | Normal ORT I/O | 0.018 ms | 14.387 ms | 0.003 ms | 14.397 ms |-| MobileFaceNet | Preallocated GPU I/O | 0.405 ms | 7.406 ms | 5.619 ms | **13.838 ms** |--With explicit GPU output tensors, `Session::run` returns before the final-device work and readback are synchronized. The output copy then pays that cost.-Reporting only the run column would falsely claim an approximately 8x YOLO-speedup; the complete timer correctly shows a 0.33% regression. Keeping normal-ORT-managed I/O is simpler and faster overall for the current CPU-preprocessing/postprocessing pipeline.--### FP32 versus FP16--All three models were converted to genuine FP16 graphs with FP16 inputs,-outputs, weights, and intermediates; this was not merely an input cast. Each-passed full ONNX checking and executed the complete corpus.--| Model | FP32 bytes | FP16 bytes | FP32 p50 | FP16 p50 | Latency change |-|---|---:|---:|---:|---:|---:|-| YOLO | 32,355,091 | 16,229,361 | 108.111 ms | **78.299 ms** | **-27.58%** |-| MobileCLIP | 143,061,211 | 71,753,862 | 136.637 ms | **102.451 ms** | **-25.02%** |-| MobileFaceNet | 5,278,803 | 2,723,399 | 14.397 ms | **12.427 ms** | **-13.68%** |--FP16 preserved all 14 face counts. MobileCLIP parity was strong: median cosine-`0.9998346`, minimum `0.9997101`. Face embeddings had median cosine-`0.9991900`, but the minimum was `0.9590737`; the two worst cases were very-small faces in `ui_app.webp`. Detector rounding slightly changes their boxes-and landmarks, and that crop difference is amplified by the embedding model.--Following the requested final policy, FP16 was therefore **not** included in-the combined run. It remains the only tested setting with a large speedup and-is worth a future mixed-precision accuracy studyβfor example FP16 YOLO/CLIP-with FP32 MobileFaceNet and explicit face-quality thresholdsβbut it should not-replace the current FP32 face pipeline without a broader retrieval/identity-evaluation.--## Final FP32 combination--The full final test used FP32 models, graph capture, all bucket caches, NCHW,-and normal ORT I/O. It completed all 14 fixtures and all expected model calls,-remained at thermal status `0`, and produced exact FP32 baseline parity:--| Correctness check | Result |-|---|---:|-| Fixtures with identical face counts | 14/14 |-| CLIP cosine, minimum | `0.9999999999999998` |-| Face-embedding cosine, minimum | `0.9999999999999998` |-| Fatal/native/ORT failures | 0 |--The combination's no-CR2 corpus median was 9,638.985 ms versus 9,676.216 ms-for baseline, only 0.38% faster. Its aggregate median model time was 3.807-seconds versus 3.786 seconds for baseline. In other words, the tiny pipeline-change came from non-model variation; the combined model configuration was-slightly slower overall. No runtime tuning knob tested here closes the gap to-the approximately 20 ms CoreML results on A17 Pro.--The remaining Android performance gap is more likely architectural: CoreML-can fuse and compile these graphs for Apple's tightly integrated GPU/ANE stack,-while ORT WebGPU emits portable Dawn/Vulkan workloads with different fusion,-dispatch, and memory behavior. The next high-value work is model-level-optimization or quantization and cross-vendor measurement, not additional-session flags from this set.--## Initial smoke-test outcome (superseded by the follow-up above)--The custom ONNX Runtime build works in a real, non-debuggable release APK, and-the indexing models genuinely execute through Dawn's Vulkan WebGPU backend on-the Pixel 8's Mali-G715. This is not inferred merely from app-level Vulkan-activity: ONNX Runtime's own execution-plan logs assigned YOLO and MobileCLIP-entirely to `WebGpuExecutionProvider`, and assigned MobileFaceNet to a-WebGPU/CPU split.--The full 14-fixture corpus completed without a crash or ML error. The run-performed one warm-up and five measured passes per fixture: 84 completed image-pipelines, 70 measured pipelines, 70 YOLO inferences, 70 MobileCLIP inferences,-and 125 measured MobileFaceNet inferences for the corpus's 25 faces per pass.--The steady pure-inference result is mixed:--| Model | WebGPU `session.run` p50 | Historical XNNPACK4 p50 | Directional change |-|---|---:|---:|---:|-| YOLO face detector B1 | 107.6 ms | 204.4 ms | **47.3% lower latency** |-| MobileCLIP B1 | 139.0 ms | 301.6 ms | **53.9% lower latency** |-| MobileFaceNet B1, per face | 99.5 ms | 19.4 ms | **5.13x slower** |--Despite the MobileFaceNet regression, the observed 25-face corpus needs about-5.862 seconds of pure WebGPU-policy inference per steady pass, versus-7.499β7.631 seconds in the earlier XNNPACK4 runs. That is a directional-21.8β23.2% reduction for this exact corpus. It is not a controlled-apples-to-apples percentage because the earlier run used Android 16 and a-Flutter profile shell, while both runs used release Rust.--The recommended production experiment is therefore **model-specific**, not a-uniform WebGPU policy:--- Use WebGPU for YOLO and MobileCLIP on supported Android devices.-- Keep MobileFaceNet on direct CPU or XNNPACK unless a graph change removes the- WebGPU/CPU partition and its transfer/dispatch overhead. The previous Pixel 8- benchmark found direct CPU fastest for this model.-- Retain XNNPACK and CPU as session-creation fallbacks.-- Validate the hybrid policy in the same release APK on more Android GPUs- before enabling it broadly.--## What was tested--The existing ML parity manifest was used without dropping difficult formats:--- 14/14 fixtures: JPEG, PNG, WebP, HEIC, panoramic images, rotations/mirroring,- and the CR2 RAW fixture.-- Face detection, face alignment, face embedding, and MobileCLIP image- embedding were enabled.-- Pet indexing was not part of this parity manifest and remained disabled.-- Each fixture was downloaded or resolved before its timed loop.-- Each fixture received one unmeasured warm-up followed by five measured- `_analyzeImage` calls.--The benchmark used four nested timing levels:--1. Dart end-to-end `_analyzeImage` time, including FFI/isolate scheduling and- the CR2 fallback behavior.-2. Rust pipeline stages: runtime entry, decode, YOLO preprocessing, face- detection, face alignment, face embedding, MobileCLIP, all pet-stage slots,- and unaccounted time.-3. Exact ONNX calls: input tensor construction, synchronous `session.run`, and- output access/copy for every model invocation.-4. Session construction and provider-fallback attempts.--Timers use microsecond-resolution Dart clocks and Rust `Instant` nanoseconds.-The Android log emission happens after the inference timer is stopped. ORT-execution-plan verbosity emitted messages during session construction, but no-plan messages during the measured inference loops.--## Release-mode proof--The normal Flutter Driver command intentionally refuses Android `--release`,-so the parity test entrypoint was built directly as an installable release APK-and launched through its explicit activity. This preserves the test logic-without silently falling back to profile mode.--| Check | Evidence |-|---|---|-| Flutter mode | Benchmark asserts `dart.vm.product == true` and `dart.vm.profile == false` before doing any work; the complete results file was produced. |-| Android manifest | `apkanalyzer manifest debuggable` returned `false`. |-| Installed package | `dumpsys package` flags were `[ HAS_CODE ALLOW_CLEAR_USER_DATA LARGE_HEAP ]`, with no `DEBUGGABLE` flag. |-| Rust mode | Cargokit built and packaged `aarch64-linux-android/release/libente_photos_rust.so`. |-| Package | `io.ente.photos.independent`, version `1.3.59` (`2158`), target SDK 36. |-| APK | `app-independent-release.apk`, 243,248,701 bytes, SHA-256 `58b93b4a488a6c452f57193090c6a762ee69312525b7f41ac93cd0a5efc0d772`. |--The APK was signed with the local Android debug certificate solely to permit-installation on the attached device. Certificate choice does not change the-release/AOT build mode; the installed manifest remained non-debuggable.--The packaged arm64 libraries included `libapp.so`, release-`libente_photos_rust.so`, and the custom `libonnxruntime.so`. The custom AAR's-SHA-256 was-`f40ef31bb6ff8399c556872bcad272bddb650b0845f3026c56a065de9b1ec579`,-matching `mobile/native/onnxruntime/version.properties`. Its native library-contains WebGPU EP, Dawn, Vulkan, and XNNPACK symbols.--## Proof that ONNX Runtime used the GPU--The attached device reported:--| Property | Value |-|---|---|-| Model / device | Pixel 8 / `shiba` |-| SoC | Google Tensor G3 |-| Vulkan hardware property | `mali` |-| Vulkan physical device | `Mali-G715` |-| Vulkan device type | Integrated GPU (`VkPhysicalDeviceType` value 1) |-| Vulkan vendor ID | 5045 (`0x13B5`, Arm) |-| Android GPU accounting | `io.ente.photos.independent` had a Vulkan device; `cpuVulkanInUse=0` |--The ML-specific evidence is stronger than those system properties:--1. The runner logged `requested=true sdk_supported=true allowed=true`.-2. Every first session attempt used `webgpu+xnnpack+cpu` and succeeded; no- XNNPACK-only or CPU-only fallback attempt occurred.-3. The ORT session options recorded WebGPU's Dawn backend as `Vulkan` and- preferred layout as `NCHW`.-4. Dawn initialized and emitted its Mali capability-limit warnings.-5. ORT's optimized execution plans reported the following placement:--| Model | WebGPU nodes | CPU nodes | Placement result |-|---|---:|---:|---|-| Static YOLO | 277 | 0 | All nodes on WebGPU |-| MobileCLIP | 660 | 0 | All nodes on WebGPU |-| Static MobileFaceNet | 132 | 33 | Split WebGPU/CPU graph |--This confirms WebGPU compute on the Mali GPU. Flutter also used Vulkan for-Impeller, but the ORT node-assignment records distinguish ML GPU execution from-rendering activity.--## Session construction--These are process-cold sessions with already-downloaded model files. All three-primary WebGPU attempts succeeded.--| Model | Provider chain | Session construction |-|---|---|---:|-| YOLO | WebGPU -> XNNPACK4 -> CPU | 239.7 ms |-| MobileCLIP | WebGPU -> XNNPACK4 -> CPU | 389.3 ms |-| MobileFaceNet | WebGPU -> XNNPACK4 -> CPU | 71.4 ms |-| **Total** | | **700.4 ms** |--These times include ORT graph optimization and Dawn pipeline/session setup.-They do not include model download. No failed session attempt was observed.--## Pure inference--`session.run` is the synchronous ORT call only. βTotal inference timerβ adds-input tensor creation and output extraction/copy, but still excludes image-decode, resize/preprocessing, detector postprocessing, face alignment, and-embedding normalization.--| Model | Calls | First `session.run` | Steady p50 | p90 | p95 | Range |-|---|---:|---:|---:|---:|---:|---:|-| YOLO | 70 | 517.4 ms | 107.6 ms | 112.5 ms | 113.2 ms | 103.3β120.4 ms |-| MobileCLIP | 70 | 503.1 ms | 139.0 ms | 145.3 ms | 149.2 ms | 129.2β151.2 ms |-| MobileFaceNet B1 | 125 | 143.2 ms | 99.5 ms | 110.6 ms | 112.7 ms | 49.4β123.5 ms |--The first-call values show expected WebGPU shader/pipeline warm-up. They come-from the first fixture warm-up and are excluded from all steady percentiles.-The MobileFaceNet range is bimodal/noisy compared with the fully GPU-placed-models, consistent with its 132-WebGPU/33-CPU partition.--Tensor wrapping and output extraction are not the explanation for the model-latencies:--| Model | Input p50 | Output p50 | Total inference-timer p50 |-|---|---:|---:|---:|-| YOLO | 0.037 ms | 0.756 ms | 108.7 ms |-| MobileCLIP | 0.031 ms | 0.007 ms | 139.0 ms |-| MobileFaceNet | 0.018 ms | 0.007 ms | 99.5 ms |--Across one 14-image steady corpus pass, pure `session.run` time averages:--| Model | Calls per corpus | Pure inference per corpus |-|---|---:|---:|-| YOLO | 14 | 1.514 s |-| MobileCLIP | 14 | 1.945 s |-| MobileFaceNet | 25 | 2.403 s |-| **Total** | **53** | **5.862 s** |--MobileFaceNet therefore accounts for about 41% of pure model inference on this-corpus even though each input is only 112x112. A hybrid provider policy has a-larger opportunity than further tuning fully GPU-placed YOLO or MobileCLIP.--## End-to-end pipeline timing--The five complete Dart corpus rounds were 17.565, 17.438, 17.332, 17.722, and-17.654 seconds; their p50 is **17.565 seconds**. These timings exclude fixture-download but include the complete `_analyzeImage` boundary and CR2's failed-native-decode attempt plus JPEG fallback.--The Rust successful-pipeline rounds were 11.735, 11.854, 11.784, 12.029, and-11.834 seconds, p50 **11.834 seconds**. The difference is dominated by-`IMG_8905.CR2`: Dart measures about 5.968 seconds, while the successful JPEG-fallback pipeline is about 0.494 seconds. The first native CR2 attempt exits-before a successful Rust `pipeline_end`, but remains included in the Dart-end-to-end number. Without CR2, the five Dart corpus rounds are-11.469β11.754 seconds.--Summed across the 70 measured successful Rust pipelines, the work divided as-follows:--| Stage | Five-pass total | Average per corpus | Share of pipeline |-|---|---:|---:|---:|-| Decode | 26.521 s | 5.304 s | 44.77% |-| YOLO preprocessing | 1.518 s | 0.304 s | 2.56% |-| Face detection, including postprocessing | 7.645 s | 1.529 s | 12.91% |-| Face alignment | 0.723 s | 0.145 s | 1.22% |-| Face embedding, 25 B1 calls per corpus | 12.038 s | 2.408 s | 20.32% |-| MobileCLIP, including preprocessing | 10.781 s | 2.156 s | 18.20% |-| Runtime entry + unaccounted | 0.009 s | 0.002 s | 0.01% |-| **Total** | **59.236 s** | **11.847 s** | **100%** |--Decode is the largest end-to-end cost on the mixed-format corpus. Within ML,-MobileFaceNet is now the dominant optimization target because WebGPU has-already cut the two large, fully GPU-placed models substantially.--### Per-fixture steady medians--The Dart total is the most complete latency. Rust stage medians cover the-successful image pipeline and make the bottleneck visible.--| Fixture | Faces | Dart total | Decode | Detection | Face embedding | CLIP |-|---|---:|---:|---:|---:|---:|---:|-| `1343_rotate_90_cw.jpg` | 0 | 434.0 ms | 129.0 ms | 109.1 ms | β | 152.1 ms |-| `1718_rotate_90_cw.HEIC` | 1 | 1,203.0 ms | 829.3 ms | 113.3 ms | 63.5 ms | 156.6 ms |-| `7765_horizontal_normal.HEIC` | 1 | 1,440.3 ms | 1,029.9 ms | 109.3 ms | 86.4 ms | 163.3 ms |-| `7949_mirror_horizontal_rotate_270_cw.HEIC` | 1 | 563.0 ms | 186.3 ms | 108.0 ms | 81.2 ms | 147.7 ms |-| `IMG_0682_pano.HEIC` | 1 | 2,464.7 ms | 2,052.8 ms | 110.3 ms | 74.9 ms | 164.4 ms |-| `IMG_8606_rotate_90_cw_contains_text.HEIC` | 0 | 845.1 ms | 535.7 ms | 108.4 ms | β | 160.4 ms |-| `IMG_8905.CR2` | 0 | 5,968.0 ms | 193.2 ms[^cr2] | 109.9 ms | β | 160.0 ms |-| `IMG_pano.jpg` | 1 | 531.8 ms | 153.4 ms | 107.9 ms | 82.1 ms | 149.7 ms |-| `astronaut.png` | 1 | 420.0 ms | 14.7 ms | 107.8 ms | 106.8 ms | 147.1 ms |-| `man.jpeg` | 1 | 397.6 ms | 1.5 ms | 109.3 ms | 98.9 ms | 146.9 ms |-| `people.jpeg` | 7 | 1,063.9 ms | 1.5 ms | 107.0 ms | 721.9 ms | 155.1 ms |-| `singapore.jpg` | 0 | 330.9 ms | 44.8 ms | 109.6 ms | β | 145.2 ms |-| `starwatchers.jpg` | 1 | 432.6 ms | 23.5 ms | 106.5 ms | 106.6 ms | 150.1 ms |-| `ui_app.webp` | 10 | 1,457.5 ms | 89.1 ms | 107.4 ms | 998.7 ms | 159.0 ms |--[^cr2]: This is the successful fallback JPEG decode only. The Dart total also- includes the failed first CR2-native path and fallback preparation.--## Correctness and smoke-test result--The app produced 14 CLIP embeddings and 25 face records per corpus, wrote its-complete result document, remained alive after the run, and logged no fatal-exception, native signal, out-of-memory error, or failed ONNX session.--Against the Python golden output, 13/14 fixtures passed. The single failure was-the pre-existing `IMG_8905.CR2` MobileCLIP decode difference:--| Metric | Worst observed | Threshold | Result |-|---|---:|---:|---|-| CLIP cosine distance | 0.196097 on CR2 | 0.015 | Known CR2 failure |-| Face-embedding cosine distance | 0.0099168 | 0.015 | Pass |-| Face-box IoU error | 0 | 0 | Pass |-| Landmark error | 0.001165 | 0.03 | Pass |-| Detection-score delta | 0.003269 | 0.05 | Pass |--A direct comparison against the previous Pixel 8 XNNPACK4 Android results is-more diagnostic for the provider change: **14/14 fixtures passed**. Maximum-differences were `1.888e-7` CLIP cosine distance, `6.912e-7` face-embedding-cosine distance, `9.222e-8` landmark delta, and `4.172e-7` score delta, with-identical face boxes. WebGPU therefore preserves the Android-visible outputs-to far tighter tolerances than the Python comparison requires.--## Memory and thermal observations--Immediately after the suite, the still-running process reported 648,832 KiB-PSS and 752,804 KiB RSS. Android attributed 513,292 KiB PSS to graphics-tracking (`GL mtrack` plus `EGL mtrack`). These are post-run whole-process-values, not peak memory or incremental WebGPU cost; they include Flutter,-decoded images, three model sessions, ORT, Dawn, and cached allocations.--The system thermal status remained `0`/none. The G3D sensor rose from about-33 C before the run to 63 C immediately after it, still with sensor status 0.-There was no thermal-throttling status transition. The phone was attached over-USB, so this run is suitable for latency and functional validation, not an-energy-efficiency claim.--## Initial recommendation (superseded by the follow-up above)--The custom AAR and WebGPU integration are technically ready for a broader-pilot: release loading, Dawn/Vulkan initialization, GPU node placement,-fallback configuration, full-corpus stability, and output parity all work on-the Pixel 8.--Do not enable WebGPU uniformly for every indexing model yet. The best next-configuration to benchmark is:--| Model | Proposed provider policy |-|---|---|-| YOLO | WebGPU -> XNNPACK4 -> CPU |-| MobileCLIP | WebGPU -> XNNPACK4 -> CPU |-| MobileFaceNet | CPU directly, or XNNPACK4 -> CPU |--Then repeat the same release corpus run on at least one Qualcomm/Adreno device,-one older supported Android device, and a low-memory device. Provider-availability and Dawn/Vulkan behavior are GPU-driver-specific, so the runtime-contract should remain βtry WebGPU with explicit fallback,β not βall Android-devices use GPU.β--Before rollout, add lightweight production telemetry for provider/session-success, per-model first and steady inference, fallback selection, and device-GPU/driver identity. Do not keep verbose ORT graph-placement logging enabled in-production.--## Limitations--- This is one Pixel 8 on Android 17. The historical XNNPACK comparison used the- same physical device on Android 16, not a same-run release control.-- The device and model files were warm from fixture/model preparation, while- the installed process and its three ORT sessions were cold.-- The benchmark output deliberately stores five timing samples per fixture;- the existing parity schema only accepts scalar timing fields. The raw output- was preserved, and `results_for_comparison.json` removes only those arrays- for the unmodified correctness comparator.-- Pet models were not enabled by the current 14-fixture parity workload.-- The CR2 failed native-decode attempt is covered by the Dart total but exits- before the Rust successful-pipeline summary; its fallback pipeline is fully- instrumented.-- Post-run memory is not peak memory, and USB-attached thermal observations are- not energy measurements.--## Raw artifact map--The evidence is kept under the gitignored-`infra/ml/test/out/android_webgpu_release_2026-07-17/` tree:--- `android/results.json`: raw 14-fixture output with all five Dart timing- samples per fixture.-- `android/results_for_comparison.json`: schema-compatible copy used only by- the parity comparator.-- `logs/final_device_logcat.txt`: provider attempts, ORT placement, exact- inference timings, pipeline stages, Dawn initialization, and smoke-test log.-- `benchmark_summary.json`: parsed timing distributions, corpus rounds, stage- totals, and per-fixture medians.-- `analyze_benchmark.rb`: reproducible parser used to create the summary.-- `comparison_report.json`: WebGPU versus Python correctness report.-- `webgpu_vs_xnnpack4_report.json`: direct WebGPU versus historical XNNPACK4- Android result comparison.-- `python/`: generated Python goldens for the exact fixture manifest and model- hashes.--The follow-up evidence is kept under the gitignored-`infra/ml/test/out/android_webgpu_tuning_2026-07-17/` tree:--- `runs/<variant>/results.json`: application-visible outputs and five measured- end-to-end samples per fixture.-- `runs/<variant>/logcat.txt`: exact per-model input, inference, output, and- total timings for all warm-up and measured calls.-- `runs/<variant>/thermal_before.txt` and `thermal_after.txt`: Android thermal- service snapshots.-- `benchmark_summary.json`: parsed distributions and FP32-baseline parity for- every isolated and final run.-- `placement_evidence.txt`: the filtered verbose ORT placement proof for all- three rewritten-model sessions.-- `models/fp16/`: the checked FP16 experiment artifacts.-- `apks/`: the exact release APKs used for FP32, FP16, and the final FP32- combination.--The fusion follow-up evidence is kept under the gitignored-`infra/ml/test/out/android_webgpu_fusions_2026-07-17/` tree:--- `runs/baseline_fp32/`, `runs/gelu_fp32/`, and- `runs/webgpu_local_fusions_fp32/`: retained results, native timing logs,- release APKs, and thermal snapshots for the two reported experiments and- their control.-- `models/mobileclip_s2_image_gelu_opset20.onnx`: the exact-GELU model used on- device.-- `benchmark_summary.json` and `analyze_fusions.py`: parsed distributions,- detailed parity metrics, and the reproducible analyzer.-- `optimize_clip_model.py`: the benchmark-only exact-GELU model generator.-- `custom_ort_webgpu_fusions.patch`: the tested ONNX Runtime source diff,- including the WebGPU PReLU and SiLU-fusion changes.-- `pixel8_vkjson.json`: the Pixel 8 Vulkan device/driver capability snapshot.--The forced WebGPU flag, system-property variants, I/O-binding pilot, and all-benchmark-only Dart/Rust instrumentation were removed after collecting and-validating these artifacts. No production provider-selection behavior was-changed. The reproducible portable MobileFaceNet transformation, its manifest,-and this report are the durable changes.