原始 Mitra 为 AutoGluon 零样本表格分类模型,通过 support/query 上下文推理预测新样本类别。本仓库将核心 Tab2D 模型迁移至单卡 Ascend 910 NPU (npu:0) 并提供可复现的 NPU 推理入口。
x_support [batch, n_support, n_features] float32y_support [batch, n_support] int64 (0-9)x_query [batch, n_query, n_features] float32padding_features [batch, n_features] boolpadding_obs_support [batch, n_support] boolpadding_obs_query__ [batch, n_query] boolpip install -r requirements.txt
# 模型权重需预先下载到本地 (正式推理不联网)
huggingface-cli download autogluon/mitra-classifier --local-dir /tmp/mitra_test
# 或使用 snapshot_downloadpython inference.py默认自动探测 torch_npu.is_available(),优先使用 npu:0,否则回退 CPU。核心模型参数与输入 Tensor 均显式迁移至 npu:0,计时前后调用 torch.npu.synchronize()。
可选: 远程权重 URL 直接加载 (需联网)
python inference.py --model-dir /path/to/mitra-classifier在 Ascend910 npu:0 上的真实运行输出 (logs/inference.log):
=== Mitra Classifier NPU Inference ===
Model: autogluon/mitra-classifier
Task: tabular-classification (12-layer Transformer, dim 512, heads 4, classes 10)
Model dir: /tmp/mitra_test
NPU available: Ascend910_9362, count 2
Loading model to npu:0...
Model param device: npu:0, dtype: torch.float32
Input: x_support torch.Size([1, 200, 8]), y_support torch.Size([1, 200]), x_query torch.Size([1, 50, 8]), device npu:0
NPU infer time (with sync): 0.2313s
NPU second run: 0.0241s
NPU benchmark 10 runs: avg 0.0227s min 0.0223 max 0.0239 p50 0.0224 rows/s 2197.8
Logits shape: torch.Size([1, 50, 10]), sample logits[0,0]: [0.94370145 0.94276094 1.4811145 0.9815529 1.2760398 ]
Probs sample [0,0]: [0.06950253 0.06943719 0.11895867 0.07218371 0.09690212 0.0811564 0.06838027 0.05455545 0.2929723 0.07595136]
Preds sample: [8 6 3 2 6 8 2 8 3 3]
Pred distribution: [ 1 3 13 7 2 3 6 2 9 4]
STATUS: NPU inference SUCCESS, real NPU kernel executed完整预测为 1×50×10 logits,softmax 后 argmax 得到 50 个 query 标签。
同一权重、输入、预处理、seed、float32 对比 (scripts/compare_outputs.py):
单样本 smoke consistency,非完整数据集精度评测。已保存 working_mitra/cpu_logits.npy 与 npu_logits.npy 可复现比较:
python .opencode/skills/npu-adapt-skills/scripts/compare_outputs.py --cpu working_mitra/cpu_logits.npy --npu working_mitra/npu_logits.npy --task classification --atol 1e-3 --rtol 1e-3NPU 同步计时 (torch.npu.synchronize()):
预热 3 次,正式测试 10 次,复跑验证动态 shape 编译后稳定。
三张 PNG 由 xterm.js 根据本次真实日志生成 (scripts/render_xterm_evidence.mjs --style raw):
assets/agent_workflow.png - 侦察、环境、下载、加载、NPU 推理、一致性、benchmark、校验全流程 (logs/workflow.log)assets/npu_device_call.png - npu-smi 与模型参数 device/dtype/input device 证明 (logs/device.log)assets/model_result.png - 默认 python inference.py 完整输出与同步耗时 (logs/inference.log)提示符固定为 atomgit@pod-a94f8701860f4700b161b00e290de466:~$ 仅为展示标签。

fit() 仍在 CPU;不支持声称 NPU 训练遵循原模型许可 (AutoGluon Mitra Classifier),权重未包含在本仓库。