本仓库是
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 |
| 本地文件 SHA256 | 183c988b918abad3cd7ae50af0fe1be9196d0353055ac6865345be2f7fdaed72 |
| 固定源版本 | 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.csvpresence, motion, breathing, heart_rate, phase_variance, person_count, fall_detected, rssi)| 组件 | 版本 | 说明 |
|---|---|---|
| 操作系统 | Linux(aarch64 容器) | — |
| Python | 3.11.14 | /usr/local/python3.11.14/bin/python3 |
| torch | 2.9.0+cpu | 容器预装匹配对,不得用普通 PyPI wheel 替换 |
| torch_npu | 2.9.0 | 容器预装匹配对,与 CANN 配套 |
| CANN | 8.5.1 | ASCEND_HOME_PATH=/usr/local/Ascend/cann-8.5.1 |
| NPU 硬件 | Ascend910B4-1(8 卡,本任务分配物理 npu:4) | npu-smi info 可见 |
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 构建。
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)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该脚本会:
npu-smi info 监视器写入 logs/npu_device_call.log;inference.py --iters 50 --hold 4.0 --device npu:4,输出写入 logs/inference.log;logs/inference.sanitized.log(去掉无害的 safetensors C 绑定调试打印);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/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,关键字段:
| 字段 | 值 |
|---|---|
| engine | torch_npu |
| exit_code | 0 |
| device.assigned | npu:4 |
| device.name | Ascend910B4-1 |
| device.available / count | true / 8 |
| versions.cann / torch / torch_npu | 8.5.1 / 2.9.0+cpu / 2.9.0 |
| placement.input_device | npu:4 |
| placement.model_device | npu:4 |
| placement.output_device | npu:4 |
| pid_evidence.pid | 950141(NPU 4 chip 0,python,118 MB,npu-smi 过程表可见) |
| output.shape | [6, 128] |
| output.stats.l2_norm_mean | 1.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 / min | 0.463 / 0.4208 ms(50 次 forward) |
| peak_memory_mb_allocated | 0.060 MB |
| elapsed_s | 8.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)渲染,未手工编辑任何数值。




a8a71fe866a13eb2743184ed51d09ea878f93afc183c988b918abad3cd7ae50af0fe1be9196d0353055ac6865345be2f7fdaed72mitinference.pyrun_inference.shlogs/npu_result.jsonlogs/inference.log / logs/inference.sanitized.loglogs/npu_device_call.loglogs/modelagent_transcript.logrender_screenshots.pyvalidate_delivery.py| 现象 | 原因 | 处理 |
|---|---|---|
torch.npu.is_available() 返回 False | CANN 环境未加载或驱动异常 | 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 NULL | safetensors 在本平台 C 绑定打印的无害调试信息 | 忽略,不影响结果;logs/inference.sanitized.log 已剔除 |
| 进程表看不到本进程 | 进程尚未建立 NPU 设备上下文或已退出 | 使用 --hold 保持上下文,或参考 logs/npu_result.json 中 pid_evidence |
| 首次算子编译较慢(几百 ms) | CANN 首次执行算子编译 | 正常,预热后可忽略 |
npu-smi 过程表只展示持有设备上下文的进程;本交付物同时以 torch_npu 张量设备断言
(input/model/output == npu:4)、torch.npu.device_count()、
torch.npu.max_memory_allocated() 以及 npu-smi 的精确 PID 行作为“在 NPU 上运行”
的权威证据。ruvnet/wifi-densepose-pretrained)。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。