atlasleong/fomo-0d-npu
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

FoMo-0D · Ascend NPU tabular outlier detection

FoMo-0D is a foundation model for zero-shot tabular outlier detection. It is a PFN-style in-context transformer that takes a reference (inlier) table plus a set of candidate rows and returns, for every candidate row, a class probability that the row is an outlier. This delivery adapts the official pretrained YuchenShen/FoMo-0D checkpoint to run the full neural forward path on a Huawei Ascend NPU through torch_npu, with strict weight verification, deterministic synthetic test data with injected anomalies, and an acceptance metric (top-k precision / recall).

FieldValue
ModelYuchenShen/FoMo-0D (PFN-style in-context transformer)
Tasktabular-outlier-detection
Source revision (model)d0638efa3cc7ec93ffcc9f9aa2ed6d15030e1161
Official implementation revision34d4339e318d96ac744850188a547b62387a718c
Weightmodel.safetensors, 19 559 720 bytes
Weight SHA25614506cee3d484d0a052ede20e2107b743ae31f1a0ca0860fb12d7f4db9e7acc4
Enginetorch_npu
Devicenpu:7 (Ascend 910B4-1, CANN 8.5.1)
LicenseMIT (upstream)

Scope note. This repository is a portable inference delivery: it does not contain the pretrained weights. Point --model-path at a local checkout of YuchenShen/FoMo-0D (with config.json + model.safetensors) and the script verifies size/SHA256 before loading.


模型简介

FoMo-0D 是一个用于表格数据零样本异常检测的基础模型。其主干是 PFN(Prior-Fitted Network)风格的上下文(in-context)Transformer:给定一段 “参考/正常”的表格行(context)和若干待评分行(test),模型直接输出每一行属于 异常类别的概率。本交付基于官方预训练权重 YuchenShen/FoMo-0D(模型仓库修订 d0638efa3cc7ec93ffcc9f9aa2ed6d15030e1161,权重 SHA256 14506cee3d484d0a052ede20e2107b743ae31f1a0ca0860fb12d7f4db9e7acc4),并固定使用官方实现修订 34d4339e318d96ac744850188a547b62387a718c 的 fomo_hub.py 与 pfns/ 源码 (逐字拷贝,保留上游 LICENSE)。

所有神经网络输入张量、模型参数与最终输出张量均被断言位于指定的 Ascend NPU (npu:7)上;若 NPU 不可用或任何放置/执行校验失败,脚本以非零码退出, 绝不静默回退到 CPU。


Evidence images

ScreenshotDescription
agent_workflowComplete ModelAgent adaptation workflow (10 steps, real versions/results).
modelagent_live_sessionSanitized ModelAgent live-session dialogue for FoMo-0D.
npu_device_callReal npu-smi info capture: the inference PID observed on NPU 7.
model_resultFinal real output and acceptance result.

All four images are rendered from the real sanitized logs in logs/ (npu_inference.log, npu_device_call.log, npu_result.json, env_versions.log, modelagent_dialogue_sanitized.txt).


Pinned revisions and hashes

  • Model card / weights revision: d0638efa3cc7ec93ffcc9f9aa2ed6d15030e1161
  • Official implementation revision: 34d4339e318d96ac744850188a547b62387a718c (source tree: fomo-0d-34d4339e318d96ac744850188a547b62387a718c)
  • Weight file: model.safetensors
    • size: 19 559 720 bytes
    • SHA256: 14506cee3d484d0a052ede20e2107b743ae31f1a0ca0860fb12d7f4db9e7acc4
  • Test input: self-authored deterministic synthetic tabular rows, CC0-1.0 (no network dataset at inference time).

环境依赖清单

The container already provides a matched torch / torch_npu pair. Do not reinstall or replace either from ordinary PyPI/CUDA wheels.

ComponentVersion (verified)
OS / archopenEuler 22.03 SP4, aarch64
Python3.11.14
torch2.9.0+cpu
torch_npu2.9.0
CANN8.5.1
NPUAscend 910B4-1 x8 (assigned npu:7)
numpy1.26.4
safetensors0.8.0
einops0.8.1
huggingface_hub0.36.2

requirements.txt pins the top-level non-torch dependencies:

numpy==1.26.4
safetensors>=0.4.3,<0.9
einops>=0.7,<0.9
huggingface_hub>=0.24,<1.0

Install with the Aliyun mirror:

python -m venv --system-site-packages /work/pipeline/runtime/venvs-tabular16/fomo-0d-npu
source /work/pipeline/runtime/venvs-tabular16/fomo-0d-npu/bin/activate
pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/

--system-site-packages is used so the container-provided torch / torch_npu remain the ones actually loaded.


分步推理操作流程

1. Load the Ascend environment

export ASCEND_RT_VISIBLE_DEVICES=0,1,2,3,4,5,6,7
source /usr/local/Ascend/ascend-toolkit/set_env.sh
npu-smi info        # confirm 8x 910B4, all OK

2. Run end-to-end NPU inference (with concurrent NPU monitor)

cd fomo-0d-npu
bash scripts/run_inference_npu.sh npu:7

The script:

  1. writes environment versions to logs/env_versions.log;
  2. launches inference.py --model-path /work/pipeline/models/tabular16/fomo-0d --device npu:7 --output-json logs/npu_result.json --hold-seconds 8;
  3. records the inference PID and concurrently samples npu-smi info into logs/npu_device_call.log while the process is alive (the short hold keeps the NPU context observable);
  4. merges stderr (real errors only) and prints the final exit code.

3. Run inference.py directly

python inference.py \
  --model-path /work/pipeline/models/tabular16/fomo-0d \
  --device npu:7 \
  --output-json logs/npu_result.json

--out-json is accepted as a backward-compatible alias of --output-json.

4. Public-checkout usage with --model-path

A public checkout works as long as the model path is supplied. Clone/copy the FoMo-0D model repo (with config.json and model.safetensors) to any directory and pass it:

python inference.py \
  --model-path /any/path/to/YuchenShen/FoMo-0D \
  --device npu:7 \
  --output-json result.json

The script will refuse to run if the weight file size or SHA256 does not match the pinned values above.


完整测试用例

Deterministic CC0 synthetic benchmark (seed 42, RandomState):

  • num_features = 100
  • context = 1000 reference inlier rows, each feature ~ U(0,1)
  • test = 20 rows: 16 inliers (U(0,1)) + 4 injected outliers whose 3 chosen features are set to extreme values 8.0 / -5.0 / 12.0
  • ground-truth outlier rows: [16, 17, 18, 19]

Command:

python inference.py \
  --model-path /work/pipeline/models/tabular16/fomo-0d \
  --device npu:7 \
  --context-size 1000 --num-test-rows 20 --num-outliers 4 --seed 42 \
  --output-json logs/npu_result.json

Real output (from logs/npu_inference.log)

[ENV] hardware_name=Ascend910B4-1 cann=8.5.1 torch=2.9.0+cpu torch_npu=2.9.0 npu_count=8 requested_device=npu:7 actual_device=npu:7
[WEIGHT] hashing model.safetensors (19559720 bytes) ...
[WEIGHT] sha256=14506cee3d484d0a052ede20e2107b743ae31f1a0ca0860fb12d7f4db9e7acc4
[MODEL] constructing FoMo0DHub from /work/pipeline/models/tabular16/fomo-0d/config.json ...
[MODEL] strict load: missing=0 unexpected=0 state_dict_keys=101
[MODEL] loaded+placed in 1.05s
[MODEL] architecture=FoMo0DHub params=4886786 param_devices=['npu'] param_device_ids=[7]
[INPUT] wrote test_input.csv (context=(1000, 100), test=(20, 100))
[INPUT] device=npu:7 context=(1000, 1, 100) test=(20, 1, 100) dtype=torch.float32
[RUN] FoMo0DHub.forward(context=1000, test=20) ...
[OUT] shape=(20, 1, 2) device=npu:7 finite=True
[OUT] anomaly_score_min=0.002771 max=1.000000 mean=0.294692
[OUT] top-4 predicted outlier rows=[16, 17, 18, 19] (true injected=[16, 17, 18, 19])
[OUT] precision@4=1.0000 recall@4=1.0000
[OUT] sample anomaly_scores=[0.0028, 0.7947, 0.0156, 0.0195, 0.2781, 0.0079, 0.0122, 0.0154] ...
[PERF] latency=0.236s peak_memory=82.9MB
[DONE] wrote logs/npu_result.json exit_code=0

NPU process evidence (from logs/npu_device_call.log)

npu-smi info captured the exact inference PID on NPU 7 while the process held the device context:

| NPU     Chip              | Process id    | Process name             | Process memory(MB)      |
| 7       0                 | 2433087       | python                   | 242                     |

(PID 2433087 was observed in samples 6–16 of the live monitor; the steady-state process memory is ~242 MB.)


输出结果

Structured results are written to logs/npu_result.json:

{
  "model_id": "YuchenShen/FoMo-0D",
  "source_revision": "d0638efa3cc7ec93ffcc9f9aa2ed6d15030e1161",
  "implementation_source_revision": "34d4339e318d96ac744850188a547b62387a718c",
  "engine": "torch_npu",
  "requested_device": "npu:7",
  "actual_device": "npu:7",
  "exit_code": 0,
  "npu_available": true,
  "npu_device_name": "Ascend910B4-1",
  "input_device": "npu:7",
  "model_device": "npu:7",
  "output_device": "npu:7",
  "placement": { "model": "npu:7", "input": "npu:7", "output": "npu:7" },
  "npu_process_evidence": {
    "pid": 2433087, "process_name": "python", "device": "npu:7",
    "observed_in_npu_smi": true, "process_memory_mb": 242.0
  },
  "weights": {
    "bytes": 19559720,
    "sha256": "14506cee3d484d0a052ede20e2107b743ae31f1a0ca0860fb12d7f4db9e7acc4",
    "size_matches": true,
    "sha256_matches": true
  },
  "strict_load": { "missing_count": 0, "unexpected_count": 0, "state_dict_keys_loaded": 101 },
  "model": { "architecture": "FoMo0DHub", "num_parameters": 4886786,
             "param_devices": ["npu"], "param_device_ids": [7] },
  "input": { "shape": [20, 1, 100], "device": "npu:7",
             "context_shape": [1000, 1, 100] },
  "output": { "shape": [20, 1, 2], "device": "npu:7", "finite": true,
              "top_k_predicted_outliers": [16, 17, 18, 19],
              "true_injected_outlier_rows": [16, 17, 18, 19],
              "precision_at_k": 1.0, "recall_at_k": 1.0 },
  "latency_s": 0.2356,
  "peak_memory_mb": 82.89
}

Key acceptance values:

  • engine torch_npu, npu_available = true, npu_device_name = Ascend910B4-1
  • input_device / model_device / output_device all npu:7 (placement assertions passed)
  • NPU process evidence: inference PID 2433087 observed on npu:7 by the live npu-smi info capture (observed_in_npu_smi = true, ~242 MB)
  • strict weight load: 0 missing / 0 unexpected keys (101 keys loaded)
  • output finite, shape (20, 1, 2)
  • top-4 predicted outlier rows = [16, 17, 18, 19] = exactly the injected anomalies
  • precision@4 = 1.0000, recall@4 = 1.0000
  • latency ≈ 0.24 s, peak device memory ≈ 83 MB on the 910B4
  • exit code 0

Acceptance criteria

  1. inference.py imports torch_npu, requires an available Ascend NPU, sets npu:7, and hard-fails if unavailable (no CPU neural fallback).
  2. Real local FoMo-0D weights are loaded strictly: file size and SHA256 are verified before loading; missing/unexpected state-dict keys are reported and cause failure unless both lists are empty.
  3. The official FoMo-0D architecture/source at the pinned implementation revision is used; upstream MIT license is preserved.
  4. Deterministic synthetic tabular context/test data with known injected anomalies is generated; the full neural forward path runs on npu:7.
  5. Model parameters, neural inputs and neural outputs are all on npu:7.
  6. Anomaly scores are finite; top-k precision/recall against the injected anomaly indices is reported.
  7. The structured JSON records revisions, engine, requested/actual device, weight hash/size, tensor shapes, strict-load counts, finite checks, ranked anomalies and metrics.
  8. Any validation or placement failure exits nonzero.

Limitations

  • The delivery does not bundle weights; it requires --model-path to point at a local FoMo-0D checkout (public checkout usage is supported).
  • The test input is self-authored CC0 synthetic tabular data. It is deterministic and reproducible, but it is not the ADBench benchmark.
  • Features are fixed to the model's num_features = 100; datasets with a different feature count need the PFN-style subsample/zero-pad procedure (see the upstream ReadMe.md).
  • Ascend does not support float64; tensors are float32.
  • The short --hold-seconds window exists only so a concurrent npu-smi monitor can observe the short-lived inference PID; it does not change results.

Troubleshooting

SymptomCause / fix
torch.npu.is_available() is FalseAscend env not loaded. Run source /usr/local/Ascend/ascend-toolkit/set_env.sh and check npu-smi info.
failed to import torch_nputorch/torch_npu pair broken. Recreate the venv with --system-site-packages; never pip-install another torch build.
weight size mismatch / weight SHA256 mismatchThe --model-path does not contain the pinned model.safetensors. Verify bytes 19559720 and SHA256 14506cee…e7acc4.
strict weight load failed: missing=…config.json/pfns/ do not match the pinned implementation revision. Use the official source at 34d4339e….
model parameters not on npu:7ASCEND_RT_VISIBLE_DEVICES hides physical card 7. Export 0,1,2,3,4,5,6,7.
No running processes found in NPU 7 during monitorInference is very short; increase --hold-seconds (e.g. HOLD_SECONDS=10).

Attribution and license

  • Model: FoMo-0D, © 2025 Yuchen Shen. Paper: FoMo-0D: A Foundation Model for Zero-shot Tabular Outlier Detection (Shen, Wen, Akoglu; TMLR 2025). Upstream repo: github.com/A-Chicharito-S/FoMo-0D.
  • Code: fomo_hub.py and pfns/ are copied verbatim from the official implementation at revision 34d4339e318d96ac744850188a547b62387a718c. Upstream license (MIT): LICENSE_FoMo0D_UPSTREAM.
  • Weights: YuchenShen/FoMo-0D revision d0638efa3cc7ec93ffcc9f9aa2ed6d15030e1161.
  • Test input: self-authored deterministic synthetic tabular rows, released CC0-1.0.
  • Backbone attribution: FoMo-0D builds on PFNs and DTE; see the upstream ReadMe.md.

Citation

@article{shen2025fomod,
  title={FoMo-0D: A Foundation Model for Zero-shot Tabular Outlier Detection},
  author={Yuchen Shen and Haomin Wen and Leman Akoglu},
  journal={Transactions on Machine Learning Research},
  issn={2835-8856},
  year={2025},
  url={https://openreview.net/forum?id=XCQzwpR9jE}
}