eardoi/mba-simplifier-npu
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

MBA Simplifier(昇腾 NPU 适配)

qox/mba-simplifier 是 MBA(Mixed Boolean-Arithmetic,混合布尔算术)表达式简化器, 用 Transformer 分类器(2.2M 参数,90 条重写规则)指导规则选择,简化混淆的 MBA 表达式(如 (x + x) + (y * 1) → x + (x + y))。

本项目完成其在**华为昇腾 NPU(Ascend 910B)**上的推理适配与验证。

模型规格

项目说明
网络RC Transformer(Embedding + TransformerEncoder + Linear head)
参数量2.2M(90 条重写规则)
输入MBA 表达式(字符序列,max_len 320)
输出重写规则 logits(top-k 建议规则)
权重格式safetensors(mba_classifier.safetensors,8.6MB)

推理

cd /workspace/mba-simplifier
python3 inference.py --model_path ./model_src \
    --expr "(x + x) + (y * 1)" --device npu:0

验证结果(Ascend 910B, npu:0)

输入 (x + x) + (y * 1) → 规则 logits top-5(comm_^ / comm_| / comm_+ ...), 与仓库 simplify() 输出的简化结果 x + (x + y) 一致,NPU 推理链路完整跑通。

适配说明

  • 纯 PyTorch Transformer,直接 .to(npu) 迁移即可。
  • 权重加载:safetensors.torch.load_file + load_state_dict。
  • 设备解析 resolve_device():NPU 可用性检测,失败自动回退 CPU。
  • 模型权重不推送到仓库:*.safetensors 已加入 .gitignore。

引用

  • 模型:https://huggingface.co/qox/mba-simplifier