模型名称: qox/mba-simplifier
模型链接: HuggingFace
模型描述: 简化 Mixed Boolean-Arithmetic (MBA) 表达式的神经符号系统。结合 BFS 查表、符号重写和可选的神经引导搜索,用于反混淆代码中的 MBA 表达式。
模型架构: 自定义 TransformerEncoder (MBA Rule Classifier, 2.2M params)
参数规模: 2,224,474 (2.2M)
输入规格:
(x & y) + (x | y))输出规格:
| 依赖项 | 版本要求 | 说明 |
|---|---|---|
| Python | >= 3.10 | 推荐 3.11(需 structural pattern matching) |
| torch | >= 2.1.0 | PyTorch 框架 |
| torch_npu | >= 2.1.0 | 昇腾 NPU 后端 |
| safetensors | >= 0.4.0 | 安全权重加载 |
| numpy | >= 1.21.0 | 数值计算 |
| 昇腾驱动 | CANN 8.0+ | 推荐 CANN 8.5.1 |
安装命令:
pip install torch>=2.1.0 torch-npu>=2.1.0 safetensors>=0.4.0 numpy>=1.21.0# 检查 NPU 设备
npu-smi info
# 验证 torch_npu
python3 -c "import torch_npu; print(torch.npu.device_count(), torch.npu.get_device_name(0))"方式一:HuggingFace(推荐)
git clone https://huggingface.co/qox/mba-simplifier
cd mba-simplifier方式二:AtomGit 镜像
git clone https://gitcode.com/gcw_coj3XaOd/qox_mba_simplifier
cd qox_mba_simplifier# 基础推理(BFS + 符号引擎,无需神经模型)
python inference.py "(x & y) + (x | y)"
# 启用神经引导推理(NPU 加速)
python inference.py --model-path mba_classifier.safetensors "complex_expression"
# 32-bit 模式
python inference.py --bits 32 "(x ^ y) + (x & y)"| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| expr (positional) | str | 必填 | MBA 表达式 |
| --bits | int | 8 | 位宽:8 或 32 |
| --model | str | None | 神经模型路径 |
| --model-path | str | None | --model 的别名 |
BFS: 18,189 entries (284ms)
Input: (x & y) + (x | y)
Simplified: x + y
Reduction: 57% (bfs)
Latency: 291.7 ms
[状态] SUCCESS=== 推理测试汇总 ===
(x & y) + (x | y) → x + y (bfs, 57% reduction)
(x | y) - (x & y) → x ^ y (bfs, 57% reduction)
x ^ x → 0 (bfs, 67% reduction)
~(~x) → x (bfs, 67% reduction)
(x + y) - 2*(x & y) → x ^ y (bfs, 67% reduction)
x & (x | y) → x (bfs, 80% reduction)
-(~x) - 1 → x (symbolic, 67% reduction)
x * 1 + y * 0 → x (bfs, 50% reduction)
总测试数: 8
成功简化: 8
简化率: 100%
平均延迟: ~292ms (cold), ~2ms (warm)输入: (x & y) + (x | y)
运行命令:
python inference.py "(x & y) + (x | y)"输出:
BFS: 18,189 entries (284ms)
Input: (x & y) + (x | y)
Simplified: x + y
Reduction: 57% (bfs)
Latency: 291.7 ms输入: (x | y) - (x & y)
运行命令:
python inference.py "(x | y) - (x & y)"输出:
BFS: 18,189 entries (285ms)
Input: (x | y) - (x & y)
Simplified: x ^ y
Reduction: 57% (bfs)
Latency: 293.4 ms输入: x ^ x
运行命令:
python inference.py "x ^ x"输出:
BFS: 18,189 entries (286ms)
Input: x ^ x
Simplified: 0
Reduction: 67% (bfs)
Latency: 291.5 ms输入: ~(~x)
运行命令:
python inference.py "~(~x)"输出:
BFS: 18,189 entries (285ms)
Input: ~(~x)
Simplified: x
Reduction: 67% (bfs)
Latency: 288.8 ms


测试数据: MBA-Blast 论文数据集(62 个 8-bit 2-var 表达式)
评测指标:
| 指标 | 结果 | 说明 |
|---|---|---|
| 正确率 | 100% | Oracle 验证(512 点随机采样) |
| 简化率 | 100% | 所有表达式均可简化 |
| 平均缩减 | 77% | AST 树大小缩减 |
| 延迟 | 6.5ms | 平均每表达式 |
评测命令:
python inference.py "(x & y) + (x | y)"
python inference.py "(x | y) - (x & y)"
python inference.py "x ^ x"
python inference.py "~(~x)"
python inference.py "(x + y) - 2*(x & y)"
python inference.py "x & (x | y)"
python inference.py "-(~x) - 1"
python inference.py "x * 1 + y * 0"