rdk-oellm-quantize-s-series

Use PTQ (post-training quantization) to quantize an LLM/VLM with D-Robotics OE-LLM into a .hbm file and pack a board-ready bundle for RDK S100 / S100P / S600.

Installation

Review the source and dependencies with a prompt. A package is available to download.

Install with an AI assistant

Copy the prompt so your assistant can review the pinned revision and dependencies first.

View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "rdk-oellm-quantize-s-series" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-ecbf7822e5243f7cd6fad96f59fa9d71a0ad163c8bd069657c24111d485d8805. Verify the upstream source and version against https://skillhub.cn/skills/user_171341e7/rdk-oellm-quantize-s-series before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.

Source and setup

skillhub.cn

Setup guidance pending

See the original source for supported tools, dependencies, and permissions.

Installation test pending

Use PTQ (post-training quantization) to quantize an LLM/VLM with D-Robotics OE-LLM into a .hbm file and pack a board-ready bundle for RDK S100 / S100P / S600.

0 Downloads

Introduction source: third_party · user_171341e7 · 0.1.0 Reference

SkillPi interpretation

Tasks
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.
Audience
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
Inputs and outputs
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
Software, accounts and paid services
**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/<fami
Limits and differences
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.
Testing
Not tested

Browse files

Browse files at the source ↗

Original SKILL.md

Open original ↗
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

Current listing version

0.1.0

Verify the source revision ↗

Safety and assessment details

Quality assessment

Out of 100 · Assessment report from SkillPi LAB.

Scenario Value95/100

Highlights

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

Highlights

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

Areas to improve

  • description 写错位置 Reported severity: Minor

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

    Recommendation: 将核心描述内容移至顶层 frontmatter 的 description 字段

  • 文档较长 Reported severity: Minor

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

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

Highlights

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

Highlights

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

The arithmetic mean of the first four original scores, rounded to a whole number.

Static text checks

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

No current rules matched the text.

This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.

Permissions and checks before use

Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.

Domains or addresses referenced in the document

These addresses may be documentation links or examples, not an approved network allowlist. Verify actual destinations and outgoing data before use.

  • github.com
  • huggingface.co

These notices grant no permissions. Your host tool must still confirm file changes, secrets, external transfers or costs as needed.

Security rating and access scope

safe · Static evidence review; not a runtime safety guarantee.

**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/<fami

Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.