rdk-oellm-quantize-s-series

使用 PTQ(post-training quantization)将 LLM/VLM 与 D-Robotics OE-LLM 量化为 .hbm,并打包为适用于 RDK S100 / S100P / S600 的板级就绪包。

安装方式

先用 Prompt 核对来源与依赖。也可下载安装包。

用 AI 助手安装

复制提示词,让助手先核对固定版本和依赖。

查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "rdk-oellm-quantize-s-series":https://skillpi.com/zh/skills/deepskill-ecbf7822e5243f7cd6fad96f59fa9d71a0ad163c8bd069657c24111d485d8805。安装前核对上游来源和版本:https://skillhub.cn/skills/user_171341e7/rdk-oellm-quantize-s-series。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。

来源与配置

skillhub.cn

配置方式待核实

请查看原始来源中的适用工具、依赖和权限要求。

安装实测待补充

使用 PTQ(post-training quantization)将 LLM/VLM 与 D-Robotics OE-LLM 量化为 .hbm,并打包为适用于 RDK S100 / S100P / S600 的板级就绪包。

0 下载

介绍来源: third_party · user_171341e7 · 0.1.0 参考来源

SkillPi 解读

能完成的任务
翻译待完成,请参阅来源文档。
适合谁
翻译待完成,请参阅来源文档。
输入和输出
翻译待完成,请参阅来源文档。
软件、账号及付费要求
翻译待完成,请参阅来源文档。
限制与区别
翻译待完成,请参阅来源文档。
实测状态
未测试

文件浏览

在原站浏览文件 ↗

原始 SKILL.md

打开原文 ↗
Frontmatter
name: rdk-oellm-quantize-s-series
slug: rdk-oellm-quantize-s-series
displayName: RDK OE-LLM Quantize (S-series)
version: 0.1.0
summary: PTQ quantize an LLM / VLM with D-Robotics OE-LLM into an .hbm and pack a board-ready bundle for RDK S100 / S100P / S600.
description: PTQ quantize an LLM or VLM with D-Robotics OE-LLM into an `.hbm` and pack a board-ready bundle for RDK S100 / S100P / S600. Use for calibration prep, Vision/Text compile, cosine verification, or packaging.
license: Apache-2.0
metadata:
  author: shockley6668
  tags:
    - oellm
    - hbdk4
    - rdk-s100p
    - rdk-s100
    - rdk-s600
    - ptq
    - llm
    - vlm
    - quantization
    - edge-deployment
  compatibility:
    boards:
      - RDK S100  (march=nash-e)
      - RDK S100P (march=nash-m)
      - RDK S600  (march=nash-p)
    toolchain: OE-LLM 1.0.0
    host_os: Ubuntu 22.04
    python: "3.10"
  upstream:
    reference_repo: https://github.com/shockley6668/gemma4-e2b-rdk-s100p
    reference_model_hub: https://huggingface.co/ShockleyWong/gemma4-e2b-rdk-s100p

OE-LLM Quantize & Deploy on RDK S-Series

<!-- SPDX-License-Identifier: Apache-2.0 Copyright (c) 2026 shockley6668 -->

Purpose

Turn a HuggingFace LLM / VLM checkpoint into an OE-LLM .hbm (Hobot BPU model) that runs on an RDK S-series board. The skill owns the host-side PTQ pipeline: environment sanity check, calibration data preparation, Vision / Text compile, cosine verification, and packaging. It stops at the tarball; the on-board runtime (hbdk4_runtime) is out of scope.

When To Use

Activate when the user's task involves any of:

  • "quantize / compile / PTQ" a model for RDK S100 / S100P / S600
  • "run oellm_build.py" or "leap_llm" against a HuggingFace model
  • prepare calibration data (COCO images for Vision, prompt JSON for Text)
  • verify cosine similarity between float and quantized outputs
  • pack .hbm + tok_embeddings.bin + tokenizer into a board bundle
  • upload the artefacts to HuggingFace Hub

Do NOT use for:

  • on-board C++ / Python inference wiring (that's a board-side skill)
  • ONNX-based tool-chains — OE-LLM ingests PyTorch nn.Module via leap_llm, not ONNX
  • training or LoRA fine-tuning

Prerequisites

  • Host machine. Ubuntu 22.04, x86_64, ≥ 64 GB RAM (128 GB recommended — Text decode compile peaks at ~100 GB RSS), ≥ 300 GB free disk, optional CUDA GPU for faster Vision calibration.
  • OE-LLM SDK 1.0.0. Obtained from D-Robotics — a tarball containing oellm_build/requirements.txt, hbdk4_compiler-*.whl, hbdk4_runtime_aarch64-*.whl, leap_llm-*.whl.
  • HuggingFace checkpoint. config.json + model.safetensors + tokenizer files, downloaded ahead of time (some models are gated — request access first).
  • leap_llm model adapter. SDK-shipped leap_llm covers common backbones; families the SDK does not know (e.g. Gemma4) need a community adapter dropped into leap_llm/models/<family>/ and registered in leap_llm/apis/model/model_factory.py. See references/model-adapter-checklist.md.
  • Board march string. Must match the target — do not guess. nash-e = S100, nash-m = S100P, nash-p = S600. Getting this wrong produces an HBM the board rejects at load.

Instructions

1. Confirm the target board and pick the right march

Ask the user which board they are targeting and select march from references/board-march-map.md. Never proceed past this step until confirmed — this is the single most common misconfiguration and every downstream artefact bakes it in.

2. Set up the environment

# Create the OE-LLM conda env once per host.
conda create -n oellm python=3.10 -y
conda activate oellm

cd /path/to/D-Robotics_LLM_S<version>_SDK/oellm_build
pip install -r requirements.txt
pip install hbdk4_compiler-*.whl
pip install leap_llm-*.whl
# hbdk4_runtime_aarch64-*.whl is board-side, install on the board, not the host.

Install order matters: requirements.txt pins the PyTorch line that hbdk4_compiler and leap_llm are built against.

If the model family is not in stock leap_llm, drop the adapter into $(python -c "import leap_llm, os; print(os.path.dirname(leap_llm.__file__))") — see references/model-adapter-checklist.md.

3. Prepare calibration data

Calibration decides how well PTQ scales fit the deployment distribution. Get this wrong and you will chase a "board outputs garbage" bug that has nothing to do with the compile.

Vision (VLM only): 50 real, diverse images. Do not use synthetic solid-colour blocks — we hit exactly this failure and the fix was 50 COCO val2017 photos.

python3 scripts/download_coco_calib_images.py \
  --output-dir ./calibration_data/images --count 50

Text: 100–200 varied prompts (multi-language, multi-length, multi-topic) in the OE-LLM JSON format.

python3 scripts/gen_text_calib_json.py \
  --output ./calibration_data/text/calibration.json --count 150

Full layout: references/calibration-data-layout.md.

4. Compile Vision (skip for pure LLM)

bash scripts/run_vision_compile.sh \
  --march <nash-e|nash-m|nash-p> \
  --model-name <e.g. gemma4-e2b-vision> \
  --input-model ./<hf_checkpoint_dir> \
  --output-dir ./output/<name>_vision \
  --calib-image-dir ./calibration_data/images \
  --device cuda:0 --vit-core-num 1

The wrapper sets ulimit -s unlimited (mandatory — compile_hbo can segfault otherwise), disables stdout buffering, and tees to a log. Expect ~110 min for a 16-layer ViT on a single core; compile_hbo is single-threaded CPU work, HBDK_JOBS does not speed it up.

Artefacts (output/<name>_vision/):

File Size Ship to board?
*_vit_ptq.hbm ~300–500 MB ✅
*_vit_ptq.bc / .convert.bc / .hbo ~1 GB total ❌ intermediate

5. Compile Text

bash scripts/run_text_compile.sh \
  --march <nash-e|nash-m|nash-p> \
  --model-name <e.g. gemma4-e2b-text> \
  --input-model ./<hf_checkpoint_dir> \
  --output-dir ./output/<name>_text \
  --calib-text ./calibration_data/text \
  --chunk-size 256 --cache-len 4096 --core-num 1 \
  [--hbdk-jobs 25] [--enable-swap] [--memlimit-gb 110]

Text decode compile peaks at ~100 GB RSS. On a 128 GB machine, the wrapper accepts --enable-swap (creates 64 GB swap via scripts/setup_swap.sh) and --memlimit-gb (uses prlimit --as) to keep OOM from taking down the host. HBDK_JOBS here is host-side compile parallelism, unrelated to on-board BPU core count.

Artefacts (output/<name>_text/):

File Size Ship to board?
*_lm_chunk_<cs>_cache_<cl>_ptq.hbm ~4–5 GB ✅
tok_embeddings.bin ~1.5 GB ✅ (external embedding table)
prefill/decode .bc / .hbo ~60+ GB total ❌ intermediate

tok_embeddings.bin is exported automatically by Gemma4TextApi.__init__ (and equivalent apis for other families) as weight * embed_scale. It stays outside the HBM because a 262k×1536×4B ≈ 1.5 GB embedding table is inefficient to bake into a BPU program — runtime does the lookup and √hidden scaling on CPU.

6. Verify cosine similarity

Run verifier_cli.py against the exported BC to compare quantized vs float output.

# Vision BC vs float
python3 scripts/verify_vision.py \
  --model-name <e.g. gemma4-e2b-vision> \
  --model-dir ./<hf_checkpoint_dir> \
  --quant-bc ./output/<name>_vision/*_vit_ptq.bc \
  --image ./calibration_data/images/<one_image>

# Text BC vs float
python3 scripts/verify_text.py \
  --model-name <e.g. gemma4-e2b-text> \
  --model-dir ./<hf_checkpoint_dir> \
  --quant-bc ./output/<name>_text/*_ptq.prefill.bc \
  --out ./output/<name>_text/verify_text.json

A healthy PTQ run lands in the 0.95–0.99 cosine range per branch. Anything under 0.90 means the calibration set is not representative — go back to step 3 before touching compile flags.

Reference measurement on Gemma4-E2B / S100P (nash-m): Vision 0.9888, Text 0.9540. See references/verification-guide.md for the interpretation table.

7. Pack the board bundle

bash scripts/pack_deploy_bundle.py \
  --vision-hbm ./output/<name>_vision/*_vit_ptq.hbm \
  --text-hbm ./output/<name>_text/*_ptq.hbm \
  --tok-embeddings ./output/<name>_text/tok_embeddings.bin \
  --tokenizer-dir ./<hf_checkpoint_dir> \
  --out ./deploy_bundle

Bundle layout:

deploy_bundle/
├── model/
│   ├── <name>_vit_ptq.hbm
│   ├── <name>_lm_chunk_256_cache_4096_ptq.hbm
│   └── tok_embeddings.bin
└── tokenizer/
    ├── tokenizer.json
    ├── tokenizer_config.json
    ├── chat_template.jinja        # if the model has one
    └── config.json

Then sha256sum deploy_bundle/model/*.hbm deploy_bundle/model/*.bin > deploy_bundle/SHA256SUMS so the board side can verify what it downloaded.

8. (Optional) Publish to HuggingFace Hub

hf auth login                              # once per host
hf upload <user>/<repo> ./deploy_bundle . --repo-type model

If your host is behind a slow link to huggingface.co, exporting HTTPS_PROXY before hf upload gives a 5–10× speedup on typical corporate networks.

Output Contract

After running, produce:

  • one .hbm per compiled branch (Vision, Text) with correct --march
  • tok_embeddings.bin alongside the Text HBM
  • a deploy_bundle/ matching the layout above, with SHA256SUMS
  • a short report listing: model name, board target + march, chunk/cache sizes, per-branch cosine, calibration image count and prompt count, total bundle size

Available Scripts

Script Purpose Key args
scripts/run_vision_compile.sh Wrap oellm_build.py for a VLM Vision branch --march, --model-name, --vit-core-num
scripts/run_text_compile.sh Wrap oellm_build.py for LLM / Text branch, with swap/memlimit guards --march, --chunk-size, --cache-len, --enable-swap, --memlimit-gb
scripts/download_coco_calib_images.py Pull N real COCO val2017 images for Vision calibration --output-dir, --count
scripts/gen_text_calib_json.py Emit an OE-LLM Text calibration JSON with diverse prompts --output, --count, --extra
scripts/verify_vision.py Cosine similarity: Vision BC vs float --model-name, --quant-bc, --image
scripts/verify_text.py Cosine similarity: Text BC vs float --model-name, --quant-bc, --out
scripts/pack_deploy_bundle.py Assemble the board tarball layout + sha256 --vision-hbm, --text-hbm, --tokenizer-dir
scripts/setup_swap.sh One-shot 64 GB swap file (invoked by run_text_compile) —

Examples

Case A — LLM on S600 (nash-p), no Vision.

bash scripts/run_text_compile.sh \
  --march nash-p --model-name qwen2-7b-text \
  --input-model ./qwen2-7b --output-dir ./output/qwen2_7b_text \
  --calib-text ./calibration_data/text --chunk-size 512 --cache-len 8192
bash scripts/pack_deploy_bundle.py \
  --text-hbm ./output/qwen2_7b_text/*_ptq.hbm \
  --tok-embeddings ./output/qwen2_7b_text/tok_embeddings.bin \
  --tokenizer-dir ./qwen2-7b --out ./deploy_bundle

Case B — VLM on S100P (nash-m), Vision + Text (the Gemma4-E2B reference).

bash scripts/download_coco_calib_images.py --output-dir ./calibration_data/images --count 50
bash scripts/run_vision_compile.sh --march nash-m --model-name gemma4-e2b-vision \
  --input-model ./gemma4-e2b --output-dir ./output/gemma4_e2b_vision \
  --calib-image-dir ./calibration_data/images --device cuda:0
bash scripts/run_text_compile.sh --march nash-m --model-name gemma4-e2b-text \
  --input-model ./gemma4-e2b --output-dir ./output/gemma4_e2b_text \
  --calib-text ./calibration_data/text --chunk-size 256 --cache-len 4096
bash scripts/pack_deploy_bundle.py \
  --vision-hbm ./output/gemma4_e2b_vision/*_vit_ptq.hbm \
  --text-hbm ./output/gemma4_e2b_text/*_ptq.hbm \
  --tok-embeddings ./output/gemma4_e2b_text/tok_embeddings.bin \
  --tokenizer-dir ./gemma4-e2b --out ./deploy_bundle

Limitations

  • Compile-only. Does not run inference on the board or validate end-to-end token output.
  • march is user-supplied. There is no runtime check that the string matches the connected board.
  • Vision compile assumes a ViT-shaped encoder. Audio branches (Conformer, e.g. Gemma4 audio) are not covered — treat as out of scope until a matching leap_llm adapter is written.
  • --enable-swap writes a 64 GB file to /swapfile and calls sudo swapon. Only run on hosts you own.
  • Cosine ≥ 0.99 does not guarantee correct end-to-end text; end-to-end verification requires running the bundle on a real board, which lives in the board-side skill.

Troubleshooting

See references/troubleshooting.md for the full pit-log. The top five, distilled:

Symptom Root cause Fix
compile_hbo segfaults early Default stack limit too small ulimit -s unlimited before invoking (wrapper does this)
conda run … log stays empty conda run buffers stdout Use conda activate oellm && PYTHONUNBUFFERED=1 python -u … \| tee log
Vision compile pins one core, HBDK_JOBS ignored compile_hbo is single-threaded CPU by design for ViT Not a bug — expect ~110 min on a fast core
Text decode OOM, host thrashes Peak ~100 GB RSS run_text_compile.sh --enable-swap --memlimit-gb 110
Board outputs gibberish though cosine is high Calibration set unrepresentative (synthetic images, English-only prompts, etc.) Re-calibrate with real data — this fixed our VLM

References

  • references/board-march-map.md — S100 / S100P / S600 ↔ nash-e / nash-m / nash-p (verified against SDK docs)
  • references/calibration-data-layout.md — directory shape and format for Vision/Text calibration data
  • references/model-adapter-checklist.md — what to add under leap_llm/models/<family>/ when the SDK does not ship your architecture
  • references/gemma4-adapter-walkthrough.md — file-by-file dissection of the reference Gemma4 adapter (2.7k LOC); use this as the concrete template when porting a new family
  • references/vlm-fusion-notes.md — soft-token id substitution, external tok_embeddings.bin, PLE-style per-layer inputs, image-token embedding replacement — for debugging on-board VLM output
  • references/verification-guide.md — how to read cosine numbers and what to change if they are too low
  • references/troubleshooting.md — full failure catalog from the Gemma4-E2B / S100P bring-up

当前收录版本

0.1.0

核对来源版本 ↗

安全与评测信息

质量评测

满分100 · 来自 SkillPi LAB 实验室的评测报告。

场景价值95/100

亮点

  • 提供从 HuggingFace 模型到 RDK S 系列板卡的完整 PTQ 量化与部署流水线
  • 解决边缘 AI 部署中的核心痛点:模型适配、校准、验证与打包
  • 面向明确的高价值工程场景,显著提升部署效率
触发精准92/100

亮点

  • 触发词精准覆盖量化、编译、校准、验证、打包等关键动作
  • 边界清晰,明确排除训练、ONNX 工具链等无关场景
结构规范94/100

待提升项

  • description 写错位置 原报告严重程度:轻微

    顶层 frontmatter 中 description 字段为空,实质描述内容位于 skill_body 内部

    改进建议:将核心描述内容移至顶层 frontmatter 的 description 字段

  • 文档较长 原报告严重程度:轻微

    SKILL.md 文件约 480 行,接近但未超过 500 行限制

    改进建议:考虑将部分参考内容(如 troubleshooting 细节)移至独立文件并通过引用链接

亮点

  • 文档结构完整,包含从前置条件到故障排查的全生命周期指导
  • 提供清晰的步骤划分、出口条件和端到端示例
  • frontmatter 元数据完整,兼容性信息明确
执行可靠91/100

亮点

  • 工具来源明确(OE-LLM SDK、leap_llm),参数说明详尽
  • 覆盖主要异常场景:OOM、segfault、stdout buffering,并提供解决方案
  • 不可逆操作(swap 创建)有明确警告,脚本封装提供安全边界
证据可验 (前四项均值)93/100

取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。

正文静态检测

100 / 100 · skillpi-20261123-no-r3-v1

正文未命中当前规则。

分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。

权限与使用前检查

根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。

文档引用的域名或地址

这些地址可能用于文档链接或示例,不是已批准的联网清单。使用前核对实际目的地及发送的数据。

  • github.com
  • huggingface.co

本站展示提示不会授予权限。涉及文件改动、密钥、外部发送或费用时,仍由你使用的工具按需确认。

安全评级与访问范围

safe · 静态证据核验,不代表运行安全保证。

翻译待完成,请参阅来源文档。

使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。