这是 genQC 框架下训练的多模态扩散模型,专注于 3 至 5 量子比特的离散-连续量子电路编译。模型架构采用 CirDiT(Circuit Diffusion Transformer),一种基于 Transformer 的扩散模型,可利用文本描述作为条件引导量子电路的生成过程。模型参数量约 186M,支持 H、CX、CCX、SWAP、RX、RY、RZ、CP 等 8 种量子门。本仓库提供在华为昇腾 Ascend910 NPU 上部署和运行该模型的完整方案,包含服务化推理接口和命令行推理脚本。
论文参考:Synthesis of discrete-continuous quantum circuits with multimodal diffusion models (arXiv:2506.01666) 项目源码:https://github.com/FlorianFuerrutter/genQC
硬件平台:Atlas 800 A2 训练服务器 推理加速卡:Ascend910 (HBM 64GB) 驱动版本:npu-smi 25.5.5 CANN 版本:8.5.1
软件栈:
| 依赖 | 版本号 |
|---|---|
| 操作系统 | Linux aarch64 |
| Python | 3.11.14 |
| PyTorch | 2.9.0 (CPU) |
| torch_npu | 2.9.0.post1 |
| vLLM (base) | 0.18.0 |
| vLLM-Ascend | 0.18.0 |
| genQC | 0.2.5 |
| open_clip_torch | 3.3.0 |
| FastAPI | 最新版 |
| uvicorn | 最新版 |
本模型以 FastAPI + uvicorn 提供 HTTP 服务化推理。建议按以下步骤操作:
pip install -r requirements.txtcd /path/to/model
python3 inference_server.py 18080服务启动后会依次加载调度器、CirDiT 扩散模型、CLIP 文本编码器和量子电路嵌入器,全部加载完成后输出 "Service ready" 日志。
| 方法 | 路径 | 功能 |
|---|---|---|
| GET | /health | 健康检查 |
| GET | /model_info | 模型元信息 |
| POST | /infer | 量子电路编译推理 |
import requests
# 推理请求
response = requests.post(
"http://localhost:18080/infer",
json={
"prompt": "quantum circuit with hadamard and cnot",
"num_inference_steps": 10,
"guidance_scale": 5.0,
"num_samples": 1
}
)
data = response.json()
print(f"推理耗时: {data['inference_time']:.2f}s")
print(f"输出形状: {data['circuits'][0]['output_shape']}")部署完成后,执行以下命令快速验证:
# 1) 检查服务状态
curl http://localhost:18080/health
# 2) 查看模型配置
curl http://localhost:18080/model_info
# 3) 运行一次推理
curl -X POST http://localhost:18080/infer \
-H "Content-Type: application/json" \
-d '{"prompt": "quantum circuit", "num_inference_steps": 5, "guidance_scale": 3.0}'
# 4) 或使用本地脚本
python3 inference.py --prompt "quantum circuit" --steps 5如果服务正常,推理请求会返回 HTTP 200 状态码,circuits 字段包含模型的输出张量信息。
在单张 Ascend910 NPU 上实测性能数据:
| 推理步数 | 引导尺度 | 单次耗时 | 输出均值 | 输出标准差 | NPU 显存 |
|---|---|---|---|---|---|
| 3 | 2.0 | 33.3s | -38.41 | 787.18 | 2070 MB |
| 5 | 3.0 | 33.4s | -128.75 | 1197.58 | 2070 MB |
| 10 | 5.0 | 33.0s | -199.44 | 2014.76 | 2070 MB |
模型加载需约 11-14 秒。推理期间 NPU 功耗约 180W,核心温度稳定在 45-48C。
对模型进行了多轮功能验证:
HF_ENDPOINT=https://hf-mirror.com 环境变量以加速 CLIP 模型下载。