Skip to content

【MIIT program】add TransPolymer models #296

Open
delolivier141-bot wants to merge 7 commits into
PaddlePaddle:developfrom
delolivier141-bot:develop
Open

【MIIT program】add TransPolymer models #296
delolivier141-bot wants to merge 7 commits into
PaddlePaddle:developfrom
delolivier141-bot:develop

Conversation

@delolivier141-bot

@delolivier141-bot delolivier141-bot commented Jun 22, 2026

Copy link
Copy Markdown

1. 概述

本 PR 新增 TransPolymer 在 PaddleMaterials 中的支持,用于聚合物性质预测任务。

TransPolymer 是一个基于 RoBERTa 结构的聚合物序列语言模型,可通过预训练聚合物序列表示,并在下游聚合物性质预测任务中进行微调。本 PR 提供 Paddle 版本模型实现、PE-I 下游微调配置、数据集适配、tokenizer、预训练权重加载方式以及最小 smoke test。

2. 本 PR 合入内容

2.1 模型实现

新增模型文件:

ppmat/models/transpolymer/
  __init__.py
  modeling.py
  tokenizer.py
  transpolymer.py

主要包含:

  • RobertaModel
  • RobertaForMaskedLM
  • TransPolymerRegressor
  • PolymerSmilesTokenizer

2.2 数据集适配

新增 PE-I CSV 数据集适配:

ppmat/datasets/transpolymer_dataset.py

支持:

  • 读取聚合物序列 CSV 文件
  • 对聚合物字符串进行 tokenizer 编码
  • 返回 input_idsattention_mask 和回归标签
  • 支持 PE-I supplementary vocabulary

2.3 训练入口

新增 TransPolymer 专用训练入口:

property_prediction/transpolymer_train.py

说明:当前 PaddleMaterials 的通用 property_prediction/train.py 主要面向图结构模型;TransPolymer 输入是 tokenized polymer strings,因此本 PR 暂时提供任务专用训练入口。同时,模型和数据集仍放入 ppmat/modelsppmat/datasets,方便后续继续接入统一 Trainer。

2.4 配置与文档

新增 PE-I 微调配置和说明文档:

property_prediction/configs/transpolymer/
  README.md
  transpolymer_pe_i_finetune.yaml

2.5 测试

新增最小 smoke test:

test/test_transpolymer_smoke.py

覆盖:

  • TransPolymer encoder 最小前向
  • TransPolymer regressor 最小前向

3. 文件放置位置

本 PR 新增文件包括:

ppmat/models/transpolymer/*
ppmat/datasets/transpolymer_dataset.py
property_prediction/transpolymer_train.py
property_prediction/configs/transpolymer/*
test/test_transpolymer_smoke.py

需要在模型注册处补充:

# ppmat/models/__init__.py
from ppmat.models.transpolymer import TransPolymerRegressor

需要在数据集注册处补充:

# ppmat/datasets/__init__.py
from ppmat.datasets.transpolymer_dataset import TransPolymerCsvDataset
from ppmat.datasets.transpolymer_dataset import transpolymer_collate_fn

4. 数据集与预训练权重

PE-I 数据集和转换后的 Paddle 预训练权重已打包到外部链接:

链接:https://pan.baidu.com/s/1wPVmTP1H0x3qSZi8HV0r9g
提取码:1227

压缩包结构:

transpolymer_artifacts/data/train_PE_I.csv
transpolymer_artifacts/data/test_PE_I.csv
transpolymer_artifacts/data/vocab/vocab_sup_PE_I.csv
transpolymer_artifacts/ckpt/pretrain.pt/config.json
transpolymer_artifacts/ckpt/pretrain.pt/model_state.pdparams

下载后请放到 PaddleMaterials 根目录下:

data/train_PE_I.csv
data/test_PE_I.csv
data/vocab/vocab_sup_PE_I.csv
ckpt/pretrain.pt/config.json
ckpt/pretrain.pt/model_state.pdparams

5. 运行方式

在 PaddleMaterials 根目录执行:

python property_prediction/transpolymer_train.py \
  -c property_prediction/configs/transpolymer/transpolymer_pe_i_finetune.yaml

运行 smoke test:

python -m pytest test/test_transpolymer_smoke.py

6. 验证环境

已验证环境:

Python 3.10
paddlepaddle-gpu 3.3.1,CUDA 11.8 wheel
NVIDIA RTX 4090
NVIDIA Driver 550.142

7. 验证结果

7.1 PyTorch / Paddle 前向一致性

转换 PyTorch checkpoint 后,与原始 PyTorch 模型进行 forward parity 检查:

MAX_TOKEN_DIFF = 0
MAX_LOGIT_DIFF = 9.5367432e-06

7.2 PE-I 下游微调结果

本地 Paddle 结果:

test RMSE = 0.8993
test R2   = 0.4508

同一服务器环境下 PyTorch baseline:

test RMSE = 0.9813
test R2   = 0.3461

论文参考结果:

test RMSE 约为 0.67
test R2   约为 0.69

当前 Paddle 版本结果已达到与本地 PyTorch baseline 同量级,但与论文报告结果仍存在一定差距。后续可继续对齐原始依赖版本、训练细节和多 seed 结果。

8. 迁移与修复说明

本次 Paddle 迁移过程中已验证并修复以下关键问题:

  • 去除 Paddle Embedding(padding_idx=...) 的运行时 padding 输出置零行为,以对齐 HuggingFace/PyTorch checkpoint 行为。
  • 修复 Paddle optimizer 参数组学习率缩放逻辑,避免实际学习率过小。
  • 修复 supplementary vocabulary 的 tokenizer 行为,在 BPE 前进行 added tokens 最长匹配,以对齐 HuggingFace tokenizer。
  • 支持加载转换后的 Paddle checkpoint。
  • 补充 PE-I 数据集读取、训练配置、README 和 smoke test。

9. 说明

大体积数据集和模型权重未直接提交到仓库,已通过外部链接提供。后续如需正式合入,可由 reviewer 上传至 BCE,并将 README 中的数据和权重链接替换为 BCE 链接。

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Comment thread ppmat/datasets/transpolymer_dataset.py Outdated
}


def transpolymer_collate_fn(batch):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

辛苦使用默认的ppmat/dataset/collator_fn

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

参考已有的model readme格式,完整的训练log,结果

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

添加模型图在abstract里

PE-I test R2: 0.4508
```

Local PyTorch baseline in the same server environment:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pr中声明精度对齐结果即可,不在该文件中显示

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

按照套件的规范进行些config

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

使用已有的trainer

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

参考dataset_mp20的格式和规范

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

以上修改都改了

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

实现cache功能

@delolivier141-bot delolivier141-bot changed the title transpolymer模型复现 【MIIT program】add TransPolymer models Jun 22, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为什么不使用已有的train.py?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@delolivier141-bot 人工看下

Comment thread ppmat/datasets/transpolymer_dataset.py Outdated
import paddle
from paddle.io import Dataset

from ppmat.models.transpolymer.tokenizer import PolymerSmilesTokenizer

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

迁移到model里,dataset里只保留原始数据,并且需实现cache的功能,dataloader只加载数据,不处理embedding向量

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

让 dataset 返回原始 SMILES,把 roberta-base tokenizer 的加载、缓存和编码逻辑放到模型输入处理或 transform 中

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

实现cache功能

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

添加模型图在abstract里

ckpt/pretrain.pt/model_state.pdparams
```

## Environment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

删除

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不够规范,需再修改

and pretrained checkpoints should be uploaded to BCE by the reviewer and the
download links should be filled in here before merge.

## Pretrained Checkpoint

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

删除

<th nowrap="nowrap">GPUs</th>
<th nowrap="nowrap">Training time</th>
<th nowrap="nowrap">Config</th>
<th nowrap="nowrap">Checkpoint | Log</th>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

添加结果链接

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@delolivier141-bot 人工看下

@leeleolay

Copy link
Copy Markdown
Collaborator

提供训练好的预训练模型权重

@leeleolay

Copy link
Copy Markdown
Collaborator

百度网盘的数据不完整

@delolivier141-bot

Copy link
Copy Markdown
Author

提供训练好的预训练模型权重

模型权重也放到百度网盘了,是需要直接传到仓库吗

@leeleolay

Copy link
Copy Markdown
Collaborator

提供训练好的预训练模型权重

模型权重也放到百度网盘了,是需要直接传到仓库吗

需要完整的训练模型的权重和log,预训练模型权重需注册到registry 支持一键推理

@delolivier141-bot

Copy link
Copy Markdown
Author

提供训练好的预训练模型权重

模型权重也放到百度网盘了,是需要直接传到仓库吗

需要完整的训练模型的权重和log,预训练模型权重需注册到registry 支持一键推理

提供训练好的预训练模型权重

模型权重也放到百度网盘了,是需要直接传到仓库吗

需要完整的训练模型的权重和log,预训练模型权重需注册到registry 支持一键推理

但是注册到registry的下载链接我们怎么做呢,或者把训练模型的权重和log放到哪里然后您这边来上传获取下载链接

@leeleolay

Copy link
Copy Markdown
Collaborator

提供训练好的预训练模型权重

模型权重也放到百度网盘了,是需要直接传到仓库吗

需要完整的训练模型的权重和log,预训练模型权重需注册到registry 支持一键推理

提供训练好的预训练模型权重

模型权重也放到百度网盘了,是需要直接传到仓库吗

需要完整的训练模型的权重和log,预训练模型权重需注册到registry 支持一键推理

但是注册到registry的下载链接我们怎么做呢,或者把训练模型的权重和log放到哪里然后您这边来上传获取下载链接

是的,提供给我链接,我会给你上传到网上的链接

@leeleolay

Copy link
Copy Markdown
Collaborator

另外原工作有多个数据,辛苦都实现下

…mer README,补充数据集说明、下载链接、解压路径和结果表;说明预训练权重/数据集与下游训练权重/log 的 artifact 拆分方式;新增预测示例 CSV;

@leeleolay leeleolay left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

重点辛苦修改dataset的规范

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

缺少md5 name url,构建build molecule和build sequence缺失

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

没有cahce的逻辑,已有的mp20都有实现了

from ppmat.models.transpolymer.transpolymer import TransPolymerRegressor

__all__ = [
"RobertaConfig",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的config?

Comment on lines +22 to +49
max_position_embeddings: int = 514
type_vocab_size: int = 1
initializer_range: float = 0.02
layer_norm_eps: float = 1e-12
pad_token_id: int = 1
bos_token_id: int = 0
eos_token_id: int = 2
position_embedding_type: str = "absolute"

@classmethod
def from_dict(cls, values):
fields = cls.__dataclass_fields__
return cls(**{k: v for k, v in values.items() if k in fields})

@classmethod
def from_pretrained(cls, path):
with open(os.path.join(path, "config.json"), "r", encoding="utf-8") as f:
return cls.from_dict(json.load(f))

def to_dict(self):
result = asdict(self)
result["model_type"] = "roberta"
return result

def save_pretrained(self, save_directory):
os.makedirs(save_directory, exist_ok=True)
with open(os.path.join(save_directory, "config.json"), "w", encoding="utf-8") as f:
json.dump(self.to_dict(), f, ensure_ascii=False, indent=2)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不符合套件的逻辑

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

该文件的很多功能套件已有实现,不符合套件风格

Comment on lines +52 to +61
class ModelOutput:
def __init__(self, **kwargs):
self.__dict__.update(kwargs)

def __getitem__(self, item):
values = tuple(v for v in self.__dict__.values() if v is not None)
return values[item]

def __iter__(self):
return iter(tuple(v for v in self.__dict__.values() if v is not None))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread ppmat/utils/save_load.py
Comment on lines +58 to +59
elif "model" in param_state_dict:
param_state_dict = param_state_dict["model"]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

按照已有的命名风格来组织该模型的合入

self.model.eval()

predict_config = config.get("Predict", None)
predict_config = config.get("Predict", None) or {}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +120 to +121
model_params = config.get("Model", {}).get("__init_params__", {})
self.smiles_key = model_params.get("smiles_key", "smiles")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants