Skip to content

支持matinvent#256

Open
learncat163 wants to merge 1 commit intoPaddlePaddle:developfrom
learncat163:pr-ad-matinvent
Open

支持matinvent#256
learncat163 wants to merge 1 commit intoPaddlePaddle:developfrom
learncat163:pr-ad-matinvent

Conversation

@learncat163
Copy link
Copy Markdown

新增 MatInvent

1. 概述

本 PR 新增 MatInvent 模块,将原 PyTorch 版本的晶体材料生成框架迁移至 PaddleMaterials

2. 主要改动

新增模型模块

  • ppmat/models/matinvent/ - MatInvent 实现
    • rl/ - 强化学习核心(采样器、训练工具、模型套件)
    • rewards/ - 奖励系统及性质计算器(PyMatGen),其他的奖励机制部分不适用
    • memory/ - 回放缓冲区与长期记忆模块

支持的骨干网络

  • DiffCSP: 基于扩散的晶体结构预测
  • MatterGen: 预训练材料生成模型

配置文件

  • structure_generation/configs/matinvent/ - 两种骨干网络的训练配置

测试文件

  • test/matinvent/ - Paddle 与 PyTorch 输出对齐测试
    • 前向传播 logits 对比
    • 训练损失对齐
    • 采样指标验证

3. 使用方法

1. RL

# MatterGen 骨干网络
python structure_generation/train.py \
    --config structure_generation/configs/matinvent/matinvent_mattergen.yaml

# DiffCSP 骨干网络
python structure_generation/train.py \
    --config structure_generation/configs/matinvent/matinvent_diffcsp.yaml

2. 采样

# 使用预训练模型
python structure_generation/sample.py \
    --config_path structure_generation/configs/matinvent/matinvent_mattergen.yaml \
    --checkpoint_path ./output/matinvent_diffcsp/models/final/model.pdparams \
    --save_path results/matinvent_mattergen \
    --mode by_dataloader

# 使用 RL 微调后的模型 
python structure_generation/sample.py \
    --config_path structure_generation/configs/matinvent/matinvent_mattergen.yaml \
    --checkpoint_path output/matinvent_mattergen/models/final/model.pdparams \
    --save_path results/matinvent_mattergen_rl \
    --mode by_dataloader

对于 DiffCSP 骨干网络,只需将配置文件替换为 matinvent_diffcsp.yaml

4. 预训练权重

一般不需要单独手动下载,运行测试脚本 test/matinvent/matinvent_test.py 会自动下载。如果确实网络原因,手动下载,如下:

  1. 在 AI Studio 上可下载:https://aistudio.baidu.com/modelsdetail/44805/space paddle版本的模型。或者通过 http下载: wget https://paddle-org.bj.bcebos.com/paddlematerials/checkpoints/structure_generation/MatInvert/matinvent_diffcsp_mp20.pdparams
    wget https://paddle-org.bj.bcebos.com/paddlematerials/checkpoints/structure_generation/MatInvert/matinvent_mattergen_mp20.pdparams ;下载之后不需要重命名

  2. 原版的模型在HuggingFace 上,需要自己解决 export HF_ENDPOINT=https://hf-mirror.com 的问题,地址:diffcsp.ckpt 来自 https://huggingface.co/jwchen25/MatInvent/diffcsp_mp20/last.ckp mattergen.ckpt 来自 https://huggingface.co/jwchen25/MatInvent/mattergen_base/last.ckpt ; 下载之后重命名为 raw-diffcsp.ckpt 和 raw-mattergen.ckpt

下载好的权重放在 ~/.paddlemat/weights/matinvent 目录下即可

5. 测试结果

测试脚本: test/matinvent/matinvent_test.py

测试说明:test/matinvent/README.md

特别说明:因为 MatInvent 原版代码硬编码了噪声发生器的代码,而且无法通过配置修改。只能进行了monkey patch,patch住了噪声发生器。否则对齐测试无法完成。

模型 前向Logits 训练对齐 采样指标 整体
diffcsp PASS PASS PASS PASS
mattergen PASS PASS PASS PASS
rl PASS PASS PASS PASS
matinvent PASS PASS PASS PASS

详细结果

diffcsp

  • forward_logits: (value=4.54e-06, threshold=1.00e-04)
  • training_alignment: (value=7.20e-06, threshold=1.00e-03)
  • sampling_metrics: (value=1.29e-04, threshold=5.00e-02)

mattergen

  • forward_logits: (value=2.67e-05, threshold=1.00e-06)
  • training_alignment: (value=2.57e-02, threshold=5.00e-02)
  • sampling_metrics: (value=0.00e+00, threshold=5.00e-02)

rl

  • forward_logits: (value=4.82e-06, threshold=1.00e-04)
  • training_alignment: (value=6.61e-06, threshold=1.00e-03)
  • sampling_metrics: (value=1.64e-04, threshold=5.00e-02)

matinvent

  • forward_logits: (value=5.28e-06, threshold=1.00e-04)
  • training_alignment: (value=6.56e-06, threshold=1.00e-03)
  • sampling_metrics: (value=9.23e-05, threshold=5.00e-02)

@paddle-bot
Copy link
Copy Markdown

paddle-bot bot commented Mar 25, 2026

Thanks for your contribution!

@paddle-bot paddle-bot bot added the contributor External developers label Mar 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor External developers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant