文档版本:v1.1
最近更新:2026-09-08
RFdiffusion2 是 RosettaCommons 开发的下一代蛋白质结构扩散生成模型,基于 RFdiffusion 架构演进,集成了 OpenFold Evoformer、SE3Transformer、Chai 框架和 SE(3) Flow Matching 等多个子系统。它通过 SE(3)-等变图神经网络对蛋白质三维结构执行去噪扩散,支持从头蛋白质设计、Motif 支架、PPI 复合物设计等任务。在完成 Ascend NPU 适配后,需要替换 CUDA 设备调用、禁用 JIT 编译、patch torch.cdist,并修复 DGL-Ascend 的 coo2csr kernel 兼容性问题。
| 阶段 | 模块 | 说明 |
|---|---|---|
| 输入编码 | Extra_emb / Templ_emb / MSA_emb | 将序列、模板结构和 MSA 编码为隐式表征 |
| 主干迭代 | RF2_block(n_extra_block + n_main_block) | 依次执行 Extra Block 和 Main Block;每个 Block 包含 1D/2D 更新和 Str2Str(SE3 坐标更新) |
| SE(3) 等变更新 | SE3TransformerWrapper(位于 Str2Str 内部) | 使用 SE3Transformer 在 KNN 图上执行等变消息传递,更新原子坐标 |
| 扩散去噪 | Diffuser(IGSO3 + 平移扩散) | 默认执行 50 步去噪;每步将带噪声坐标输入 RoseTTAFoldModule 预测结构 |
| OpenFold 集成 | EvoformerStack / StructureModule / InvariantPointAttention | RFdiffusion2 内嵌 OpenFold 的 Evoformer 和 IPA 模块,需迁移 CUDA 调用 |
| Chai 集成 | chai_lab.utils.tensor_utils | Chai 框架的 cdist 实现,需适配 NPU 设备检测 |
| 输出 | save_outputs | 将最终坐标写入 PDB 文件,元数据写入 TRB 文件 |
| 项目 | 规格 |
|---|---|
| 任务类型 | 蛋白质结构生成(仅推理) |
| 框架依赖 | PyTorch + torch_npu + DGL(Ascend 版)+ e3nn + SE3Transformer + OpenFold |
| 预训练权重 | RFD_173.pt |
| 扩散步数 | 默认 50 步(可配置,验证使用 10 步) |
| 模型运行器 | NRBStyleSelfCond |
| 运行设备 | Atlas 800T A2(单卡 NPU,Ascend 910B3) |
PyTorch 版本要求:PyTorch 2.7.1 + torch_npu 2.7.1.post4(已验证)
DGL 版本要求:重新编译 DGL-ascend,并回退 coo2csr kernel 至旧版二分查找实现
| 路径 | 用途 |
|---|---|
/workspace/RFdiffusion2 | RFdiffusion2 源码目录 |
/root/dgl-ascend | DGL Ascend 版源码(需重新编译) |
/workspace/RFdiffusion2/rf_diffusion/model_weights/RFD_173.pt | 预训练权重 |
/workspace/RFdiffusion2/rf_diffusion/run_inference.py | 推理入口脚本 |
/workspace/RFdiffusion2/rf_diffusion/config/inference/aa.yaml | 推理配置文件 |
/workspace/RFdiffusion2/env_npu.sh | NPU 环境变量配置 |
/workspace/RFdiffusion2/scripts_npu/run_npu_verification.sh | 一键验证脚本 |
| 组件 | 版本 |
|---|---|
| Python | 3.11.15 |
| PyTorch | 2.7.1+cpu |
| torch_npu | 2.7.1.post4 |
| CANN | 9.0.0 (V100R001C10SPC001B250) |
| DGL(Ascend) | 2.1.0(自定义编译) |
| e3nn | 0.6.0 |
| SE3Transformer | 可编辑安装 |
| OpenFold | 内嵌(非独立安装) |
| hydra-core | 1.3.5 |
| omegaconf | 2.3.1 |
| numpy | 1.26.4 |
| scipy | 1.17.1 |
| biopython | 1.83 |
| mdtraj | 1.11.0 |
| 镜像环境 | 镜像地址 |
|---|---|
| 公网 | swr.cn-south-1.myhuaweicloud.com/ascendhub/torch-npu:2.7.1.post4-910b-openeuler24.03-py3.11 |
注:RFdiffusion2 是纯推理工具。适配工作包括 CUDA→NPU 设备迁移、JIT 禁用、cdist patch、DGL 算子替换和 coo2csr kernel 修复。
RFdiffusion2 的 NPU 适配共涉及 28 个 Python 文件(+145 -65 行)和 DGL-Ascend 的 3 个 C++ 文件(coo2csr kernel 回退),用于解决 6 类 CUDA 依赖问题:
| 适配类别 | 涉及文件数 | 说明 |
|---|---|---|
| CUDA→NPU 设备迁移 | 8 | .cuda() → .npu()、torch.cuda.is_available() → torch.npu.is_available()、empty_cache / manual_seed / get_device_name 等 |
| autocast 装饰器迁移 | 12 | @torch.cuda.amp.autocast → @torch.amp.autocast('npu')(PyTorch 2.x 标准新 API) |
| JIT 禁用 | 4 | 移除 @torch.jit.script 装饰器、torch.jit.script(nn.Sequential) → nn.Sequential、e3nn set_optimization_defaults(jit_mode="eager") |
| torch.cdist patch | 1 | NPU 不支持 torch.cdist,用 bmm + sqrt 手动实现 |
| nvtx range 替换 | 4 | from torch.cuda.nvtx import range → contextlib.nullcontext |
| DGL 算子替换 | 1 | dgl.ops.e_dot_v 不支持,用 dgl.ops.copy_u + 手动 dot 替代 |
| coo2csr kernel 回退 | 3 (C++) | counting-sort kernel 在 910B3 上启动失败,回退到旧版二分查找 |
| 设备型号 | NPU 配置 |
|---|---|
| Atlas 800T A2 | 单卡(Ascend 910B3,6 AI Core,64GB HBM) |
IMAGE_ID=swr.cn-south-1.myhuaweicloud.com/ascendhub/torch-npu:2.7.1.post4-910b-openeuler24.03-py3.11
CONTAINER_NAME=rfdiffusion2
docker run -u root --privileged \
--name ${CONTAINER_NAME} \
--device /dev/davinci0 \
--device /dev/davinci_manager \
--device /dev/devmm_svm \
--device /dev/hisi_hdc \
-v /usr/local/dcmi:/usr/local/dcmi \
-v /usr/local/bin/npu-smi:/usr/local/bin/npu-smi \
-v /usr/local/Ascend/driver:/usr/local/Ascend/driver \
-v /etc/ascend_install.info:/etc/ascend_install.info \
-itd ${IMAGE_ID} /bin/bash# 克隆 DGL-Ascend
cd /root
git clone --recursive https://github.com/BUPT-GAMMA/dgl-ascend.git
cd dgl-ascend
# 安装编译依赖
yum install gcc-gfortran
ln -s /usr/lib64/libgfortran.so.5 /usr/lib64/libgfortran.so
ln -s /usr/lib64/libgomp.so.1 /usr/lib64/libgomp.so
# 编译 DGL-Ascend
cd /root/dgl-ascend/script/
bash build_dgl_ascend.sh
# 安装 DGL Python 绑定
cd /root/dgl-ascend/python/
pip install -e . -i https://mirrors.aliyun.com/pypi/simple/
# 克隆 RFdiffusion2
cd /workspace
git clone https://github.com/RosettaCommons/RFdiffusion2.git
cd RFdiffusion2
# 安装 Python 依赖
pip install e3nn hydra-core omegaconf pyrsistent pydantic transformers \
biopython mdtraj biotite einops ml_collections pytorch-lightning \
torchmetrics torchdata icecream wandb rdkit openbabel-wheel \
-i https://mirrors.aliyun.com/pypi/simple/
# 安装 SE3Transformer(RFdiffusion2 子模块)
cd rf2aa/SE3Transformer
pip install -e . --no-build-isolation
cd /workspace/RFdiffusion2
# 配置环境变量
cp env_npu.sh /workspace/RFdiffusion2/
source /workspace/RFdiffusion2/env_npu.sh# 创建权重目录
mkdir -p /workspace/RFdiffusion2/rf_diffusion/model_weights
# 从 HuggingFace 镜像下载
pip install huggingface_hub -q
HF_ENDPOINT=https://hf-mirror.com python3 -c "
from huggingface_hub import hf_hub_download
path = hf_hub_download(
repo_id='RosettaCommons/RFdiffusion2',
filename='RFD_173.pt',
local_dir='/workspace/RFdiffusion2/rf_diffusion/model_weights'
)
print(f'Downloaded to: {path}')
"RFdiffusion2 的 NPU 适配共涉及 28 个 Python 文件(+145 -65 行)和 DGL-Ascend 的 3 个 C++ 文件(coo2csr kernel 回退),用于解决 6 类 CUDA 依赖问题。
问题:DGL-Ascend commit 73dff995 引入的 counting-sort kernel 在 910B3 上启动失败(LaunchAscendKernel ret 507000)。
根因:新版 kernel 查询 ACL_DEV_ATTR_VECTOR_CORE_NUM 在 910B3 上返回错误 107000,fallback 到硬编码的 kDefaultVectorCoreCount=40,超出 910B3 实际 6 个 AI Core 限制。
修复:回退到 commit 73169844 的旧版二分查找 kernel。
适配补丁统一存放在 GitCode 仓库:
https://gitcode.com/xuejikan11/RFdiffusion2-Ascend-Adaptation
├── dgl-ascend/
│ └── dgl_ascend_coo2csr_revert.patch
└── rfdiffusion2/patches/
└── rfdiffusion2_npu_adaptation.patch补丁托管说明:上述两个 patch 文件托管于外部仓库
xuejikan11/RFdiffusion2-Ascend-Adaptation,本仓库不包含 patch 文件,请通过下方命令从外部仓库获取。
§4.1 已完成 dgl-ascend(/root/dgl-ascend)和 RFdiffusion2(/workspace/RFdiffusion2)的 clone 与编译安装。现在下载补丁并应用到这两个仓库:
# 下载补丁文件
git clone https://gitcode.com/xuejikan11/RFdiffusion2-Ascend-Adaptation.git /tmp/ascend-adaptation
# ── DGL coo2csr 回退 ──
cd /root/dgl-ascend
# 方法 1: 应用 patch
git apply /tmp/ascend-adaptation/dgl-ascend/dgl_ascend_coo2csr_revert.patch
# 方法 2: 手动 checkout 旧版文件
git checkout 73169844 -- src/array/ascend/coo2csr.cc src/array/ascend/coo2csr_kernel.cpp
rm -f src/array/ascend/coo2csr_tiling.h # 旧版不需要此文件
# 重新编译(使用官方构建脚本)
# §4.1 已执行 pip install -e .,开发者模式下 libdgl.so 为符号链接,编译后自动生效,无需重复安装
cd /root/dgl-ascend/script/
bash build_dgl_ascend.sh
# ── RFdiffusion2 NPU 适配 ──
cd /workspace/RFdiffusion2
git apply /tmp/ascend-adaptation/rfdiffusion2/patches/rfdiffusion2_npu_adaptation.patch也可以不 clone 仓库,直接用 curl 下载单个 patch 文件:
curl -o /tmp/dgl_ascend_coo2csr_revert.patch \
https://gitcode.com/xuejikan11/RFdiffusion2-Ascend-Adaptation/raw/main/dgl-ascend/dgl_ascend_coo2csr_revert.patch
curl -o /tmp/rfdiffusion2_npu_adaptation.patch \
https://gitcode.com/xuejikan11/RFdiffusion2-Ascend-Adaptation/raw/main/rfdiffusion2/patches/rfdiffusion2_npu_adaptation.patch
cd /root/dgl-ascend && git apply /tmp/dgl_ascend_coo2csr_revert.patch
cd /workspace/RFdiffusion2 && git apply /tmp/rfdiffusion2_npu_adaptation.patch旧版 kernel 特点:
blockDim=1(单 block launch),通过多 stream 实现并行,在任何 Ascend 设备上安全aclrtGetDeviceInfo 查询设备参数GlobalTensor.GetValue/SetValue 进行 scalar 读写KERNEL_TASK_TYPE_DEFAULTRFdiffusion2 NPU 适配补丁已在上方 §4.3.1 中一并应用(git apply rfdiffusion2_npu_adaptation.patch)。
以下按修改类型逐项说明:
文件:rf_diffusion/inference/model_runners.py(+4 -2 行)
设备检测由 CUDA 改为 NPU 优先,支持 RF2_FORCE_CPU 环境变量强制 CPU:
# 前: if torch.cuda.is_available():
# self.device = torch.device("cuda")
# 后: if torch.npu.is_available() and os.environ.get('RF2_FORCE_CPU', '0') != '1':
# self.device = torch.device("npu")
# elif torch.cuda.is_available():
# self.device = torch.device("cuda")同时将权重加载的 map_location 从 self.device 改为 'cpu'。checkpoint 文件(1.3GB)除了 model_state_dict(7208 个 tensor)外,还包含完整的 RFScore 模型类对象、optimizer_state_dict、scheduler_state_dict、DictConfig 等非 tensor Python 对象。torch.load(map_location='npu') 会尝试对所有 pickle 图中的 storage 执行设备重映射,而这些非 tensor 对象(如 optimizer 的 param_groups、DictConfig)不适用于设备重映射。改为 'cpu' 加载后,仅通过 self.model.load_state_dict(model_weights) + self.model.to(self.device) 将需要的权重迁移到 NPU,避免对无关对象执行设备映射。
文件:rf_diffusion/run_inference.py(+1 -1 行)
TRB metadata 中 device 字段支持 NPU:
# 前: device = torch.cuda.get_device_name(torch.cuda.current_device()) if torch.cuda.is_available() else 'CPU'
# 后: device = torch.npu.get_device_name(torch.npu.current_device()) if torch.npu.is_available() else (...)文件:rf2aa/set_seed.py(+7 -1 行)
随机种子设置支持 NPU:
# 前: torch.cuda.manual_seed(seed)
# 后: try: torch.npu.manual_seed(seed)
# except (RuntimeError, AttributeError): pass
# try: torch.cuda.manual_seed(seed)
# except (RuntimeError, AssertionError): pass文件:rf2aa/__init__.py(+31 行,新增)
全局禁用 e3nn JIT 和 NPU 内部格式,patch torch.cdist:
# 禁用 e3nn JIT(NPU 不支持 torch.jit.script)
from e3nn import set_optimization_defaults
set_optimization_defaults(jit_mode="eager")
# patch torch.cdist(NPU 不支持原生 cdist)
_original_cdist = torch.cdist
def _npu_cdist(x1, x2, p=2.0, compute_mode="use_mm_for_euclid_dist"):
if x1.is_npu or x2.is_npu:
x1_sq = (x1 ** 2).sum(dim=-1, keepdim=True)
x2_sq = (x2 ** 2).sum(dim=-1, keepdim=True).transpose(-2, -1)
cross = x1 @ x2.transpose(-2, -1)
dist_sq = x1_sq + x2_sq - 2 * cross
dist_sq = dist_sq.clamp(min=0)
return dist_sq.sqrt()
return _original_cdist(x1, x2, p=p, compute_mode=compute_mode)
torch.cdist = _npu_cdist
# 禁用 JIT profiler
torch._C._jit_set_profiling_executor(False)
torch._C._jit_set_profiling_mode(False)涉及 12 个文件(各 +1 -1 行):
| 文件 | 修改 |
|---|---|
rf2aa/model/Track_module.py | @torch.cuda.amp.autocast → @torch.amp.autocast('npu') |
rf2aa/model/simulator_blocks.py | 同上 |
openfold/model/primitives.py | 同上 |
openfold/model/structure_module.py | 同上 |
fused_mpnn/openfold/model/primitives.py | 同上 |
fused_mpnn/openfold/model/structure_module.py | 同上 |
se3_flow_matching/openfold/model/primitives.py | 同上 |
se3_flow_matching/openfold/model/structure_module.py | 同上 |
# 前: @torch.cuda.amp.autocast(enabled=False)
# 后: @torch.amp.autocast('npu', enabled=False)涉及 8 个文件:
| 文件 | 修改 |
|---|---|
openfold/model/evoformer.py | torch.cuda.empty_cache() → torch.npu.empty_cache() if torch.npu.is_available() else torch.cuda.empty_cache() |
openfold/utils/rigid_utils.py | .cuda() → .npu() |
se3_flow_matching/openfold/model/evoformer.py | 同 evoformer |
se3_flow_matching/openfold/utils/rigid_utils.py | 同 rigid_utils |
fused_mpnn/openfold/model/evoformer.py | 同 evoformer |
fused_mpnn/openfold/utils/rigid_utils.py | 同 rigid_utils |
rf2aa/memory.py | t.is_cuda → t.is_cuda or (hasattr(t, 'is_npu') and t.is_npu) |
rf2aa/debug.py | 同上 |
涉及 4 个文件(各 +3 -2 行):
| 文件 | 修改 |
|---|---|
rf2aa/SE3Transformer/se3_transformer/model/basis.py | from torch.cuda.nvtx import range → nullcontext;移除 @torch.jit.script |
rf2aa/SE3Transformer/se3_transformer/model/layers/attention.py | 同上 |
rf2aa/SE3Transformer/se3_transformer/model/layers/convolution.py | 同上;torch.jit.script(nn.Sequential) → nn.Sequential |
rf2aa/SE3Transformer/se3_transformer/model/layers/norm.py | 同上;移除 @torch.jit.script |
# 前: from torch.cuda.nvtx import range as nvtx_range
# 后: from contextlib import nullcontext
# def nvtx_range(*args, **kwargs):
# return nullcontext()文件:rf2aa/SE3Transformer/se3_transformer/model/layers/attention.py(额外 +5 -1 行)
# 前: edge_weights = dgl.ops.e_dot_v(graph, key, query).squeeze(-1)
# 后: NPU DGL SDDMM 不支持 lhs_target=edge,使用 copy_u + 手动 dot 替代
query_gathered = dgl.ops.copy_u(graph, query)
edge_weights = (key * query_gathered).sum(dim=-1, keepdim=True)
edge_weights = edge_weights.squeeze(-1)| 文件 | 修改 |
|---|---|
openfold/utils/logger.py | torch.cuda.profiler 导入失败时使用空实现 |
se3_flow_matching/openfold/utils/logger.py | 同上 |
openfold/model/structure_module.py | attn_core_inplace_cuda 导入失败时设为 None,inplace_safe 增加非空检查 |
se3_flow_matching/openfold/model/structure_module.py | 同上 |
rf2aa/model/layers/Attention_module.py | torch.cuda.get_device_properties 调用前检查 torch.cuda.is_available(),NPU 直接使用 SDPA |
lib/chai/chai_lab/utils/tensor_utils.py | x.is_cuda → x.is_cuda or x.is_npu |
#!/usr/bin/env bash
# RFdiffusion2 NPU 端到端推理测试
source /workspace/RFdiffusion2/env_npu.sh
export USER=root PYTORCH_NPU_ALLOC_CONF=expandable_segments:True
cd /workspace/RFdiffusion2
rm -rf samples_test && mkdir -p samples_test
python3 -m rf_diffusion.run_inference \
--config-name=aa \
inference.ckpt_path=REPO_ROOT/rf_diffusion/model_weights/RFD_173.pt \
inference.num_designs=1 \
inference.design_startnum=0 \
inference.output_prefix=samples_test/npu \
inference.deterministic=True \
inference.input_pdb=rf_diffusion/test_data/1qys_ori.pdb \
'contigmap.contigs=["60"]' \
inference.model_runner=NRBStyleSelfCond \
diffuser.T=10 \
inference.final_step=1 \
inference.write_trb=True \
inference.write_trb_indep=True \
inference.write_trb_trajectory=True# 一键运行 NPU + CPU 对比验证
bash scripts_npu/run_npu_verification.sh
# 或手动分步对比
python3 scripts_npu/verify_npu_precision.py \
--npu-trb samples_verify/npu_0-atomized-bb-False.trb \
--cpu-trb samples_verify_cpu/cpu_0-atomized-bb-False.trb \
--npu-minutes 0.66 \
--cpu-minutes 3.45torch-npu:2.7.1.post4-910b-openeuler24.03-py3.11| 场景 | 残基数 | 步数 | 单个设计耗时 | 每步耗时 |
|---|---|---|---|---|
| NPU 无条件设计 60aa | 60 | 10 | 39.6s (0.66min) | 3.96s |
| CPU 无条件设计 60aa | 60 | 10 | 207.0s (3.45min) | 20.70s |
| 加速比 | 5.2x |
| 指标 | 值 | 判定 |
|---|---|---|
| 输入 indep_true RMSD | 0.00000000 Å | PASS(完全一致) |
| Step | RMSD (Å) | Max Diff (Å) |
|---|---|---|
| 1 | 1.7390 | 12.7117 |
| 2 | 1.7447 | 13.0425 |
| 3 | 1.7903 | 11.6363 |
| 4 | 1.7460 | 12.4202 |
| 5 | 2.0562 | 15.8457 |
| 6 | 2.0403 | 18.8590 |
| 7 | 1.8955 | 13.4571 |
| 8 | 1.3014 | 10.3971 |
| 9 | 0.5854 | 5.3092 |
| 10 | 0.3206 | 3.1814 |
| Step | RMSD (Å) | Max Diff (Å) |
|---|---|---|
| 1 | 1.7835 | 13.2040 |
| 2 | 1.5311 | 11.8052 |
| 3 | 1.3238 | 11.4608 |
| 4 | 1.1484 | 9.6390 |
| 5 | 1.0045 | 8.0917 |
| 6 | 0.7875 | 7.4636 |
| 7 | 0.6096 | 5.2915 |
| 8 | 0.4979 | 5.2222 |
| 9 | 0.3314 | 4.0729 |
| 10 | 0.1386 | 2.3506 |
| 指标 | 值 | 判定 |
|---|---|---|
| 最终 indep xyz RMSD | 0.1386 Å | PASS(< 1.0 Å) |
| 最终 indep xyz MaxDiff | 2.3506 Å | 正常(见分析) |
MaxDiff 2.35 Å 分析:出现在 Residue 46 的 backbone 氧原子(O),是单个原子的离群值。Backbone 氧原子对二面角微小变化高度敏感,在 10 步扩散模型的 FP32 浮点误差累积下属正常范围。整体 RMSD 仅 0.139 Å,侧链精度极高(0.070 Å),不影响精度判定。
| 部位 | RMSD (Å) | MaxDiff (Å) |
|---|---|---|
| Backbone (N, CA, C, O) | 0.3652 | 2.3506 |
| Sidechain (4+) | 0.0703 | 1.1843 |
| 轨迹 | Step 1 RMSD | Step 10 RMSD | 判定 |
|---|---|---|---|
| pX0 | 1.7390 Å | 0.3206 Å | PASS(递减) |
| Denoised | 1.7835 Å | 0.1386 Å | PASS(递减) |
| 指标 | 数值 |
|---|---|
| HBM 总量 | 64 GB |
| 推理后 HBM | 无泄漏 |
| 连续推理稳定性 | 多次推理无崩溃 |
| NPU 与 CPU 输入一致性 | 0.000000 Å |
| NPU 与 CPU 最终 RMSD | 0.139 Å |
| NPU 与 CPU 加速比 | 5.2x |
Q1:运行时报 LaunchAscendKernel ret 507000?
A:这是 DGL-Ascend 的 coo2csr counting-sort kernel 在 910B3 上启动失败。根因是 ACL_DEV_ATTR_VECTOR_CORE_NUM 查询返回错误 107000,fallback 到硬编码 40 超出 910B3 的 6 个 AI Core 限制。需要回退 coo2csr kernel 到旧版二分查找实现,详见 §迁移适配。
Q2:运行时报 RegisterAscendBinary aiv ret 107000 警告?
A:910B3 不支持纯 AIV binary 注册,但该警告不阻塞执行,kernel 正常运行,可忽略。
Q3:torch.cdist 报错或结果异常?
A:NPU 不支持 torch.cdist 原生算子。RFdiffusion2 的 rf2aa/__init__.py 中已添加 patch,使用手动 bmm + sqrt 实现 ||x1-x2|| = sqrt(||x1||² + ||x2||² - 2*x1·x2^T)。确保 rf2aa/__init__.py 的 patch 已正确加载。
Q4:@torch.jit.script 装饰器导致编译错误?
A:NPU 不支持 torch.jit.script。适配已移除 SE3Transformer 中所有 @torch.jit.script 装饰器,并在 rf2aa/__init__.py 中设置 set_optimization_defaults(jit_mode="eager")。
Q5:torch.cuda.amp.autocast 警告或报错?
A:PyTorch 2.x 已废弃 torch.cuda.amp.autocast,需替换为 torch.amp.autocast('npu', ...)。涉及 12 个文件,详见 §迁移适配。
Q6:attn_core_inplace_cuda 模块找不到?
A:这是 OpenFold 的 CUDA 扩展,NPU 环境下不可用。适配代码已添加 try/except 将其设为 None,并在 inplace_safe 逻辑中增加非空检查,自动回退到非 inplace 实现。
Q7:dgl.ops.e_dot_v 报错?
A:Ascend DGL 的 SDDMM 不支持 lhs_target=edge。已使用 dgl.ops.copy_u + 手动 dot 替代,详见 §迁移适配。
Q8:如何强制使用 CPU 运行?
A:设置环境变量 export RF2_FORCE_CPU=1,model_runners.py 中的设备检测会跳过 NPU 直接使用 CPU。
Q9:权重加载时 map_location 为什么要改为 'cpu'?
A:RFdiffusion2 的 checkpoint(1.3GB)不仅包含 model_state_dict(7208 个 tensor),还包含完整的 RFScore 模型类对象、optimizer_state_dict、scheduler_state_dict、DictConfig 等非 tensor Python 对象。torch.load(map_location='npu') 会对 pickle 图中所有 storage 执行设备重映射,而这些非 tensor 对象(如 optimizer 的 param_groups、DictConfig)不适用于设备重映射。改为 'cpu' 加载后,仅通过 load_state_dict + model.to('npu') 将所需权重迁移到 NPU,是更安全的标准模式。