模型定位:面向 3-5 量子比特离散-连续量子电路编译任务的多模态扩散模型,基于 genQC 训练框架构建,核心生成网络为 CirDiT(Circuit Diffusion Transformer)。
技术要点:
本仓库提供该模型在华为昇腾 Ascend910 NPU 上的完整适配方案,含服务化推理接口(FastAPI)与命令行推理脚本。
引用:Synthesis of discrete-continuous quantum circuits with multimodal diffusion models(arXiv:2506.01666)
| 类别 | 项目 | 规格 |
|---|---|---|
| 硬件 | 推理卡 | Ascend910 (64GB HBM) |
| 硬件 | NPU 驱动 | npu-smi 25.5.5 |
| 软件 | CANN | 8.5.1 |
| 软件 | Python | 3.11.14 |
| 软件 | PyTorch | 2.9.0+cpu |
| 软件 | torch_npu | 2.9.0.post1 |
| 软件 | vLLM-Ascend | 0.18.0 |
| 软件 | genQC | 0.2.5 |
| 软件 | open_clip_torch | 3.3.0 |
| 软件 | 服务框架 | FastAPI + uvicorn |
服务进程以 uvicorn 承载,模型权重加载完成后自动监听指定端口。
# 安装依赖
pip install -r requirements.txt
# 启动服务(默认 18080 端口,可传参替换)
python3 inference_server.py 18080启动时序:初始化调度器 → 加载 CirDiT 主模型 → 加载 CLIP 文本编码器 → 加载量子电路嵌入器 → 组装流水线 → 就绪(实测约 11-14s)。
| 方法 | 路径 | 说明 |
|---|---|---|
| GET | /health | 健康探测,返回运行设备 |
| GET | /model_info | 模型元信息(参数量/门池/设备) |
| POST | /infer | 电路编译推理 |
{
"prompt": "quantum circuit with hadamard and cnot",
"num_inference_steps": 10,
"guidance_scale": 5.0,
"num_samples": 1
}{
"status": "success",
"circuits": [
{
"sample_id": 0,
"output_shape": [1, 32, 16, 16],
"output_stats": {"mean": -128.75, "std": 1197.58, "min": -3732.80, "max": 4894.53}
}
],
"inference_time": 33.40,
"model_info": {"parameters_M": 186.14}
}# 健康检查
curl http://localhost:18080/health
# 元信息
curl http://localhost:18080/model_info
# 推理
curl -X POST http://localhost:18080/infer \
-H "Content-Type: application/json" \
-d '{"prompt": "quantum circuit", "num_inference_steps": 5, "guidance_scale": 3.0, "num_samples": 1}'
# 本地脚本
python3 inference.py --prompt "quantum circuit" --steps 5 --guidance 3.0单卡 Ascend910 实测:
| 步数 | 引导尺度 | 耗时(s) | 输出均值 | 输出标准差 |
|---|---|---|---|---|
| 3 | 2.0 | 33.29 | -38.41 | 787.18 |
| 5 | 3.0 | 33.40 | -128.75 | 1197.58 |
| 10 | 5.0 | 33.02 | -199.44 | 2014.76 |
资源占用:模型驻留显存 ~2070MB;推理时 NPU 功耗 166-183W,温度 45-48C;HBM 利用率约 16.7%。
HF_ENDPOINT=https://hf-mirror.com 以下载 CLIP 预训练权重。