eardoi/FoMo-0D-npu
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

FoMo-0D(昇腾 NPU 适配)

FoMo-0D(Foundation Model for 0-Dimensional data)是零样本异常检测基础模型 (4.9M 参数,PFNs 架构,NeurIPS 2025),无需训练即可对表格数据进行异常检测。

本项目完成其在**华为昇腾 NPU(Ascend 910B)**上的推理适配与验证。

模型规格

项目说明
网络FoMo0DHub(PFNs 先验拟合网络)
参数量4.9M
输入train_x / test_x(形状 (seq, batch, features))
输出异常分数 (test_seq, batch, n_class=2)
权重格式ckpt(best.ckpt)

环境准备

# 需先从 GitHub clone 官方代码库(含 fomo_hub.py 模型定义)
git -c http.version=HTTP/1.1 clone --depth 1 \
  https://gh-proxy.com/https://github.com/A-Chicharito-S/FoMo-0D.git /tmp/FoMo-0D

推理

cd /workspace/FoMo-0D
/workspace/tf4venv/bin/python inference.py \
    --model_path YuchenShen/FoMo-0D --repo_code /tmp/FoMo-0D \
    --n_train 5000 --n_test 10 --bs 3 --device npu:0

参数

参数说明默认值
--model_pathHF repo id 或本地目录YuchenShen/FoMo-0D
--repo_codeGitHub 官方代码目录/tmp/FoMo-0D
--n_train训练序列长度5000
--n_test测试序列长度10
--bsbatch size3
--device推理设备(npu:0 / cpu)npu:0
--output结果保存文件(可选,npy)stdout

验证结果(Ascend 910B, npu:0)

输入:train (5000,3,100) / test (10,3,100)

[info] model on npu:0: 4.9M
[info] input: train (5000,3,100) / test (10,3,100)
============================================================
[info] 输出形状: (10, 3, 2) (test_seq, batch, n_class=2)
============================================================

FoMo-0D 在 NPU 上完成零样本异常检测(输出 (10,3,2) 异常分数), NPU 推理链路完整跑通。

适配说明

  • GitHub 代码依赖:模型定义在官方仓库(fomo_hub.py), 需先 clone 代码库(GitHub 直连超时,用 gh-proxy 镜像)。
  • FoMo0DHub.from_pretrained(repo_id) 加载权重后 .to('npu:0') 迁移。
  • 推理输入为 model(train_x=..., test_x=...)(PFNs 先验拟合格式)。
  • 设备解析 resolve_device():NPU 可用性检测,失败自动回退 CPU。
  • 模型权重不推送到仓库:*.ckpt 已加入 .gitignore。

目录结构

.
├── README.md          # 模型卡片(本文件)
├── inference.py       # NPU 推理脚本
└── assets/            # 适配过程截图素材

引用

  • 模型:https://huggingface.co/YuchenShen/FoMo-0D
  • 代码:https://github.com/A-Chicharito-S/FoMo-0D