waylong/autogluon-mitra-classifier-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

autogluon/mitra-classifier — Ascend NPU 适配

NPU Ascend910 #NPU

模型简介

autogluon/mitra-classifier 是基于 12 层 Transformer (dim 512, 4 heads, 75.67M 参数) 的表格基础模型,通过纯合成数据与混合随机分类器预训练,支持上下文学习 (in-context learning) 范式的零样本分类。模型卡见 autogluon/mitra-classifier。

  • Hugging Face: autogluon/mitra-classifier
  • Revision: c425e9fa0910a6be1c494321792e7ba2a1367b1a
  • 权重: model.safetensors 288.7 MB, 参数量 75,670,026, FP32, Tab2D
  • 配置: config.json dim 512 dim_output 10 n_layers 12 n_heads 4 task CLASSIFICATION
  • 原生依赖: torch, torch_npu, einops, einx, safetensors, scikit-learn, 无 trust_remote_code

任务路由: 普通表格分类 — 输入 x_support [B, n_s=142, f=13] + y_support [B, n_s] + x_query [B, n_q=36, f=13] → 输出 logits [B, n_q, 10] (取前 3 列对应 Wine 的 3 类),经 softmax 得 probs 与 preds。

数据契约

  • 输入:
    • x_support [1, 142, 13] float32, 训练集 142 行 13 特征, 均值 68.55, 无缺失
    • y_support [1, 142] int64, 类别 0/1/2 (47/57/38)
    • x_query [1, 36, 13] float32, 测试集 36 行
    • padding masks 均为 False, 轴顺序 [B, S, F], 列顺序固定 13 列
    • 划分: train_test_split(test_size=0.2, random_state=42, stratify=y) 确定性
  • 输出:
    • logits [36, 10] finite, 样本 [0,:5]=[10.309,4.542,2.193,3.034,-0.454]
    • probs [36, 3] 样本 [0]=[0.9965,0.0031,0.00029]
    • preds accuracy 1.0 (36/36)
  • 预处理: 均值填充(无缺失) + 模型内部 Tab2DQuantileEmbeddingX 分位数归一化, 无外部 StandardScaler

环境

  • 硬件: Ascend 910B ×2 (npu:0 Ascend910_9362, npu-smi 25.5.5, CANN 8.5.1)
  • 驱动: torch.npu.is_available()==True, device_count=2, torch.npu.get_device_name(0)=Ascend910_9362
  • Python 3.11.14, torch 2.9.0+cpu, torch_npu 2.9.0.post1+gitee7ba04, numpy 1.26.4, scikit-learn 1.8.0

安装

pip install -r requirements.txt

NPU 推理

python inference.py

日志示例见 assets/model_result.png。

真实结果

  • logits [36,10] finite, accuracy 1.0, 首轮 0.452s, 次轮 0.028s

一致性

python /opt/atomgit/.opencode/skills/npu-adapt-skills/scripts/compare_outputs.py --cpu working/cpu_logits.npy --npu working/npu_logits.npy --task classification --atol 1e-2 --rtol 1e-2
  • max_abs_error 0.00581 mean 0.00129 argmax 1.0 passed true (atol 1e-2 rtol 1e-2)

性能

avg 0.0275s min 0.0270s max 0.0285s p50 0.0273s p90 0.0279s p95 0.0282s throughput 1310.6 rows/s compile 0.452s

证据图

  • assets/agent_workflow.png — 工作流
  • assets/npu_device_call.png — NPU 设备
  • assets/model_result.png — 推理结果

三图由 xterm.js 根据真实日志渲染。

限制

  • dim_output 10 但 Wine 仅 3 类需切片
  • 需同时提供 x_support/y_support