LimiX-16M 是由 stable-ai 发布的表格基础模型(Tabular Foundation Model),参数量 16.5M,采用 FeaturesTransformer 架构,支持分类与回归两类任务。该模型的核心创新在于双维注意力机制——在特征维度与样本维度上分别施加注意力计算,从而捕捉表格数据中复杂的跨特征与跨样本依赖关系。
模型架构细节:
本仓库提供在华为昇腾 Ascend910 NPU 上的完整推理部署方案,包含服务化代码、配置文件与使用说明。
| 组件 | 版本 |
|---|---|
| NPU 硬件 | Ascend910 (HBM 64GB) |
| 操作系统 | Linux (aarch64) |
| Python | 3.11.14 |
| PyTorch | 2.9.0 (CPU) |
| torch_npu | 2.9.0.post1 |
| CANN | 8.5.1 |
| NPU 驱动 | 25.5.5 |
| scikit-learn | 1.8.0 |
| FastAPI | 0.123.10 |
| uvicorn | 0.46.0 |
pip install torch numpy pandas scikit-learn fastapi uvicorn pydantic
pip install torch_npu # 根据 NPU 驱动版本安装对应版本从 HuggingFace 或 GitCode 镜像下载模型权重文件 LimiX-16M.ckpt(约 66MB),放置于模型目录中。
# 设置 NPU 设备可见性(单卡场景)
export ASCEND_RT_VISIBLE_DEVICES=0
export LIMIX_CKPT=/path/to/LimiX-16M.ckpt
# 启动推理服务
python3 inference.py --port 8060 --device npu服务启动后将在指定端口监听 HTTP 请求,支持 /healthz、/v1/models 和 /v1/predict 三个端点。
curl http://127.0.0.1:8060/healthz
# 预期响应: {"status":"ok","model":"stable-ai/LimiX-16M","device":"npu"}以下命令使用一个简单的二分类示例对服务进行快速验证:
curl -s http://127.0.0.1:8060/v1/predict \
-H "Content-Type: application/json" \
-d '{
"x_train": [[1.799, 0.184], [0.916, 0.145], [2.139, 0.212]],
"y_train": [0, 1, 0],
"x_test": [[1.512, 0.153]],
"task": "classification"
}'预期输出包含分类概率、预测类别和推理延迟,如:
{"task":"classification","n_classes":2,"classes":[0,1],
"probabilities":[[0.428,0.572]],"predicted_class_idx":[1],
"predicted_class":[1],"n_train":3,"n_test":1,"latency_s":1.41}在 Ascend910 NPU 单卡环境下的实测推理性能:
| 任务类型 | 样本数 | 推理延迟 | AICore 峰值 |
|---|---|---|---|
| 分类(双类) | 5 train + 2 test | ~1.41s | 约 0% |
| 分类(完整数据集) | 284 train + 285 test | ~1.84s | 约 0% |
| 回归 | 5 train + 2 test | ~1.5s | 约 0% |
性能说明:
使用 sklearn 的 breast_cancer 数据集(30 特征,569 样本,二分类)进行精度验证:
| 指标 | NPU 结果 |
|---|---|
| ROC AUC | 0.99896 |
| Accuracy | 0.98246 |
| 最大概率偏差 | 0.00222 |
| 推理加速比 | 28x (vs CPU) |
NPU 与 CPU 推理结果的预测一致性(prediction_agreement)达到 1.0,说明在 bf16 混合精度下无损精度。
.ckpt 文件内部的 config 字段中,需通过 torch.load() 读取。torch.cuda.manual_seed_all 等 CUDA 特定调用,已在部署版本中适配为设备感知的种子初始化。mix_precision=False 关闭。