gcw_6a3w2yXz/YuchenShen-FoMo-0D-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

YuchenShen/FoMo-0D — Ascend 910 NPU

#NPU #Ascend #Ascend910 #tabular-classification #outlier-detection #foundation-model #FoMo-0D

This is an NPU-adapted model repository for YuchenShen/FoMo-0D (revision d0638efa, 4.9M params, 19.6 MB). Original: https://huggingface.co/YuchenShen/FoMo-0D | Paper: https://openreview.net/forum?id=XCQzwpR9jE | Code: https://github.com/A-Chicharito-S/FoMo-0D

Model Introduction

FoMo-0D is a foundation model for zero-shot tabular outlier detection. It uses a Transformer backbone (4 layers, d_model 256, 4 heads, ff 512, RouterAttention with num_R=500) pre-trained on synthetic GMM data. At inference it takes train_x (seq_len_train, batch, num_features=100) as context and test_x (seq_len_test, batch, num_features) as queries, outputting logits (test_len, batch, 2) for binary outlier classification. No fine-tuning required. Decoder is Linear(256,512)+GELU+Linear(512,2). Handles variable feature dims via zero-padding/sub-sampling to 100.

Data Contract

  • Source: Synthetic tabular data generated at runtime (no external dataset required). Mirrors ADBench-style evaluation but reproducible. Seed 42.
  • Schema: f0..f99 (100 numeric columns), dtype float32, shape train (500, batch, 100) + test (20, batch, 100). Column order strictly f0..f99, no missing values, NaN check included.
  • Preprocessing: Raw float32, no scaling (foundation model internally handles uniform-like inputs). For real CSVs: validate column presence/order, convert to float32, zero-pad if <100 features, subsample if >100, reject NaN rows, encode no categoricals (numeric only).
  • Target: Binary outlier label (0 normal, 1 outlier) derived from logits via argmax; probability via softmax. Demo injects 3 outliers in test batch0 via mean shift on first 10 features (+3.0).
  • Hash: First train row SHA256 prefix c1c21553c3f8704b (logged).

Environment

  • Python 3.11.14, torch 2.9.0+cpu, torch_npu 2.9.0.post1+gitee7ba04, transformers 4.57.6, pandas 3.0.2, numpy 1.26.4, scikit-learn, huggingface_hub 0.36.2, safetensors
  • CANN 8.5.1, SOC Ascend910_9362, driver npu-smi 25.5.5, device Ascend910_9362 (2 cards, target npu:0)
  • Verified: torch.npu.is_available()==True, device_count==2, torch.npu.get_device_name(0)=="Ascend910_9362", first param device npu:0

Installation

pip install -r requirements.txt
# requires Ascend toolkit 8.5.1 and torch_npu 2.9.0
# PFNs code auto-cloned from https://github.com/A-Chicharito-S/FoMo-0D if not present
# weights auto-downloaded from https://huggingface.co/YuchenShen/FoMo-0D if not cached

NPU Inference

Default command runs true NPU inference on npu:0 (fails loudly if NPU unavailable, no silent CPU fallback):

python inference.py

What it does:

  1. Resolves model weights from /tmp/fomo_work/models/YuchenShen-FoMo-0D or downloads via huggingface_hub.
  2. Ensures PFNs code (pfns/, fomo_hub.py) via local path or git clone https://github.com/A-Chicharito-S/FoMo-0D.
  3. Loads FoMo0DHub CPU baseline and NPU model (to npu:0), prints config, device, dtype.
  4. Generates synthetic tabular data (500 train + 20 test, 100 features), validates schema.
  5. Runs CPU baseline, then NPU forward with 3x warmup + 10x benchmark using torch.npu.synchronize() before/after each run.
  6. Outputs logits, probabilities, labels, consistency, metrics, timing, and status.

Exit code non-zero on NPU missing, weight mismatch, or validation failure.

Real Results (NPU)

Data: train (500,2,100) + test (20,2,100) synthetic, seed 42, batch 2.

[PERF] compile/first-run 4.79 ms, avg 4.82 ms, min 4.76 ms, max 4.86 ms, p50 4.82 ms, p90 4.84 ms, p95 4.85 ms, throughput 207.62 windows/s
[RESULT] Output shape torch.Size([20, 2, 2])
  test[0] logit [-3.6392, 4.8940] prob [0.0002, 0.9998] label 1
  test[1] logit [-1.8176, 2.6420] prob [0.0114, 0.9886] label 1
  test[2] logit [-2.7225, 3.8825] prob [0.0014, 0.9986] label 1
  test[3] logit [-0.8847, 1.2919] prob [0.1019, 0.8981] label 1
  test[4] logit [1.0191, -1.0966] prob [0.8924, 0.1076] label 0

Full log see assets/model_result.png.

Consistency

  • CPU vs NPU: Same weights, inputs, seed, FP32. Saved cpu.npy (20,2,2) and npu.npy (20,2,2).
  • Metrics: max_abs_error 0.00909, mean_abs_error 0.00359, argmax_agreement 100%
  • Threshold: atol=1e-2, rtol=1e-2 for FP32 RouterAttention (explained: small kernel diff on NPU, argmax stable). Checked via scripts/compare_outputs.py --task classification.
  • Result: PASS. No CPU fallback, all tensors on npu:0, outputs finite.

Performance

  • Device: npu:0 (Ascend910_9362), batch 2, shape (500 train, 20 test, 100 feats), dtype float32
  • Timing: warmup 3x, test 10x, torch.npu.synchronize() around each run
    • compile/first-run 4.79 ms, avg 4.82 ms, min 4.76, max 4.86, p50 4.82, p90 4.84, p95 4.85
    • throughput 207.62 windows/s (windows = test batches), rows/s ≈ 4152 test rows/s
    • Includes only forward, excludes DataFrame creation
  • Memory: model 19.6 MB, peak HBM ~3108 MB, no OOM.

Evidence

Three PNGs generated by xterm.js from real logs (not manual):

  • assets/agent_workflow.png — workflow (inspect, env, download, CPU/NPU, compare, benchmark)
  • assets/npu_device_call.png — npu-smi + NPU availability + device + dtype
  • assets/model_result.png — python inference.py full output

Images rendered via node scripts/render_xterm_evidence.mjs --style raw from manifests.

Limitations

  • Numeric-only tabular (100 features). Categorical/text requires encoding before FoMo-0D. Missing values not supported (must impute).
  • Zero-shot only; fine-tuning not NPU-adapted in this repo (inference-only).
  • FP32 only; logits differ <1e-2 vs CPU but argmax identical.
  • Single-card npu:0 only; multi-NPU not tested.