标签:#NPU #Ascend #Ascend910 #Tabular #Mitra #Classifier #FoundationModel
Mitra(Mixed synthetic priors for enhancing tabular foundation models, arXiv:2510.21204)是亚马逊科学团队提出的表格基础模型,在纯合成数据上预训练,通过 in-context learning(上下文学习) 范式完成表格分类/回归。其核心是 12 层 Transformer(约 72M 参数),输入为特征值嵌入(Tab2DEmbeddingX)+ 标签嵌入(Tab2DEmbeddingYClasses),行方向与列方向交替做注意力(attention across observations + attention across features)。
本仓库适配的是 autogluon/mitra-classifier 分类检查点,把 AutoGluon 内置的 MitraClassifier(sklearn 接口,Tab2D 架构)真实运行在单卡昇腾 NPU(npu:0)上:
load_wine,13 特征、3 类)| 项目 | 值 |
|---|---|
| 主机 | Atlas 800(昇腾 910B) |
| NPU | Ascend910_9362(单卡 npu:0) |
| torch / torch_npu | 2.9.0 / 2.9.0.post1 |
| Python | 3.11 |
| AutoGluon | 1.6.1 |
| 权重 | autogluon/mitra-classifier(model.safetensors 302MB, fp32) |
| revision | c425e9fa0910a6be1c494321792e7ba2a1367b1a |
| 项目 | 值 |
|---|---|
| 输入 | 二维表格 [n_rows, n_features=13],float32 |
| 特征列 | alcohol, malic_acid, ash, alcalinity_of_ash, magnesium, total_phenols, flavanoids, nonflavanoid_phenols, proanthocyanins, color_intensity, hue, od280_od315_of_diluted_wines, proline |
| 目标 | target ∈ {0, 1, 2}(类别编码按原数据保序) |
| 划分 | 官方示例 train_test_split(test_size=0.2, random_state=42, stratify=y) |
| 训练集 / 测试集 | 142 / 36 行 |
| 预处理 | Mitra 内置 Preprocessor(支持集/查询集标准化 + 量化嵌入);推理时特征缺失标记与列顺序保持不变 |
| 输出 | [n_query, 10] logits(取前 n_classes=3 做 softmax)→ [n_query, 3] 概率;预测标签为概率 argmax |
pip install -r requirements.txt依赖见 requirements.txt:torch、torch_npu、autogluon.tabular==1.6.1、einops、einx、loguru、omegaconf、transformers、huggingface_hub[torch]、safetensors、pandas、scikit-learn。
python inference.py脚本流程:检测 npu:0 → 通过 huggingface_hub.snapshot_download 获取权重(自动走 HF_ENDPOINT 镜像)→ 本地加载 MitraClassifier(fine_tune=False, device='npu', hf_model=<checkpoint>) → fit()(仅预处理 + 支持集前向,不做权重更新)→ predict_proba() 在 npu:0 上完成上下文学习推理 → 输出同步耗时、准确率与样例预测。
说明:
fit()仅拟合数据预处理并执行一次支持集前向评估(fine_tune=False时max_epochs=0),模型核心 forward 全部在npu:0上执行;第一个参数 device 为npu:0,无 CPU fallback。
使用 Wine 官方示例(36 行测试集):
| 指标 | 值 |
|---|---|
| 测试集准确率 (accuracy) | 0.9722(35/36;多次运行 1.0 ~ 0.9722,单行在 bf16 autocast 噪声内翻转) |
| 单次推理耗时(含预处理,同步后,首轮含编译) | ~162 ms |
| 稳定推理耗时(预热后) | ~42.6 ms |
| 吞吐 | ~845 rows/s(稳定阶段) |
| NPU 峰值显存 | ~527 MB |
样例预测(true / pred / prob):
row 0: true=0 pred=0 prob=0.9972
row 1: true=2 pred=2 prob=0.8347
row 2: true=0 pred=0 prob=0.9802
row 3: true=1 pred=1 prob=0.6154
row 4: true=1 pred=1 prob=0.9229
row 5: true=0 pred=0 prob=0.9944
row 6: true=0 pred=0 prob=0.9977
row 7: true=1 pred=1 prob=0.7053
row 8: true=1 pred=1 prob=0.9890
row 9: true=2 pred=2 prob=0.9927
...使用同一权重、同一输入切片、同一预处理、同一随机种子,在 CPU 与 npu:0 分别运行模型 forward(均强制 fp32):
| 指标 | 值 |
|---|---|
| 最大绝对误差 (logits) | 0.00483 |
| 平均绝对误差 (logits) | 0.00125 |
| argmax 一致率 | 1.0000(36/36) |
| softmax 概率最大绝对误差 | 0.00056 |
| 判定阈值 | atol=5e-3, rtol=1e-3(PASS) |
说明:端到端 MitraClassifier.predict_proba() 在 NPU 上由框架内建 torch.autocast(device_type='npu', dtype=bfloat16) 执行,CPU 侧为 fp32,故直接端到端概率最大绝对误差约 0.074(argmax 仍 100% 一致);在受控 fp32 forward 对比下误差降至 ~0.005,满足表格分类任务的一致性要求。
| 指标 | 值 |
|---|---|
| 预热 / 正式轮次 | 3 / 10 |
| avg / min / max | 42.60 / 41.84 / 43.66 ms |
| p50 / p90 / p95 | 42.77 / 42.91 / 43.29 ms |
| batch(单样本分块) | 1(batch_size=1, 36 行 query) |
| shape / dtype | [1, 142+36, 13] fp32 输入(量化嵌入后 bf16 autocast) |
| 吞吐 | 845.2 rows/s |
每轮前后均调用 torch.npu.synchronize()。首轮编译耗时已并入预热轮次,上表为稳定推理阶段。
三张图片均由 xterm.js 依据本次任务真实日志渲染生成(非原始桌面截图):
| 图片 | 内容 |
|---|---|
![]() | 侦察、数据检查、模型下载、NPU 推理、一致性、benchmark 与提交校验全流程日志 |
![]() | npu-smi info、NPU 可用性、设备名、模型参数 device/dtype、输入输出 Tensor device |
![]() | 默认 python inference.py 的真实完整输出:schema/窗口摘要、真实预测、同步耗时与状态 |
autogluon/mitra-regressor 为回归版本,未在本仓库适配。npu:0 验证。@article{zhang2025mitra,
title={Mitra: Mixed synthetic priors for enhancing tabular foundation models},
author={Zhang, Xiyuan and Maddix, Danielle C and Yin, Junming and Erickson, Nick and Ansari, Abdul Fatir and Han, Boran and Zhang, Shuai and Akoglu, Leman and Faloutsos, Christos and Mahoney, Michael W and others},
journal={arXiv preprint arXiv:2510.21204},
year={2025}
}