小大模型算子生成能力边界探索实验

一、实验概述

评估 LLM 在 Triton-Ascend 算子生成上的能力边界,为智能选模提供数据支撑,并验证 FixAgent + 子进程隔离 + 智能选模带来的效率提升。

  • 实验框架: AKG Agent (L1 CodeChecker → L2 triton.compile → L3 NPU + Reference)
  • LLM FixAgent: deepseek-chat, prompt → parse_modifications → DiffApplier
  • 验证日期: 2026-05-12

二、硬件与软件环境

组件 规格
NPU Ascend 910B4 (Atlas 800 A2)
CANN 8.5.0
Triton-Ascend 3.2.0
Python 3.11

三、数据集

数据集 算子数 Reference 覆盖 参考实现
KernelBench (numpy) 66 100% (66/66) NumPy
KernelBench (mindspore) 100 100% (100/100) MindSpore + PyTorch fallback
合计 166 100%

复杂度分布:

复杂度 等级 算子数 典型算子
≤2.0 C1 (elementwise) 59 relu, sigmoid, tanh, add
2.0-3.0 C2 (reduction) 40 layernorm, softmax, pooling
3.0-4.0 C3 (matmul) 49 矩阵乘法
4.0+ C4 (complex/conv) 18 卷积、loss 函数

验证流程: L1 语法检查 → L2 编译检查 → L3 NPU 执行 + Reference 数值对比 (<1e-3)。

四、测试模型

配置 模型 参数量 API 成本 厂商
fast deepseek-chat ~200B $0.001/op DeepSeek
standard deepseek-reasoner ~200B $0.003/op DeepSeek
zhipu-5.1 glm-5.1 ~200B $0.001/op 智谱
qwen-7b qwen2.5-coder-7b 7B $0.0005/op 阿里
qwen-14b qwen2.5-coder-14b 14B $0.0008/op 阿里
qwen-32b qwen2.5-coder-32b 32B $0.0015/op 阿里

五、实验结果

5.1 Numpy 66

模型 L3 通过率 首次通过 Fix 次数
deepseek-reasoner 27/66 (41%) 22 81
glm-5.1 25/66 (38%) 23 108
deepseek-chat 24/66 (36%) 24 84
qwen2.5-coder-32b 22/66 (33%) 16 96
qwen2.5-coder-14b 18/66 (27%) 15 102
qwen2.5-coder-7b 15/66 (23%) 9 111

5.2 Mindspore 100

模型 L3 通过率 首次通过 Fix 次数
deepseek-reasoner 27/100 (27%) 24 145
deepseek-chat 25/100 (25%) 22 142
glm-5.1 23/100 (23%) 19 216
qwen2.5-coder-7b 20/100 (20%) 9 169
qwen2.5-coder-32b 19/100 (19%) 16 167
qwen2.5-coder-14b 17/100 (17%) 13 167

5.3 按复杂度 (numpy + mindspore 合并)

模型 C1 (59 ops) C2 (40 ops) C3 (49 ops) C4 (18 ops)
deepseek-chat 26/59 (44%) 1/40 (3%) 21/49 (43%) 1/18 (6%)
deepseek-reasoner 26/59 (44%) 4/40 (10%) 21/49 (43%) 3/18 (17%)
glm-5.1 24/59 (41%) 4/40 (10%) 13/49 (27%) 7/18 (39%)
qwen2.5-coder-7b 24/59 (41%) 2/40 (5%) 8/49 (16%) 1/18 (6%)
qwen2.5-coder-14b 25/59 (42%) 0/40 (0%) 7/49 (14%) 3/18 (17%)
qwen2.5-coder-32b 25/59 (42%) 1/40 (3%) 13/49 (27%) 2/18 (11%)

5.4 错误类型分布

错误类型 占比 说明
Triton-Ascend 编译错误 ~45% unsupported dtype, LLVM assertion, vector core exception
Reference 数值不匹配 ~30% 执行成功但 max_diff > 1e-3
运行时 NPU 错误 ~15% ACL stream synchronize failed
Model 初始化参数错误 ~10% LLM 生成的 init 缺少参数

六、智能选模 E2E 对比

6.1 对比策略

策略 规则 说明
A) deepseek-chat 全部算子用 deepseek-chat 实用质量基线
B) qwen-7b 全部算子用 qwen-7b 成本基线
C) 智能选模 model_selector per-complexity 查表 平衡通过率与成本

6.2 最终结果 (166 算子)

策略 通过率 推理时间 生成时间 总成本 成本/通过
deepseek-chat 46/166 (27.7%) 5460s 1020s $0.401 $0.0087
qwen-7b 32/166 (19.3%) 5195s 1787s $0.228 $0.0071
智能选模 51/166 (30.7%) 2412s 9508s $0.478 $0.0094

6.3 智能选模模型分布

模型 被选次数 占比 通过率
glm-5.1 ~120 75% 38%
deepseek-chat ~35 25% 54%

七、能力边界结论

7.1 当前能力

能力维度 边界 说明
elementwise 算子 20-25% relu/sigmoid/tanh,简单但 LLM 编码不稳定
matmul 算子 9-35% deepseek-reasoner 最强,qwen-7b 最弱
reduction 算子 0-10% 所有模型表现差,Triton-Ascend 后端限制
conv/complex 算子 0-39% glm-5.1 可用,多数模型失败
Python 语法 ~100% L1 CodeChecker 全部通过
FixAgent 修复提升 +4-10% 每模型 2-7 算子通过修复通过

7.2 主要瓶颈

  1. Triton-Ascend 后端限制 (~45% 错误):编译错误、LLVM assertion 无法通过 LLM 修复绕过
  2. 数值精度 (~30% 错误):NPU 执行成功但精度不达标(softmax、layernorm 等)
  3. 子进程稳定性: LLVM assertion 触发 core dump,必须子进程隔离

7.3 智能选模结论

  • 智能选模通过率 30.7% > 27.7%(+3pp,多过 5 个算子)
  • C4 复杂算子提升最显著:20% vs 3%(glm-5.1 在该场景明显优于其他模型)
  • 推理时间 2412s < 5460s(glm-5.1 NPU 推理快 2.3 倍)
  • 但生成时间慢 9x,总成本高 19%——当前模型组合下收益有限
  • 生产建议: C4 算子专用 glm-5.1,其余用 deepseek-chat