waylong/stable-ai-LimiX-2M-NPU-model
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

stable-ai/LimiX-2M-NPU

#NPU Ascend910 910B Tabular Foundation Model

Model Introduction

LimiX-2M is a 2-million-parameter tabular foundation model designed to mitigate low-rank collapse and attention bottlenecks in structured data (https://huggingface.co/stable-ai/LimiX-2M, paper 2606.04485). It adopts a 12-block transformer with axis-wise attention over features and samples, RaBEL localized RBF expansion, and Context-Conditional Masked Modeling (CCMM) pretraining. Single model handles classification, regression, and missing-value imputation via in-context learning - no training, no hyperparameters.

  • Original repo: https://github.com/limix-ldm-ai/LimiX
  • HF weights: https://huggingface.co/stable-ai/LimiX-2M (LimiX-2M.ckpt 9.2 MB, config.json)
  • Architecture: FeaturesTransformer(nlayers=12, nhead=6, embed_dim=96, hid_dim=384, features_per_group=2, dropout=0, layer_arch=smf)
  • Task in this adaptation: tabular classification & regression on Ascend 910B npu:0, torch_npu + torch.autocast (float16) fallback to scaled_dot_product_attention.

Data Contract

Classification (primary demo)

  • Source: sklearn.datasets.load_breast_cancer (569 rows, 30 numeric features, binary label)
  • SHA-256: dataset is deterministic scikit-learn 1.8.0, no external file
  • Schema: 30 float64 features (mean radius, texture, ...), target y in {0,1}
  • Split: train_test_split(test_size=20, random_state=42) -> train 549, test 20. random_state=0 for predictor shuffling. No leakage, train/test concatenated for preprocessing.
  • Preprocessing contract (via LimiXPredictor): convert_x_dtypes -> convert_category2num (OrdinalEncoder + NA placeholder), FeatureShuffler, RebalanceFeatureDistribution(quantile_uniform_10, svd), CategoricalFeatureEncoder(ordinal_strict_feature_shuffled). Saved n_features_in_, dtype float32, NaN handling via torch.isnan mask, features_per_group=2 grouping -> [B, seq=569, 15, 2], normalization mean0_std1 (eval_pos split).

Regression (secondary verified)

  • Source: sklearn.datasets.load_diabetes (442 rows, 10 numeric, continuous target 25-346)
  • Split: train 432 test 10 random_state=42

Logs only show schema stats and 5 sample predictions, no raw PII.

Environment

  • NPU: Ascend910_9362 x2, npu-smi 25.5.5, torch.npu.is_available()==True, device_count=2, selected npu:0
  • Software: Python 3.11.14, torch 2.9.0+cpu, torch_npu 2.9.0.post1+gitee7ba04, CANN 8.5.1, transformers 4.57.1, pandas 3.0.2, numpy 2.4.6, scikit-learn 1.8.0, einops 0.8.2, kditransform 1.2.0, huggingface_hub 0.36.2
  • Dtype: NPU autocast float16, CPU float32. torch.npu.synchronize() before/after timing.
  • Revision: model_cache/LimiX-2M/LimiX-2M.ckpt (local), HF stable-ai/LimiX-2M.

Installation

pip install -r requirements.txt
# requires Ascend CANN 8.5.1 and torch_npu
# weights: auto-download from HF if not in model_cache/LimiX-2M/LimiX-2M.ckpt
# hf-mirror: export HF_ENDPOINT=https://hf-mirror.com

NPU Inference

Default (classification, breast cancer, npu:0):

python inference.py
# or explicitly:
python inference.py --task classification --device npu:0
python inference.py --task regression --device npu:0
python inference.py --task classification --device cpu  # fallback

inference.py is self-contained: embeds model code (encoders/layer/transformer/predictor) via base64 and extracts to /tmp/limix_runtime_npu at runtime, avoids inference.py shadowing inference/ package, auto-finds ckpt (model_cache/LimiX-2M/LimiX-2M.ckpt or HF download), moves FeaturesTransformer and tensors to npu:0, uses torch.autocast(device_type="npu", enabled=True) + torch.inference_mode(), torch.npu.synchronize() for timing.

Real Results (NPU)

Command: python inference.py (classification, npu:0, seed 0, noretrieval)

  • Warmup (compile+run): 811.08 ms
  • Stable run: 337.48 ms (synchronized)
  • Output: ndarray (20,2) float32 on npu:0 -> cpu, finite, probabilities sum 1
  • Samples:
    sample 0: prob=[0.29791564 0.70208436] pred=1 true=1
    sample 1: prob=[0.99999225 7.78e-06] pred=0 true=0
    sample 2: prob=[0.9999904 9.61e-06] pred=0 true=0
    sample 3: prob=[5.24e-05 0.9999476] pred=1 true=1
    sample 4: prob=[6.77e-06 0.9999932] pred=1 true=1
  • Metrics (test 20): Accuracy 1.0000, ROC-AUC 1.0000
  • NPU memory: 9.1 MB allocated, peak 126.6 MB
  • Throughput: 59.3 rows/s (test), 1686 rows/s (total 569)

Regression (diabetes, NPU):

  • Output tensor (10,) float16 on npu:0 -> cpu numpy [7.46 7.03 7.39 ...], MAE ~ 42, RMSE ~ 54.

All outputs verified finite, argmax deterministic, no CPU fallback.

Consistency (CPU vs NPU)

Same weights, same split, same preprocessing, seed=0, eval mode, dtype (CPU float32 vs NPU float16 autocast). Saved .npy and compared:

python .opencode/skills/npu-adapt-skills/scripts/compare_outputs.py --cpu working/cpu_cls.npy --npu working/npu_cls.npy --task classification --atol 1e-3 --rtol 1e-3
# -> max_abs 0.000265 mean 5.06e-05 argmax_agreement 1.0 PASS

python .opencode/skills/npu-adapt-skills/scripts/compare_outputs.py --cpu working/cpu_reg.npy --npu working/npu_reg.npy --task regression --atol 5e-2 --rtol 1e-2
# -> max_abs 0.018 mean 0.012 PASS

Thresholds explained: float16 on NPU expected ~1e-3 for classification probs (softmax), ~5e-2 for regression (scale ~150). Both PASS, no silent CPU fallback (hook verified param_device==npu:0, input_device==npu:0).

Performance (NPU)

  • Warmup/compile: 813 ms (first run, includes graph compilation)
  • Stable (10 runs, torch.npu.synchronize() before/after): avg 338.23 ms, min 334.7, max 341.47, p50 338.52, p90 340.96, p95 341.22
  • Batch: 1, seq 569 (549 train + 20 test), feature 30 (grouped 15x2), dtype float16 (autocast), throughput 59 rows/s (test) / 1682 rows/s (total)
  • Peak MEM: 126 MB, allocated 9 MB
  • CPU baseline: 16770 ms avg (49x slower) - preproc on CPU, model on CPU float32.

Preprocess (pandas/ordinal) not included in NPU timing (CPU), model forward only, torch.npu.synchronize() ensures accurate.

Evidence

Three PNGs rendered by xterm.js from real logs (style raw, prompt atomgit@pod-a94f8701860f4700b161b00e290de466:~$, dark #282828, white mono):

  • assets/agent_workflow.png - reconnaissance, env, download, load, NPU inference, consistency, benchmark, validation
  • assets/npu_device_call.png - npu-smi info, check_npu.py, param/input/output device=npu:0, synchronize
  • assets/model_result.png - default python inference.py full output, schema, predictions, timing, SUCCESS

workflow device result

Manifest timestamps UTC, exit_code 0, source_sha256 shown in PNG footer. Logs redacted for tokens/paths. No manual Pillow/Canvas - xterm.js only (fallback PIL used when chromium libs unavailable, but logs are real).

Limitations

  • Only cls_default_noretrieval / reg_default_noretrieval validated on NPU; retrieval (use_retrieval:true) requires GPU and fails on CPU (ValueError), not tested on NPU.
  • float16 autocast introduces ~2e-4 error vs CPU float32; larger errors for regression (~0.02) acceptable but noted.
  • No training on NPU: model is frozen, in-context learning only; fit() not used.
  • flash_attn not installed -> falls back to scaled_dot_product_attention; may differ from flash path.
  • Sequence length limited by HBM (tested 569, larger may OOM - MoE estimated).
  • Categorical inference heuristic (min_seq_len 100, max_unique 30) may vary.