跳转到主要内容

这是本节的多页打印视图。

返回本页常规视图

参考手册

配置格式说明、Python 下载与加载接口、评测命令行、许可证与引用信息。

本节列出 checkpoint 配置格式、Python 加载接口、CPU 评测命令行与发布许可的精确说明。

1 - config.json 配置规范

已发布 sage-projector-v1 checkpoint 配置与 TrainKit 导出配置的字段说明。

每个已发布组件目录都包含 projector.safetensors 和一个遵循 format_version: "sage-projector-v1" 的 config.json。

顶层字段

字段说明
format_version格式版本标识,当前为 "sage-projector-v1"。
component_type组件类型,值为 "scientific_projector"。
task与仓库索引对应的任务标识(例如 "cif/jarvis"、"eeg/neu06")。
weights同目录下的权重文件名,值为 "projector.safetensors"。
projector供 modeling_projector.build 读取的架构配置对象(见下表)。
output_dim目标语言模型输入嵌入维度(例如 4096)。
base_model对象,包含 repo_id、revision、dtype 与 training_fingerprint。
prompt提示词渲染布局:system、names、template_kwargs、include_reasoning 与 atom_numbering。
scientific_inputs数组,每项包含 encoder、preprocessing、representation(feature_dim、modality、rows、maximum_tokens)、scientific_readout 与 side_features_per_object。
training_step导出该 checkpoint 时的整数训练步数。
training可选溯源字段,由 TrainKit 导出写入(包含 step、export、xtuner_revision、initialized_from、trainable_parameters,以及配方记录的学习率、尺寸配置、清单版本与 dataset.json / features.json 溯源信息)。

projector 字段说明

当前已发布的九个 checkpoint 均采用 kind: "atom"。结合已发布配置与 modeling_projector.build,各字段含义如下:

字段适用范围说明
id通用(atom)架构标识(例如 "scientific-cif-positions")。
kind通用"atom"、"atom-set",或非以上两者时退回 lead projector。
modality通用(atom)模态标识(例如 "cif"、"eeg"、"spectra")。
feature_dim通用每个科学 token 或原子的输入特征维度。
tokensLead / atomatom 配置为 null;LeadProjector 为整数槽位数。
hidden_dim通用(atom / Lead)MLP 隐藏层宽度。
index_dim通用(atom / atom-set)可学习位置嵌入宽度(atom_index)。
max_atoms通用(atom / atom-set)atom_index 的最大位置槽位数。
discrete_sizes、discrete_dim可选(atom)逐原子离散属性嵌入表大小与嵌入维度(例如 spectra/qm9s:[3]、16)。
side_dim、side_hidden_dim可选(atom)逐对象侧特征宽度与侧通道 MLP 隐藏宽度(例如 protein-seq/mpbind:2 / 128;rna/ncrna:13 / 128)。
task_head_outputs可选辅助任务头输出维度(protein-seq/mpbind、protein-struct/psr 为 1)。
readout_classes、readout_uses_side可选(atom)预训练科学分类读出类别数及是否拼接侧特征(protein-seq/mpbind:1、false)。
output_scale、depth、block_mult、block_exit_norm可选输出 L2 范数缩放及残差 MLP 块相关参数。
graph_layers、graph_hidden_dim可选(atom)基于图边与键类型的键消息残差层参数。
context_layers、context_dim、context_heads可选(atom)对象内部 Transformer 上下文残差层参数。
model_dim、layers、heads、ffn_dimatom-setAtomSetProjector 的 Transformer 编码器参数。

示例(cif/jarvis/config.json)

{
  "format_version": "sage-projector-v1",
  "component_type": "scientific_projector",
  "task": "cif/jarvis",
  "weights": "projector.safetensors",
  "projector": {
    "hidden_dim": 1024,
    "id": "scientific-cif-positions",
    "kind": "atom",
    "modality": "cif",
    "feature_dim": 64,
    "tokens": null,
    "index_dim": 32,
    "max_atoms": 512
  },
  "output_dim": 4096,
  "base_model": {
    "repo_id": "zai-org/GLM-5.3-Flash-BF16",
    "revision": "f9fed3bbc82291073373d67452e9f25317ef7577",
    "dtype": "bfloat16",
    "training_fingerprint": "5113ec01897c403098c40c38c897d9abb67222ec5caca80a862129037b30e6ea"
  },
  "prompt": {
    "system": "You are reading one crystal. Answer from the supplied scientific payload. Give brief reasoning and then the requested answer format.",
    "names": [["crystal"], ["First crystal", "Second crystal"]],
    "template_kwargs": { "reasoning_effort": "low" },
    "include_reasoning": true,
    "atom_numbering": false
  },
  "scientific_inputs": [
    {
      "encoder": {
        "name": "chgnet-0.3.0",
        "checkpoint_sha256": "d14ab7c0f093efe64b60a7bcd540bca10e74fb7f46c86108a079af60524659d1",
        "states": "one 64-dimensional state per atom entering the energy MLP; 6/3 angstrom cutoffs"
      },
      "preprocessing": null,
      "representation": {
        "feature_dim": 64,
        "modality": "cif",
        "rows": 60698,
        "maximum_tokens": 140
      },
      "scientific_readout": null,
      "side_features_per_object": false
    }
  ],
  "training_step": 2822
}

2 - load_projector 接口

仓库根目录 load_projector.py 与 modeling_projector.py 提供的命令行和 Python 接口。

load_projector.py 与 modeling_projector.py 位于仓库根目录,提供命令行下载工具和 Python 加载接口。

命令行下载

python load_projector.py <projector_id> [--repo-id REPO_ID] [--revision REVISION] [--local-dir PATH]
参数 / 选项默认值说明
projector_id—(必填)Hugging Face 根 config.json 中以 backbone/modality/task 形式列出的组件 ID(例如 glm-5.3-flash/cif/jarvis)。
--repo-idinternlm/Sage-SciPerceptionHugging Face 仓库 ID。
--revisionmain用于解析索引的分支、tag 或 commit revision。
--local-dirNone可选本地目标目录;设置后会将根 config.json 与组件文件写入该目录。

命令会在标准输出打印下载后的本地组件目录路径。

Python 函数(load_projector.py)

download_projector

download_projector(
    projector_id,
    repo_id="internlm/Sage-SciPerception",
    revision="main",
    local_dir=None,
    cache_dir=None,
) -> Path

先按 revision 获取根 config.json,读取 index["projectors"][projector_id],再将后续组件 config.json 与 weights 下载固定到同一解析快照(index_path.parent.name)。若传入 local_dir,根 config.json 也会一并保存到 local_dir。返回组件目录的 Path 对象。

load_projector

load_projector(directory, device="cpu") -> tuple[nn.Module, dict]

从 directory 读取 config.json,调用 modeling_projector.build(config["projector"], config["output_dim"]) 构建模型,通过 safetensors.torch.load_file(..., device="cpu") 以 strict=True 加载 config["weights"],再将模型迁移至 device 并设为 .requires_grad_(False).eval(),返回 (model, config)。

from load_projector import download_projector, load_projector

component_dir = download_projector("glm-5.3-flash/cif/jarvis", local_dir="./checkpoints")
projector, config = load_projector(component_dir, device="cpu")

模型辅助函数(modeling_projector.py)

函数说明
build(spec, output_dim, *, train_core=False, train_side_only=False) -> nn.Module根据 config["projector"] 构建 AtomProjector、AtomSetProjector 或 LeadProjector,并按配置挂载可选子模块(task_head、readout、side、graph、context)。
load_initial(model, state)用核心权重初始化 AtomProjector,并校验可选前缀(graph.、task_head.、side.、context.、readout.)要么全部存在、要么全部缺失,防止部分加载。

3 - scip-eval 命令行

EvalKit 评测命令行参数、输出 JSON 结构与 Python 评分接口说明。

scip-eval 是 EvalKit 的命令行入口。评分仅需 Python 3.12+ 与 uv,在 CPU 上运行,无需 torch、transformers 或网络连接。

基本用法

uv run --project evalkit scip-eval --version
uv run --project evalkit scip-eval score --task <TASK> --references <PATH> --responses <PATH> [--out-dir <PATH>] [--only-responded] [--workers <N>]

--dataset 可作为 --task 的别名使用。当前包版本为 0.1.0。

scip-eval score 参数

选项必填说明
--task、--dataset是evalkit.datasets.DATASETS 中注册的任务 ID:atom3d-psr、beacon-ncrna、gue-splice、llm4mat-jarvis、mpbind-ba1、qm9s-allspectra、scits-neu06、scits-phu01、simxrd-ol。详见已注册数据集。
--references是冻结参考集文件或目录路径(例如 SciTS meta_data.jsonl)。
--responses是预测结果 JSONL 路径,每行包含 eval_id、content 及可选 status、run_id。
--out-dir否输出目录;指定后写入 summary.json 与 scores.jsonl。
--only-responded否仅对 --responses 中出现的冻结 ID 计分,并将 scope 标记为子集。默认对全部冻结 ID 计分,缺失 ID 按空内容处理。
--workers否并行指标数据集(如 qm9s-allspectra)的工作进程数(默认:1)。

大多数数据集在 CPU 上仅依赖 Python 3.12 标准库;可选运行时依赖适用于 atom3d-psr(scipy,仅原始 LMDB 输入提取需 lmdb)与 qm9s-allspectra(rdkit、myopic-mces、pulp)。命令执行后会在标准输出打印 summary.json 的内容。

输出结构

指定 --out-dir 时,evalkit.score.write_outputs 会写入两个文件。其中信封字段(task、dataset、protocol、source、references_sha256、scope、responses、run)在所有数据集间共享,协议元信息、指标键名与逐题字段按数据集协议区分(以下以 scits-neu06 为例):

  • summary.json:顶层字段包含 task、dataset、protocol、source、classes、references_sha256、rules、scope、responses(path、unique_ids、superseded_records、unexpected_ids)、run(bound、run_id、unbound_records)、rows、macro_f1、accuracy、correct、invalid、missing、statuses 与 per_class。
  • scores.jsonl:每行对应一条受评样本,包含 eval_id、reference、prediction、valid、correct 与 status。

Python 接口

from pathlib import Path
from evalkit.score import score_files, write_outputs

result = score_files(
    "scits-neu06",
    Path("/path/to/SciTS/meta_data.jsonl"),
    Path("/path/to/run/responses.jsonl"),
    only_responded=False,
    workers=1,
)
write_outputs(result, Path("/path/to/run/score"))

evalkit.contract.read_predictions 会校验运行一致性:如果单个 JSONL 文件混有多个 run_id,或同时包含带 run_id 与不带 run_id 的记录,读取阶段会直接报错拒绝聚合。

训练预检命令行

TrainKit 还提供 scip-train preflight,用于在 CPU 上统计 token 长度、XTuner 打包与 collator 对齐情况(scip-train neu06-preflight 作为别名保留)。详见训练指南。

4 - 许可证与引用

Apache License 2.0 许可条款、上游依赖说明与 BibTeX 引用格式。

许可证

书生·元征(Sage-SciPerception)采用 Apache License 2.0(Apache-2.0)开源。完整条款见仓库根目录的 LICENSE。

上游数据集、底座语言模型与科学编码器仍分别遵循各自的原许可证,例如 OpenTSLab/SciTS(CC-BY-NC-SA-4.0)以及 brain-bzh/reve-base(REVE Responsible Use License v1.0)。

引用

如果你在研究或项目中使用了书生·元征(Sage-SciPerception),请按仓库中的 CITATION.cff 引用:

@misc{sage_sciperception,
  author       = {{InternLM}},
  title        = {{Sage-SciPerception}},
  version      = {0.1.0},
  note         = {GitHub repository},
  year         = {2026},
  url          = {https://github.com/InternLM/Sage-SciPerception}
}