eardoi/cirdit-multimodal-compile-3to5qubit-npu
模型介绍
文件和版本
Pull Requests
讨论
分析

cirdit_multimodal_compile_3to5qubit 昇腾 NPU 适配

CirDiT(cirdit_multimodal_compile_3to5qubit_v1.1) 是一个基于多模态扩散模型的量子电路编译模型(genQC):将目标酉矩阵编译为 3–5 个量子比特的离散-连续量子电路(≤32 门),采用 UnitaryCLIPPartialNoiseCompilationCirDiT 架构。

模型规格

项目取值
模型Floki00/cirdit_multimodal_compile_3to5qubit_v1.1
架构UnitaryCLIPPartialNoiseCompilationCirDiT(packing 6 + core 12 层 Transformer)
参数量约 186.1M(float32,safetensors 731MB)
输入电路潜在表示 x[1,3,32,16] + 时间步 + 文本嵌入 c_emb[1,37,512] + 目标酉矩阵 U[1,2,8,8]
输出[1,3,32,16] 电路张量编码(速度场)
支持3–5 个量子比特,≤32 门
许可证Apache-2.0
精度float32

环境要求

  • 硬件:Ascend 910B 系列(≥1 张)
  • CANN ≥ 8.0(source /usr/local/Ascend/ascend-toolkit/set_env.sh)
  • Python 3.10 – 3.11
  • torch 2.9.0 / torch_npu 2.9.0.post1
  • genQC、open_clip_torch

环境准备

export PIP_INDEX_URL=https://repo.huaweicloud.com/repository/pypi/simple/
pip install torch torch_npu genQC open_clip_torch

模型权重

模型权重(model.safetensors 731MB + embedder.safetensors + config.yaml + beta_schedule)可从 Hugging Face 获取:

export HF_ENDPOINT=https://hf-mirror.com
huggingface-cli download Floki00/cirdit_multimodal_compile_3to5qubit_v1.1 --local-dir model_src

推理

python3 inference.py --device npu:0

可选参数:--qubits 3(3-5)、--seed 0

输出示例:

[info] pipeline loaded (13.75s), CirDiT params=186.1M device=npu:0
[info] input: x(1, 3, 32, 16) t_h=500 t_w=500 c_emb(1, 37, 512) U(1, 2, 8, 8)
[info] Inference complete (569.5 ms)
[result] out shape (1, 3, 32, 16) finite=True mean=0.0222 std=0.9101
[info] device proof: model on npu:0

验证结果

  • 设备:Ascend 910B(npu:0)
  • 推理:✅ 通过(186.1M 参数均已真实加载,全部计算均在 npu:0 上执行)
  • CPU-NPU 一致性:✅ cosine=1.000000(>0.999),L2 相对误差 0.000013(<1%)
  • 性能:NPU 耗时 569.5ms(含编译)
  • 验证日期:2026-08-22

适配说明

  • 模型通过 genQC 的 MultimodalDiffusionPipeline_ParametrizedCompilation.from_config_file 加载, 核心 CirDiT 模型直接通过 .to("npu:0") 迁移。
  • 完整扩散采样(generate_compilation_tensors)在 CPU 上执行上千步速度较慢,本适配聚焦单步 denoising 前向(velocity 场预测)作为 NPU 运行验证,与社区参考方案保持一致。
  • 文本编码器采用 OpenCLIP(laion/CLIP-ViT-B-32-DataComp.XL-s13B-b90K),需通过 hf-mirror 预先下载权重。

目录结构

├── inference.py       # NPU 推理脚本
├── weights/           # 模型权重 + config(不推送)
├── README.md          # 本模型卡片
└── assets/            # 截图素材

引用

@article{fuerrutter2025genqc,
  title={Synthesis of discrete-continuous quantum circuits with multimodal diffusion models},
  author={Fuerrutter, Florian and others},
  journal={arXiv:2506.01666},
  year={2025}
}