ohhoohho/wifi-view
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

WiFi-View CSI Embedding — Ascend NPU 适配版

基于 Vikkyv9/wifi-view(源自 ruvnet/wifi-densepose-pretrained 的 v2 收敛版 CSI 编码器)适配华为昇腾 NPU 的推理部署方案。

模型信息

项值
模型来源Vikkyv9/wifi-view (csi-embed-v2.safetensors)
架构Enc: 8 → 64 → 128(2× Linear + BatchNorm + GELU + L2-Normalize)
输入标准化后的 8 维 CSI 特征([B, 8])
输出128 维 L2 归一化嵌入([B, 128],模长 = 1)
参数量~9,280(对比学习 InfoNCE 训练,温度 0.1)
权重格式safetensors fp32 (~40 KB)
训练基准held-out temporal-triplet 准确率 66.4%(raw) → 82.3%(v2)
LicenseMIT
运行硬件华为昇腾 NPU(torch_npu 2.x)

⚠️ 上游该仓同时含 v1 model.safetensors(头文件损坏 + flat-loss 未收敛,官方已标注弃用)与 2/4/8-bit 量化的 ESP32 精简版。本仓库采用官方推荐的 v2 全精度版 csi-embed-v2.safetensors(重命名为 model.safetensors),仅此一个权重即可完成推理。

架构图

 WiFi 信号 ──ESP32-S3─► 8 维 CSI 特征 (standardized)
                              │
                    Enc (8->64->128)   ← 本适配的核心
                    Linear+BatchNorm+GELU+L2
                              │
                        128 维嵌入
                              │
        ┌─────────────┬────────┴───────┬───────────┐
   Presence head  Activity head  Vitals head  (Roam)

快速开始

1. 环境依赖

pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/

见 requirements.txt。

2. 权重获取

仓库内已含 model.safetensors(v2 编码器)。若需从源刷新:

pip install huggingface_hub -i https://mirrors.aliyun.com/pypi/simple/
HF_ENDPOINT=https://hf-mirror.com huggingface-cli download Vikkyv9/wifi-view \
  csi-embed-v2.safetensors --local-dir ./ && mv ./csi-embed-v2.safetensors ./model.safetensors

3. 单帧推理(NPU)

# 8 维标准化 CSI 特征
python inference.py --model ./model.safetensors --device npu:0 \
  --features "0.5,-0.2,0.8,0.1,-0.6,0.3,0.7,-0.4"

输出 128 维 L2 归一化嵌入。断言:嵌入模长趋近 1。

4. 批量推理

# features.npy 形状为 [B, 8] 或 [8]
python inference.py --model ./model.safetensors --device npu:0 --input ./features.npy

5. NPU/CPU 一致性自检

python inference.py --model ./model.safetensors --device npu:0 --selftest
# 期望输出:平均余弦 = 1.000000(逐位一致)

量化版(ESP32 端)

仓库另含 model-q2/q4/q8.bin(TurboQuant 2/4/8-bit, <0.5% 质量损失)与 ESP32 SRAM 8KB 预算版 csi-embed-v2-int4.bin,主要用于边缘 MCU 部署;NPU 建议直接用全精度 fp32。

NPU 适配说明

  • 无重写:官方 csi-embed-v2.py 的 Enc 结构本就直接兼容 torch_npu;推理态固定 BatchNorm running 统计(eval()),与官方加载逻辑逐位一致。
  • 精度:NPU 输出与 CPU 输出 cosine 相似度 = 1.000000(L2 归一化后模长一致)。
  • 不走 vLLM-Ascend:该模型为 9K 参数的嵌入式 CNN/MLP(非文本 LLM),按惯例直接用 torch_npu 加载推理,无需服务化引擎。
  • 适配参考:昇腾 vLLM-Ascend / torch_npu 官方容器(CANN 8.5.1,torch 2.x,torch_npu 2.9.0)。

脚本参数

--model    : safetensors 权重路径         (默认 ./model.safetensors)
--device   : 推理设备,npu:0 / cpu         (默认 npu:0)
--features : 逗号分隔的 8 维 CSI 特征
--input    : npy 输入文件 [B,8] 或 [8]
--selftest : 运行 NPU/CPU 一致性自检
--json     : 以 JSON 输出嵌入向量

服务化(可选)

如希望 HTTP 服务化暴露嵌入接口,可用 inference.py 作为后端核,接入 FastAPI:

# pip install fastapi uvicorn
from fastapi import FastAPI
app = FastAPI()
# POST /embed {features:[8]} -> {"embedding":[128]}

如需完整 ChatCompletions 风格服务化,可接入 vLLM-Ascend(针对通用 LLM 场景)。

License

  • 模型:MIT(上游 Vikkyv9/wifi-view)
  • 适配脚本:Apache-2.0

适配结论:WiFi-View v2 CSI 编码器已成功在昇腾 NPU 上原生运行,9K 参数、embedding 输出 CPU/NPU 一致(cos=1.000000),推理路径稳定。