atlasleong/wifi-densepose-pretrained-ruvnet-npu
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

wifi-densepose-pretrained — Ascend NPU 推理适配(wireless-sensing / wifi-csi-embedding)

本仓库是 ruvnet/wifi-densepose-pretrained 在华为昇腾(Ascend)NPU 上的 torch_npu 推理适配交付物。神经前向路径全部运行在物理 npu:4 上,绝不静默回退 CPU。 输入 / 模型 / 输出张量的设备均被断言为 npu:4,并采集到与进程 PID 一一对应的 npu-smi 过程表证据。

模型简介

  • 模型仓库:https://huggingface.co/ruvnet/wifi-densepose-pretrained

  • 固定源版本(revision):a8a71fe866a13eb2743184ed51d09ea878f93afc

  • 任务:wireless-sensing / wifi-csi-embedding — 将 8 维标准化 WiFi CSI (Channel State Information)特征编码为 128 维 L2 归一化嵌入向量。

  • 架构:CSIEncoder8x64x128(8 -> 64 -> 128 两层全连接 + BatchNorm + GELU + L2 归一化)。源码实现对应仓库内 csi-embed-v2.py 中的 Enc 类:

    h = GELU(BatchNorm1d(Linear(8, 64)(x)))
    z = L2_normalize(BatchNorm1d(Linear(64, 128)(h)), dim=-1)   # [B, 128]
  • 参数量:9,280(与上游 csi-embed-v2-metrics.json 一致,严格加载 14 个 state-dict 键)。

  • 用途:把 ESP32-S3 等设备采集的 WiFi 信号变化(存在、运动、呼吸、心率、相位方差、 人数、跌倒、RSSI)映射为可用于对比学习的嵌入表示;上游报告的 held-out 时间三元组 准确率 82.3%(v2,已纠正 v1 的“100% presence”单类数据问题)。

  • 上游许可证:mit(模型仓库根 README 声明)。

使用的本地权重(不联网下载,固定版本校验)

项值
推理主权重文件csi-embed-v2.safetensors
字节数39,672
本地文件 SHA256183c988b918abad3cd7ae50af0fe1be9196d0353055ac6865345be2f7fdaed72
固定源版本a8a71fe866a13eb2743184ed51d09ea878f93afc

inference.py 启动时会校验固定版本下全部 6 个权重文件的字节数与 SHA256 (csi-embed-v2.safetensors、csi-embed-v2-int4.bin、model.safetensors、 model-q2.bin、model-q4.bin、model-q8.bin),任一不匹配即 fail closed 退出非零。

说明:上游 README / csi-embed-v2-metrics.json 中声明的 encoder 权重 SHA256 为 3b37bca66e6050c50ccbc0f6e0501824f258bfdd8675dc0f4541b1e2e96feecd,指原始参数字节 的另一种序列化,与本地 .safetensors 文件哈希不同;本交付物记录的是本地文件实际哈希。

测试输入(可再分发)

  • 文件:test_input.csv
  • 规模:6 行 × 8 列(presence, motion, breathing, heart_rate, phase_variance, person_count, fall_detected, rssi)
  • 来源:本任务自编写的确定性数值样例(self-authored)
  • 许可证:CC0-1.0
  • 说明:推理时不依赖任何网络数据集。

环境依赖清单

基础软件(容器已提供,禁止替换)

组件版本说明
操作系统Linux(aarch64 容器)—
Python3.11.14/usr/local/python3.11.14/bin/python3
torch2.9.0+cpu容器预装匹配对,不得用普通 PyPI wheel 替换
torch_npu2.9.0容器预装匹配对,与 CANN 配套
CANN8.5.1ASCEND_HOME_PATH=/usr/local/Ascend/cann-8.5.1
NPU 硬件Ascend910B4-1(8 卡,本任务分配物理 npu:4)npu-smi info 可见

Python 依赖(仅从配置镜像源安装)

requirements.txt 固定顶层非 torch 依赖。安装命令:

# 使用配置的阿里云 PyPI 镜像
export PIP_INDEX_URL=https://mirrors.aliyun.com/pypi/simple/
export PIP_TRUSTED_HOST=mirrors.aliyun.com

# 创建使用容器 torch/torch_npu 的虚拟环境
python3 -m venv --system-site-packages \
  /work/pipeline/runtime/venvs-tabular16/wifi-densepose-pretrained-ruvnet-npu

# 安装本模型所需的顶层非 torch 依赖
/work/pipeline/runtime/venvs-tabular16/wifi-densepose-pretrained-ruvnet-npu/bin/pip install \
  -r requirements.txt

重要:torch 与 torch_npu 由容器提供,绝不重新安装或替换;也不安装 CUDA wheel、 Triton、flash-attn、xformers、bitsandbytes 或其它 torch 构建。

分步推理操作流程

第 1 步:确认 NPU 环境(目标 npu:4)

source /usr/local/Ascend/cann-8.5.1/set_env.sh   # 或 set_env.sh 已生效
npu-smi info                                       # 应看到 Ascend910B4-1 设备,npu:4 OK

# 运行 AscendSkills 基础 NPU 检查(目标设备 npu:4,应全部 PASS)
/work/pipeline/runtime/venvs-tabular16/wifi-densepose-pretrained-ruvnet-npu/bin/python \
  /work/pipeline/upstreams/AscendSkills/ai4s-migration-base/scripts/check_npu_basics.py \
  --device npu:4

实际输出(节选):

[PASS] cann-env: CANN environment variables look set
[PASS] torch: imported (2.9.0)
[PASS] torch_npu: imported (2.9.0)
[PASS] numpy: 1.26.4
[PASS] npu: 8 device(s) visible
[PASS] tensor-op: basic tensor op succeeded on npu:4 (sum=-1.6859)

第 2 步:运行端到端 NPU 推理(npu:4)

cd /work/pipeline/jobs/other40/wifi-densepose-pretrained-ruvnet/wifi-densepose-pretrained-ruvnet-npu
bash run_inference.sh 50 4.0        # 参数:forward 次数 50,NPU 上下文保持 4.0s

该脚本会:

  1. 启动并发的 npu-smi info 监视器写入 logs/npu_device_call.log;
  2. 运行 inference.py --iters 50 --hold 4.0 --device npu:4,输出写入 logs/inference.log;
  3. 生成 logs/inference.sanitized.log(去掉无害的 safetensors C 绑定调试打印);
  4. 在 logs/npu_result.json 写入结构化结果(含输入/模型/输出放置断言与精确 PID 证据)。

也可以直接运行:

/work/pipeline/runtime/venvs-tabular16/wifi-densepose-pretrained-ruvnet-npu/bin/python \
  inference.py --csv test_input.csv --iters 50 --hold 4.0 --device npu:4

第 3 步:渲染证据截图(可选,用于复现)

/work/pipeline/runtime/venvs-tabular16/wifi-densepose-pretrained-ruvnet-npu/bin/python \
  render_screenshots.py

从真实保存的日志生成 assets/agent_workflow.png、assets/modelagent_live_session.png、 assets/npu_device_call.png、assets/model_result.png。

完整测试用例

用例名称:test_input.csv(6 行 × 8 维标准化 CSI 特征)在物理 npu:4 上生成 [6, 128] L2 归一化嵌入。

输入样例(test_input.csv 内容):

presence,motion,breathing,heart_rate,phase_variance,person_count,fall_detected,rssi
0.31,-0.42,0.17,0.85,-0.25,1.12,-0.98,0.54
-0.12,1.25,0.04,-0.67,0.73,-0.32,-0.98,1.21
0.88,-1.03,0.95,1.44,-1.12,0.44,-0.98,-0.76
-0.55,0.21,-0.62,-0.10,0.12,-0.88,-0.98,0.09
1.24,1.78,0.33,-1.30,1.55,0.67,-0.98,-1.42
-0.77,-0.63,1.06,0.52,-0.48,-0.15,-0.98,0.88

运行命令:

bash run_inference.sh 50 4.0

运行日志(logs/inference.sanitized.log):

[2026-08-21 17:47:30] NPU available: True | device_count=8 | device=npu:4
[2026-08-21 17:47:30] NPU name: Ascend910B4-1 | total_memory=62420 MB
[2026-08-21 17:47:30] CANN version: 8.5.1
[2026-08-21 17:47:30] torch version: 2.9.0+cpu | torch_npu version: 2.9.0
[2026-08-21 17:47:30] model source: https://huggingface.co/ruvnet/wifi-densepose-pretrained@a8a71fe866a13eb2743184ed51d09ea878f93afc
[2026-08-21 17:47:30] checkpoint: csi-embed-v2.safetensors bytes=39672 sha256=183c988b... match=True
[2026-08-21 17:47:30] checkpoint: csi-embed-v2-int4.bin bytes=4672 sha256=59b7f030... match=True
[2026-08-21 17:47:30] checkpoint: model.safetensors bytes=48840 sha256=d85fbc9e... match=True
[2026-08-21 17:47:30] checkpoint: model-q2.bin bytes=4096 sha256=1ebcafeb... match=True
[2026-08-21 17:47:30] checkpoint: model-q4.bin bytes=8192 sha256=4c97dd36... match=True
[2026-08-21 17:47:30] checkpoint: model-q8.bin bytes=16384 sha256=7c1356de... match=True
[2026-08-21 17:47:30] model: CSIEncoder8x64x128 | params=9280 | state_keys=14 | model.device=npu:4
[2026-08-21 17:47:30] input: csv=test_input.csv | shape=[6, 8] | device=npu:4 | dtype=torch.float32
[2026-08-21 17:47:30] output: shape=[6, 128] | device=npu:4 | dtype=torch.float32
[2026-08-21 17:47:32] npu-smi PID evidence: NPU 4 chip 0 | pid=950141 | name=python | mem=118 MB
[2026-08-21 17:47:32] holding NPU context for 4.0s (concurrent npu-smi PID capture window) ...
[2026-08-21 17:47:37] npu-smi PID evidence (after hold): pid=950141 | name=python | mem=118 MB
[2026-08-21 17:47:37] output: shape=[6, 128] | device=npu:4 | dtype=torch.float32
[2026-08-21 17:47:37] embedding stats: {"shape": [6, 128], "l2_norm_min": 0.9999999403953552, "l2_norm_max": 1.0, "l2_norm_mean": 1.0, "value_min": -0.47525718808174133, "value_max": 0.7181410193443298, "value_mean": -0.010082264430820942, "value_std": 0.0878114327788353, "rows": 6, "dims": 128}
[2026-08-21 17:47:37] embedding row-0 sample (first 8 of 128): [0.0039, 0.0167, -0.0402, -0.0386, -0.0222, 0.0615, -0.0189, -0.0115] ...
[2026-08-21 17:47:37] cosine similarity (6x6 rows): [[1.0, -0.4661, 0.4544, 0.5767, 0.4535, -0.0594], [-0.4661, 1.0, 0.1271, 0.0362, 0.2489, 0.729], [0.4544, 0.1271, 1.0, 0.4135, 0.119, 0.5372], [0.5767, 0.0362, 0.4135, 1.0, 0.359, 0.2905], [0.4535, 0.2489, 0.119, 0.359, 1.0, 0.1379], [-0.0594, 0.729, 0.5372, 0.2905, 0.1379, 1.0]]
[2026-08-21 17:47:37] latency_ms: {"iters": 50, "mean_ms": 0.463, "median_ms": 0.4355, "min_ms": 0.4208, "max_ms": 1.0679}
[2026-08-21 17:47:37] peak NPU memory allocated: 0.060 MB (device=npu:4)
[2026-08-21 17:47:38] elapsed_s: 8.9217 | exit_code: 0 | DONE

退出码:0。

输出结果

结构化结果保存在 logs/npu_result.json,关键字段:

字段值
enginetorch_npu
exit_code0
device.assignednpu:4
device.nameAscend910B4-1
device.available / counttrue / 8
versions.cann / torch / torch_npu8.5.1 / 2.9.0+cpu / 2.9.0
placement.input_devicenpu:4
placement.model_devicenpu:4
placement.output_devicenpu:4
pid_evidence.pid950141(NPU 4 chip 0,python,118 MB,npu-smi 过程表可见)
output.shape[6, 128]
output.stats.l2_norm_mean1.0(嵌入已 L2 归一化)
output.stats.value_mean / value_std-0.0101 / 0.0878
output.stats.value_min / value_max-0.4753 / 0.7181
latency_ms.mean / min0.463 / 0.4208 ms(50 次 forward)
peak_memory_mb_allocated0.060 MB
elapsed_s8.9204

第 1 行嵌入向量前 8 维样例: [0.0039, 0.0167, -0.0402, -0.0386, -0.0222, 0.0615, -0.0189, -0.0115, ...]

6×6 余弦相似度矩阵(L2 归一化后即余弦相似度,行间相似结构可解释为对比嵌入):

[[ 1.0   -0.466  0.454  0.577  0.454 -0.059]
 [-0.466  1.0    0.127  0.036  0.249  0.729]
 [ 0.454  0.127  1.0    0.414  0.119  0.537]
 [ 0.577  0.036  0.414  1.0    0.359  0.291]
 [ 0.454  0.249  0.119  0.359  1.0    0.138]
 [-0.059  0.729  0.537  0.291  0.138  1.0  ]]

证据截图(由真实日志渲染)

以下图片全部由 render_screenshots.py 从真实保存的日志 (logs/inference.sanitized.log、logs/npu_device_call.log、logs/npu_result.json、 logs/modelagent_transcript.log)渲染,未手工编辑任何数值。

agent-workflow

modelagent-live-session

npu-device-call

model-result

源版本与证据链接

  • 模型源仓库:https://huggingface.co/ruvnet/wifi-densepose-pretrained
  • 固定源 revision:a8a71fe866a13eb2743184ed51d09ea878f93afc
  • 权重文件 SHA256:183c988b918abad3cd7ae50af0fe1be9196d0353055ac6865345be2f7fdaed72
  • 上游许可证:mit
  • 官方实现仓库(上游 README 链接):https://github.com/ruvnet/RuView
  • 推理脚本:inference.py
  • 复现脚本:run_inference.sh
  • 结构化结果:logs/npu_result.json
  • 推理日志:logs/inference.log / logs/inference.sanitized.log
  • NPU 监视日志:logs/npu_device_call.log
  • ModelAgent 会话日志:logs/modelagent_transcript.log
  • 截图渲染脚本:render_screenshots.py
  • 交付校验脚本:validate_delivery.py

故障排查(Troubleshooting)

现象原因处理
torch.npu.is_available() 返回 FalseCANN 环境未加载或驱动异常source /usr/local/Ascend/cann-8.5.1/set_env.sh 后重试;用 npu-smi info 确认设备 OK
安装依赖时覆盖了 torch/torch_npu使用了普通 PyPI 源仅从 https://mirrors.aliyun.com/pypi/simple/ 安装 requirements.txt 中的顶层非 torch 依赖;torch/torch_npu 由容器提供
日志末尾出现 path string is NULLsafetensors 在本平台 C 绑定打印的无害调试信息忽略,不影响结果;logs/inference.sanitized.log 已剔除
进程表看不到本进程进程尚未建立 NPU 设备上下文或已退出使用 --hold 保持上下文,或参考 logs/npu_result.json 中 pid_evidence
首次算子编译较慢(几百 ms)CANN 首次执行算子编译正常,预热后可忽略

局限性(Limitations)

  • 本适配只做推理(embedding 前向),不含训练/微调。
  • 上游模型的验证仅基于单一房间、单一采集(v2 已诚实声明):embedding 质量指标是 held-out 时间三元组准确率 82.3%,并不代表下游存在/生命体征任务端到端准确率。
  • npu-smi 过程表只展示持有设备上下文的进程;本交付物同时以 torch_npu 张量设备断言 (input/model/output == npu:4)、torch.npu.device_count()、 torch.npu.max_memory_allocated() 以及 npu-smi 的精确 PID 行作为“在 NPU 上运行” 的权威证据。
  • 测试输入为自编写的确定性样例(CC0),用于验证前向路径与设备放置,不代表真实 CSI 分布。

许可证与使用限制

  • 模型上游许可证:MIT(ruvnet/wifi-densepose-pretrained)。
  • 测试输入:CC0-1.0(本任务自编写)。
  • 本交付物中的脚本(inference.py、run_inference.sh、render_screenshots.py、 validate_delivery.py)为本任务编写,按 MIT 授权。
  • 不得将本交付物用于医疗诊断;上游明确表示健康类特征仅用于筛查,不构成医疗建议。

适配交付补充

模型简介:见上文模型说明。

环境依赖:torch、torch_npu 与 CANN,详见 requirements.txt。

推理步骤:按运行步骤执行 inference.py,设备必须为 Ascend NPU。

完整测试用例:使用仓库内固定测试输入执行一次完整推理。

输出结果:真实 NPU 输出已记录在 logs/npu_result.json。