44 lines
1.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 离线预训练分子 embedding
三个预训练编码器作为额外的 chemical token 接入模型。embedding 离线生成、
存为 `.npy`(按 csv 行顺序对齐),训练时通过 `{smiles: vector}` 查表注入。
npy 文件与预训练权重不入库,运行下列脚本可复现。
## MolFormer (768d)
`ibm/MoLFormer-XL-both-10pct`HuggingFace 直接加载。
注意:需 transformers>=4.57(依赖 `transformers.masking_utils`
与项目 pin 的 4.45 冲突,建议装到独立目录后用 sys.path 隔离。
`encode_molformer.py`
## GraphMVP (300d)
ICLR'225 层 GIN + OGB AtomEncoder/BondEncoder。
权重https://github.com/chao1224/GraphMVP → Drive 文件夹
`GraphMVP_complate_features_for_regression/GraphMVP/pretraining_model.pth`
注意:新版 OGB 的 chirality 类别数为 5checkpoint 为 4加载时按形状逐层对齐。
`encode_graphmvp.py`
## GROVER (3200d = atom 1600 + bond 1600)
NeurIPS'20dualtrans (hidden 800, depth 6)。
代码https://github.com/tencent-ailab/grover权重 grover_base。
原项目基于 Python 3.6.8 / PyTorch 1.1,在现代环境需两处补丁:
1. `grover/util/utils.py``torch.load``weights_only=False`
2. `build_model` 前用 checkpoint 自带 args 补齐 current_args 缺失字段,
并为 dropout 等推理期字段提供默认值
`encode_grover.py`
## 使用
```bash
python -m lnp_ml.modeling.pretrain main --device cuda \
--output-dir models/pretrain/<name> \
--<name>-emb data/interim/<name>_emb_external.npy \
--<name>-csv data/external/all_data_LiON.csv
python -m lnp_ml.modeling.nested_cv_optuna \
--device cuda --n-trials 15 --epochs-per-trial 30 --n-repeats 3 --seed 42 \
--<name>-emb data/interim/<name>_emb.npy \
--<name>-csv data/interim/internal.csv \
--init-from-pretrain models/pretrain/<name>/pretrain_delivery.pt \
--output-dir models/full/<name>_s42
```