Ascend-SACT/RFdiffusion2
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

RFdiffusion2

文档版本: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 兼容性问题。


模型分析

1.1 模型架构

阶段模块说明
输入编码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 / InvariantPointAttentionRFdiffusion2 内嵌 OpenFold 的 Evoformer 和 IPA 模块,需迁移 CUDA 调用
Chai 集成chai_lab.utils.tensor_utilsChai 框架的 cdist 实现,需适配 NPU 设备检测
输出save_outputs将最终坐标写入 PDB 文件,元数据写入 TRB 文件

1.2 模型规格

项目规格
任务类型蛋白质结构生成(仅推理)
框架依赖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 至旧版二分查找实现


快速开始

2.1 模型与代码路径

路径用途
/workspace/RFdiffusion2RFdiffusion2 源码目录
/root/dgl-ascendDGL 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.shNPU 环境变量配置
/workspace/RFdiffusion2/scripts_npu/run_npu_verification.sh一键验证脚本

2.2 环境依赖

组件版本
Python3.11.15
PyTorch2.7.1+cpu
torch_npu2.7.1.post4
CANN9.0.0 (V100R001C10SPC001B250)
DGL(Ascend)2.1.0(自定义编译)
e3nn0.6.0
SE3Transformer可编辑安装
OpenFold内嵌(非独立安装)
hydra-core1.3.5
omegaconf2.3.1
numpy1.26.4
scipy1.17.1
biopython1.83
mdtraj1.11.0

2.3 镜像版本

镜像环境镜像地址
公网swr.cn-south-1.myhuaweicloud.com/ascendhub/torch-npu:2.7.1.post4-910b-openeuler24.03-py3.11

2.4 部署步骤(概览)

  1. 拉取并启动镜像(参见 §准备运行环境)
  2. 在容器内通过 git clone 获取 RFdiffusion2 和 DGL-Ascend 仓库
  3. 安装 Python 依赖,编译 DGL-Ascend(参见 §运行引导 / 安装依赖)
  4. 下载预训练权重(参见 §运行引导 / 下载预训练权重)
  5. 应用 DGL coo2csr kernel 回退补丁(参见 §运行引导 / 迁移适配)
  6. 应用 RFdiffusion2 NPU 适配补丁(参见 §运行引导 / 迁移适配)
  7. 运行推理(参见 §运行引导 / 测试示例)

注:RFdiffusion2 是纯推理工具。适配工作包括 CUDA→NPU 设备迁移、JIT 禁用、cdist patch、DGL 算子替换和 coo2csr kernel 修复。

2.5 实现细节

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 patch1NPU 不支持 torch.cdist,用 bmm + sqrt 手动实现
nvtx range 替换4from torch.cuda.nvtx import range → contextlib.nullcontext
DGL 算子替换1dgl.ops.e_dot_v 不支持,用 dgl.ops.copy_u + 手动 dot 替代
coo2csr kernel 回退3 (C++)counting-sort kernel 在 910B3 上启动失败,回退到旧版二分查找

准备运行环境

3.1 硬件环境

设备型号NPU 配置
Atlas 800T A2单卡(Ascend 910B3,6 AI Core,64GB HBM)

3.2 启动镜像

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

运行引导

4.1 安装依赖

# 克隆 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

4.2 下载预训练权重

# 创建权重目录
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}')
"

4.3 迁移适配

RFdiffusion2 的 NPU 适配共涉及 28 个 Python 文件(+145 -65 行)和 DGL-Ascend 的 3 个 C++ 文件(coo2csr kernel 回退),用于解决 6 类 CUDA 依赖问题。

4.3.1 DGL coo2csr kernel 回退

问题: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_DEFAULT

4.3.2 RFdiffusion2 NPU 适配补丁

RFdiffusion2 NPU 适配补丁已在上方 §4.3.1 中一并应用(git apply rfdiffusion2_npu_adaptation.patch)。

以下按修改类型逐项说明:

4.3.2.1 设备选择迁移

文件: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
4.3.2.2 torch.cdist patch + JIT 禁用

文件: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)
4.3.2.3 autocast 装饰器迁移

涉及 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)
4.3.2.4 CUDA 设备调用迁移

涉及 8 个文件:

文件修改
openfold/model/evoformer.pytorch.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.pyt.is_cuda → t.is_cuda or (hasattr(t, 'is_npu') and t.is_npu)
rf2aa/debug.py同上
4.3.2.5 nvtx range 替换 + JIT script 移除

涉及 4 个文件(各 +3 -2 行):

文件修改
rf2aa/SE3Transformer/se3_transformer/model/basis.pyfrom 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()
4.3.2.6 DGL e_dot_v 算子替换

文件: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)
4.3.2.7 其他兼容性修复
文件修改
openfold/utils/logger.pytorch.cuda.profiler 导入失败时使用空实现
se3_flow_matching/openfold/utils/logger.py同上
openfold/model/structure_module.pyattn_core_inplace_cuda 导入失败时设为 None,inplace_safe 增加非空检查
se3_flow_matching/openfold/model/structure_module.py同上
rf2aa/model/layers/Attention_module.pytorch.cuda.get_device_properties 调用前检查 torch.cuda.is_available(),NPU 直接使用 SDPA
lib/chai/chai_lab/utils/tensor_utils.pyx.is_cuda → x.is_cuda or x.is_npu

4.4 测试示例

#!/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

4.5 运行验证脚本

# 一键运行 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.45

测试结果

5.1 测试环境

  • 设备:Atlas 800T A2(单卡,Ascend 910B3,6 AI Core,64GB HBM)
  • 镜像:torch-npu:2.7.1.post4-910b-openeuler24.03-py3.11
  • CPU:HUAWEI Kunpeng 920 5250 @ 2.6GHz(164 核用于 CPU 参考)
  • 操作系统:openEuler 24.03 LTS-SP2
  • CANN:9.0.0

5.2 推理性能

场景残基数步数单个设计耗时每步耗时
NPU 无条件设计 60aa601039.6s (0.66min)3.96s
CPU 无条件设计 60aa6010207.0s (3.45min)20.70s
加速比5.2x

5.3 精度结果

5.3.1 输入一致性

指标值判定
输入 indep_true RMSD0.00000000 ÅPASS(完全一致)

5.3.2 pX0 逐步轨迹对比

StepRMSD (Å)Max Diff (Å)
11.739012.7117
21.744713.0425
31.790311.6363
41.746012.4202
52.056215.8457
62.040318.8590
71.895513.4571
81.301410.3971
90.58545.3092
100.32063.1814

5.3.3 去噪轨迹对比

StepRMSD (Å)Max Diff (Å)
11.783513.2040
21.531111.8052
31.323811.4608
41.14849.6390
51.00458.0917
60.78757.4636
70.60965.2915
80.49795.2222
90.33144.0729
100.13862.3506

5.3.4 最终输出

指标值判定
最终 indep xyz RMSD0.1386 ÅPASS(< 1.0 Å)
最终 indep xyz MaxDiff2.3506 Å正常(见分析)

MaxDiff 2.35 Å 分析:出现在 Residue 46 的 backbone 氧原子(O),是单个原子的离群值。Backbone 氧原子对二面角微小变化高度敏感,在 10 步扩散模型的 FP32 浮点误差累积下属正常范围。整体 RMSD 仅 0.139 Å,侧链精度极高(0.070 Å),不影响精度判定。

5.3.5 Backbone vs Sidechain 分析

部位RMSD (Å)MaxDiff (Å)
Backbone (N, CA, C, O)0.36522.3506
Sidechain (4+)0.07031.1843

5.3.6 收敛性

轨迹Step 1 RMSDStep 10 RMSD判定
pX01.7390 Å0.3206 ÅPASS(递减)
Denoised1.7835 Å0.1386 ÅPASS(递减)

5.4 NPU 资源使用

指标数值
HBM 总量64 GB
推理后 HBM无泄漏
连续推理稳定性多次推理无崩溃
NPU 与 CPU 输入一致性0.000000 Å
NPU 与 CPU 最终 RMSD0.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,是更安全的标准模式。