模型名称: stable-ai/LimiX-16M(LimiX: Unleashing Structured-Data Modeling Capability for Generalist Intelligence) 模型链接: https://huggingface.co/stable-ai/LimiX-16M 模型描述: LimiX-16M 是 16M 参数表格基础模型(tabular foundation model),采用 "tokenize-and-route" 框架(RaBEL 分词 + readout-aligned routing 架构)。单模型统一支持分类/回归/缺失值填补/特征选择等任务。本部署演示表格分类:输入训练表格 X_train + 标签 y_train + 测试表格 X_test,输出每个测试样本的类别概率。 模型架构: Transformer(特征 X 与目标 Y 先嵌入为 token,attention 同时作用于样本维与特征维,检索式 readout-aligned routing) 参数规模: ~63MB(LimiX-16M.ckpt 66,177,586 字节,16M params) 适配引擎: torch_npu(昇腾 NPU 推理引擎)
| 依赖项 | 版本 | 说明 |
|---|---|---|
| torch | 2.9.0 | |
| torch_npu | 2.9.0.post1 | |
| kditransform | latest | RaBEL 分词(官方依赖) |
| scikit-learn | >= 1.2 | 数据集与指标 |
| fastapi / uvicorn / pydantic | - | 服务化推理(server.py) |
| einops / numpy / pandas | - | 官方依赖 |
注:本模型是 .ckpt 权重 + 官方 LimiX 代码仓库(
inference.predictor.LimiXPredictor),权重与 config 放/tmp/LimiX-16M,代码放/tmp/LimiX-repo(git clone gh-proxy 镜像)。
# 乳腺癌数据集分类(默认 npu:0)
python inference.py --device npu:0
# 随机表格数据
python inference.py --dataset random --device npu:0推理流程:LimiXPredictor(device=torch.device('npu:0'), model_path=ckpt, inference_config=config) → clf.predict(X_train, y_train, X_test, task_type='Classification') → 类别概率。
以下输出为在昇腾 Ascend 910(CANN 8.5.1 + torch_npu 2.9.0)上实测获得(乳腺癌数据集 569 样本 / 30 特征,train 284 / test 285)。
命令:
python inference.py --device npu:0
输出:
[INFO] 数据集: breast_cancer (569 样本, 30 特征) [INFO] 推理: train (284, 30), test (285, 30) ... [结果] prediction shape: (285, 2)(类别概率) [结果] 测试集前 5 样本预测: [['0.223', '0.777'], ['1.000', '0.000'], ['1.000', '0.000'], ['0.000', '1.000'], ['0.000', '1.000']] [结果] accuracy: 0.9825 roc_auc: 0.9990 [耗时] 3.227s(285 个测试样本)
结果说明: 285 个测试样本分类,accuracy 0.9825 / roc_auc 0.9990,3.227s 完成,验证了 LimiX-16M 在昇腾 NPU 上的表格分类推理链路通畅。

python server.py --port 8000 --device npu:0接口:
GET /health → {"status":"ok","model":"stable-ai/LimiX-16M","device":"npu:0","loaded":true}POST /infer(JSON:{"train_data":[[...]], "train_labels":[...], "test_data":[[...]]})→ {"prediction":[[...]], "n_test":..., "elapsed_s":...}实测(服务化):
POST /infer(8 训练样本 2 类 / 3 测试样本)→ {"prediction":[[0.998,0.002],[0.0043,0.9957],[0.3271,0.6729]],"n_test":3,"elapsed_s":2.611}/tmp/LimiX-16M/LimiX-16M.ckpt(63MB),代码位于 /tmp/LimiX-repo/(GitHub limix-ldm-ai/LimiX),避免占用有限的 /opt 空间,不纳入本仓库inference(无 __init__.py),本部署脚本自身名 inference.py 会抢占包名,需先把脚本目录移出 sys.path、强制从 /tmp/LimiX-repo 解析(inference.py 内已处理).to("cuda")、device="cuda"、is_cuda 判断、torch.cuda.* 调用,NPU 适配 3 层:
torch.Tensor.to——.to("cuda") 字符串参数替换为 npu(不改动官方源码)utils/data_utils.py cluster_test_data——is_cuda 判断改为 device.type != "cpu",device="cuda" factory 改 "cpu"(聚类/检索预处理走 CPU,主推理 NPU)inference_method.py——torch.device(f"cuda:{device}") → npu、torch.cuda.empty_cache() → torch.npu.empty_cache()、model.cuda(rank) → model.to(npu)(备份 .bak 保留原版)setup() 用 nccl 后端 + CUDA_VISIBLE_DEVICES,默认 inference_with_DDP=False 走单卡路径(无需 nccl);如需多卡需改 hccl 后端