#NPU Ascend910 tabular-classification zero-shot outlier-detection foundation-model
YuchenShen/FoMo-0D revision d0638efa3cc7ec93ffcc9f9aa2ed6d15030e1161 (19.5 MB safetensors, 4.89M params)4 layers / emsize 256 / nhead 4 / nhid 512, RouterAttention num_R 500, last_layer_no_R True (ConTextTab/PFN lineage), 输入 seq_len 5000 (可变), num_features 100, 解码头 standard (Linear 256->512 GELU ->2) 2 分类 logitsFoMo0DHub (含 PFN transformer/layer/encoders/utils) 整体 to(npu:0) float32,本仓 inference.py 自包含嵌入式 pfns 源码,无隐式联网,从本地 snapshot 加载(train_x (5000,bs,100), test_x (10,bs,100)) -> output (10,bs,2),超过/不足 100 维按 PFN 策略 subsample/zero-padsklearn.datasets.load_breast_cancer 30 数值特征,569 行
0 benign (212) 正常 / 1 malignant (357) 异常RandomState(42) 抽 train 150 正常 (context) 与 test 50 (25正常+25异常) 混合,seed 42QuantileTransformer(output_distribution='normal', n_quantiles=min(1000,N)) 按列分位数正态化,若 d<100 则 transform 后 zero-pad 至 100,若 d>100 则随机 subsample 100 列 (rng 42),保持列顺序契约(seq_len, batch=1, 100) float32,train (150,1,100) mean 0.0394 std 0.5450, test (50,1,100) mean -0.1183 std 0.7410np.concatenate + Quantile + pad 流程确定性可复现logits (50,1,2) float32 -> softmax proba (50,1,2) -> score = proba[:,0,1] 异常概率working/cpu_logits.npy vs working/npu_logits.npy 同权对齐比较 (logits argmax)npu:0 (64 GB HBM, npu-smi 25.5.5 assoc host 0B:00.0)ASCEND_TOOLKIT_HOME /usr/local/Ascend/cann-8.5.1)snapshot_download(YuchenShen/FoMo-0D) 缓存 /opt/atomgit/.cache/huggingface/hub/models--YuchenShen--FoMo-0D/snapshots/d0638e.../model.safetensors 19.5 MB,revision 固定,FoMo0DHub.from_pretrained(map_location='cpu').to('npu:0')torch.npu.is_available()==True, device_count=2, 选中 npu:0, 首参 npu:0 float32 (model.transformer_encoder.layers.0.router_att.router npu:0)pip install -r requirements.txt
# 需预装 CANN Toolkit 8.5.1 使 torch_npu 可用
# 权重已通过 hf-mirror 缓存,无需联网;若首次运行会走 HF_ENDPOINT=https://hf-mirror.com 自动缓存python inference.py
# 或显式
python inference.py --device npu:0 --context 150 --test-size 50
python inference.py --device cpu # CPU 对比脚本自动: 检测 NPU、加载本地权重到 npu:0、打印 device/dtype、输入输出摘要、同步计时(torch.npu.synchronize())、性能与一致性、AUC 等。
train (150,1,100) mean 0.0394 std 0.5450 test (50,1,100) mean -0.1183 std 0.7410param npu:0 float32, router npu:0, estimator npu:0first-run 0.0064s shape (50,1,2) logits mean 0.0270 min -7.266 max 8.187
logits[0,0] [-3.2811, 4.4991] proba [0.00042, 0.99958] logits[1,0] [-1.9091, 2.7699]score = proba[:,0,1] 前5 [0.99958, 0.99079, 0.2273, 0.9941, 0.00458]AUCROC 0.7568 AUCPR 0.7231 F1@0.5 0.4444 (异常阈值 0.5,11/50 判异常)warmup 3 + 10 iter 首轮 0.0064s 稳定 avg 0.0049s min 0.0048 max 0.0049 p50 0.0049 p90 0.0049 throughput 10240 rows/s (50 rows / avg)SUCCESS 退出码 0, 无 CPU fallback, 全程 npu:0 同步计时完整日志见
assets/model_result.png
model.safetensors 19.5 MB)、同一输入 (seed 42 的 breast_cancer 50 test、同一 quantile+pad 流程、batch 1、float32、eval mode)working/cpu_logits.npy vs working/npu_logits.npy (50,1,2) logitspython scripts/compare_outputs.py --cpu ... --npu ... --task classification --atol 0.02 --rtol 0.02max_abs 0.011731 mean_abs 0.003700 argmax_match 1.0000 PASS (阈值 FP32 2e-2,NPU 融合算子与 double→float cast 引入约 1e-2 误差,proba max_abs 0.0038)npu:0torch.npu.synchronize(),首轮编译与稳定分开150 context + 50 test, dtype float32, batch 1 (seq_len 150+50)rows/s (test rows / avg latency)first 0.0064s avg 0.0049s min 0.0048 max 0.0049 p50 0.0049 p90 0.0049 rows/s 10240 (npu:0)3109 MB / 65536 (npu-smi)0.08s (含 quantile 预处理), NPU ~16x (forward 部分)三图由 xterm.js 根据本次真实日志渲染 (--style raw), 非手工绘图:
assets/agent_workflow.png — 侦察/下载/加载/NPU推理/一致性/性能全流程assets/npu_device_call.png — npu-smi + check_npu + 参数 device Proofassets/model_result.png — 默认 python inference.py 完整输出

图片由 xterm.js 根据真实日志生成, 提示符为 atomgit@pod-a94f8701860f4700b161b00e290de466:~$ 展示标签, 非桌面截图.
context 150 + test 50 轻量验证;生产可设 5000 context 需约 2 GB 显存,本仓未启用最大序列npu:0 验证,float32;bfloat16 可提速但需重验阈值seed 42),不足则 zero-padn_quantiles min(1000,N) 与官方 preprocess_transform='quantile' 一致,但未覆盖 normalize_with_test 等细粒度选项forward,未覆盖训练/微调的 NPU 迁移YuchenShen-FoMo-0D-NPU/
├── inference.py
├── readme.md
├── requirements.txt
└── assets/
├── agent_workflow.png
├── npu_device_call.png
└── model_result.png