1
gcw_xUvjaUyi/cirdit-multimodal-compile-3to5qubit-v1.1-npu
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

cirdit-multimodal-compile-3to5qubit-v1.1-npu

Floki00/cirdit_multimodal_compile_3to5qubit_v1.1 — 面向 3-5 qubit 量子线路编译的多模态扩散模型,昇腾 Ascend NPU 推理适配。

  • 原模型:HuggingFace Floki00/cirdit_multimodal_compile_3to5qubit_v1.1
  • 论文:Synthesis of discrete-continuous quantum circuits with multimodal diffusion models (arXiv:2506.01666)
  • 架构:genQC MultimodalDiffusionPipeline_ParametrizedCompilation
    • 主模型:UnitaryCLIPPartialNoiseCompilationCirDiT(扩散 Transformer,DDIM,v-type 预测,~150M 参数)
    • 文本编码器:CachedFrozenOpenCLIPEmbedder(OpenCLIP ViT-B-32 / datacomp_xl_s13b_b90k)
    • 门嵌入器:RotationalMultimodialPresetEmbedderTiny
  • 门集合:h, cx, ccx, swap, rx, ry, rz, cp,线路最多 32 门

昇腾 NPU 适配说明

  • 固定使用 npu:0(Ascend 910),全文件不含任何 GPU 专用设备调用。
  • 入口处 try-except 捕获 NPU 初始化异常(torch_npu 导入失败或 npu:0 不可用),打印清晰错误并优雅退出。
  • 权重缓存路径固定为 ./model_weights/Floki00__cirdit_multimodal_compile_3to5qubit_v1.1;启动时优先加载本地缓存,未命中才从 hf-mirror.com 下载。
  • 生成日志落在 ./logs/ascend/(Ascend 运行日志)。
  • 若 NPU 上个别算子不支持,可按需回退 greedy / float32(本工程默认 float32)。

双模式

1) CLI 单次推理

python3 inference.py --text "compile a 3-qubit circuit that implements the quantum Fourier transform"

可选参数:

参数说明默认
--text文本提示词(必填),描述要编译的线路-
--qubitsqubit 数 3-5,自动从文本解析,解析不到取 33
--stepsDDIM 去噪步数50
--guidanceCFG 引导尺度3.0
--seed随机种子-

输出 JSON 包含 compiled_circuit(指令列表)与 qasm 字符串。

2) FastAPI 服务

uvicorn inference:app --host 0.0.0.0 --port 8101

POST /predict:

curl -X POST http://127.0.0.1:8101/predict \
  -H 'Content-Type: application/json' \
  -d '{"text":"compile a 4-qubit circuit that implements the quantum Fourier transform"}'

请求体:{"text": "...", "qubits": 3, "steps": 50, "guidance": 3.0, "seed": 1}(后四者可省略)。

安装

pip install -r requirements.txt
pip install genQC==0.2.5

依赖:torch / torch_npu(Ascend 环境)、transformers、open_clip_torch、omegaconf、matplotlib、safetensors、einops、numpy、fastapi、uvicorn。

目录

inference.py                         # 双模式推理入口 (CLI + FastAPI)
download_weights.py                  # 权重下载工具 (hf-mirror, 断点续传)
model_weights/Floki00__cirdit_.../   # 权重本地缓存 (git 忽略)
assets/                              # 运行截图
logs/                                # 运行日志 (git 忽略)