Adaptation of ruvnet/wifi-densepose-pretrained
("WiFi-DensePose") to run on Huawei Ascend NPU via torch_npu (no CUDA anywhere).
The original repo ships a csi-encoder-8-64-128 contrastive CSI embedding model
(8 -> 64 -> 128) with a rank-8 task LoRA, optional per-room node LoRAs and a
human-presence head, serialized as model.safetensors (+ node-*.json,
presence-head.json). This project loads those weights in torch, reconstructs the
forward pass, and runs it on npu:0.
x: [B, 8] (the feat8
contract documented in csi-embed-v2.py). A raw CSI amplitude matrix
[T,K] / [B,T,K] is also accepted and reduced to 8 statistical features
(mean/std/max/min/median/ptp/energy/activity) — see caveat below.model.safetensors + csi-embed-v2.py):
h = GELU(BN1(Linear8->64(x))), z = L2norm(BN2(Linear64->128(h))),
then z += scaling * ((z @ A) @ B) (task LoRA, rank 8, scaling 2.0), renormalised,
then optional per-room node LoRA (node-1/2.json, rank 4, alpha 8, scaling 2).presence = sigmoid(z @ w + b) (human-presence probability) and the
128-dim L2-normalised CSI embedding.| file | purpose |
|---|---|
inference.py | CLI + FastAPI (--serve) inference on NPU |
model.py | torch WiFiDensePoseModel (loads model.safetensors, node-*.json) |
make_sample.py | generate sample_csi.pt ([1,8]) and sample_amp.npy ([64,64]) |
requirements.txt | pip deps (all already present on the host) |
model_weights/ | cached weights (git-ignored) |
export ASCEND_RT_VISIBLE_DEVICES=1
source /usr/local/Ascend/ascend-toolkit/set_env.sh
# generate sample inputs
python3 make_sample.py
# CLI inference
python3 inference.py --input sample_csi.pt --node 1 --num_workers 0
# FastAPI service
python3 inference.py --serve --port 8000
# GET / -> HTML upload form
# POST /predict -> multipart file (.pt/.npy) or JSON
# curl -X POST http://0.0.0.0:8000/predict -F "file=@sample_csi.pt"Device selection uses the spec's try/except: NPU if available (npu:0), CPU fallback.
Cached at ./model_weights/ruvnet/wifi-densepose-pretrained (downloaded via
_shared/download_weights.py, hf-mirror). Note: the uploaded
model.safetensors pads its safetensors JSON header with NUL bytes instead of ASCII
spaces (non spec-compliant); model.py repairs the header transparently so the
standard safetensors loader can read it.
config.json, csi-embed-v2.py,
model.safetensors, model.rvf.jsonl, node-*.json and presence-head.json.model.safetensors differ from csi-embed-v2.safetensors
(different training); model.safetensors is treated as the primary model.[T,K]/[B,T,K]) is reduced to 8 statistical features
with an on-the-fly standardisation; this is an approximation because the original
CSI feature-extractor is not part of the repo. Prefer feeding the 8-dim
standardized feature vector directly.grep -rin cuda --include=*.py . is clean.