昇腾 NPU 适配版 LimiX-2M:一个 2M 参数的表格数据(tabular)基础模型,支持分类、回归与缺失值预测,无需微调、无需训练,直接通过 in-context learning 完成推理。
LimiX 是一类面向结构化数据的通用表格智能模型,旨在克服低秩塌缩与注意力瓶颈两大难题。LimiX-2M 仅 2M 参数即可在分类、回归、缺失值插补等任务上超越 XGBoost、CatBoost、AutoGluon 与 TabPFN。
关键特性
模型架构:12 层 transformer,采用 axis-wise attention(分别对特征轴与样本轴做注意力),并基于 RaBEL 框架把每个标量展开为紧凑的局部 RBF 特征,改善浅层有效秩。预训练方式为 Context-Conditional Masked Modeling(CCMM)。
官方推理代码面向 CUDA,本仓库完成以下昇腾 NPU 适配(已随 limix/ vendored 源码一并交付):
| 问题 | 官方代码 | 本仓库修复 |
|---|---|---|
| 设备硬编码 | torch.tensor(..., device="cuda")、.to("cuda") | 检索(top-k)索引改在调用处透传实际 device,并统一归一化到 CPU 计算 |
| CUDA 专属 API | torch.cuda.empty_cache() / torch.cuda.manual_seed_all() / torch.cuda.set_device() | 改为安全封装:无 CUDA 构建自动降级(NPU 下使用 torch.npu.empty_cache()) |
| 注意力分数计算 | attention_score.to("cuda") | 去掉强制搬移,随张量所在设备计算 |
| 设备选择 | demo 固定 torch.device('cuda') | inference.py 自动选择 npu:0 → cuda:0 → cpu |
说明:本机 torch 为 CPU 编译版(未编译 CUDA),经上述适配后模型在 Ascend 910 (Ascend910_9362) 上推理通过。
LimiX-2M-npu/
├── inference.py # 推理脚本(必选)
├── readme.md # 部署说明文档(必选)
├── requirements.txt # 环境依赖清单(推荐)
├── LimiX-2M.ckpt # 模型权重(14MB)
├── config.json # HF 元信息
├── limix/ # vendored 官方源码(已做 NPU 适配)
│ ├── model/ # transformer / layer / encoders
│ ├── inference/ # predictor / preprocess / inference_method
│ ├── utils/ # loading / data_utils / inference_utils / retrieval_utils
│ └── config/ # 官方推理配置(cls/reg × retrieval/noretrieval)
└── assets/
├── agent_workflow.png
├── npu_device_call.png
└── model_result.png# 1. 创建 Python 3.10+ 环境(昇腾 NPU 需安装 torch_npu 并配置 CANN)
pip install -r requirements.txt -i https://repo.huaweicloud.com/repository/pypi/simple
# 2. 权重文件
# 已随仓库交付:LimiX-2M.ckpt(14MB)
# 也可从镜像自动下载:inference.py 会在权重缺失时从 hf-mirror 自动拉取# 默认用例:内置乳腺癌二分类演示数据(无需任何外部文件)
python inference.py
# 自定义表格数据(训练 CSV 含特征 + 标签列,测试 CSV 仅特征)
python inference.py \
--train-csv train.csv --label-column target --test-csv test.csv \
--task-type Classification --output preds.csv
# 回归任务
python inference.py --task-type Regression --output preds.csv
# 指定权重 / 设备
python inference.py --weights ./LimiX-2M.ckpt --device npu:0输出:分类任务为每类概率矩阵(列 = 类别),回归任务为连续预测值,写入 --output(默认 predictions.csv)。
accuracy = 0.9766,roc_auc = 0.9981,输出概率矩阵 (171, 2) 全部有限@article{zhang2025limix,
title={Limix: Unleashing structured-data modeling capability for generalist intelligence},
author={Zhang, Xingxuan and Ren, Gang and Yu, Han and Yuan, Hao and Wang, Hui and Li, Jiansheng and Wu, Jiayun and Mo, Lang and Mao, Li and Hao, Mingchao and others},
journal={arXiv preprint arXiv:2509.03505},
year={2025}
}
@article{limix2m2026,
title={LimiX-2M: Mitigating Low-Rank Collapse and Attention Bottlenecks in Tabular Foundation Models},
author={Zhang, Xingxuan and others},
journal={arXiv preprint arXiv:2606.04485},
year={2026}
}