CryoFM2 是来自字节跳动 Seed 团队的冷冻电镜密度图生成基础模型,论文 A Generative Foundation Model for Cryo-EM Densities。
本模型基于 Flow Matching 机制学习从简单高斯分布到复杂 Cryo-EM 密度图分布的连续映射。
| 属性 | 值 |
|---|---|
| 模型类型 | 3D UNet (Flow Matching) |
| 输入尺寸 | 64×64×64 体素 |
| 输入通道 | 2 (无条件生成) / 3 (条件增强) |
| 输出通道 | 1 |
| 下采样块 | DownBlock3D, DownBlock3D, AttnDownBlock3D, AttnDownBlock3D |
| 上采样块 | AttnUpBlock3D, AttnUpBlock3D, UpBlock3D, UpBlock3D |
| 块输出通道 | (64, 128, 256, 512) |
| 每块层数 | 2 |
| 注意力头维度 | 8 |
| 归一化 | GroupNorm (32 groups) |
| 激活函数 | SiLU |
| 时间嵌入 | Positional Encoding |
(batch_size, 2, 64, 64, 64) 的噪声张量(batch_size, 1, 64, 64, 64) 的密度图| 依赖项 | 版本要求 | 说明 |
|---|---|---|
| 操作系统 | CentOS 7.6+ / Ubuntu 18.04+ | 支持主流 Linux 发行版 |
| CANN | 5.0.RC2+ | 华为昇腾计算架构 |
| Python | 3.10 / 3.12 | 推荐 3.10+ |
| PyTorch | 2.0.0+ | 推荐 2.12 |
| torch_npu | 与 PyTorch 版本匹配 | 昇腾 PyTorch 扩展 |
| cryofm | 0.1.0 | 官方库 (pip install git+https://github.com/ByteDance-Seed/cryofm.git) |
| diffusers | 0.40.0+ | 模型组件 |
| mmengine | 0.10.7+ | 配置文件加载 |
# 1) 激活已预装 torch / torch_npu 的 conda 环境
conda activate pt2100
# 2) 安装 cryofm 官方库(使用华为云源)
pip install git+https://github.com/ByteDance-Seed/cryofm.git \
-i https://repo.huaweicloud.com/repository/pypi/simple
# 3) 验证环境
python -c "
import torch, torch_npu
print('torch:', torch.__version__)
print('torch_npu:', torch_npu.__version__)
print('NPU 可用:', torch.npu.is_available())
"# 进入适配目录
cd /workspace/agent4/cryofm-v2-ascend
# 确认上游权重存在
ls -la /workspace/agent3/ByteDance-Seed/cryofm-v2/
# 期望输出:config.yaml cryofm2-pretrain/ cryofm2-emhancer/ cryofm2-emready/# 检查 NPU 设备状态
npu-smi info
# 验证 torch_npu 安装
python -c "import torch; import torch_npu; print('NPU 可用:', torch.npu.is_available())"# 无条件生成(默认 pretrain 模型)
python inference.py --device npu:0
# EMhancer 风格增强
python inference.py --device npu:0 --variant emhancer
# EMReady 风格增强
python inference.py --device npu:0 --variant emready
# 生成多个样本
python inference.py --device npu:0 --num_samples 4
# 指定其他 NPU 卡
python inference.py --device npu:1conda activate pt2100
cd /workspace/agent4/cryofm-v2-ascend
python inference.py --device npu:0 --num_samples 1实际输出:
============================================================
CryoFM2 昇腾 NPU 推理
============================================================
[Device] npu:0
[Model Path] /workspace/agent3/ByteDance-Seed/cryofm-v2/cryofm2-pretrain
[Loading] Model config...
Model type: unet
Process: fm
[Loading] Model weights from safetensors...
Loaded 380 weights
[Creating] UNet3DModel...
[Loading] Weights into model...
Model loaded successfully
[Model Loaded] Allocated: 0.32 GB, Reserved: 0.66 GB
[npu-smi info]
+------------------------------------------------------------------------------------------------+
| npu-smi 25.5.2 Version: 25.5.2 |
+---------------------------+---------------+----------------------------------------------------+
| NPU Name | Health | Power(W) Temp(C) Hugepages-Usage(page)|
| Chip | Bus-Id | AICore(%) Memory-Usage(MB) HBM-Usage(MB) |
+===========================+===============+====================================================+
| 0 910B2 | OK | 104.3 41 0 / 0 |
| 0 | 0000:C1:00.0 | 0 0 / 0 4165 / 65536 |
+===========================+===============+====================================================+
+---------------------------+---------------+----------------------------------------------------+
| NPU Chip | Process id | Process name | Process memory(MB) |
+===========================+===============+====================================================+
| 0 0 | 1668840 | python | 796 |
+===========================+===============+====================================================+
[Creating] Model wrapper for sampling...
Input shape: 1x2x64x64x64
[Running] Flow matching sampling (200 steps)...
100%|██████████| 200/200 [00:11<00:00, 17.57it/s]
[npu-smi info]
+------------------------------------------------------------------------------------------------+
| npu-smi 25.5.2 Version: 25.5.2 |
+---------------------------+---------------+----------------------------------------------------+
| NPU Name | Health | Power(W) Temp(C) Hugepages-Usage(page)|
| Chip | Bus-Id | AICore(%) Memory-Usage(MB) HBM-Usage(MB) |
+===========================+===============+====================================================+
| 0 910B2 | OK | 140.9 44 0 / 0 |
| 0 | 0000:C1:00.0 | 0 0 / 0 5380 / 65536 |
+===========================+===============+====================================================+
+---------------------------+---------------+----------------------------------------------------+
| NPU Chip | Process id | Process name | Process memory(MB) |
+===========================+===============+====================================================+
| 0 0 | 1668840 | python | 2011 |
+===========================+===============+====================================================+
[Results]
Output shape: torch.Size([1, 64, 64, 64])
Output dtype: torch.float32
Output min: -4.2705, max: 12.2534
Output mean: 0.1077, std: 1.2960
[Memory After Inference] Allocated: 0.32 GB, Reserved: 1.75 GB
[Done]| 指标 | 值 |
|---|---|
| 推理耗时 | ~11 秒 (200 steps) |
| NPU 峰值显存 | ~2 GB |
| 生成样本形状 | (1, 64, 64, 64) |