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-botdelolivier141-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__.pyfromppmat.models.transpolymerimportTransPolymerRegressor

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

# ppmat/datasets/__init__.pyfromppmat.datasets.transpolymer_datasetimportTransPolymerCsvDatasetfromppmat.datasets.transpolymer_datasetimporttranspolymer_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.

}


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-botdelolivier141-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 人工看下

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;

@leeleolayleeleolay 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都有实现了

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.

这个url怎么获取呢,url需要支持下载的包括些什么文件呢?模型权重?数据集?

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.

“build molecule和build sequence”是指dataset 支持 build_molecule_cfg,返回 molecule还是说参考 mp20 的“build/cache”模式,不强制返回 molecule

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.

数据和模型权重可以百度网盘的形式发给我,我上传到bce后给你url,注意相关文件的格式

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.

通过网盘分享的文件:transpolymer_artifacts.tar
链接: https://pan.baidu.com/s/14Y1Tt8eVngPz42Qf7VVO0A 提取码: 1227
您看这样可以不

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.

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.

您说的权重格式具体指什么呢,我看您这个参考链接里给的是训练后的权重和log,我给的是预训练模型权重,还是说意思是要建一个checkpoints文件夹,把预训练模型权重放这个里面?

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.

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 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 freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@delolivier141-bot@CLAassistant@leeleolay
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
【MIIT program】add TransPolymer models by delolivier141-bot · Pull Request #296 · PaddlePaddle/PaddleMaterials · GitHub
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-botdelolivier141-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__.pyfromppmat.models.transpolymerimportTransPolymerRegressor

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

# ppmat/datasets/__init__.pyfromppmat.datasets.transpolymer_datasetimportTransPolymerCsvDatasetfromppmat.datasets.transpolymer_datasetimporttranspolymer_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.

}


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-botdelolivier141-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 人工看下

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;

@leeleolayleeleolay 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都有实现了

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.

这个url怎么获取呢,url需要支持下载的包括些什么文件呢?模型权重?数据集?

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.

“build molecule和build sequence”是指dataset 支持 build_molecule_cfg,返回 molecule还是说参考 mp20 的“build/cache”模式,不强制返回 molecule

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.

数据和模型权重可以百度网盘的形式发给我,我上传到bce后给你url,注意相关文件的格式

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.

通过网盘分享的文件:transpolymer_artifacts.tar
链接: https://pan.baidu.com/s/14Y1Tt8eVngPz42Qf7VVO0A 提取码: 1227
您看这样可以不

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.

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.

您说的权重格式具体指什么呢,我看您这个参考链接里给的是训练后的权重和log,我给的是预训练模型权重,还是说意思是要建一个checkpoints文件夹,把预训练模型权重放这个里面?

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.

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 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 freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@delolivier141-bot@CLAassistant@leeleolay
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' 【MIIT program】add TransPolymer models by delolivier141-bot · Pull Request #296 · PaddlePaddle/PaddleMaterials · GitHub
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-botdelolivier141-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__.pyfromppmat.models.transpolymerimportTransPolymerRegressor

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

# ppmat/datasets/__init__.pyfromppmat.datasets.transpolymer_datasetimportTransPolymerCsvDatasetfromppmat.datasets.transpolymer_datasetimporttranspolymer_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.

}


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-botdelolivier141-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 人工看下

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;

@leeleolayleeleolay 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都有实现了

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.

这个url怎么获取呢,url需要支持下载的包括些什么文件呢?模型权重?数据集?

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.

“build molecule和build sequence”是指dataset 支持 build_molecule_cfg,返回 molecule还是说参考 mp20 的“build/cache”模式,不强制返回 molecule

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.

数据和模型权重可以百度网盘的形式发给我,我上传到bce后给你url,注意相关文件的格式

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.

通过网盘分享的文件:transpolymer_artifacts.tar
链接: https://pan.baidu.com/s/14Y1Tt8eVngPz42Qf7VVO0A 提取码: 1227
您看这样可以不

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.

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.

您说的权重格式具体指什么呢,我看您这个参考链接里给的是训练后的权重和log,我给的是预训练模型权重,还是说意思是要建一个checkpoints文件夹,把预训练模型权重放这个里面?

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.

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 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 freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@delolivier141-bot@CLAassistant@leeleolay
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' 【MIIT program】add TransPolymer models by delolivier141-bot · Pull Request #296 · PaddlePaddle/PaddleMaterials · GitHub
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-botdelolivier141-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__.pyfromppmat.models.transpolymerimportTransPolymerRegressor

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

# ppmat/datasets/__init__.pyfromppmat.datasets.transpolymer_datasetimportTransPolymerCsvDatasetfromppmat.datasets.transpolymer_datasetimporttranspolymer_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.

}


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-botdelolivier141-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 人工看下

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;

@leeleolayleeleolay 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都有实现了

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.

这个url怎么获取呢,url需要支持下载的包括些什么文件呢?模型权重?数据集?

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.

“build molecule和build sequence”是指dataset 支持 build_molecule_cfg,返回 molecule还是说参考 mp20 的“build/cache”模式,不强制返回 molecule

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.

数据和模型权重可以百度网盘的形式发给我,我上传到bce后给你url,注意相关文件的格式

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.

通过网盘分享的文件:transpolymer_artifacts.tar
链接: https://pan.baidu.com/s/14Y1Tt8eVngPz42Qf7VVO0A 提取码: 1227
您看这样可以不

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.

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.

您说的权重格式具体指什么呢,我看您这个参考链接里给的是训练后的权重和log,我给的是预训练模型权重,还是说意思是要建一个checkpoints文件夹,把预训练模型权重放这个里面?

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.

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 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 freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@delolivier141-bot@CLAassistant@leeleolay
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' 【MIIT program】add TransPolymer models by delolivier141-bot · Pull Request #296 · PaddlePaddle/PaddleMaterials · GitHub
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-botdelolivier141-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__.pyfromppmat.models.transpolymerimportTransPolymerRegressor

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

# ppmat/datasets/__init__.pyfromppmat.datasets.transpolymer_datasetimportTransPolymerCsvDatasetfromppmat.datasets.transpolymer_datasetimporttranspolymer_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.

}


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-botdelolivier141-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 人工看下

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;

@leeleolayleeleolay 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都有实现了

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.

这个url怎么获取呢,url需要支持下载的包括些什么文件呢?模型权重?数据集?

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.

“build molecule和build sequence”是指dataset 支持 build_molecule_cfg,返回 molecule还是说参考 mp20 的“build/cache”模式,不强制返回 molecule

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.

数据和模型权重可以百度网盘的形式发给我,我上传到bce后给你url,注意相关文件的格式

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.

通过网盘分享的文件:transpolymer_artifacts.tar
链接: https://pan.baidu.com/s/14Y1Tt8eVngPz42Qf7VVO0A 提取码: 1227
您看这样可以不

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.

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.

您说的权重格式具体指什么呢,我看您这个参考链接里给的是训练后的权重和log,我给的是预训练模型权重,还是说意思是要建一个checkpoints文件夹,把预训练模型权重放这个里面?

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.

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 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 freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@delolivier141-bot@CLAassistant@leeleolay
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' 【MIIT program】add TransPolymer models by delolivier141-bot · Pull Request #296 · PaddlePaddle/PaddleMaterials · GitHub
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-botdelolivier141-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__.pyfromppmat.models.transpolymerimportTransPolymerRegressor

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

# ppmat/datasets/__init__.pyfromppmat.datasets.transpolymer_datasetimportTransPolymerCsvDatasetfromppmat.datasets.transpolymer_datasetimporttranspolymer_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.

}


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-botdelolivier141-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 人工看下

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;

@leeleolayleeleolay 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都有实现了

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.

这个url怎么获取呢,url需要支持下载的包括些什么文件呢?模型权重?数据集?

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.

“build molecule和build sequence”是指dataset 支持 build_molecule_cfg,返回 molecule还是说参考 mp20 的“build/cache”模式,不强制返回 molecule

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.

数据和模型权重可以百度网盘的形式发给我,我上传到bce后给你url,注意相关文件的格式

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.

通过网盘分享的文件:transpolymer_artifacts.tar
链接: https://pan.baidu.com/s/14Y1Tt8eVngPz42Qf7VVO0A 提取码: 1227
您看这样可以不

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.

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.

您说的权重格式具体指什么呢,我看您这个参考链接里给的是训练后的权重和log,我给的是预训练模型权重,还是说意思是要建一个checkpoints文件夹,把预训练模型权重放这个里面?

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.

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 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 freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@delolivier141-bot@CLAassistant@leeleolay
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' 【MIIT program】add TransPolymer models by delolivier141-bot · Pull Request #296 · PaddlePaddle/PaddleMaterials · GitHub
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-botdelolivier141-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__.pyfromppmat.models.transpolymerimportTransPolymerRegressor

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

# ppmat/datasets/__init__.pyfromppmat.datasets.transpolymer_datasetimportTransPolymerCsvDatasetfromppmat.datasets.transpolymer_datasetimporttranspolymer_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.

}


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-botdelolivier141-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 人工看下

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;

@leeleolayleeleolay 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都有实现了

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.

这个url怎么获取呢,url需要支持下载的包括些什么文件呢?模型权重?数据集?

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.

“build molecule和build sequence”是指dataset 支持 build_molecule_cfg,返回 molecule还是说参考 mp20 的“build/cache”模式,不强制返回 molecule

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.

数据和模型权重可以百度网盘的形式发给我,我上传到bce后给你url,注意相关文件的格式

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.

通过网盘分享的文件:transpolymer_artifacts.tar
链接: https://pan.baidu.com/s/14Y1Tt8eVngPz42Qf7VVO0A 提取码: 1227
您看这样可以不

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.

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.

您说的权重格式具体指什么呢,我看您这个参考链接里给的是训练后的权重和log,我给的是预训练模型权重,还是说意思是要建一个checkpoints文件夹,把预训练模型权重放这个里面?

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.

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 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 freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@delolivier141-bot@CLAassistant@leeleolay
, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })(); 【MIIT program】add TransPolymer models by delolivier141-bot · Pull Request #296 · PaddlePaddle/PaddleMaterials · GitHub
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-botdelolivier141-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__.pyfromppmat.models.transpolymerimportTransPolymerRegressor

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

# ppmat/datasets/__init__.pyfromppmat.datasets.transpolymer_datasetimportTransPolymerCsvDatasetfromppmat.datasets.transpolymer_datasetimporttranspolymer_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.

}


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-botdelolivier141-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 人工看下

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;

@leeleolayleeleolay 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都有实现了

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.

这个url怎么获取呢,url需要支持下载的包括些什么文件呢?模型权重?数据集?

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.

“build molecule和build sequence”是指dataset 支持 build_molecule_cfg,返回 molecule还是说参考 mp20 的“build/cache”模式,不强制返回 molecule

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.

数据和模型权重可以百度网盘的形式发给我,我上传到bce后给你url,注意相关文件的格式

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.

通过网盘分享的文件:transpolymer_artifacts.tar
链接: https://pan.baidu.com/s/14Y1Tt8eVngPz42Qf7VVO0A 提取码: 1227
您看这样可以不

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.

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.

您说的权重格式具体指什么呢,我看您这个参考链接里给的是训练后的权重和log,我给的是预训练模型权重,还是说意思是要建一个checkpoints文件夹,把预训练模型权重放这个里面?

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.

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 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 freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@delolivier141-bot@CLAassistant@leeleolay