[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6BY5T6RQENC1DMWZ8NZ8JFF":3,"skill-same:01M6BY5T6RQENC1DMWZ8NZ8JFF":67},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":8,"repositoryFullName":9,"ownerLogin":10,"ownerAvatarUrl":11,"ownerAccountNo":12,"ownerDisplayName":13,"repositoryNo":14,"starsCount":15,"licenseSpdxId":16,"licenseFileUrl":13,"sourceHtmlUrl":17,"categories":18,"keywords":29,"publishedAt":40,"linkOnly":41,"markdownContent":42,"markdownBody":43,"frontMatter":44,"refName":45,"commitSha":46,"skillDirectory":47,"forksCount":48,"repositoryHtmlUrl":49,"repositoryHomepageUrl":50,"ownerHtmlUrl":51,"ownerBlogUrl":13,"ownerDescription":13,"updatedAt":52,"install":53,"resources":66},"01M6BY5T6RQENC1DMWZ8NZ8JFF","on-device-verification","LiteRT 模型设备端验证","Prove a converted or quantized LiteRT model on the actual device via the CompiledModel API - confirm GPU residency, compare device output against the source model, and diagnose device-only failures such as silent CPU fallback, whole-graph compile ceilings, and fp16 range breaks. Use after conversion or quantization, when device output is wrong or NaN, when a clean graph fails to compile only on device, or when GPU and CPU outputs are suspiciously identical.","通过 CompiledModel API 在真实设备上验证转换或量化后的 LiteRT 模型——确认 GPU 驻留情况，将设备端输出与源模型进行比较，并诊断仅在设备上出现的故障，例如静默 CPU 回退、整图编译上限以及 fp16 数值范围溢出。适用于转换或量化之后；设备输出错误或为 NaN 时；一张本可正常编译的计算图仅在设备上编译失败时；或 GPU 与 CPU 输出可疑地完全一致的情况。","google-ai-edge\u002Flitert-samples","google-ai-edge","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F150697620?v=4","01M6BY4NHMZF88PJAC1E1QJY8N",null,"01M6BY4NNXP8PC95Y6CABCJXP9",495,"Apache-2.0","https:\u002F\u002Fgithub.com\u002Fgoogle-ai-edge\u002Flitert-samples\u002Fblob\u002Fmain\u002Fskills\u002Fon-device-verification\u002FSKILL.md",[19,24],{"categoryNo":20,"categoryName":21,"taxonomyType":22,"taxonomyTypeDesc":23},"01M8BRZZF9D7PVFN5MXSPWWD61","AI 工程师","PROFESSION","适用职业",{"categoryNo":25,"categoryName":26,"taxonomyType":27,"taxonomyTypeDesc":28},"01M8BZTWSXAPNKVKA1N0JGMJK2","AI 模型评估与基准测试","SCENARIO","使用场景",[30,31,32,33,34,35,36,37,38,39],"verification","on device verification","litert","diagnose","compile","gpu","graph","FP16","api","model","2026-11-10 10:12:30",false,"---\nname: on-device-verification\ndescription: Prove a converted or quantized LiteRT model on the actual device via the CompiledModel API - confirm GPU residency, compare device output against the source model, and diagnose device-only failures such as silent CPU fallback, whole-graph compile ceilings, and fp16 range breaks. Use after conversion or quantization, when device output is wrong or NaN, when a clean graph fails to compile only on device, or when GPU and CPU outputs are suspiciously identical.\n---\n\n# On-device verification\n\nA device result is done when three things hold:\n\n1. the model compiles and runs on the accelerator you claim it runs on,\n2. the output matches the source model numerically **and** on a task-level\n   gate,\n3. the record names the device, the runtime version, and the residency\n   line. A number without those is not reproducible and not a result.\n\nHost-side checks (the CompiledModel checker used in `gpu-clean-conversion`)\nexercise the host GPU. The device has its own shader compiler, its own\nprecision behavior, and its own memory ceiling — every failure mode in the\ntable below was hit by a model that had already passed on the host. The\nPython API below runs on the host only (`ai-edge-litert` ships wheels for\nLinux, macOS and Windows); on a phone the same inputs go through the app's\ninference class or a push-run-pull binary (last bullet of \"Watch for\").\n\n## Loop\n\n**1. Dump references from the source model, once.** Fixed inputs — one\nreal sample plus fixed-seed random — saved as `.npy` next to the recipe\n(`dump_*_ref.py`). These are ground truth for every later step; regenerate\nthem only when the source model changes.\n\n**2. Run the same inputs on the host runtime, CPU then GPU, then on the\ndevice.** One argument switches the accelerator (`ai-edge-litert` 2.2.0, 2.3.0):\n\n```python\nfrom ai_edge_litert.compiled_model import CompiledModel\nfrom ai_edge_litert.hardware_accelerator import HardwareAccelerator\n\nmodel = CompiledModel.from_file(\n    \"model.tflite\", hardware_accel=HardwareAccelerator.GPU)  # or .CPU\n```\n\nThe device-CPU run is the control. If it already diverges from the source\ndump, the problem is the conversion, not the GPU — go back to\n`gpu-clean-conversion`. A full worked example of the A\u002FB lives in this\nrepo at `samples\u002Flitert\u002Fspeech_recognition\u002Fconvert\u002Fverify_tflite.py` (its\n`ai_edge_torch.compiled_model` import no longer resolves with litert-torch\n0.9.4; read it as `ai_edge_litert.compiled_model`).\n\nAsk for the strict accelerator. Compiling with\n`HardwareAccelerator.CPU | HardwareAccelerator.GPU` permits partial\ndelegation and hides fallback; use the combined mode only to discover\n*which* ops fell back after a strict GPU compile fails. Strict is per\ngraph, not per op: when the GPU cannot compile the graph, `from_file` raises\n(`Some ops are not accelerated. Add kLiteRtHwAcceleratorCpu …` in 2.3.0);\nwhen the delegate declines one node while building (`TopK requires src\ntensor C dimension to be divisible by 4`), that node runs on the CPU with\nonly the log line, the call returns, and `is_fully_accelerated()` still\nreads true (measured with the 2.2.0 and 2.3.0 wheels on a Mac). The log is\nthe residency signal.\n\n**3. Read the delegate log before reading any numbers.** The CompiledModel\nruntime prints, per op it declines and then as a total:\n\n```\nFollowing operations are not supported by GPU delegate:\nTRANSPOSE: Tensor \"...\" has bad input dims size: 6.\nN operations will run on the GPU, and the remaining M operations will run on the CPU.\n```\n\nRecord it as `N\u002FT` (N on the GPU of T nodes; `benchmark_model` prints the\nsame as `Replacing N out of T node(s) with delegate` plus a partition count).\nAny op left on the CPU means part of the graph runs there — decide whether\nthat is acceptable before quoting any accuracy or latency number.\n\n**4. Gate the output three ways.**\n\n- **Numeric**: correlation and max abs diff against the source dump.\n  Expect genuine GPU fp16 to drift in the last digits — exact equality is\n  a symptom, not a pass (see below).\n- **Task**: argmax match, IoU, token-for-token greedy decode — whatever\n  the model is for.\n- **Artifact**, for generative models: the decoded text \u002F audio \u002F image.\n  An artifact gate catches argmax ties that numeric tolerance misses.\n\n**5. Record it**: device, runtime version, `N\u002FT` (and the partition count\nwhere `benchmark_model` gave one), correlation, max abs diff, task result —\none row per device in the recipe README.\n\n## The silent CPU fallback\n\nA recurring false positive: everything runs and the numbers match\nperfectly. If the GPU output is **bit-identical to the device CPU fp32\noutput, re-read the residency line before believing the GPU ran** — a\nfull `N\u002FT` decides, not the equality; fp16 GPU runs usually drift in the\nlast digits, and an fp32-forced or integer graph may not.\n\nWhen the comparison is between two bundles of the same weights (a re-pack against its source, external against inline weights), byte-compare the text on single-thread CPU (`--cpu-thread-count 1`) or on the GPU: at the default thread count the CPU greedy text of one file moves between fresh processes, so a byte difference there is not a file difference. Long replies in several fresh processes per file are the test; short answers agree even when long ones do not.\n\n## Device-only failures\n\n| What you see | What it is, what to do |\n|---|---|\n| GPU compile fails on device for a graph that is op-clean and passed the host check | A whole-graph compile ceiling, not a bad op — a fused graph can fail where each half compiles. Split at a natural block boundary (conv frontend \u002F transformer encoder), verify split == monolith bit-exact on the host, ship the halves |\n| The file refuses to load at all | The >2 GB flatbuffer limit. Split, or quantize below it |\n| Full residency, wrong numbers | Bisect by intermediates: re-export with block-boundary tensors as extra outputs and find the first one that diverges. In the cases on record the cause was a reduction (mean, variance, Σx²) in fp16, not the op suspected. If materializing a tap *fixes* the numbers, that localizes the bug to a fusion boundary — record it as a finding, not a nuisance |\n| Wrong-but-plausible output, and every hypothesis costs a slow re-export | Micro-probe instead: export ~1 KB graphs — the suspect subexpression and each candidate fix — and run them through the device harness you already have. Minutes per hypothesis instead of a re-export per hypothesis |\n| NaN or garbage only on the GPU, in a model with large-magnitude residuals or deep modulation paths | An fp16 range break. Confirm the attribution by forcing fp32 on the delegate (`CompiledModel.GpuOptions(precision = …)` in Kotlin; ~2× memory, slower); then fix it properly with the fp16-safe rewrites in `gpu-clean-conversion`, or keep the offending block on CPU and run the rest on GPU |\n| The process dies while loading or running a large float model | A memory ceiling, not a model bug. Weights + activations + delegate buffers must fit in available memory. Do not run a multi-GiB fp32 build in-process on a phone \"just to check\" — quantize or split first, then verify the smaller thing |\n| A deep transformer shipped as an fp16 graph is bit-exact on desktop and noise on the device CPU | Android ARM XNNPACK computes fp16 **activations** natively; desktop XNNPACK upcasts to fp32. Deep residual streams compound the difference to collapse. Ship fp32 activations for CPU inference on device (fp16 *weights* that dequantize on load are a size route, not this case) |\n| Attention quality collapses only for a small-head submodule | head_dim is the fp16-fragile axis, not token count: the same graph at head_dim 64 held corr 0.998 where head_dim 16 fell to 0.86. Pad heads to ≥32 or keep the small-head module on CPU |\n| A `[1,N,C]` token tensor that is a graph output **and** feeds other consumers comes back corrupted | 3-D fan-out corruption — the later branch is clobbered, it cascades, and it reads exactly like an fp16 wall downstream (4-D NCHW maps with the same fan-out are fine). Keep token tensors as sole leaf outputs (or keep them 4-D) and push per-token heads to the host — exact, since per-token ops commute with the gather |\n| An output that is one of the graph's own inputs, passed through with no op writing it, comes back as stale bytes; a graph that also reads that tensor computes on that unwritten buffer (zeros in the case on record) | The CompiledModel API binds the output to its own buffer and the graph reads the tensor from that output binding, which nothing writes. Measured on one speech encoder with LiteRT 2.2.0 (Android, CPU) and ai-edge-litert 2.4.0.dev20261011 (macOS, CPU and Metal); the Interpreter API keeps one tensor and gives the right answer, so a host Interpreter check passes. Export without the pass-through output (or produce it with a real op), or write the value into the output buffer as well, or bind one buffer to both; when a host hands streaming state back, copy pass-through states from the inputs |\n| A fused-LSTM-style graph with **variable tensors** (state kept inside the graph) will not load | The CompiledModel loader rejects it: `model_load.cc: Variable tensors not yet supported` (2.2.0 and 2.3.0, `from_file` and `from_buffer`). Re-export the graph stateless — the recurrent state as explicit inputs and outputs that the host feeds back each call — and verify the per-call parity on that form |\n\n## Watch for\n\n- **Two references, two verdicts.** The source-framework dump is the\n  truth; the device CPU run is the control that isolates the GPU. A\n  GPU-vs-CPU comparison alone can pass while both are wrong.\n- **Gate a reduced-precision form on the whole check set, long inputs\n  included.** On one speech encoder a subset of 7–9 rows passed the NPU\n  (fp16 arithmetic) and one phone's GPU at FP16_WITH_FP32_ACCUM; the\n  whole set (41–90 windows by window length, every window of the opening\n  10 minutes of a 54-minute recording among them) failed both. The failing\n  tokens were quiet but not silent, at the same moments of the recording\n  on every backend and every window cut, and an int8 form failed at most\n  of those moments too: content-sensitive tokens, not an op bug. List\n  the failures by input position before bisecting ops, and keep the\n  subset for speed iterations only.\n- **The fp32-forcing knob is for attribution, not shipping.** It tells\n  you precision is the cause; the fix is a rewrite or hybrid placement.\n- **First inference includes shader compilation.** Correctness on the\n  first run is fine; never quote first-run latency, and never let a\n  latency number travel without its residency line.\n- **One device proves correctness, not portability.** GPU compilers\n  differ per vendor — a compile ceiling on one chip may not exist on\n  another. \"Runs on Android GPUs\" means a device matrix (your own\n  devices, or a device farm), recorded as one row each.\n- **One runtime proves it for that runtime.** A delegate rejection or\n  miscompute is a fact about the runtime version you measured: ops have\n  been *dropped* between minor versions (`RELU_0_TO_1`: accepted in 2.1.3,\n  rejected from 2.1.5 — LiteRT#8598), a miscompute's victim output has\n  *moved* between versions, and mixing accelerator and core libraries\n  across versions falls back to the CPU with a log line at most. When a wall\n  appears after an upgrade, bisect the runtime pin on the real graph —\n  micro-probes have repeatedly failed to reproduce walls that only fire\n  in full-graph context, so a negative micro-probe is not a refutation.\n- **Localize miscomputes with single-output graphs, never fan-out\n  taps.** A multi-output tapped probe is itself exposed to\n  output-aliasing bugs and has produced a confidently wrong culprit;\n  in single-output form every op was exact and the *assembly* was the\n  bug.\n- **Sweep the delegate options to classify a miscompute.** Run the same\n  graph across precision, buffer-storage, and backend options: a\n  bit-identical wrong result across all of them places the bug in the\n  shared graph-compilation layer and rules out precision\u002Fstorage in one\n  pass. And know what the precision flag can do: forcing fp32 rescues\n  overflow→NaN cases only — it does **not** fix precision compounding\n  (the delegate still reduces in fp16), so \"fp32 didn't help\" does not\n  exonerate fp16.\n- **Time the enqueue and the readback as separate counters.** `run()`\n  is asynchronous; timing it alone has reported a 4× GPU win that did\n  not exist. A large readback time is usually the deferred compute, not\n  the transfer. Per-call overhead adds up: it makes small\n  per-step graphs (KV-cache decoders re-uploading state every token) a\n  net GPU loss — estimate `calls × per-call overhead` against the CPU\n  time before re-exporting for GPU; the crossover sits around\n  hundreds of nodes per call.\n- **The host CPU run is the numerical reference, not a GPU test** — the\n  host GPU (the Metal accelerator of the macOS wheel) is a different\n  compiler from the phone's, so a host GPU pass is not a device result.\n  For the device loop, a minimal push-run-pull binary (tflite in, output\n  tensor out; the LiteRT C++ SDK zip and its CompiledModel API) iterates\n  in seconds without an app rebuild.\n- **Hybrid models: one Engine per conversation, one process per timing\n  run.** A new Conversation on a shared LiteRT-LM Engine starts with an\n  empty context but keeps the live state buffers, so its prompt prefills\n  on the previous conversation's linear-attention state (GatedDeltaNet,\n  Mamba, short-conv layers — LiteRT-LM#3165); slot-addressed KV caches\n  are not affected. A harness that loops N runs in one process measures\n  a drifting model and reports success. Run N processes, and gate each\n  prompt length in a fresh process.\n\n## Output layout\n\nVerification is part of the model recipe, not a side script:\n\n```\nmodels\u002F\u003Cfamily>\u002F\u003Cmodel>\u002Fconverted\u002F\n  dump_*_ref.py            source-model reference dumps (.npy)\n  verify_*.py              parity vs those references, accelerator as a flag\n  README.md                per-device table: device | accelerator |\n                           N\u002FM nodes, partitions | corr | max abs | task gate\n```\n\nKeep the dump and the verify separately runnable: references are dumped\nonce on the host, verification re-runs on every device and after every\nmodel change.\n","# On-device verification\n\nA device result is done when three things hold:\n\n1. the model compiles and runs on the accelerator you claim it runs on,\n2. the output matches the source model numerically **and** on a task-level\n   gate,\n3. the record names the device, the runtime version, and the residency\n   line. A number without those is not reproducible and not a result.\n\nHost-side checks (the CompiledModel checker used in `gpu-clean-conversion`)\nexercise the host GPU. The device has its own shader compiler, its own\nprecision behavior, and its own memory ceiling — every failure mode in the\ntable below was hit by a model that had already passed on the host. The\nPython API below runs on the host only (`ai-edge-litert` ships wheels for\nLinux, macOS and Windows); on a phone the same inputs go through the app's\ninference class or a push-run-pull binary (last bullet of \"Watch for\").\n\n## Loop\n\n**1. Dump references from the source model, once.** Fixed inputs — one\nreal sample plus fixed-seed random — saved as `.npy` next to the recipe\n(`dump_*_ref.py`). These are ground truth for every later step; regenerate\nthem only when the source model changes.\n\n**2. Run the same inputs on the host runtime, CPU then GPU, then on the\ndevice.** One argument switches the accelerator (`ai-edge-litert` 2.2.0, 2.3.0):\n\n```python\nfrom ai_edge_litert.compiled_model import CompiledModel\nfrom ai_edge_litert.hardware_accelerator import HardwareAccelerator\n\nmodel = CompiledModel.from_file(\n    \"model.tflite\", hardware_accel=HardwareAccelerator.GPU)  # or .CPU\n```\n\nThe device-CPU run is the control. If it already diverges from the source\ndump, the problem is the conversion, not the GPU — go back to\n`gpu-clean-conversion`. A full worked example of the A\u002FB lives in this\nrepo at `samples\u002Flitert\u002Fspeech_recognition\u002Fconvert\u002Fverify_tflite.py` (its\n`ai_edge_torch.compiled_model` import no longer resolves with litert-torch\n0.9.4; read it as `ai_edge_litert.compiled_model`).\n\nAsk for the strict accelerator. Compiling with\n`HardwareAccelerator.CPU | HardwareAccelerator.GPU` permits partial\ndelegation and hides fallback; use the combined mode only to discover\n*which* ops fell back after a strict GPU compile fails. Strict is per\ngraph, not per op: when the GPU cannot compile the graph, `from_file` raises\n(`Some ops are not accelerated. Add kLiteRtHwAcceleratorCpu …` in 2.3.0);\nwhen the delegate declines one node while building (`TopK requires src\ntensor C dimension to be divisible by 4`), that node runs on the CPU with\nonly the log line, the call returns, and `is_fully_accelerated()` still\nreads true (measured with the 2.2.0 and 2.3.0 wheels on a Mac). The log is\nthe residency signal.\n\n**3. Read the delegate log before reading any numbers.** The CompiledModel\nruntime prints, per op it declines and then as a total:\n\n```\nFollowing operations are not supported by GPU delegate:\nTRANSPOSE: Tensor \"...\" has bad input dims size: 6.\nN operations will run on the GPU, and the remaining M operations will run on the CPU.\n```\n\nRecord it as `N\u002FT` (N on the GPU of T nodes; `benchmark_model` prints the\nsame as `Replacing N out of T node(s) with delegate` plus a partition count).\nAny op left on the CPU means part of the graph runs there — decide whether\nthat is acceptable before quoting any accuracy or latency number.\n\n**4. Gate the output three ways.**\n\n- **Numeric**: correlation and max abs diff against the source dump.\n  Expect genuine GPU fp16 to drift in the last digits — exact equality is\n  a symptom, not a pass (see below).\n- **Task**: argmax match, IoU, token-for-token greedy decode — whatever\n  the model is for.\n- **Artifact**, for generative models: the decoded text \u002F audio \u002F image.\n  An artifact gate catches argmax ties that numeric tolerance misses.\n\n**5. Record it**: device, runtime version, `N\u002FT` (and the partition count\nwhere `benchmark_model` gave one), correlation, max abs diff, task result —\none row per device in the recipe README.\n\n## The silent CPU fallback\n\nA recurring false positive: everything runs and the numbers match\nperfectly. If the GPU output is **bit-identical to the device CPU fp32\noutput, re-read the residency line before believing the GPU ran** — a\nfull `N\u002FT` decides, not the equality; fp16 GPU runs usually drift in the\nlast digits, and an fp32-forced or integer graph may not.\n\nWhen the comparison is between two bundles of the same weights (a re-pack against its source, external against inline weights), byte-compare the text on single-thread CPU (`--cpu-thread-count 1`) or on the GPU: at the default thread count the CPU greedy text of one file moves between fresh processes, so a byte difference there is not a file difference. Long replies in several fresh processes per file are the test; short answers agree even when long ones do not.\n\n## Device-only failures\n\n| What you see | What it is, what to do |\n|---|---|\n| GPU compile fails on device for a graph that is op-clean and passed the host check | A whole-graph compile ceiling, not a bad op — a fused graph can fail where each half compiles. Split at a natural block boundary (conv frontend \u002F transformer encoder), verify split == monolith bit-exact on the host, ship the halves |\n| The file refuses to load at all | The >2 GB flatbuffer limit. Split, or quantize below it |\n| Full residency, wrong numbers | Bisect by intermediates: re-export with block-boundary tensors as extra outputs and find the first one that diverges. In the cases on record the cause was a reduction (mean, variance, Σx²) in fp16, not the op suspected. If materializing a tap *fixes* the numbers, that localizes the bug to a fusion boundary — record it as a finding, not a nuisance |\n| Wrong-but-plausible output, and every hypothesis costs a slow re-export | Micro-probe instead: export ~1 KB graphs — the suspect subexpression and each candidate fix — and run them through the device harness you already have. Minutes per hypothesis instead of a re-export per hypothesis |\n| NaN or garbage only on the GPU, in a model with large-magnitude residuals or deep modulation paths | An fp16 range break. Confirm the attribution by forcing fp32 on the delegate (`CompiledModel.GpuOptions(precision = …)` in Kotlin; ~2× memory, slower); then fix it properly with the fp16-safe rewrites in `gpu-clean-conversion`, or keep the offending block on CPU and run the rest on GPU |\n| The process dies while loading or running a large float model | A memory ceiling, not a model bug. Weights + activations + delegate buffers must fit in available memory. Do not run a multi-GiB fp32 build in-process on a phone \"just to check\" — quantize or split first, then verify the smaller thing |\n| A deep transformer shipped as an fp16 graph is bit-exact on desktop and noise on the device CPU | Android ARM XNNPACK computes fp16 **activations** natively; desktop XNNPACK upcasts to fp32. Deep residual streams compound the difference to collapse. Ship fp32 activations for CPU inference on device (fp16 *weights* that dequantize on load are a size route, not this case) |\n| Attention quality collapses only for a small-head submodule | head_dim is the fp16-fragile axis, not token count: the same graph at head_dim 64 held corr 0.998 where head_dim 16 fell to 0.86. Pad heads to ≥32 or keep the small-head module on CPU |\n| A `[1,N,C]` token tensor that is a graph output **and** feeds other consumers comes back corrupted | 3-D fan-out corruption — the later branch is clobbered, it cascades, and it reads exactly like an fp16 wall downstream (4-D NCHW maps with the same fan-out are fine). Keep token tensors as sole leaf outputs (or keep them 4-D) and push per-token heads to the host — exact, since per-token ops commute with the gather |\n| An output that is one of the graph's own inputs, passed through with no op writing it, comes back as stale bytes; a graph that also reads that tensor computes on that unwritten buffer (zeros in the case on record) | The CompiledModel API binds the output to its own buffer and the graph reads the tensor from that output binding, which nothing writes. Measured on one speech encoder with LiteRT 2.2.0 (Android, CPU) and ai-edge-litert 2.4.0.dev20261011 (macOS, CPU and Metal); the Interpreter API keeps one tensor and gives the right answer, so a host Interpreter check passes. Export without the pass-through output (or produce it with a real op), or write the value into the output buffer as well, or bind one buffer to both; when a host hands streaming state back, copy pass-through states from the inputs |\n| A fused-LSTM-style graph with **variable tensors** (state kept inside the graph) will not load | The CompiledModel loader rejects it: `model_load.cc: Variable tensors not yet supported` (2.2.0 and 2.3.0, `from_file` and `from_buffer`). Re-export the graph stateless — the recurrent state as explicit inputs and outputs that the host feeds back each call — and verify the per-call parity on that form |\n\n## Watch for\n\n- **Two references, two verdicts.** The source-framework dump is the\n  truth; the device CPU run is the control that isolates the GPU. A\n  GPU-vs-CPU comparison alone can pass while both are wrong.\n- **Gate a reduced-precision form on the whole check set, long inputs\n  included.** On one speech encoder a subset of 7–9 rows passed the NPU\n  (fp16 arithmetic) and one phone's GPU at FP16_WITH_FP32_ACCUM; the\n  whole set (41–90 windows by window length, every window of the opening\n  10 minutes of a 54-minute recording among them) failed both. The failing\n  tokens were quiet but not silent, at the same moments of the recording\n  on every backend and every window cut, and an int8 form failed at most\n  of those moments too: content-sensitive tokens, not an op bug. List\n  the failures by input position before bisecting ops, and keep the\n  subset for speed iterations only.\n- **The fp32-forcing knob is for attribution, not shipping.** It tells\n  you precision is the cause; the fix is a rewrite or hybrid placement.\n- **First inference includes shader compilation.** Correctness on the\n  first run is fine; never quote first-run latency, and never let a\n  latency number travel without its residency line.\n- **One device proves correctness, not portability.** GPU compilers\n  differ per vendor — a compile ceiling on one chip may not exist on\n  another. \"Runs on Android GPUs\" means a device matrix (your own\n  devices, or a device farm), recorded as one row each.\n- **One runtime proves it for that runtime.** A delegate rejection or\n  miscompute is a fact about the runtime version you measured: ops have\n  been *dropped* between minor versions (`RELU_0_TO_1`: accepted in 2.1.3,\n  rejected from 2.1.5 — LiteRT#8598), a miscompute's victim output has\n  *moved* between versions, and mixing accelerator and core libraries\n  across versions falls back to the CPU with a log line at most. When a wall\n  appears after an upgrade, bisect the runtime pin on the real graph —\n  micro-probes have repeatedly failed to reproduce walls that only fire\n  in full-graph context, so a negative micro-probe is not a refutation.\n- **Localize miscomputes with single-output graphs, never fan-out\n  taps.** A multi-output tapped probe is itself exposed to\n  output-aliasing bugs and has produced a confidently wrong culprit;\n  in single-output form every op was exact and the *assembly* was the\n  bug.\n- **Sweep the delegate options to classify a miscompute.** Run the same\n  graph across precision, buffer-storage, and backend options: a\n  bit-identical wrong result across all of them places the bug in the\n  shared graph-compilation layer and rules out precision\u002Fstorage in one\n  pass. And know what the precision flag can do: forcing fp32 rescues\n  overflow→NaN cases only — it does **not** fix precision compounding\n  (the delegate still reduces in fp16), so \"fp32 didn't help\" does not\n  exonerate fp16.\n- **Time the enqueue and the readback as separate counters.** `run()`\n  is asynchronous; timing it alone has reported a 4× GPU win that did\n  not exist. A large readback time is usually the deferred compute, not\n  the transfer. Per-call overhead adds up: it makes small\n  per-step graphs (KV-cache decoders re-uploading state every token) a\n  net GPU loss — estimate `calls × per-call overhead` against the CPU\n  time before re-exporting for GPU; the crossover sits around\n  hundreds of nodes per call.\n- **The host CPU run is the numerical reference, not a GPU test** — the\n  host GPU (the Metal accelerator of the macOS wheel) is a different\n  compiler from the phone's, so a host GPU pass is not a device result.\n  For the device loop, a minimal push-run-pull binary (tflite in, output\n  tensor out; the LiteRT C++ SDK zip and its CompiledModel API) iterates\n  in seconds without an app rebuild.\n- **Hybrid models: one Engine per conversation, one process per timing\n  run.** A new Conversation on a shared LiteRT-LM Engine starts with an\n  empty context but keeps the live state buffers, so its prompt prefills\n  on the previous conversation's linear-attention state (GatedDeltaNet,\n  Mamba, short-conv layers — LiteRT-LM#3165); slot-addressed KV caches\n  are not affected. A harness that loops N runs in one process measures\n  a drifting model and reports success. Run N processes, and gate each\n  prompt length in a fresh process.\n\n## Output layout\n\nVerification is part of the model recipe, not a side script:\n\n```\nmodels\u002F\u003Cfamily>\u002F\u003Cmodel>\u002Fconverted\u002F\n  dump_*_ref.py            source-model reference dumps (.npy)\n  verify_*.py              parity vs those references, accelerator as a flag\n  README.md                per-device table: device | accelerator |\n                           N\u002FM nodes, partitions | corr | max abs | task gate\n```\n\nKeep the dump and the verify separately runnable: references are dumped\nonce on the host, verification re-runs on every device and after every\nmodel change.\n",{"name":5,"description":7},"main","9467001474dc4e072ebc588e5eb9b5fdcf63abbc","skills\u002Fon-device-verification",134,"https:\u002F\u002Fgithub.com\u002Fgoogle-ai-edge\u002Flitert-samples","https:\u002F\u002Fdevelopers.google.com\u002Fedge\u002Flitert","https:\u002F\u002Fgithub.com\u002Fgoogle-ai-edge","2026-11-13 14:36:51",{"source":9,"skillName":5,"commands":54,"prompt":64,"zipAvailable":65},[55,58,61],{"tool":56,"command":57},"npx","npx skills add google-ai-edge\u002Flitert-samples --skill on-device-verification",{"tool":59,"command":60},"bunx","bunx skills add google-ai-edge\u002Flitert-samples --skill on-device-verification",{"tool":62,"command":63},"pnpm","pnpm dlx skills add google-ai-edge\u002Flitert-samples --skill on-device-verification","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fgoogle-ai-edge\u002Flitert-samples\u002Fblob\u002Fmain\u002Fskills\u002Fon-device-verification\u002FSKILL.md",true,[],[68,97,126,149,172,189],{"skillNo":69,"name":70,"nameZh":71,"description":72,"descriptionZh":73,"repositoryFullName":9,"ownerLogin":10,"ownerAvatarUrl":11,"ownerAccountNo":12,"ownerDisplayName":13,"repositoryNo":14,"starsCount":15,"licenseSpdxId":16,"licenseFileUrl":13,"sourceHtmlUrl":74,"categories":75,"keywords":80,"publishedAt":40},"01M6BY5F447DRN3YDJVRWDG9MZ","litert-google-tensor","LiteRT 模型 Pixel TPU 编译","Compiles LiteRT (.tflite) models ahead-of-time for Google Tensor TPUs (Tensor G5 on Pixel 10, Tensor G6 on Pixel 11) locally on Linux x86_64 or remotely via Google Colab (--colab on macOS, Windows, or ARM hosts), benchmarks them on a USB-attached Pixel with LiteRT's benchmark_model (NPU latency, peak memory, TPU tile time, TPU energy, optional CPU baseline), and packages compiled models for an Android Gradle app as a Google Play AI pack with the Tensor NPU runtime module and a Kotlin loader, applies it to the app and verifies it on a Pixel. Use when the user asks to compile, AOT-compile, or prepare a .tflite model for the Pixel TPU\u002FNPU, check whether a .tflite is already Tensor-compiled, measure on-device NPU performance of a compiled model, or package or deploy a compiled model into their Android app (or replace the one it ships). Don't use for Qualcomm, MediaTek, or Samsung NPUs, GPU-only benchmarking, LiteRT-LM or LLM (.litertlm) models, on-device JIT compilation, non-Gradle builds, or publishing to Google Play.","在本地 Linux x86_64 上，或通过 Google Colab 远程（在 macOS、Windows 或 ARM 主机上使用 --colab），为 Google Tensor TPU（Pixel 10 上的 Tensor G5、Pixel 11 上的 Tensor G6）提前（AOT）编译 LiteRT（.tflite）模型；使用 LiteRT 的 benchmark_model 在通过 USB 连接的 Pixel 上进行基准测试（NPU 延迟、峰值内存、TPU tile 时间、TPU 能耗、可选的 CPU 基线）；并将编译后的模型打包为 Android Gradle 应用的 Google Play AI pack，其中包含 Tensor NPU 运行时模块和 Kotlin 加载器，将其应用到应用并在 Pixel 上验证。当用户要求编译、AOT 编译或准备用于 Pixel TPU\u002FNPU 的 .tflite 模型，检查某个 .tflite 是否已针对 Tensor 编译，测量编译模型在设备端的 NPU 性能，或将编译模型打包\u002F部署到其 Android 应用（或替换应用内置的模型）时使用。不适用于 Qualcomm、MediaTek 或 Samsung NPU、仅 GPU 基准测试、LiteRT-LM 或 LLM（.litertlm）模型、设备端 JIT 编译、非 Gradle 构建，或发布到 Google Play。","https:\u002F\u002Fgithub.com\u002Fgoogle-ai-edge\u002Flitert-samples\u002Fblob\u002Fmain\u002Fskills\u002Flitert-google-tensor\u002FSKILL.md",[76,77],{"categoryNo":20,"categoryName":21,"taxonomyType":22,"taxonomyTypeDesc":23},{"categoryNo":78,"categoryName":79,"taxonomyType":27,"taxonomyTypeDesc":28},"01M8C7TWSEQ7QTRNCZXZP1RXM5","AI 模型推理与服务部署",[32,81,82,83,84,39,85,34,86,87,88,89,90,35,91,92,93,94,95,96],"tensor","litert google tensor","google","windows","memory","performance","linux","kotlin","package","play","android","packages","benchmarking","tpu","baseline","benchmark",{"skillNo":98,"name":99,"nameZh":100,"description":101,"descriptionZh":102,"repositoryFullName":9,"ownerLogin":10,"ownerAvatarUrl":11,"ownerAccountNo":12,"ownerDisplayName":13,"repositoryNo":14,"starsCount":15,"licenseSpdxId":16,"licenseFileUrl":13,"sourceHtmlUrl":103,"categories":104,"keywords":107,"publishedAt":40},"01M6BY5BY9H6SDG9GRRTT04EWA","litert-conversion-workflow","大模型转 LiteRT-LM 包","Convert a Hugging Face LLM or vision-language model checkpoint into a .litertlm bundle that runs on the LiteRT-LM runtime with verified quality - classify the architecture against known runtime walls, pick the recipe family (dense, reasoning, hybrid SSM, VLM), export, quantize, gate the result against the source model, and publish. Use when converting a new LLM or VLM to LiteRT-LM, when a converted bundle crashes on the first message or dies at engine creation, when a quantized model answers worse than its source, or when deciding whether a model is convertible at all.","将 Hugging Face 的 LLM 或视觉语言模型检查点转换为 .litertlm 包，使其在 LiteRT-LM 运行时上以经验证的质量运行——依据已知的运行时限制对架构进行分类，选择配方系列（dense、reasoning、hybrid SSM、VLM），导出、量化、对照源模型对结果进行把关，并发布。当把新的 LLM 或 VLM 转换为 LiteRT-LM，当转换后的包在首条消息就崩溃或在引擎创建时失败，当量化后的模型回答质量不如源模型，或需要判断某个模型是否可转换时使用。","https:\u002F\u002Fgithub.com\u002Fgoogle-ai-edge\u002Flitert-samples\u002Fblob\u002Fmain\u002Fskills\u002Flitert-conversion-workflow\u002FSKILL.md",[105,106],{"categoryNo":20,"categoryName":21,"taxonomyType":22,"taxonomyTypeDesc":23},{"categoryNo":78,"categoryName":79,"taxonomyType":27,"taxonomyTypeDesc":28},[108,32,109,110,111,39,112,113,114,115,116,117,118,119,120,121,122,123,124,125],"litert conversion workflow","workflow","conversion","publish","pick","architecture","creation","recipe","message","classify","result","at","quantize","export","verified","hugging face","source","face",{"skillNo":127,"name":128,"nameZh":129,"description":130,"descriptionZh":131,"repositoryFullName":9,"ownerLogin":10,"ownerAvatarUrl":11,"ownerAccountNo":12,"ownerDisplayName":13,"repositoryNo":14,"starsCount":15,"licenseSpdxId":16,"licenseFileUrl":13,"sourceHtmlUrl":132,"categories":133,"keywords":138,"publishedAt":40},"01M6BY5835F3RMMW9KCCZ006JM","litert-compiled-model-migration","TFLite 迁移至 LiteRT","Rapidly migrate an Android application from legacy TensorFlow Lite (TFLite) to the modern LiteRT CompiledModel API (2.x) in Open Source GitHub repositories, keeping the TensorFlow Lite Support Library as LiteRT Support (litert-support 2.3.0). Covers buffer reuse, NPU JIT compilation, a reference implementation, and a two-stage verification gate (compile check, then an on-device parity test against a golden output).","在开源 GitHub 仓库中，将 Android 应用从旧版 TensorFlow Lite（TFLite）快速迁移到现代 LiteRT CompiledModel API（2.x），并将 TensorFlow Lite Support Library 保留为 LiteRT Support（litert-support 2.3.0）。涵盖缓冲区复用、NPU JIT 编译、参考实现，以及两阶段验证关卡（先编译检查，再针对黄金输出进行设备端一致性测试）。","https:\u002F\u002Fgithub.com\u002Fgoogle-ai-edge\u002Flitert-samples\u002Fblob\u002Fmain\u002Fskills\u002Flitert-compiled-model-migration\u002FSKILL.md",[134,135],{"categoryNo":20,"categoryName":21,"taxonomyType":22,"taxonomyTypeDesc":23},{"categoryNo":136,"categoryName":137,"taxonomyType":27,"taxonomyTypeDesc":28},"01M8CABKJRWVBRTZY60Q85V272","Android 开发与构建测试",[32,39,139,140,34,141,142,143,38,91,30,144,145,146,147,148],"litert compiled model migration","tensorflow","open","open source","migrate","test","github","support","jit","library",{"skillNo":150,"name":151,"nameZh":152,"description":153,"descriptionZh":154,"repositoryFullName":9,"ownerLogin":10,"ownerAvatarUrl":11,"ownerAccountNo":12,"ownerDisplayName":13,"repositoryNo":14,"starsCount":15,"licenseSpdxId":16,"licenseFileUrl":13,"sourceHtmlUrl":155,"categories":156,"keywords":159,"publishedAt":40},"01M6BY55P8GVX66H0FG8JHXHWF","gpu-clean-conversion","PyTorch 模型转 LiteRT GPU","Convert a PyTorch or Hugging Face model into a LiteRT model that runs fully on the GPU via the CompiledModel API with verified-correct output, and lay it out as a model recipe. Use when converting a new model, or when a converted model is rejected by the GPU, falls back to CPU, or returns wrong numbers on device.","将 PyTorch 或 Hugging Face 模型转换为通过 CompiledModel API 完全在 GPU 上运行、且输出经验证正确的 LiteRT 模型，并将其组织为模型配方（model recipe）。当转换新模型，或转换后的模型被 GPU 拒绝、回退到 CPU，或在设备上返回错误结果时使用。","https:\u002F\u002Fgithub.com\u002Fgoogle-ai-edge\u002Flitert-samples\u002Fblob\u002Fmain\u002Fskills\u002Fgpu-clean-conversion\u002FSKILL.md",[157,158],{"categoryNo":20,"categoryName":21,"taxonomyType":22,"taxonomyTypeDesc":23},{"categoryNo":78,"categoryName":79,"taxonomyType":27,"taxonomyTypeDesc":28},[160,35,161,110,32,39,162,163,164,38,165,166,115,167,168,169,170,171,122,123],"gpu clean conversion","clean","correct","pytorch","convert","back","as","use","output","with","via","CPU",{"skillNo":173,"name":174,"nameZh":175,"description":176,"descriptionZh":177,"repositoryFullName":9,"ownerLogin":10,"ownerAvatarUrl":11,"ownerAccountNo":12,"ownerDisplayName":13,"repositoryNo":14,"starsCount":15,"licenseSpdxId":16,"licenseFileUrl":13,"sourceHtmlUrl":178,"categories":179,"keywords":182,"publishedAt":40},"01M6BY52X9KX3VRXQJS622DZH3","compiled-model-app-scaffolding","LiteRT 模型 Android 应用搭建","Build a new Android app (Kotlin, Compose) around a verified LiteRT model using the CompiledModel API - the app architecture, the inference-layer lifecycle rules, model delivery, and the UI traps that masquerade as model bugs. Use when turning a converted and device-verified model into a demo or product app, when an app's inference layer leaks memory or blocks the UI, or when a model that verified clean looks wrong inside an app.","围绕经过验证的 LiteRT 模型，使用 CompiledModel API 构建新的 Android 应用（Kotlin、Compose）——涵盖应用架构、推理层的生命周期规则、模型交付，以及那些伪装成模型 bug 的 UI 陷阱。当需要将已转换并完成设备验证的模型做成演示或产品应用时，当应用的推理层出现内存泄漏或阻塞 UI 时，或当验证无误的模型在应用内表现异常时使用。","https:\u002F\u002Fgithub.com\u002Fgoogle-ai-edge\u002Flitert-samples\u002Fblob\u002Fmain\u002Fskills\u002Fcompiled-model-app-scaffolding\u002FSKILL.md",[180,181],{"categoryNo":20,"categoryName":21,"taxonomyType":22,"taxonomyTypeDesc":23},{"categoryNo":136,"categoryName":137,"taxonomyType":27,"taxonomyTypeDesc":28},[183,39,91,32,184,85,185,88,186,113,38,187,188],"compiled model app scaffolding","product","lifecycle","ui","demo","inference",{"skillNo":190,"name":191,"nameZh":192,"description":193,"descriptionZh":194,"repositoryFullName":9,"ownerLogin":10,"ownerAvatarUrl":11,"ownerAccountNo":12,"ownerDisplayName":13,"repositoryNo":14,"starsCount":15,"licenseSpdxId":16,"licenseFileUrl":13,"sourceHtmlUrl":195,"categories":196,"keywords":199,"publishedAt":40},"01M6BY501NESZTA4NSEKX9BSDE","benchmark-on-ddp","LiteRT模型性能基准测试","Measure a LiteRT .tflite model with `benchmark_model` on Developer Device Platform (DDP) lab phones through `litert benchmark --ddp`, or on the Mac you run it from, and turn the session into rows of the performance leaderboard under benchmark\u002Fleaderboard - one matrix entry per model, one session per accelerator, collect results.pb and runtime_info.pb, rebuild board.json, check the page, commit the data. Use when a model needs latency and memory numbers per platform, device and accelerator, or when a new benchmark_model release means re-measuring the board.","通过 `litert benchmark --ddp` 在 Developer Device Platform (DDP) 实验室手机上，或在运行它的 Mac 上，使用 `benchmark_model` 测量 LiteRT .tflite 模型，并将测试会话转化为 benchmark\u002Fleaderboard 下的性能排行榜数据行——每个模型一个矩阵条目，每个加速器一次会话，收集 results.pb 和 runtime_info.pb，重建 board.json，检查页面，提交数据。适用于模型需要按平台、设备和加速器给出延迟与内存数据，或新的 benchmark_model 版本发布意味着需要重新测量排行榜时。","https:\u002F\u002Fgithub.com\u002Fgoogle-ai-edge\u002Flitert-samples\u002Fblob\u002Fmain\u002Fskills\u002Fbenchmark-on-ddp\u002FSKILL.md",[197,198],{"categoryNo":20,"categoryName":21,"taxonomyType":22,"taxonomyTypeDesc":23},{"categoryNo":25,"categoryName":26,"taxonomyType":27,"taxonomyTypeDesc":28},[96,200,32,39,85,201,202,203,86,204,205,206,207,208],"benchmark on ddp","page","run","json","collect","release","data","commit","developer"]