[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6BY4XWDFDMABPEJJ0W74891":3,"skill-same:01M6BY4XWDFDMABPEJJ0W74891":64},{"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":37,"linkOnly":38,"markdownContent":39,"markdownBody":40,"frontMatter":41,"refName":42,"commitSha":43,"skillDirectory":44,"forksCount":45,"repositoryHtmlUrl":46,"repositoryHomepageUrl":47,"ownerHtmlUrl":48,"ownerBlogUrl":13,"ownerDescription":13,"updatedAt":49,"install":50,"resources":63},"01M6BY4XWDFDMABPEJJ0W74891","accuracy-safe-quantization","LiteRT模型精度安全量化","Shrink a converted LiteRT model with ai-edge-quantizer (fp16 \u002F int8 \u002F int4) without losing accuracy, verifying parity against the float source after every step. Use when choosing a quantization recipe for a new model, when a quantized model fails to load, degrades on a task benchmark, or degenerates over long generations, or when deciding between dynamic-range, weight-only, and blockwise variants.","使用 ai-edge-quantizer 对转换后的 LiteRT 模型进行压缩（fp16 \u002F int8 \u002F int4），在不损失精度的前提下，每一步后都对照浮点源模型验证一致性。适用于为新模型选择量化方案、量化模型加载失败、在任务基准测试中性能下降或长文本生成中退化，以及需要在动态范围、仅权重和分块（blockwise）变体之间做出选择的情况。","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\u002Faccuracy-safe-quantization\u002FSKILL.md",[19,24],{"categoryNo":20,"categoryName":21,"taxonomyType":22,"taxonomyTypeDesc":23},"01M8BRZZF9D7PVFN5MXSPWWD61","AI 工程师","PROFESSION","适用职业",{"categoryNo":25,"categoryName":26,"taxonomyType":27,"taxonomyTypeDesc":28},"01M8C7RZZQT16HYSRGF5KGZPXV","前沿模型改造技术","SCENARIO","使用场景",[30,31,32,33,34,35,36],"safe","accuracy safe quantization","litert","benchmark","edge","FP16","model","2026-11-10 10:12:30",false,"---\nname: accuracy-safe-quantization\ndescription: Shrink a converted LiteRT model with ai-edge-quantizer (fp16 \u002F int8 \u002F int4) without losing accuracy, verifying parity against the float source after every step. Use when choosing a quantization recipe for a new model, when a quantized model fails to load, degrades on a task benchmark, or degenerates over long generations, or when deciding between dynamic-range, weight-only, and blockwise variants.\n---\n\n# Accuracy-safe quantization\n\nA quantization is done when three things hold, in this order:\n\n1. it exports and the file shrinks by what the recipe predicts,\n2. **output parity with the float source holds on a task-level check**, not\n   just a smoke test,\n3. the quantized model still passes the deployment check on the target\n   runtime and device.\n\nQuantization rewrites the graph, so step 3 is a fresh obligation every time:\nre-run the same CompiledModel verification you used to accept the float\nconversion (see the `gpu-clean-conversion` skill), then the on-device\nnumerical check.\n\nAll recipes below are `ai-edge-quantizer` (`pip install ai-edge-quantizer`;\n0.9.0 as of 2026-10, which pins `ai-edge-litert` 2.2.0 on the host),\nplain Python, no build step. Worked examples live in this repo under\n`models\u002Fbonsai\u002Fbonsai_image_4b\u002Fconverted\u002F` and\n`models\u002Fqwen\u002Fqwen3_tts\u002Fconverted\u002F`.\n\n## Choosing a lane\n\nStart with the lightest recipe that meets the size budget, and move down\nonly on evidence:\n\n| Budget \u002F model | Recipe |\n|---|---|\n| ~2× smaller, zero risk | **fp16 float-casting.** Weights cast to fp16, compute stays float. On a GPU that already computes in fp16 this is close to free numerically — verify anyway |\n| ~4× smaller — encoders, conv nets, diffusion blocks | **Dynamic-range int8 channelwise.** int8 weights, float activations; this shape rides the GPU delegate |\n| Dynamic int8 lost quality (conditioning, embeddings) | **Weight-only, same bits.** Inserts an explicit DEQUANTIZE so the matmul runs in float and activations are never quantized — more quality, some latency |\n| ~7× smaller — LLM \u002F autoregressive decoders | **int4 blockwise-32 + OCTAV, embeddings int8.** Never channelwise for a decoder: it looks fine on short outputs and degenerates over long generations. A blockwise recipe needs the quantized dimension divisible by the block (a 3-input linear fails block-32 with `Quantized dimension 3 … is not divisible`) |\n| Data-free int4 still fails the task gate | **Calibrated ingest.** Take a GPTQ checkpoint and preserve its grid with `DEQUANTIZED_WEIGHT_RECOVERY` — see the routing table |\n\nFull-integer static quantization (`static_wi8_ai8` — quantized activations,\ncalibration data required) is a different lane aimed at NPU\u002FAOT targets and\nis not covered here.\n\n## Recipes\n\nRecipes layer by regex: broad rule first, narrow overrides after — that is\nhow one file mixes lanes (bonsai's DiT puts everything at int8 channelwise,\nthen overrides `.*TransformerBlock_.*` to int4 blockwise).\n\nfp16 float-casting:\n\n```python\nfrom ai_edge_quantizer import quantizer, recipe_manager\nfrom ai_edge_quantizer.recipe import AlgorithmName, qtyping\n\nrm = recipe_manager.RecipeManager()\nrm.add_quantization_config(\n    regex=\".*\", operation_name=qtyping.TFLOperationName.ALL_SUPPORTED,\n    op_config=qtyping.OpQuantizationConfig(\n        weight_tensor_config=qtyping.TensorQuantizationConfig(\n            num_bits=16, dtype=qtyping.TensorDataType.FLOAT),\n        compute_precision=qtyping.ComputePrecision.FLOAT),\n    algorithm_key=AlgorithmName.FLOAT_CASTING)\nquantizer.Quantizer(\"model_fp32.tflite\", rm.get_quantization_recipe()) \\\n    .quantize().export_model(\"model_fp16.tflite\")\n```\n\nDynamic-range int (swap bits \u002F granularity \u002F algorithm per the table):\n\n```python\nfrom ai_edge_quantizer.qtyping import QuantGranularity as G\nfrom ai_edge_quantizer.qtyping import TFLOperationName as OP\n\nrm = recipe_manager.RecipeManager()\nrm.add_dynamic_config(regex=\".*\", operation_name=OP.FULLY_CONNECTED,\n                      num_bits=4, granularity=G.BLOCKWISE_32,\n                      algorithm_key=AlgorithmName.OCTAV)\nrm.add_dynamic_config(regex=\".*\", operation_name=OP.EMBEDDING_LOOKUP,\n                      num_bits=8, granularity=G.CHANNELWISE)\n```\n\nWeight-only uses the same signature via `rm.add_weight_only_config(...)` —\n`models\u002Fbonsai\u002Fbonsai_image_4b\u002Fconverted\u002Fquantize_weight_only.py` wraps it\nas a reusable CLI.\n\n`ai_edge_quantizer.recipe` also ships these as presets\n(`dynamic_wi8_afp32()`, `dynamic_wi4b32_afp32()`, `weight_only_wi8_afp32()`,\n…). The litert-torch LLM exporter accepts a preset name as its\n`quantization_recipe` argument, and a custom recipe can be registered by\nassigning a callable onto the module — the qwen3_tts talker recipe\n(`models\u002Fqwen\u002Fqwen3_tts\u002Fconverted\u002Fexport_talker.py`) registers `BOCTAV4`\n(blockwise-32 OCTAV int4 + int8 embeddings) that way.\n\n## Verify after every step\n\n- **Size first.** fp16 ≈ ½, int8 ≈ ¼, int4 blockwise ≈ ⅐ of fp32 (block\n  scales add overhead). If the file did not shrink as predicted, the regex\n  did not match — fix that before measuring anything.\n- **Parity against the float reference.** Same inputs through the float and\n  quantized models; correlation on outputs plus the task-level check\n  (argmax match, token-for-token greedy decode, IoU).\n- **A smoke gate is a floor, not a parity verdict.** An LLM can pass most of\n  a handful of chat prompts and still score near zero on a real benchmark.\n  Before publishing an int4 decoder, run a task benchmark at real length\n  (e.g. GSM8K-style, n≥100) against the float baseline.\n- **Long generations, specifically.** Granularity problems do not show up\n  in short outputs.\n- **On the target device.** Host emulation of int kernels is pessimistic —\n  int8 graphs have scored visibly worse on host CPU than the same graphs on\n  the device GPU delegate. Never reject a recipe on desktop numbers alone;\n  never accept one without device numbers.\n\n## When it breaks or degrades\n\n| What you see | Knob to turn |\n|---|---|\n| Runtime refuses to load: `unsupported scale value (0.000000) … for INT4 tensor` | Sparse weights produced all-zero blocks, whose min-max scale is 0. Patch each zero scale to the tensor's smallest nonzero scale — dequantization is unchanged because those blocks are all zero. ⚠ Blockwise scales live in separate fp16 scale tensors, **not** `QuantizationParameters.scale` — patching the latter via the flatbuffer object API succeeds silently and changes nothing; edit the scale tensor's buffer directly. `models\u002Fbonsai\u002Fbonsai_image_4b\u002Fconverted\u002Ffix_zero_block_scales.py` |\n| Dynamic-range int8 collapses a conv net outright (near-zero output correlation, every input misclassified) while the file loads and runs fine | Activation-quantization sensitivity — squeeze-excite and SiLU-family conv nets are the known class. **Weight-only int8 at the same size is typically near-lossless on the same model.** This collapse has shipped inside published artifacts, so parity-check any dynamic-int8 model you did not gate yourself before building on it |\n| Decoder is coherent for a while, then degenerates | Channelwise → `BLOCKWISE_32`; `MIN_MAX_UNIFORM_QUANT` → `OCTAV` |\n| Dynamic-range lost fidelity (prompt conditioning, embeddings) | Weight-only at the same bits |\n| int4 fails the task gate at block-128 | Block-32. Data-free block-128 can collapse outright on small models |\n| int4 fails the task gate at block-32 too | Data-free min-max\u002FOCTAV has hit its limit for this family. Ingest a calibrated GPTQ checkpoint: dequantize it, then quantize with `algorithm_key=AlgorithmName.DEQUANTIZED_WEIGHT_RECOVERY` at the granularity matching the GPTQ group size (gs128 → `BLOCKWISE_128`). Symmetric checkpoints only, `desc_act=False` only |\n| Recovery raises `NOT dequantized (fake-quantized) weights` | That tensor was never on the GPTQ grid (`lm_head`, tied embeddings, first\u002Flast layers). The raise is a triage signal, not a bug: route the named tensor to a plain int8 entry by regex |\n| A specific head or block is the culprit | Exclude it by regex — keep it at int8 or float and leave the rest at int4 |\n| Everything above still degrades | fp16 float-casting is the floor. If fp16 fails parity, the problem is upstream of quantization — go back to `gpu-clean-conversion` step 5 |\n\nSome models are genuinely 4-bit sensitive — small reasoning-distilled\ndecoders (~1–2 B) often fail int4 quality gates that instruct-tuned peers\nand larger models pass. When int4 fails on quality, ship int8 as the\nquality row rather than forcing it; int4 becomes a speed reference.\n\n## Watch for\n\n- **Embeddings stay int8** even in int4 recipes — both shipped LLM-lane\n  recipes in this repo do this deliberately.\n- **Bytes are not speed.** int4's latency win depends on the backend's\n  kernel efficiency: the same model can gain ~1.5× on one device and\n  barely 1.1× on another. Measure on the target; don't project from\n  file size.\n- **Check whether the container is exact.** Ternary weights land in int4\n  blockwise as exactly {-7, 0, +7} — zero rounding error. When the weight\n  distribution matches the container, parity is free; verify it rather\n  than budgeting for loss that isn't there. For exact-container cases use\n  **min-max, not OCTAV** — OCTAV's clipping optimization can move a grid\n  that min-max reproduces exactly.\n- **int2 has recipes before it has a consumer**: ai-edge-quantizer 0.9.0\n  ships `dynamic_wi2b32_afp32` and its siblings (2.5 bits\u002Fweight at\n  block-32 with an fp16 scale per block), and as of 2026-08 the CPU runtime refused the tensor type at\n  prepare — a hard load failure, not degradation. Re-test the load on the\n  runtime you ship before spending time there.\n- **Auxiliary tables cast to fp16 need the same discipline.** Casting\n  host-side embedding\u002Fprojection tables halves them; verify generated\n  outputs are unchanged before shipping (qwen3_tts did, and it held).\n- **Pin the toolchain.** Quantized-graph compatibility moves with the\n  runtime; a graph exported from a dev checkout can fail GPU kernel\n  initialization on a release runtime. Record `ai-edge-quantizer` \u002F\n  `litert-torch` versions in the recipe README next to the numbers.\n\n## Output layout\n\nQuantization extends the model recipe from `gpu-clean-conversion`; it does\nnot get its own tree:\n\n```\nmodels\u002F\u003Cfamily>\u002F\u003Cmodel>\u002Fconverted\u002F\n  export_*.py              float export (existing)\n  quantize_*.py            one script per quantized variant\n  verify_*.py              parity checks, reused for every variant\n  README.md                recipe, sizes, parity numbers, gate results,\n                           device, toolchain versions\n```\n\nKeep each variant separately re-runnable. State which variant is the\nquality row and which is the speed row when they differ. Weights are not\ncommitted.\n","# Accuracy-safe quantization\n\nA quantization is done when three things hold, in this order:\n\n1. it exports and the file shrinks by what the recipe predicts,\n2. **output parity with the float source holds on a task-level check**, not\n   just a smoke test,\n3. the quantized model still passes the deployment check on the target\n   runtime and device.\n\nQuantization rewrites the graph, so step 3 is a fresh obligation every time:\nre-run the same CompiledModel verification you used to accept the float\nconversion (see the `gpu-clean-conversion` skill), then the on-device\nnumerical check.\n\nAll recipes below are `ai-edge-quantizer` (`pip install ai-edge-quantizer`;\n0.9.0 as of 2026-10, which pins `ai-edge-litert` 2.2.0 on the host),\nplain Python, no build step. Worked examples live in this repo under\n`models\u002Fbonsai\u002Fbonsai_image_4b\u002Fconverted\u002F` and\n`models\u002Fqwen\u002Fqwen3_tts\u002Fconverted\u002F`.\n\n## Choosing a lane\n\nStart with the lightest recipe that meets the size budget, and move down\nonly on evidence:\n\n| Budget \u002F model | Recipe |\n|---|---|\n| ~2× smaller, zero risk | **fp16 float-casting.** Weights cast to fp16, compute stays float. On a GPU that already computes in fp16 this is close to free numerically — verify anyway |\n| ~4× smaller — encoders, conv nets, diffusion blocks | **Dynamic-range int8 channelwise.** int8 weights, float activations; this shape rides the GPU delegate |\n| Dynamic int8 lost quality (conditioning, embeddings) | **Weight-only, same bits.** Inserts an explicit DEQUANTIZE so the matmul runs in float and activations are never quantized — more quality, some latency |\n| ~7× smaller — LLM \u002F autoregressive decoders | **int4 blockwise-32 + OCTAV, embeddings int8.** Never channelwise for a decoder: it looks fine on short outputs and degenerates over long generations. A blockwise recipe needs the quantized dimension divisible by the block (a 3-input linear fails block-32 with `Quantized dimension 3 … is not divisible`) |\n| Data-free int4 still fails the task gate | **Calibrated ingest.** Take a GPTQ checkpoint and preserve its grid with `DEQUANTIZED_WEIGHT_RECOVERY` — see the routing table |\n\nFull-integer static quantization (`static_wi8_ai8` — quantized activations,\ncalibration data required) is a different lane aimed at NPU\u002FAOT targets and\nis not covered here.\n\n## Recipes\n\nRecipes layer by regex: broad rule first, narrow overrides after — that is\nhow one file mixes lanes (bonsai's DiT puts everything at int8 channelwise,\nthen overrides `.*TransformerBlock_.*` to int4 blockwise).\n\nfp16 float-casting:\n\n```python\nfrom ai_edge_quantizer import quantizer, recipe_manager\nfrom ai_edge_quantizer.recipe import AlgorithmName, qtyping\n\nrm = recipe_manager.RecipeManager()\nrm.add_quantization_config(\n    regex=\".*\", operation_name=qtyping.TFLOperationName.ALL_SUPPORTED,\n    op_config=qtyping.OpQuantizationConfig(\n        weight_tensor_config=qtyping.TensorQuantizationConfig(\n            num_bits=16, dtype=qtyping.TensorDataType.FLOAT),\n        compute_precision=qtyping.ComputePrecision.FLOAT),\n    algorithm_key=AlgorithmName.FLOAT_CASTING)\nquantizer.Quantizer(\"model_fp32.tflite\", rm.get_quantization_recipe()) \\\n    .quantize().export_model(\"model_fp16.tflite\")\n```\n\nDynamic-range int (swap bits \u002F granularity \u002F algorithm per the table):\n\n```python\nfrom ai_edge_quantizer.qtyping import QuantGranularity as G\nfrom ai_edge_quantizer.qtyping import TFLOperationName as OP\n\nrm = recipe_manager.RecipeManager()\nrm.add_dynamic_config(regex=\".*\", operation_name=OP.FULLY_CONNECTED,\n                      num_bits=4, granularity=G.BLOCKWISE_32,\n                      algorithm_key=AlgorithmName.OCTAV)\nrm.add_dynamic_config(regex=\".*\", operation_name=OP.EMBEDDING_LOOKUP,\n                      num_bits=8, granularity=G.CHANNELWISE)\n```\n\nWeight-only uses the same signature via `rm.add_weight_only_config(...)` —\n`models\u002Fbonsai\u002Fbonsai_image_4b\u002Fconverted\u002Fquantize_weight_only.py` wraps it\nas a reusable CLI.\n\n`ai_edge_quantizer.recipe` also ships these as presets\n(`dynamic_wi8_afp32()`, `dynamic_wi4b32_afp32()`, `weight_only_wi8_afp32()`,\n…). The litert-torch LLM exporter accepts a preset name as its\n`quantization_recipe` argument, and a custom recipe can be registered by\nassigning a callable onto the module — the qwen3_tts talker recipe\n(`models\u002Fqwen\u002Fqwen3_tts\u002Fconverted\u002Fexport_talker.py`) registers `BOCTAV4`\n(blockwise-32 OCTAV int4 + int8 embeddings) that way.\n\n## Verify after every step\n\n- **Size first.** fp16 ≈ ½, int8 ≈ ¼, int4 blockwise ≈ ⅐ of fp32 (block\n  scales add overhead). If the file did not shrink as predicted, the regex\n  did not match — fix that before measuring anything.\n- **Parity against the float reference.** Same inputs through the float and\n  quantized models; correlation on outputs plus the task-level check\n  (argmax match, token-for-token greedy decode, IoU).\n- **A smoke gate is a floor, not a parity verdict.** An LLM can pass most of\n  a handful of chat prompts and still score near zero on a real benchmark.\n  Before publishing an int4 decoder, run a task benchmark at real length\n  (e.g. GSM8K-style, n≥100) against the float baseline.\n- **Long generations, specifically.** Granularity problems do not show up\n  in short outputs.\n- **On the target device.** Host emulation of int kernels is pessimistic —\n  int8 graphs have scored visibly worse on host CPU than the same graphs on\n  the device GPU delegate. Never reject a recipe on desktop numbers alone;\n  never accept one without device numbers.\n\n## When it breaks or degrades\n\n| What you see | Knob to turn |\n|---|---|\n| Runtime refuses to load: `unsupported scale value (0.000000) … for INT4 tensor` | Sparse weights produced all-zero blocks, whose min-max scale is 0. Patch each zero scale to the tensor's smallest nonzero scale — dequantization is unchanged because those blocks are all zero. ⚠ Blockwise scales live in separate fp16 scale tensors, **not** `QuantizationParameters.scale` — patching the latter via the flatbuffer object API succeeds silently and changes nothing; edit the scale tensor's buffer directly. `models\u002Fbonsai\u002Fbonsai_image_4b\u002Fconverted\u002Ffix_zero_block_scales.py` |\n| Dynamic-range int8 collapses a conv net outright (near-zero output correlation, every input misclassified) while the file loads and runs fine | Activation-quantization sensitivity — squeeze-excite and SiLU-family conv nets are the known class. **Weight-only int8 at the same size is typically near-lossless on the same model.** This collapse has shipped inside published artifacts, so parity-check any dynamic-int8 model you did not gate yourself before building on it |\n| Decoder is coherent for a while, then degenerates | Channelwise → `BLOCKWISE_32`; `MIN_MAX_UNIFORM_QUANT` → `OCTAV` |\n| Dynamic-range lost fidelity (prompt conditioning, embeddings) | Weight-only at the same bits |\n| int4 fails the task gate at block-128 | Block-32. Data-free block-128 can collapse outright on small models |\n| int4 fails the task gate at block-32 too | Data-free min-max\u002FOCTAV has hit its limit for this family. Ingest a calibrated GPTQ checkpoint: dequantize it, then quantize with `algorithm_key=AlgorithmName.DEQUANTIZED_WEIGHT_RECOVERY` at the granularity matching the GPTQ group size (gs128 → `BLOCKWISE_128`). Symmetric checkpoints only, `desc_act=False` only |\n| Recovery raises `NOT dequantized (fake-quantized) weights` | That tensor was never on the GPTQ grid (`lm_head`, tied embeddings, first\u002Flast layers). The raise is a triage signal, not a bug: route the named tensor to a plain int8 entry by regex |\n| A specific head or block is the culprit | Exclude it by regex — keep it at int8 or float and leave the rest at int4 |\n| Everything above still degrades | fp16 float-casting is the floor. If fp16 fails parity, the problem is upstream of quantization — go back to `gpu-clean-conversion` step 5 |\n\nSome models are genuinely 4-bit sensitive — small reasoning-distilled\ndecoders (~1–2 B) often fail int4 quality gates that instruct-tuned peers\nand larger models pass. When int4 fails on quality, ship int8 as the\nquality row rather than forcing it; int4 becomes a speed reference.\n\n## Watch for\n\n- **Embeddings stay int8** even in int4 recipes — both shipped LLM-lane\n  recipes in this repo do this deliberately.\n- **Bytes are not speed.** int4's latency win depends on the backend's\n  kernel efficiency: the same model can gain ~1.5× on one device and\n  barely 1.1× on another. Measure on the target; don't project from\n  file size.\n- **Check whether the container is exact.** Ternary weights land in int4\n  blockwise as exactly {-7, 0, +7} — zero rounding error. When the weight\n  distribution matches the container, parity is free; verify it rather\n  than budgeting for loss that isn't there. For exact-container cases use\n  **min-max, not OCTAV** — OCTAV's clipping optimization can move a grid\n  that min-max reproduces exactly.\n- **int2 has recipes before it has a consumer**: ai-edge-quantizer 0.9.0\n  ships `dynamic_wi2b32_afp32` and its siblings (2.5 bits\u002Fweight at\n  block-32 with an fp16 scale per block), and as of 2026-08 the CPU runtime refused the tensor type at\n  prepare — a hard load failure, not degradation. Re-test the load on the\n  runtime you ship before spending time there.\n- **Auxiliary tables cast to fp16 need the same discipline.** Casting\n  host-side embedding\u002Fprojection tables halves them; verify generated\n  outputs are unchanged before shipping (qwen3_tts did, and it held).\n- **Pin the toolchain.** Quantized-graph compatibility moves with the\n  runtime; a graph exported from a dev checkout can fail GPU kernel\n  initialization on a release runtime. Record `ai-edge-quantizer` \u002F\n  `litert-torch` versions in the recipe README next to the numbers.\n\n## Output layout\n\nQuantization extends the model recipe from `gpu-clean-conversion`; it does\nnot get its own tree:\n\n```\nmodels\u002F\u003Cfamily>\u002F\u003Cmodel>\u002Fconverted\u002F\n  export_*.py              float export (existing)\n  quantize_*.py            one script per quantized variant\n  verify_*.py              parity checks, reused for every variant\n  README.md                recipe, sizes, parity numbers, gate results,\n                           device, toolchain versions\n```\n\nKeep each variant separately re-runnable. State which variant is the\nquality row and which is the speed row when they differ. Weights are not\ncommitted.\n",{"name":5,"description":7},"main","9467001474dc4e072ebc588e5eb9b5fdcf63abbc","skills\u002Faccuracy-safe-quantization",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":51,"prompt":61,"zipAvailable":62},[52,55,58],{"tool":53,"command":54},"npx","npx skills add google-ai-edge\u002Flitert-samples --skill accuracy-safe-quantization",{"tool":56,"command":57},"bunx","bunx skills add google-ai-edge\u002Flitert-samples --skill accuracy-safe-quantization",{"tool":59,"command":60},"pnpm","pnpm dlx skills add google-ai-edge\u002Flitert-samples --skill accuracy-safe-quantization","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fgoogle-ai-edge\u002Flitert-samples\u002Fblob\u002Fmain\u002Fskills\u002Faccuracy-safe-quantization\u002FSKILL.md",true,[],[65,85,113,142,165,188],{"skillNo":66,"name":67,"nameZh":68,"description":69,"descriptionZh":70,"repositoryFullName":9,"ownerLogin":10,"ownerAvatarUrl":11,"ownerAccountNo":12,"ownerDisplayName":13,"repositoryNo":14,"starsCount":15,"licenseSpdxId":16,"licenseFileUrl":13,"sourceHtmlUrl":71,"categories":72,"keywords":77,"publishedAt":37},"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 输出可疑地完全一致的情况。","https:\u002F\u002Fgithub.com\u002Fgoogle-ai-edge\u002Flitert-samples\u002Fblob\u002Fmain\u002Fskills\u002Fon-device-verification\u002FSKILL.md",[73,74],{"categoryNo":20,"categoryName":21,"taxonomyType":22,"taxonomyTypeDesc":23},{"categoryNo":75,"categoryName":76,"taxonomyType":27,"taxonomyTypeDesc":28},"01M8BZTWSXAPNKVKA1N0JGMJK2","AI 模型评估与基准测试",[78,79,80,81,35,82,83,36,32,84],"on device verification","verification","graph","api","compile","diagnose","gpu",{"skillNo":86,"name":87,"nameZh":88,"description":89,"descriptionZh":90,"repositoryFullName":9,"ownerLogin":10,"ownerAvatarUrl":11,"ownerAccountNo":12,"ownerDisplayName":13,"repositoryNo":14,"starsCount":15,"licenseSpdxId":16,"licenseFileUrl":13,"sourceHtmlUrl":91,"categories":92,"keywords":97,"publishedAt":37},"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",[93,94],{"categoryNo":20,"categoryName":21,"taxonomyType":22,"taxonomyTypeDesc":23},{"categoryNo":95,"categoryName":96,"taxonomyType":27,"taxonomyTypeDesc":28},"01M8C7TWSEQ7QTRNCZXZP1RXM5","AI 模型推理与服务部署",[98,99,100,32,101,82,102,36,103,104,33,105,106,107,108,109,110,84,111,112],"google","litert google tensor","tensor","performance","memory","windows","package","linux","baseline","tpu","benchmarking","packages","android","play","kotlin",{"skillNo":114,"name":115,"nameZh":116,"description":117,"descriptionZh":118,"repositoryFullName":9,"ownerLogin":10,"ownerAvatarUrl":11,"ownerAccountNo":12,"ownerDisplayName":13,"repositoryNo":14,"starsCount":15,"licenseSpdxId":16,"licenseFileUrl":13,"sourceHtmlUrl":119,"categories":120,"keywords":123,"publishedAt":37},"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",[121,122],{"categoryNo":20,"categoryName":21,"taxonomyType":22,"taxonomyTypeDesc":23},{"categoryNo":95,"categoryName":96,"taxonomyType":27,"taxonomyTypeDesc":28},[124,125,32,126,127,128,129,130,131,132,133,134,135,136,137,138,139,36,140,141],"conversion","workflow","litert conversion workflow","source","face","hugging face","verified","export","quantize","at","result","classify","message","creation","architecture","pick","publish","recipe",{"skillNo":143,"name":144,"nameZh":145,"description":146,"descriptionZh":147,"repositoryFullName":9,"ownerLogin":10,"ownerAvatarUrl":11,"ownerAccountNo":12,"ownerDisplayName":13,"repositoryNo":14,"starsCount":15,"licenseSpdxId":16,"licenseFileUrl":13,"sourceHtmlUrl":148,"categories":149,"keywords":154,"publishedAt":37},"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",[150,151],{"categoryNo":20,"categoryName":21,"taxonomyType":22,"taxonomyTypeDesc":23},{"categoryNo":152,"categoryName":153,"taxonomyType":27,"taxonomyTypeDesc":28},"01M8CABKJRWVBRTZY60Q85V272","Android 开发与构建测试",[155,36,32,82,156,157,158,159,160,161,162,79,110,81,163,164],"litert compiled model migration","tensorflow","open","library","jit","support","github","test","migrate","open source",{"skillNo":166,"name":167,"nameZh":168,"description":169,"descriptionZh":170,"repositoryFullName":9,"ownerLogin":10,"ownerAvatarUrl":11,"ownerAccountNo":12,"ownerDisplayName":13,"repositoryNo":14,"starsCount":15,"licenseSpdxId":16,"licenseFileUrl":13,"sourceHtmlUrl":171,"categories":172,"keywords":175,"publishedAt":37},"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",[173,174],{"categoryNo":20,"categoryName":21,"taxonomyType":22,"taxonomyTypeDesc":23},{"categoryNo":95,"categoryName":96,"taxonomyType":27,"taxonomyTypeDesc":28},[124,176,84,177,178,129,130,179,180,181,182,141,183,184,32,81,185,186,187,36],"clean","gpu clean conversion","output","CPU","via","with","use","as","back","convert","pytorch","correct",{"skillNo":189,"name":190,"nameZh":191,"description":192,"descriptionZh":193,"repositoryFullName":9,"ownerLogin":10,"ownerAvatarUrl":11,"ownerAccountNo":12,"ownerDisplayName":13,"repositoryNo":14,"starsCount":15,"licenseSpdxId":16,"licenseFileUrl":13,"sourceHtmlUrl":194,"categories":195,"keywords":198,"publishedAt":37},"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",[196,197],{"categoryNo":20,"categoryName":21,"taxonomyType":22,"taxonomyTypeDesc":23},{"categoryNo":152,"categoryName":153,"taxonomyType":27,"taxonomyTypeDesc":28},[36,199,32,200,102,201,110,202,203,112,204,138,81],"compiled model app scaffolding","product","lifecycle","demo","inference","ui"]