模型来源: ByteDance-Seed/cryofm-v2
(镜像: https://ai.gitcode.com/hf_mirrors/ByteDance-Seed/cryofm-v2)
本说明对应昇腾 NPU 上的推理适配笔记,与 inference.py 配套使用。
CryoFM2(Cryo-EM Flow Matching foundational model 2)是 ByteDance Seed 团队发布的一个基于流匹配(Flow Matching)的冷冻电镜(cryo-EM)密度图生成式基础模型。它学习从简单高斯分布到高质量冷冻电镜密度图分布的连续映射,作为密度图先验,可服务于生成、增强、去噪、修复等下游任务。
cryofm2-pretrain);微调输入通道:3(cryofm2-emhancer/cryofm2-emready)注意:CryoFM2 不是大语言模型,不适用 vLLM / vLLM-Ascend。其推理依赖 PyTorch 生态 +
cryofm源码包,inference.py基于torch_npu在昇腾 NPU 上完成 Flow Matching 采样并导出 MRC 密度图。
| 变体 | 类型 | 说明 |
|---|---|---|
cryofm2-pretrain | 无条件 | 通用密度图生成 / 修改(去噪、修复) |
cryofm2-emhancer | 条件 | EMhancer 风格密度图增强 |
cryofm2-emready | 条件 | EMReady 风格密度图增强 |
| 组件 | 版本 |
|---|---|
| CPU/OS | Linux x86 |
| NPU | Ascend 910Bseries(torch.npu.is_available()=True) |
| CANN | 8.5.1 |
| Python | 3.10.x |
| torch | 2.9.0 |
| torch_npu | 2.9.0.post1+giteeDist |
| cryofm | 官方源码包(可编辑安装) |
# 1) 昇腾 NPU + CANN 需先就绪(npu-smi 可见设备)
npu-smi info
# 2) 安装 torch / torch_npu(版本须与 CANN 匹配)
pip install torch==2.9.0 torch-npu==2.9.0.post1
# 3) 安装 cryofm 官方源码包(含 3D UNet / Flow Matching / MRC IO)
git clone https://github.com/ByteDance-Seed/cryofm.git
cd cryofm && pip install -e .
cd ..
# 4) 本项目依赖
pip install -r requirements.txtCryoFM2 权重托管在 HuggingFace,可从中拉取(Git 镜像):
# 方式一:HF 官方(需可访问 hf.co)
pip install huggingface_hub && hf download ByteDance-Seed/cryofm-v2 --local-dir ./cryofm-v2
# 方式二:Git 镜像(推荐,国内可达)
git clone https://atomgit.com/ByteDance-Seed/cryofm # 若你的镜像在 gitcode/atomgit 下,同上替换权重目录结构(三个子目录各含 config.yaml + model.safetensors):
cryofm-v2/
├── cryofm2-pretrain/
├── cryofm2-emhancer/
└── cryofm2-emready/inference.py 在本地昇腾 NPU 上执行 3D 密度图的 Flow Matching 无条件/条件采样:
noise(64^3) --Flow Matching ODE 反演 N 步--> 64^3 latent --(z_scale 反归一化)--> 保存 .mrcpython3 inference.py \
--variant pretrain \
--model-dir ./cryofm-v2/cryofm2-pretrain \
--device auto # auto | npu:0 | cpu
--method euler \
--steps 50 --num-samples 3 \
--output-dir ./outputspython3 inference.py \
--variant emhancer \
--model-dir ./cryofm-v2/cryofm2-emhancer \
--device npu:0 --steps 50 --num-samples 3 --output-dir ./outputs输出:
outputs/<variant>/report.json 推断报告(参数量、设备、耗时、输出体素形态)成功输出示意(部分):
[info] variant : pretrain (CryoFM2Uncond)
[info] params : 150,241,344 (150.2 M)
[info] device : npu:0
[ok] NPU 生成完成: vol_shape=[3, 64, 64, 64] 耗时=3.412s
[ok] saved #0: ./outputs/pretrain/pretrain-sample-0.mrc
[ok] report -> ./outputs/pretrain/report.jsonimport torch, torch_npu
from inference import resolve_device, load_model, generate, save_samples
device = resolve_device("auto") # npu:0
lit_model = load_model("pretrain", "./cryofm-v2/cryofm2-pretrain", device)
vol, elapsed = generate("pretrain", lit_model, device, "euler", steps=50, num_samples=2, output_tag=1)
files = save_samples(vol, "./outputs", "pretrain")vol_shape)与 MRC 文件输出,确认 NPU 产出形态与参考实现一致。euler 求解 5 步采样耗时约 3–4 s(3 个样本);步数增加(如官方 200 步)耗时会线性上涨。# 1) 安装环境 2) 拉取权重 3) 推理
bash -c 'python3 inference.py \
--variant pretrain --model-dir ./cryofm-v2/cryofm2-pretrain \
--device auto --steps 5 --num-samples 3 --method euler --output-dir ./outputs'相对官方 CUDA 版的昇腾适配关键点:
cuda 相关执行路径替换为 torch_npu,推理统一在 npu 后端完成;torch.autocast("cuda", bfloat16) 改为适配后经本地 autocast 上下文,在 NPU 上以 bfloat16 采样;--variant 区分三个官方变体。互动团队:liuhongwei (liuhongwei-2026),适配自开源模型 【ByteDance-Seed/cryofm-v2】。(模型以 Apache-2.0 许可发布。)