Model: Floki00/cirdit_multimodal_compile_3to5qubit_v1.1
Pinned revision: bd2c968349d0915580b5acbaf970d2fc446d2503
Task: multimodal-quantum-circuit-compilation
Framework: pytorch · Engine: torch_npu 2.9.0 · Hardware: Ascend 910B4-1 (physical npu:5, 64 GB HBM, CANN 8.5.1)
This repository adapts the pinned genQC CirDiT model for complete, real Ascend
NPU inference on physical npu:5. It loads all applicable complete real
weights (no random / partial / dummy / config-only / CPU-fallback substitutes),
runs the full diffusion denoising trajectory on the NPU, decodes the sampled
tensor encodings into quantum circuits and reports the compiled-circuit quality
(unitary infidelity) against a redistributable 4-qubit QFT test unitary.
Paper: “Synthesis of discrete-continuous quantum circuits with multimodal diffusion models” · Project page: https://florianfuerrutter.github.io/genQC/
本仓库将钉住的本地模型 Floki00/cirdit_multimodal_compile_3to5qubit_v1.1
(源修订 bd2c968349d0915580b5acbaf970d2fc446d2503,Apache-2.0 许可证)适配到
昇腾 910B4-1 物理卡 npu:5 上执行完整真实的 NPU 推理。
gate_pool = ['h', 'cx', 'ccx', 'swap', 'rx', 'ry', 'rz', 'cp']DPMScheduler,40 步),联合 CFG 引导CachedFrozenOpenCLIPEmbedder(ViT-B-32 / datacomp_xl_s13b_b90k)| 文件 | 字节数 (bytes) | SHA256 |
|---|---|---|
model.safetensors | 765,519,544 | 9fe6326a260eee854e71d02075f89a2d9e79c10be2d77e9fea4cd27a856ffef9 |
embedder.safetensors | 1,308 | 071b1f29feeac8eaaa62e3ca17946c2a40bf8ea08de8237f3d74286c5672057a |
beta_schedule_learned_linear.safetensors | 4,072 | 128fc8d486718ba92a84d072a95b4130a052ff14e89843249ac2a3c25bcf5936 |
OpenCLIP 文本塔外部依赖(自包含缓存于本目录 .cache/huggingface):
| 文件 | 字节数 (bytes) | SHA256 |
|---|---|---|
open_clip_model.safetensors (laion/CLIP-ViT-B-32-DataComp.XL-s13B-b90K) | 605,143,284 | 3c00043509d2e3f35ec62bd85a643a393883dcda624d8208d034cc390c708297 |
inference.py 启动时会校验以上四个文件,并做输入/模型/输出的 npu:5 放置断言。
| 组件 | 版本 |
|---|---|
| Python | 3.11.14 |
| torch | 2.9.0+cpu(保持原样,禁止替换) |
| torch_npu | 2.9.0(保持原样,禁止替换) |
| CANN / Ascend Toolkit | 8.5.1 |
| numpy | 1.26.4 |
| genQC | 0.2.5 |
| open_clip | 3.3.0 |
| qiskit | 2.5.2 |
| safetensors | 0.8.0 |
| npu-smi | 25.5.1 |
| 物理设备 | Ascend 910B4-1, npu:5, 64 GB HBM |
注意:本容器内的 numpy 1.26.4 自定义构建会拒绝
copy=None(qiskit 2.x 的__array__会用到)。inference.py在导入时安装了一个极小的numpy.array垫片,把copy=None规范化为copy=True,因此无需替换 numpy 版本。
pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/非 torch 依赖通过阿里云 PyPI 镜像安装;torch / torch_npu 保持预装版本不变。
cd cirdit-multimodal-compile-3to5qubit-v1.1-npu
export HF_ENDPOINT=https://hf-mirror.com # 必须先于 huggingface_hub 导入
export HF_HOME=$PWD/.cache/huggingface # OpenCLIP 文本塔自包含缓存
python3 inference.py --samples 8 --timesteps 40脚本执行 9 个阶段(全部为真实 NPU 计算,失败即退出,绝不回退 CPU):
torch.npu.is_available()、set_device(5)、
current_device()==5 断言。MultimodalDiffusionPipeline_ParametrizedCompilation.from_config_file
加载到 npu:5。npu:5。lambda_h=1.0, lambda_w=0.35, g_h=0.3, g_w=0.1。QFT(4) 目标幺正(genQC benchmark,Apache-2.0)。npu:5 上的进程内存。UnitaryInfidelityNorm.distance 计算编译质量。QFT(4),形状 [16, 16] complex128
(来源:genQC.benchmark.bench_compilation.SpecialUnitaries.QFT,Apache-2.0)Compile 4 qubits using: ['h', 'cx', 'ccx', 'swap', 'rx', 'ry', 'rz', 'cp']samples=8,system_size=5,num_of_qubits=4,max_gates=32,seed=0timesteps=40(DPM-Solver++(2M),v-type 预测)UnitaryInfidelityNorm.distance(approx_U, target_U),越小越好$ cd cirdit-multimodal-compile-3to5qubit-v1.1-npu
$ HF_ENDPOINT=https://hf-mirror.com HF_HOME=$PWD/.cache/huggingface python3 inference.py --samples 8 --timesteps 40[2026-08-22 22:44:49][INFO] genQC CirDiT multimodal compilation on npu:5
[2026-08-22 22:44:51][INFO] torch.npu.is_available() = True
[2026-08-22 22:44:51][INFO] torch.npu.current_device() = 5 (expected 5)
[2026-08-22 22:44:54][INFO] model.safetensors: 765519544 bytes sha256=9fe6326a260eee854e71d02075f89a2d9e79c10be2d77e9fea4cd27a856ffef9
[2026-08-22 22:44:54][INFO] embedder.safetensors: 1308 bytes sha256=071b1f29feeac8eaaa62e3ca17946c2a40bf8ea08de8237f3d74286c5672057a
[2026-08-22 22:44:54][INFO] beta_schedule_learned_linear.safetensors: 4072 bytes sha256=128fc8d486718ba92a84d072a95b4130a052ff14e89843249ac2a3c25bcf5936
[2026-08-22 22:45:14][INFO] placement={"model": "npu:5", "text_encoder": "npu:5", "embedder": "npu:5", "scheduler": "npu:5", "scheduler_w": "npu:5", "pipeline.device": "npu:5"}
[2026-08-22 22:45:14][INFO] target unitary: QFT(4) shape=(16, 16) dtype=torch.complex128
[2026-08-22 22:45:22][INFO] sampling finished in 7.79s
[2026-08-22 22:45:22][INFO] decoded 8 samples, 8 valid circuits
[2026-08-22 22:45:22][INFO] best infidelity = 2.165e-02 gates=['swap', 'h', 'cp', 'h', 'swap', 'cp', 'cp', 'h', 'cp', 'cp', 'h']
[2026-08-22 22:45:22][INFO] npu-smi proc-mem captures: 23 (host PIDs on npu:5: ['182335'])
[2026-08-22 22:45:22][INFO] TOTAL WALL TIME: 33.20s
[2026-08-22 22:45:22][INFO] DONE: complete real NPU inference on npu:5 succeeded.| 指标 | 值 |
|---|---|
| 进程退出码 | 0 |
| 总墙钟时间 | 33.20 s |
| 管线加载 | 19.93 s |
| 去噪采样(40 步,8 样本) | 7.79 s |
| 有效电路 | 8 / 8 |
| 最佳 infidelity(QFT(4)) | 2.165e-02 |
| 最佳电路门数 | 11 |
| 最佳电路门序列 | swap, h, cp, h, swap, cp, cp, h, cp, cp, h |
| 输出张量形状 | (8, 4, 32) tokens · (8, 1, 32) params |
| 并发 npu-smi 采集 | 23 次,宿主 PID 182335(容器 PID 305949) |
npu-smi 报告的是容器进程的宿主命名空间 PID(已用内存探针验证:在
npu:5上分配 1 GiB,npu-smi 以同一宿主 PID 显示约 1.14 GB 占用)。容器内os.getpid()为305949,与 npu-smi 显示的182335一致对应同一进程。
inference.py # 完整 NPU 推理脚本(主交付物)
readme.md / README.md # 本文档(字节一致)
requirements.txt # 钉版本依赖(Aliyun 安装)
.gitignore
logs/inference_npu5_raw.log # 原始(已清理)运行日志
logs/inference_npu5.log # 结构化日志
logs/npu_result.json # 结构化结果(含权重哈希、放置、npu-smi 证据)
logs/npu_smi_process_npu5.txt# 并发 npu-smi 进程内存证据
SHA256SUMS # 交付物校验和
assets/agent_workflow.png # 推理工作流图
assets/modelagent_live_session.png # 实时会话截图
assets/npu_device_call.png # 物理设备调用证据
assets/model_result.png # 模型运行结果图推理工作流

实时 NPU 会话(agent live session)

物理设备调用(npu-smi / npu:5)

模型运行结果

模型权重与本仓库代码均采用 Apache License 2.0。测试幺正 QFT 取自
genQC(Apache-2.0)的 benchmark.bench_compilation.SpecialUnitaries。
HF_ENDPOINT=https://hf-mirror.com(主机无法直连 huggingface.co),且
HF_ENDPOINT / HF_HOME 必须在导入 huggingface_hub / open_clip 之前设置。UnitaryInfidelityNorm 为准。