agentleFS
D-RoboticsD-Robotics/dsh-plugin-rdk/skills/oe-skills-s/hmct/SKILL.md

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。

The file

Files
SKILL.md

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校准数据目录(子目录名需与模型输入名一致)

可选参数

参数默认值说明
--marchnash-pBPU 芯片架构
--input_shape从 ONNX 自动推断输入 shape,如 [1,3,224,224]
--preprocess无预处理参数(mean/std/scale/color_convert/resizer/pyramid 等)
--name_prefixmodel输出模型名称或路径前缀
--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.yaml

YAML 配置示例

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

执行步骤

  1. 确认 --onnx_path 和 --cali_data_dir,未提供则询问
  2. 确认 --march 参数,未指定则使用默认值 nash-p
  3. 运行 hb_config_generator 生成 YAML 配置
  4. 向用户展示 YAML 配置摘要,等待用户确认(默认强制门禁)
  5. 用户确认后,转交 j6-hbdk-compile Skill 执行 hb_compile -c
  6. 检查输出日志,确认构建成功
  7. 向用户报告结果和输出文件路径

参考文档

  • hb_config_generator 使用文档见 horizon-tc-ui Skill
  • hb_compile YAML 配置参考见 j6-hbdk-compile Skill

路由 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

执行步骤

  1. 确认 --onnx_path,未提供则询问
  2. 确认 --march 参数,未指定则使用默认值 nash-p
  3. 运行 hb_config_generator --check-mode 生成验证 YAML
  4. 向用户展示 YAML 配置摘要,等待用户确认
  5. 用户确认后,转交 j6-hbdk-compile Skill 执行 hb_compile -c
  6. 若通过则告知用户模型兼容;若失败则分析错误原因

路由 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

需要收集的参数

参数必填说明
模型路径是校准后的模型文件路径
校准数据路径是校准数据路径
分析目标节点视工具而定部分工具需要指定节点列表

执行步骤

  1. 确认用户需要运行哪项分析工具
  2. 确认模型路径和校准数据路径
  3. 如果不确定运行哪项,建议先运行 runall 一键分析
  4. 使用 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         ← 敏感度分析脚本

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.