hmct-workflow
Skill1 starsChanged 3 months agoApache-2.0View on GitHub
HMCT 模型转换与 PTQ 量化总入口——优先使用 hb_compile + YAML 配置方式。 根据用户意图自动路由: (1) 提供了校准数据 → 使用 hb_config_generator 生成 YAML 配置,再调用 j6-hbdk-compile 执行编译; (2) 未提供校准数据 → 使用 hb_config_generator 生成快速验证配置,再调用 j6-hbdk-compile 验证; (3) 用户希望进行精度调优 → 转交 j6-hmct-cosine-similarity-tuning SKILL 执行多阶段调优; (4) 用户希望进行单项精度 debug 分析(节点灵敏度、数据分布、累积误差等)→ 调用 hmct-debugger CLI 执行对应分析工具。 当用户提示词中出现 HMCT、模型转换、模型量化、PTQ、hb_compile、YAML 配置、精度调优、cosine similarity、节点灵敏度、数据分布、累积误差、debug 等关键词时应触发此 Skill。
In this repository59 other files it gives its agents.
- bsp-bootloader-buildSkill
- bsp-deb-buildSkill
- bsp-env-setupSkill
- bsp-image-buildSkill
- bsp-kernel-buildSkill
- bsp-rootfs-customSkill
- bsp-source-syncSkill
- bsp-s-seriesSkill
- horizon-routerSkill
- ucpSkill
- x5-accuracy-diagnosticsSkill
- x5-board-monitorSkill
- x5-bpu-python-apiSkill
- x5-calibration-data-prepareSkill
- x5-consistency-diagnosticsSkill
- x5-environment-installSkill
- x5-environment-probeSkill
- x5-environment-setupSkill
- x5-model-diagnosticsSkill
- x5-model-preflightSkill
- x5-performance-diagnosticsSkill
- x5-ptq-compileSkill
- x5-ptq-config-authoringSkill
- x5-ptq-deploySkill
- x5-qat-adaptationSkill
- x5-qat-compileSkill
- x5-qat-deploySkill
- x5-qat-trainingSkill
- x5-routerSkill
- x5-runtime-cpp-inferSkill
- x5-runtime-deploySkill
- x5-runtime-perf-evalSkill
- rdk-accessoriesSkill
- rdk-board-delegateSkill
- rdk-board-knowledgeSkill
- rdk-camera-setupSkill
- rdk-command-manualSkill
- rdk-diagnosticSkill
- rdk-docs-referenceSkill
- rdk-ecosystemSkill
- rdk-embodied-lerobotSkill
- rdk-gpio-40pinSkill
- rdk-hardwareSkill
- rdk-headless-modeSkill
- rdk-llm-deploymentSkill
- rdk-log-forensicsSkill
- rdk-memory-auditSkill
- rdk-model-benchmarkSkill
- rdk-model-deploySkill
- rdk-model-zooSkill
- rdk-multimediaSkill
- rdk-network-remoteSkill
- rdk-peripheral-cookbookSkill
- rdk-source-mapSkill
- rdk-system-configSkill
- rdk-system-maintainSkill
- rdk-tros-setupSkill
- rdk-vision-pipelineSkill
- d-robotics-pack-installerSkill
The file
Files
HMCT 工作流路由
本 Skill 是 HMCT 工具链的统一入口,根据用户意图自动分发到对应子流程。
路由规则
用户请求
│
├─ 意图:模型转换 / 量化构建 / PTQ,且提供了校准数据(cali_data_dir)
│ └─→ 路由 A:通过 hb_config_generator 生成 YAML → j6-hbdk-compile 编译
│
├─ 意图:模型转换 / 验证模型 / 快速检查,未提供校准数据
│ └─→ 路由 B:通过 hb_config_generator 生成快速验证 YAML → j6-hbdk-compile 验证
│
├─ 意图:精度调优 / cosine similarity 不达标 / 混精度配置
│ └─→ 路由 C:精度调优工作流(转交 j6-hmct-cosine-similarity-tuning)
│
├─ 意图:单项 debug 分析(灵敏度、分布、累积误差等)
│ └─→ 路由 D:精度 Debug 工具
│
└─ 不确定
└─→ 询问用户意图后再路由路由 A:完整量化构建(YAML 驱动,推荐)
触发条件: 用户希望执行模型量化转换,且提供了校准数据。
关键词: 模型转换、量化构建、PTQ 构建、校准、hb_compile、YAML 配置
优先使用 hb_config_generator + hb_compile 方式(而非 run_build.py)。
工作流
Step 1: 收集参数 → Step 2: hb_config_generator 生成 YAML → Step 3: 用户确认 YAML → Step 4: hb_compile -c 编译需要收集的参数
必填
| 参数 | 说明 |
--onnx_path | 输入 ONNX 模型路径 |
--cali_data_dir | 校准数据目录(子目录名需与模型输入名一致) |
可选参数
| 参数 | 默认值 | 说明 |
--march | nash-p | BPU 芯片架构 |
--input_shape | 从 ONNX 自动推断 | 输入 shape,如 [1,3,224,224] |
--preprocess | 无 | 预处理参数(mean/std/scale/color_convert/resizer/pyramid 等) |
--name_prefix | model | 输出模型名称或路径前缀 |
--calibration_type | 由 HMCT 决定 | 激活校准方法(max / kl / load 等) |
执行方式
# Step 1: 使用 hb_config_generator 生成 YAML 配置
hb_config_generator \
--model-path <模型路径> \
--calibration-data-dir <校准数据目录> \
--march <芯片架构> \
--output-path <输出目录>/compile_config.yaml
# Step 2: 用户确认 YAML 配置(默认必须确认)
# 向用户展示生成的 YAML 配置摘要(模型路径、march、校准数据等)
# Step 3: 使用 hb_compile 执行编译
hb_compile -c <输出目录>/compile_config.yamlYAML 配置示例
model:
onnx: /path/to/model.onnx
march: nash-p
calibration:
data_dir: /path/to/cali_data
calibration_type: max
input:
input_source: pyramid
preprocessing:
mean: [123.675, 116.28, 103.53]
scale: [0.01712475, 0.017507, 0.0174292]
output:
out_dir: ./compile_output
model_name: quantized_model执行步骤
- 确认
--onnx_path和--cali_data_dir,未提供则询问 - 确认
--march参数,未指定则使用默认值nash-p - 运行
hb_config_generator生成 YAML 配置 - 向用户展示 YAML 配置摘要,等待用户确认(默认强制门禁)
- 用户确认后,转交 j6-hbdk-compile Skill 执行
hb_compile -c - 检查输出日志,确认构建成功
- 向用户报告结果和输出文件路径
参考文档
hb_config_generator使用文档见horizon-tc-uiSkillhb_compileYAML 配置参考见j6-hbdk-compileSkill
路由 B:快速验证(YAML 驱动)
触发条件: 用户希望验证模型是否能走通转换流程,但未提供校准数据。
关键词: 验证模型、check_model、快速检查、测试转换、能不能转
工作流
Step 1: 收集参数 → Step 2: hb_config_generator 生成验证 YAML(启用 check 模式) → Step 3: 用户确认 → Step 4: hb_compile -c 验证需要收集的参数
| 参数 | 必填 | 说明 |
--onnx_path | 是 | 输入 ONNX 模型路径 |
--march | 否 | BPU 芯片架构,默认 nash-p |
--input_shape | 否 | 输入 shape |
执行方式
# Step 1: 生成 YAML 配置(check 模式使用随机校准数据)
hb_config_generator \
--model-path <模型路径> \
--march <芯片架构> \
--output-path <输出目录>/compile_config.yaml \
--check-mode
# Step 2: 用户确认 YAML 配置
# Step 3: 执行快速验证编译
hb_compile -c <输出目录>/compile_config.yaml执行步骤
- 确认
--onnx_path,未提供则询问 - 确认
--march参数,未指定则使用默认值nash-p - 运行
hb_config_generator --check-mode生成验证 YAML - 向用户展示 YAML 配置摘要,等待用户确认
- 用户确认后,转交 j6-hbdk-compile Skill 执行
hb_compile -c - 若通过则告知用户模型兼容;若失败则分析错误原因
路由 C:精度调优工作流
触发条件: 用户希望对量化后模型进行精度调优,或反馈 cosine similarity 不达标。
关键词: 精度调优、cosine similarity、精度不达标、混精度、INT16、敏感节点、node_config、PTQ 调优
转交目标
转交至 j6-hmct-cosine-similarity-tuning Skill 处理。
需要收集的参数
| 参数 | 必填 | 说明 |
--onnx_path | 是 | 输入 ONNX 模型路径 |
--cali_data_dir | 是 | 校准数据目录 |
--march | 否 | BPU 芯片架构,默认 nash-p |
--work_dir | 否 | 工作目录,默认 ONNX 所在目录 |
--node_config_path | 否 | 固定节点配置文件 |
--num_sample | 否 | 敏感度分析的 bad case 数量,默认 1 |
--progressive_thresholds | 否 | 渐进阈值列表,默认 0.99 0.999 0.9999 0.99999 |
--calibration_type | 否 | 激活校准方法,写入 model_config.activation.calibration_type;默认不指定(由 HMCT 决定);可传单值(如 max)或多值(如 max kl,触发 modelwise search) |
--per_channel | 否 | 激活 per-channel 量化开关,接受 true/false(可同时传两个值触发搜索) |
--asymmetric | 否 | 激活非对称量化开关,接受 true/false(可同时传两个值触发搜索) |
--bias_correction | 否 | 是否开启权重 bias correction,接受 true/false |
--bias_correction_num_sample | 否 | bias correction 样本数(int >= 1),仅 --bias_correction true 时生效 |
--bias_correction_metric | 否 | bias correction 误差度量,可选 cosine-similarity/mse/mae/mre/sqnr/chebyshev |
执行方式
# 默认(由 HMCT 自动选择校准方法)
python3 HMCT_Skill/j6-hmct-cosine-similarity-tuning/script/hmct_precision_tuning.py \
--onnx_path <模型路径> \
--cali_data_dir <校准数据目录> \
--march <芯片架构>
# 显式指定单一校准方法
python3 HMCT_Skill/j6-hmct-cosine-similarity-tuning/script/hmct_precision_tuning.py \
--onnx_path <模型路径> \
--cali_data_dir <校准数据目录> \
--calibration_type max
# 多校准方法(HMCT 触发 modelwise search)
python3 HMCT_Skill/j6-hmct-cosine-similarity-tuning/script/hmct_precision_tuning.py \
--onnx_path <模型路径> \
--cali_data_dir <校准数据目录> \
--calibration_type max kl调优流程概览
INT8 基线 → 全 INT16 ─┬─ 达标 → INT8+INT16 渐进回退
└─ 未达标 → INT16+dual-int16 ─┬─ 达标 → 渐进回退
└─ 未达标 → 全 FP16 ─┬─ 达标 → 渐进回退
└─ 未达标 → 深层分析参考文档
完整调优流程见 j6-hmct-cosine-similarity-tuning/SKILL.md
路由 D:精度 Debug 工具(单项分析)
触发条件: 用户希望针对性地运行某一项 debug 分析(如节点灵敏度、数据分布、累积误差),而非完整调优流程。
关键词: 节点灵敏度、数据分布、逐通道分布、累积误差、tensor 分析、debug、hmct-debugger
可用工具
| 工具 | 说明 | CLI 命令 |
get-sensitivity-of-nodes | 节点灵敏度排序 | hmct-debugger get-sensitivity-of-nodes |
plot-distribution | 量化前后数据分布对比 | hmct-debugger plot-distribution |
get-channelwise-data-distribution | 逐通道数据分布 | hmct-debugger get-channelwise-data-distribution |
plot-acc-error | 逐层累积误差可视化 | hmct-debugger plot-acc-error |
tensor-analysis | 张量级详细分析 | hmct-debugger tensor-analysis |
sensitivity-analysis | 敏感节点深入分析 | hmct-debugger sensitivity-analysis |
runall | 一键运行全部 debug 功能 | hmct-debugger runall |
需要收集的参数
| 参数 | 必填 | 说明 |
| 模型路径 | 是 | 校准后的模型文件路径 |
| 校准数据路径 | 是 | 校准数据路径 |
| 分析目标节点 | 视工具而定 | 部分工具需要指定节点列表 |
执行步骤
- 确认用户需要运行哪项分析工具
- 确认模型路径和校准数据路径
- 如果不确定运行哪项,建议先运行
runall一键分析 - 使用 CLI 命令或 Python API 执行,向用户报告输出路径
参考文档
完整参数说明见 reference/debug_tools.md
路由判定示例
| 用户输入 | 路由 | 原因 |
| "帮我把 model.onnx 转换为量化模型,校准数据在 ./cali_data" | A | 有校准数据,执行 YAML 驱动编译 |
| "构建时帮我加上 input_dict 做归一化预处理" | A | 需传预处理参数到 YAML |
| "用 quant_config.json 量化这个模型" | A | 按 YAML 配置方式执行 |
| "我想看下这个模型能不能在 nash-e 上跑通" | B | 验证意图,无校准数据 |
| "帮我验证一下 model.onnx 能否转换成功" | B | 验证意图 |
| "用随机数据快速跑一遍流程" | B | 验证意图,走 check 模式 |
| "量化后精度下降了,帮我调优" | C | 精度调优意图 |
| "cosine similarity 只有 0.95,怎么提升" | C | 精度不达标 |
| "帮我做混精度配置,把敏感节点设成 INT16" | C | 精度调优意图 |
| "帮我看看哪些节点灵敏度最差" | D | 单项 debug 分析 |
| "画一下 conv1 的数据分布" | D | 单项 debug 分析 |
| "我有个 ONNX 模型想用 HMCT 处理" | 询问 | 意图不明确,需进一步确认 |
目录结构
HMCT_Skill/
├── SKILL.md ← 本文件(路由入口)
├── reference/
│ ├── build_model.md ← build_model / check_model 参考文档
│ ├── run_build.py ← 一键构建/验证脚本(备选路径,推荐用 YAML 方式)
│ └── debug_tools.md ← 精度 debug 工具参考文档
└── j6-hmct-cosine-similarity-tuning/
├── SKILL.md ← 精度调优 Skill 定义
├── example.md ← Prompt 示例
└── script/
├── hmct_precision_tuning.py ← 主调优脚本(含构建逻辑)
└── get_sensitivity_of_nodes.py ← 敏感度分析脚本Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

