g
gcw_coj3XaOd/stable-ai_LimiX-2M
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

LimiX-2M - 昇腾 NPU 推理部署

1. 模型简介

模型名称: LimiX-2M

模型链接: HuggingFace

模型描述: LimiX-2M 是一个 2M 参数的表格基础模型(Tabular Foundation Model),基于 RaBEL 框架,支持小样本学习(In-Context Learning)于结构化/表格数据。模型采用 Transformer 架构,通过特征分组和检索增强实现分类与回归任务。

模型架构: FeaturesTransformer (12-layer Transformer with feature-wise & sequence-wise attention)

参数规模: ~2M 参数

输入规格:

  • X_train: [n_train_samples, n_features] numpy array,训练特征
  • y_train: [n_train_samples] numpy array,训练标签
  • X_test: [n_test_samples, n_features] numpy array,测试特征

输出规格:

  • 分类任务:[n_test_samples, n_classes] 概率矩阵
  • 回归任务:[n_test_samples, 1] 预测值

2. 环境依赖

依赖项版本要求说明
Python>= 3.10推荐 3.11
torch>= 2.0.0PyTorch 框架
torch_npu>= 2.0.0昇腾 NPU 后端
scikit-learn>= 1.2.0数据加载与评估
kditransform>= 0.1.0特征离散化变换
einops>= 0.6.0张量操作
pandas>= 1.5.0数据处理
scipy>= 1.9.0科学计算
xgboost>= 1.7.0可选,基线对比
numpy>= 1.23.0数组操作
昇腾驱动CANN 8.0+推荐 CANN 8.5.1

安装命令:

pip install torch torch-npu scikit-learn kditransform einops pandas scipy xgboost numpy

3. 推理步骤

3.1 环境准备

# 检查 NPU 设备
npu-smi info

# 验证 torch_npu
python3 -c "import torch_npu; print(torch.npu.device_count(), torch.npu.get_device_name(0))"

3.2 模型下载

方式一:HuggingFace(推荐)

huggingface-cli download stable-ai/LimiX-2M --local-dir ./LimiX-2M

方式二:AtomGit 镜像(HuggingFace 下载慢时使用)

 huggingface-cli download --repo-type model https://ai.gitcode.com/hf_mirrors/stable-ai/LimiX-2M --local-dir ./LimiX-2M

3.3 运行推理

cd deliverables
python3 inference.py --model-path ../weights/LimiX-2M.ckpt

3.4 推理参数说明

参数类型默认值说明
--model-pathstr必填模型 checkpoint 路径(.ckpt 文件)
--deviceint0NPU 设备索引
--mix-precisionflagTrue使用混合精度推理

4. 推理成功日志

4.1 推理日志

[设备] Ascend910_9362 (npu:0)
[信息] 加载模型: /path/to/LimiX-2M.ckpt
[信息] 模型加载成功
[信息] 训练集: (455, 30), 测试集: (114, 30)
[信息] 开始推理...
[结果] 准确率(Accuracy): 0.9649
[结果] AUC: 0.9961
[结果] 预测样本数: 114
[结果] 正类预测数: 71
[状态] SUCCESS

5. 测试样例及输出结果

样例 1:乳腺癌分类(Breast Cancer Classification)

运行命令:

cd deliverables
python3 inference.py --model-path ../weights/LimiX-2M.ckpt

输出:

[设备] Ascend910_9362 (npu:0)
[信息] 加载模型: /tmp/adapt_stable-ai_limix-2m/weights/LimiX-2M.ckpt
[信息] 模型加载成功
[信息] 训练集: (455, 30), 测试集: (114, 30)
[信息] 开始推理...
[结果] 准确率(Accuracy): 0.9649
[结果] AUC: 0.9961
[结果] 预测样本数: 114
[结果] 正类预测数: 71
[状态] SUCCESS

6. Agent适配截图

6.1 Agent 完整适配工作流

Agent 适配流程

6.2 NPU 设备调用日志

NPU 设备调用

6.3 模型适配结果

模型适配结果


7. 精度评测

测试数据: Breast Cancer Wisconsin Dataset (569 samples, 30 features)

评测指标:

指标结果说明
Accuracy0.9649测试集 114 样本
AUC0.9961二分类 ROC-AUC

评测命令:

cd deliverables
python3 inference.py --model-path ../weights/LimiX-2M.ckpt

实际输出:

[结果] 准确率(Accuracy): 0.9649
[结果] AUC: 0.9961
[状态] SUCCESS

8. NPU 配置说明

  • NPU 型号: Ascend910_9362
  • NPU 卡数: 2 卡(单卡推理)
  • CANN 版本: 8.5.1
  • torch_npu 版本: 2.9.0.post1

9. 已知问题

  1. 模型配置中 feature_positional_embedding_type 设置为 none,不添加额外位置编码
  2. 检索增强(retrieval)默认使用聚类采样,cluster_num=47
  3. 输入特征数需为 features_per_group(默认2)的整数倍,不足时自动填充零