ohhoohho/cirdit_multimodal_compile_3to5qubit_v1.1
模型介绍
文件和版本
Pull Requests
讨论
分析

cirdit_multimodal_compile_3to5qubit_v1.1

昇腾 NPU 适配 | CirDiT 多模态扩散量子线路编译模型(3~5 qubit)

基于 genQC 的「离散-连续量子线路多模态扩散模型」(CirDiT, 150M)。 输入 35 qubit 目标酉矩阵 U, 经过多模态扩散采样输出对应的量子线路(离散门序列 + 连续参数)。

  • 模型形态:多模态扩散 (CirDiT + frozen OpenCLIP 文本编码器 + 旋转预设嵌入器)
  • 目标酉:3~5 qubit(num_of_qubits=5,min_gates=4,max_gates=32)
  • 门库:h cx ccx swap rx ry rz cp(含参数门)
  • 参考论文:Synthesis of discrete-continuous quantum circuits with multimodal diffusion models

环境

部署到昇腾 NPU(910 系列), 运行环境:

组件版本
PyTorch>= 2.5
torch_npu>= 2.9.0 (CANN 8.5.1)
genQC0.2.5
numpy/scipy见 requirements.txt

权重与模型位置

权重默认读取 ./model/ 目录(config.yaml + model.safetensors + embedder.safetensors + beta_schedule_learned_linear.safetensors)。 如缺失,inference.py 会自动从 HF 镜像(https://hf-mirror.com) 或 gitcode LFS batch 兜底下载。

python -c "from inference import ensure_weights; ensure_weights('./model')"

快速开始

1) 环境

pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/
export HF_ENDPOINT=https://hf-mirror.com

2) 命令行单次编译(NPU)

python inference.py --target qft --num-qubits 3 --samples 1 --device npu:0

3) 启动 HTTP 服务化推理(NPU)

python inference.py --serve --port 8000 --device npu:0

请求编译:

curl -X POST http://127.0.0.1:8000/compile \
     -H 'Content-Type: application/json' \
     -d '{"num_qubits":3,"target":"qft","samples":1}'

健康检查:

curl http://127.0.0.1:8000/health
# {"status":"ok","device":"npu:0"}

NPU 部署说明

  • 该模型为非 LLM 扩散模型, 使用 torch_npu 直接推理(非 vLLM-Ascend)。
  • genQC 管线通过 from_config_file(..., device=torch.device('npu:N')) 将全部权重加载/执行到昇腾 NPU。
  • frozen OpenCLIP 文本编码器(ViT-B-32, datacomp_xl_s13b_b90k) 首次运行需下载权重(约 600MB), 走 HF 镜像。
  • NPU 上单次采样(QFT 3-qubit, 20 步)约 0.7 s, 较 CPU 提升约 46x。

项目结构

cirdit_multimodal_compile_3to5qubit_v1.1/
├── inference.py        # 昇腾 NPU 推理脚本(CLI + HTTP 服务)
├── README.md           # 本文档
├── requirements.txt    # 依赖清单
├── model/              # 权重目录(配置 + 权重, 大权重不随仓库提交)
└── assets/             # 截图素材(agent_workflow / npu_device_call / model_result)