原始模型: https://huggingface.co/Ambiq/compressionkit-ecg-2x
Ambiq 生物信号 RVQ 压缩解码器(ECG 心电,2x 上采样版本):
[N, 16, T, 1](16 阶码本残差)UpSample(1,2) -> Conv2d(48, 1x7) -> ReLU -> SeparableConv(48, 1x5) -> ReLU -> LayerNorm(48) -> Conv2d(1, 1x1)权重来源: 原始 HF 仓库为 gated 仓库(HTTP 401 无法匿名获取),已获授权在本地下载 decoder.keras,
经 keras2torch.py(本仓库一并入库)转换为 PyTorch safetensors 权重(键布局 <layer>.weight/.depthwise/.pointwise/.bias/.gamma/.beta)。
| 指标 | 数值 |
|---|---|
| output cos_sim (CPU vs NPU) | 1.000000 |
| max_abs_err | 3.154e-03 |
| CPU 延迟 | 21.399 ms/iter (batch=256) |
| NPU 延迟 | 0.745 ms/iter |
| 加速比 | 28.73x |
环境: Python 3.11.14 / torch 2.9.0+cpu / torch_npu 2.9.0.post1 / CANN 8.5.1 / Ascend 910 ×2
pip install -r requirements.txt
python inference.py --variant ecg-2x自动检测 torch_npu:有 NPU 则输出 CPU vs NPU 对比,无则 CPU-only。
| 文件 | 说明 |
|---|---|
inference.py | CPU/NPU 推理对比脚本(Decoder 类 + KEY_REMAP 权重映射) |
keras2torch.py | decoder.keras → PyTorch safetensors 权重转换脚本 |
decoder-ecg-2x.safetensors | 转换后的解码器权重 |
meta-ecg-2x.json | 模型层结构元数据 |
assets/agent_workflow.png | 适配工作流 |
assets/npu_device_call.png | NPU 设备调用证据 |
assets/model_result.png | 精度与性能对比结果 |