yuhangzang commited on
Commit
525c481
·
1 Parent(s): fd0cd31

docs(model-card): improve discovery and inference usage

Browse files
Files changed (5) hide show
  1. .gitignore +7 -0
  2. README.md +136 -24
  3. README_zh.md +130 -24
  4. examples/vllm_cif.py +101 -0
  5. projectors/glm-5.3-flash/README.md +38 -18
.gitignore ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ var/
2
+ output/
3
+ .playwright-cli/
4
+ .cache/
5
+ __pycache__/
6
+ *.py[cod]
7
+ .DS_Store
README.md CHANGED
@@ -2,49 +2,161 @@
2
  language:
3
  - en
4
  - zh
 
5
  tags:
6
  - scientific-perception
7
  - multimodal
8
  - projector
 
 
 
 
 
9
  ---
10
 
11
- <p align="center">
12
- <img src="assets/branding/sage-sciprojector-hero-titled.png" alt="Sage Sci Perception: a young scholar explores scientific representations." width="100%">
13
- </p>
14
-
15
  <h1 align="center">Sage-SciPerception</h1>
16
- <p align="center"><strong>Sage Sci Perception · 书生·元征</strong></p>
17
- <p align="center">Scientific perception for language models.</p>
18
-
19
- <p align="center"><strong>English</strong> · <a href="README_zh.md">简体中文</a></p>
20
 
21
  <p align="center">
 
 
22
  <a href="https://github.com/InternLM/Sage-SciPerception">GitHub</a> ·
23
- <a href="#framework">Framework</a> ·
24
- <a href="#results">Results</a>
25
  </p>
26
 
27
- ## Introduction
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
 
29
- Sage Sci Perception (书生·元征) connects scientific encoders to a language model through trainable projectors. It maps molecular graphs, spectra, crystal structures, protein and nucleic-acid sequences, and scientific signals into the language model's input space, enabling natural-language analysis and structured scientific answers.
30
 
31
- Projectors are organized by language backbone, modality, and task, and used with their corresponding scientific encoders and configurations.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
  ## Framework
34
 
35
  <p align="center">
36
- <img src="assets/framework.gif" alt="Scientific inputs pass through scientific encoders and trainable projectors into a language model." width="100%">
37
  </p>
38
 
39
- ## Results
 
 
40
 
41
- Selected results from task-specific checkpoints, evaluated on generated answers.
42
 
43
- | Benchmark | Task | Metric ↑ | Score |
44
- |---|---|---|---:|
45
- | QM9S | Joint-spectrum structure identification | Acc@1 (%) | **49.75** |
46
- | JARVIS-DFT | Formation-energy prediction | MAD/MAE | **15.03** |
47
- | MPBind, assembly-1 reconstruction | PPI interface sites | Mean per-protein F1 (%) | **61.12** |
48
- | SciTS PHU01 | ECG classification | Macro-F1 (%) | **71.53** |
49
- | SciTS NEU06 | Sleep staging | Macro-F1 (%) | **72.01** |
50
- | BEACON ncRNA | RNA family classification | Accuracy (%) | **97.35** |
 
2
  language:
3
  - en
4
  - zh
5
+ library_name: pytorch
6
  tags:
7
  - scientific-perception
8
  - multimodal
9
  - projector
10
+ - chemistry
11
+ - biology
12
+ - materials-science
13
+ - time-series
14
+ thumbnail: https://huggingface.co/internlm/Sage-SciPerception/resolve/main/assets/branding/sage-sciprojector-hero-titled.png
15
  ---
16
 
 
 
 
 
17
  <h1 align="center">Sage-SciPerception</h1>
18
+ <p align="center"><strong>Scientific perception for language models · 书生·元征</strong></p>
19
+ <p align="center">Connect crystals, spectra, biological sequences, and biosignals to language models through trained projectors.</p>
20
+ <p align="center"><strong>Continuously expanding scientific modalities, tasks, and language model support.</strong></p>
 
21
 
22
  <p align="center">
23
+ <a href="#released-projectors">Get weights</a> ·
24
+ <a href="#inference">Inference</a> ·
25
  <a href="https://github.com/InternLM/Sage-SciPerception">GitHub</a> ·
26
+ <a href="https://huggingface.co/internlm/Sage-SciPerception/blob/main/README_zh.md">简体中文</a>
 
27
  </p>
28
 
29
+ <p align="center">
30
+ <img src="assets/branding/sage-sciprojector-hero-titled.png" alt="Sage Sci Perception: a young scholar explores scientific representations." width="640">
31
+ </p>
32
+
33
+ Sage Sci Perception maps scientific representations into a language model's input space, enabling natural-language analysis and structured scientific answers. Use it to explore interfaces between your scientific workflow and a language model: material property prediction, biomolecular sequence labeling, spectral structure identification, and signal classification.
34
+
35
+ Projectors are organized by modality, task, and language-model version. Start with the available checkpoints below, or use the [inference guide](#inference) to connect projected scientific inputs to a serving workflow. Each checkpoint records its matching language model and input representation in `config.json`.
36
+
37
+ ## Released projectors
38
+
39
+ Open a task to browse its files, or download its weights and configuration directly. Additional modalities, tasks, and compatible language-model versions will be added as the project develops.
40
+
41
+ | Benchmark / task | Metric ↑ | Score | Projector |
42
+ |---|---|---:|---|
43
+ | [JARVIS-DFT](https://huggingface.co/internlm/Sage-SciPerception/tree/main/projectors/glm-5.3-flash/cif/jarvis)<br>Formation energy | MAD/MAE | **15.03** | [Weights](https://huggingface.co/internlm/Sage-SciPerception/resolve/main/projectors/glm-5.3-flash/cif/jarvis/projector.safetensors?download=true) · [config](https://huggingface.co/internlm/Sage-SciPerception/blob/main/projectors/glm-5.3-flash/cif/jarvis/config.json) |
44
+ | [MPBind](https://huggingface.co/internlm/Sage-SciPerception/tree/main/projectors/glm-5.3-flash/protein-seq/mpbind)<br>PPI interface sites | Per-protein F1 (%) | **61.12** | [Weights](https://huggingface.co/internlm/Sage-SciPerception/resolve/main/projectors/glm-5.3-flash/protein-seq/mpbind/projector.safetensors?download=true) · [config](https://huggingface.co/internlm/Sage-SciPerception/blob/main/projectors/glm-5.3-flash/protein-seq/mpbind/config.json) |
45
+ | [QM9S](https://huggingface.co/internlm/Sage-SciPerception/tree/main/projectors/glm-5.3-flash/spectra/qm9s)<br>Molecular structure identification | Acc@1 (%) | **49.75** | [Weights](https://huggingface.co/internlm/Sage-SciPerception/resolve/main/projectors/glm-5.3-flash/spectra/qm9s/projector.safetensors?download=true) · [config](https://huggingface.co/internlm/Sage-SciPerception/blob/main/projectors/glm-5.3-flash/spectra/qm9s/config.json) |
46
+ | [SciTS PHU01](https://huggingface.co/internlm/Sage-SciPerception/tree/main/projectors/glm-5.3-flash/ecg/phu01)<br>ECG classification | Macro-F1 (%) | **71.53** | [Weights](https://huggingface.co/internlm/Sage-SciPerception/resolve/main/projectors/glm-5.3-flash/ecg/phu01/projector.safetensors?download=true) · [config](https://huggingface.co/internlm/Sage-SciPerception/blob/main/projectors/glm-5.3-flash/ecg/phu01/config.json) |
47
+ | [GUE splice](https://huggingface.co/internlm/Sage-SciPerception/tree/main/projectors/glm-5.3-flash/dna/splice)<br>Splice-site classification | MCC (%) | **87.87** | [Weights](https://huggingface.co/internlm/Sage-SciPerception/resolve/main/projectors/glm-5.3-flash/dna/splice/projector.safetensors?download=true) · [config](https://huggingface.co/internlm/Sage-SciPerception/blob/main/projectors/glm-5.3-flash/dna/splice/config.json) |
48
+ | [SciTS NEU06](https://huggingface.co/internlm/Sage-SciPerception/tree/main/projectors/glm-5.3-flash/eeg/neu06)<br>Sleep staging | Macro-F1 (%) | **72.01** | [Weights](https://huggingface.co/internlm/Sage-SciPerception/resolve/main/projectors/glm-5.3-flash/eeg/neu06/projector.safetensors?download=true) · [config](https://huggingface.co/internlm/Sage-SciPerception/blob/main/projectors/glm-5.3-flash/eeg/neu06/config.json) |
49
+ | [BEACON ncRNA](https://huggingface.co/internlm/Sage-SciPerception/tree/main/projectors/glm-5.3-flash/rna/ncrna)<br>RNA family classification | Accuracy (%) | **97.35** | [Weights](https://huggingface.co/internlm/Sage-SciPerception/resolve/main/projectors/glm-5.3-flash/rna/ncrna/projector.safetensors?download=true) · [config](https://huggingface.co/internlm/Sage-SciPerception/blob/main/projectors/glm-5.3-flash/rna/ncrna/config.json) |
50
+ | [SimXRD OL](https://huggingface.co/internlm/Sage-SciPerception/tree/main/projectors/glm-5.3-flash/xrd/simxrd)<br>Crystal-system classification | Accuracy (%) | **63.60** | [Weights](https://huggingface.co/internlm/Sage-SciPerception/resolve/main/projectors/glm-5.3-flash/xrd/simxrd/projector.safetensors?download=true) · [config](https://huggingface.co/internlm/Sage-SciPerception/blob/main/projectors/glm-5.3-flash/xrd/simxrd/config.json) |
51
+ | [ATOM3D PSR](https://huggingface.co/internlm/Sage-SciPerception/tree/main/projectors/glm-5.3-flash/protein-struct/psr)<br>Protein structure ranking | Spearman (%) | **35.36** | [Weights](https://huggingface.co/internlm/Sage-SciPerception/resolve/main/projectors/glm-5.3-flash/protein-struct/psr/projector.safetensors?download=true) · [config](https://huggingface.co/internlm/Sage-SciPerception/blob/main/projectors/glm-5.3-flash/protein-struct/psr/config.json) |
52
+
53
+ Scores come from generated answers using each task's selected checkpoint. Metrics differ across rows; **MAD/MAE is a ratio where higher is better**, rather than an error to minimize. MPBind uses the assembly-1 reconstructed evaluation set and mean per-protein F1; PSR uses mean Spearman. Each projector is trained for its respective task.
54
+
55
+ ## Inference
56
+
57
+ Our serving path inserts the projected scientific vectors into the language model's **full templated prompt embeddings**, then sends them to vLLM through `prompt_embeds` at `/v1/completions`. Text tokens use the matching language model's input embedding table; the scientific span uses the projector output. Scientific feature extraction and projection run in the client, while the language-model service generates the answer.
58
+
59
+ ### 1. Prepare the weights and scientific inputs
60
+
61
+ The complete [crystal client example](https://huggingface.co/internlm/Sage-SciPerception/blob/main/examples/vllm_cif.py) implements feature projection, native chat-template rendering, text embedding lookup, scientific-span insertion, and the HTTP request. Download it with the loader modules and matching projector:
62
+
63
+ ```bash
64
+ python -m pip install torch safetensors huggingface_hub
65
+ python -m pip install --upgrade transformers
66
+ hf download internlm/Sage-SciPerception \
67
+ examples/vllm_cif.py load_projector.py modeling_projector.py \
68
+ projectors/glm-5.3-flash/cif/jarvis/config.json \
69
+ projectors/glm-5.3-flash/cif/jarvis/projector.safetensors \
70
+ --local-dir ./sage-sciperception
71
+ cd sage-sciperception
72
+ ```
73
 
74
+ Prepare `cif_features.pt` as a PyTorch tensor of shape `[num_atoms, 64]`: the real CHGNet 0.3.0 atom states specified by `cif/jarvis/config.json`, in atom order. The local language-model directory must match the exact revision recorded in the checkpoint's `config.json`. The client reads its tokenizer, configuration, and sharded safetensors input embedding table without loading the full language model.
75
 
76
+ ### 2. Start the vLLM server
77
+
78
+ In your inference environment, start a compatible vLLM server with `--enable-prompt-embeds`. Choose tensor parallelism for the selected model and your hardware; the command below shows an eight-way deployment example.
79
+
80
+ ```bash
81
+ vllm serve /path/to/matching-base-model \
82
+ --served-model-name sage-sciperception \
83
+ --enable-prompt-embeds \
84
+ --tensor-parallel-size 8 \
85
+ --generation-config vllm \
86
+ --max-model-len 8192 \
87
+ --host 127.0.0.1 --port 8000
88
+ ```
89
+
90
+ ### 3. Generate an answer
91
+
92
+ Once the server is ready, run the client from the `sage-sciperception` directory prepared in step 1:
93
+
94
+ ```bash
95
+ python examples/vllm_cif.py \
96
+ --component ./projectors/glm-5.3-flash/cif/jarvis \
97
+ --base-model /path/to/matching-base-model \
98
+ --features /path/to/cif_features.pt \
99
+ --api-base http://127.0.0.1:8000/v1 \
100
+ --model sage-sciperception
101
+ ```
102
+
103
+ The transport core below is an excerpt from the client. `prompt_embeds` already includes the native system, user, and assistant-generation prefixes, with the projector vectors inserted in the scientific span:
104
+
105
+ ```python
106
+ buffer = io.BytesIO()
107
+ torch.save(prompt_embeds.cpu().contiguous(), buffer)
108
+ body = {
109
+ "model": "sage-sciperception",
110
+ "prompt_embeds": base64.b64encode(buffer.getvalue()).decode("ascii"),
111
+ "max_tokens": 4096,
112
+ "temperature": 0,
113
+ }
114
+ request = urllib.request.Request(
115
+ "http://127.0.0.1:8000/v1/completions",
116
+ data=json.dumps(body).encode("utf-8"),
117
+ headers={"Content-Type": "application/json"},
118
+ )
119
+ ```
120
+
121
+ The Completions endpoint consumes the assembled embeddings directly. Keep the checkpoint's system prompt, template options, and scientific input representation when preparing a request. The [component index](https://huggingface.co/internlm/Sage-SciPerception/blob/main/projectors/glm-5.3-flash/README.md#scientific-inputs) describes the currently available inputs; the crystal example uses its own task's format. See the [vLLM prompt embedding documentation](https://docs.vllm.ai/en/v0.32.0/features/prompt_embeds/) for the serving interface.
122
+
123
+ Scientific encoder weights and preprocessing runners are separate dependencies. Task-adapted scientific models for DNA, MPBind, and ncRNA are not yet included here. This inference example starts from prepared scientific features.
124
+
125
+ ### Optional: check projector loading on CPU
126
+
127
+ From the same downloaded directory, you can verify the projector's parameter count and output dimension on CPU without starting the language-model service:
128
+
129
+ ```python
130
+ from load_projector import load_projector
131
+
132
+ projector, config = load_projector(
133
+ "projectors/glm-5.3-flash/cif/jarvis", device="cpu"
134
+ )
135
+ print(config["task"])
136
+ print(sum(p.numel() for p in projector.parameters()))
137
+ print(config["output_dim"])
138
+ ```
139
+
140
+ Expected output:
141
+
142
+ ```text
143
+ cif/jarvis
144
+ 4314304
145
+ 4096
146
+ ```
147
+
148
+ To load another task, download its matching weights and configuration from the [component index](https://huggingface.co/internlm/Sage-SciPerception/blob/main/projectors/glm-5.3-flash/README.md). Forward inputs vary by task; consult its scientific input description when preparing predictions.
149
 
150
  ## Framework
151
 
152
  <p align="center">
153
+ <img src="assets/framework.gif" alt="Scientific inputs pass through scientific representations and trainable projectors into a language model." width="100%">
154
  </p>
155
 
156
+ A task-specific projector maps scientific features to the language model's embedding dimension. During the language-mapping stage, the scientific models and language model stay frozen while the projector is trained. Some tasks use scientific models that were adapted to their task beforehand, or combine encoder states with scientific readouts.
157
+
158
+ ## Feedback and next steps
159
 
160
+ For integration questions, missing assets, or examples you would like to see, [open a GitHub issue](https://github.com/InternLM/Sage-SciPerception/issues/new). Include the task, your scientific input format, and the step you want to run. You can also use the [Hugging Face community tab](https://huggingface.co/internlm/Sage-SciPerception/discussions) for release questions, or follow [InternLM](https://huggingface.co/internlm) for updates.
161
 
162
+ License metadata has not yet been specified for this release.
 
 
 
 
 
 
 
README_zh.md CHANGED
@@ -1,40 +1,146 @@
1
- <p align="center">
2
- <img src="assets/branding/sage-sciprojector-hero-zh.png" alt="书生·元征:书生探索科学表征。" width="100%">
3
- </p>
4
-
5
  <h1 align="center">书生·元征</h1>
6
- <p align="center"><strong>Sage Sci Perception</strong></p>
7
- <p align="center">让大模型感知科学数据。</p>
8
-
9
- <p align="center"><a href="README.md">English</a> · <strong>简体中文</strong></p>
10
 
11
  <p align="center">
 
 
12
  <a href="https://github.com/InternLM/Sage-SciPerception">GitHub</a> ·
13
- <a href="#整体框架">整体框架</a> ·
14
- <a href="#评测结果">评测结果</a>
15
  </p>
16
 
17
- ## 简介
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
- 书生·元征(Sage Sci Perception)通过可训练的投影模块,将科学编码器接入语言模型。分子图、谱图、晶体结构、蛋白质与核酸序列以及科学信号被映射到语言模型的输入空间,使其能够生成自然语言分析和结构化科学答案。
20
 
21
- 投影模块按语言模型底座、模态和任务组织,与对应的科学编码器及配置配套使用。
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
  ## 整体框架
24
 
25
  <p align="center">
26
- <img src="assets/framework.gif" alt="科学输入经科学编码器与可训练投影模块,接入语言模型。" width="100%">
27
  </p>
28
 
29
- ## 评测结果
 
 
30
 
31
- 以下为各任务独立 checkpoint 的部分评测结果,按生成答案判分。
32
 
33
- | 榜单 | 任务 | 指标 ↑ | 得分 |
34
- |---|---|---|---:|
35
- | QM9S | 三谱联合分子结构识别 | Acc@1(%) | **49.75** |
36
- | JARVIS-DFT | 形成能预测 | MAD/MAE | **15.03** |
37
- | MPBind,assembly-1 重建集 | PPI 界面位点预测 | 逐蛋白平均 F1(%) | **61.12** |
38
- | SciTS PHU01 | 心电分类 | 宏平均 F1(%) | **71.53** |
39
- | SciTS NEU06 | 睡眠分期 | 宏平均 F1(%) | **72.01** |
40
- | BEACON ncRNA | RNA 家族分类 | 准确率(%) | **97.35** |
 
 
 
 
 
1
  <h1 align="center">书生·元征</h1>
2
+ <p align="center"><strong>Sage Sci Perception · 让大模型感知科学数据。</strong></p>
3
+ <p align="center">通过投影模块,将晶体、谱图、生物序列与生理信号接入语言模型。</p>
4
+ <p align="center"><strong>持续扩展科学模态、任务与语言模型支持。</strong></p>
 
5
 
6
  <p align="center">
7
+ <a href="#已发布权重">下载权重</a> ·
8
+ <a href="#推理使用">推理使用</a> ·
9
  <a href="https://github.com/InternLM/Sage-SciPerception">GitHub</a> ·
10
+ <a href="https://huggingface.co/internlm/Sage-SciPerception">English</a>
 
11
  </p>
12
 
13
+ <p align="center">
14
+ <img src="assets/branding/sage-sciprojector-hero-zh.png" alt="书生·元征:书生探索科学表征。" width="640">
15
+ </p>
16
+
17
+ 书生·元征(Sage Sci Perception)将科学表征映射到语言模型的输入空间,使其能够生成自然语言分析和结构化科学答案。你可以用它探索科学工作流与语言模型的连接,包括材料性质预测、生物序列标注、谱图结构识别与信号分类。
18
+
19
+ projector 按模态、任务与语言模型版本组织。你可以从下表下载已有权重,也可以参考[推理使用说明](#推理使用),将科学输入接入推理服务。各权重的 `config.json` 记录了对应语言模型和科学输入表示。
20
+
21
+ ## 已发布权重
22
+
23
+ 点击任务名称查看配套文件,或直接下载权重和配置。后续将持续增加科学模态、任务与适配的语言模型版本。
24
+
25
+ | 榜单 / 任务 | 指标 ↑ | 得分 | 下载 |
26
+ |---|---|---:|---|
27
+ | [JARVIS-DFT](https://huggingface.co/internlm/Sage-SciPerception/tree/main/projectors/glm-5.3-flash/cif/jarvis)<br>形成能预测 | MAD/MAE | **15.03** | [权重](https://huggingface.co/internlm/Sage-SciPerception/resolve/main/projectors/glm-5.3-flash/cif/jarvis/projector.safetensors?download=true) · [config](https://huggingface.co/internlm/Sage-SciPerception/blob/main/projectors/glm-5.3-flash/cif/jarvis/config.json) |
28
+ | [MPBind](https://huggingface.co/internlm/Sage-SciPerception/tree/main/projectors/glm-5.3-flash/protein-seq/mpbind)<br>PPI 界面位点 | 逐蛋白 F1(%) | **61.12** | [权重](https://huggingface.co/internlm/Sage-SciPerception/resolve/main/projectors/glm-5.3-flash/protein-seq/mpbind/projector.safetensors?download=true) · [config](https://huggingface.co/internlm/Sage-SciPerception/blob/main/projectors/glm-5.3-flash/protein-seq/mpbind/config.json) |
29
+ | [QM9S](https://huggingface.co/internlm/Sage-SciPerception/tree/main/projectors/glm-5.3-flash/spectra/qm9s)<br>分子结构识别 | Acc@1(%) | **49.75** | [权重](https://huggingface.co/internlm/Sage-SciPerception/resolve/main/projectors/glm-5.3-flash/spectra/qm9s/projector.safetensors?download=true) · [config](https://huggingface.co/internlm/Sage-SciPerception/blob/main/projectors/glm-5.3-flash/spectra/qm9s/config.json) |
30
+ | [SciTS PHU01](https://huggingface.co/internlm/Sage-SciPerception/tree/main/projectors/glm-5.3-flash/ecg/phu01)<br>心电分类 | 宏平均 F1(%) | **71.53** | [权重](https://huggingface.co/internlm/Sage-SciPerception/resolve/main/projectors/glm-5.3-flash/ecg/phu01/projector.safetensors?download=true) · [config](https://huggingface.co/internlm/Sage-SciPerception/blob/main/projectors/glm-5.3-flash/ecg/phu01/config.json) |
31
+ | [GUE splice](https://huggingface.co/internlm/Sage-SciPerception/tree/main/projectors/glm-5.3-flash/dna/splice)<br>剪接位点分类 | MCC(%) | **87.87** | [权重](https://huggingface.co/internlm/Sage-SciPerception/resolve/main/projectors/glm-5.3-flash/dna/splice/projector.safetensors?download=true) · [config](https://huggingface.co/internlm/Sage-SciPerception/blob/main/projectors/glm-5.3-flash/dna/splice/config.json) |
32
+ | [SciTS NEU06](https://huggingface.co/internlm/Sage-SciPerception/tree/main/projectors/glm-5.3-flash/eeg/neu06)<br>睡眠分期 | 宏平均 F1(%) | **72.01** | [权重](https://huggingface.co/internlm/Sage-SciPerception/resolve/main/projectors/glm-5.3-flash/eeg/neu06/projector.safetensors?download=true) · [config](https://huggingface.co/internlm/Sage-SciPerception/blob/main/projectors/glm-5.3-flash/eeg/neu06/config.json) |
33
+ | [BEACON ncRNA](https://huggingface.co/internlm/Sage-SciPerception/tree/main/projectors/glm-5.3-flash/rna/ncrna)<br>RNA 家族分类 | 准确率(%) | **97.35** | [权重](https://huggingface.co/internlm/Sage-SciPerception/resolve/main/projectors/glm-5.3-flash/rna/ncrna/projector.safetensors?download=true) · [config](https://huggingface.co/internlm/Sage-SciPerception/blob/main/projectors/glm-5.3-flash/rna/ncrna/config.json) |
34
+ | [SimXRD OL](https://huggingface.co/internlm/Sage-SciPerception/tree/main/projectors/glm-5.3-flash/xrd/simxrd)<br>晶系分类 | 准确率(%) | **63.60** | [权重](https://huggingface.co/internlm/Sage-SciPerception/resolve/main/projectors/glm-5.3-flash/xrd/simxrd/projector.safetensors?download=true) · [config](https://huggingface.co/internlm/Sage-SciPerception/blob/main/projectors/glm-5.3-flash/xrd/simxrd/config.json) |
35
+ | [ATOM3D PSR](https://huggingface.co/internlm/Sage-SciPerception/tree/main/projectors/glm-5.3-flash/protein-struct/psr)<br>蛋白质结构排序 | Spearman(%) | **35.36** | [权重](https://huggingface.co/internlm/Sage-SciPerception/resolve/main/projectors/glm-5.3-flash/protein-struct/psr/projector.safetensors?download=true) · [config](https://huggingface.co/internlm/Sage-SciPerception/blob/main/projectors/glm-5.3-flash/protein-struct/psr/config.json) |
36
+
37
+ 得分来自各任务选定 checkpoint 的生成答案,不同任务的指标不能直接比较。**MAD/MAE 是越高越好的比值**,不是需要最小化的误差。MPBind 使用 assembly-1 重建评测集及逐蛋白平均 F1;PSR 使用平均 Spearman。各模块分别针对对应任务训练。
38
+
39
+ ## 推理使用
40
+
41
+ 我们的服务路线是:将 projector 输出的科学向量插入语言模型的**完整聊天提示词嵌入**,再通过 `prompt_embeds` 发给 vLLM 的 `/v1/completions`。文本位置使用对应语言模型的输入嵌入表,科学载荷位置使用 projector 的输出。科学特征提取与投影在客户端完成,语言模型服务负责生成答案。
42
+
43
+ ### 1. 准备权重与科学输入
44
+
45
+ 完整的[晶体客户端示例](https://huggingface.co/internlm/Sage-SciPerception/blob/main/examples/vllm_cif.py)包含特征投影、原生 chat template 渲染、文本嵌入读取、科学载荷替换及 HTTP 请求。先下载示例、加载模块和对应任务权重:
46
+
47
+ ```bash
48
+ python -m pip install torch safetensors huggingface_hub
49
+ python -m pip install --upgrade transformers
50
+ hf download internlm/Sage-SciPerception \
51
+ examples/vllm_cif.py load_projector.py modeling_projector.py \
52
+ projectors/glm-5.3-flash/cif/jarvis/config.json \
53
+ projectors/glm-5.3-flash/cif/jarvis/projector.safetensors \
54
+ --local-dir ./sage-sciperception
55
+ cd sage-sciperception
56
+ ```
57
 
58
+ 准备 `cif_features.pt`:这是形状为 `[num_atoms, 64]` 的 PyTorch 张量,内容为 `cif/jarvis/config.json` 指定的真实 CHGNet 0.3.0 原子状态,保持原子顺序。本地语言模型目录应与权重 `config.json` 记录的精确版本一致。客户端从该目录读取 tokenizer、配置和分片 safetensors 中的输入嵌入表,无需加载完整语言模型。
59
 
60
+ ### 2. 启动 vLLM 服务
61
+
62
+ 在推理服务环境中,启动支持 `--enable-prompt-embeds` 的 vLLM 服务。张量并行度根据所选模型与设备选择;以下命令以八路并行为例。
63
+
64
+ ```bash
65
+ vllm serve /path/to/matching-base-model \
66
+ --served-model-name sage-sciperception \
67
+ --enable-prompt-embeds \
68
+ --tensor-parallel-size 8 \
69
+ --generation-config vllm \
70
+ --max-model-len 8192 \
71
+ --host 127.0.0.1 --port 8000
72
+ ```
73
+
74
+ ### 3. 生成答案
75
+
76
+ 服务就绪后,在步骤 1 准备的 `sage-sciperception` 目录中运行客户端:
77
+
78
+ ```bash
79
+ python examples/vllm_cif.py \
80
+ --component ./projectors/glm-5.3-flash/cif/jarvis \
81
+ --base-model /path/to/matching-base-model \
82
+ --features /path/to/cif_features.pt \
83
+ --api-base http://127.0.0.1:8000/v1 \
84
+ --model sage-sciperception
85
+ ```
86
+
87
+ 下面是客户端中的传输代码摘录。此时 `prompt_embeds` 已包含原生 system、user 以及 assistant 生成前缀,并在科学载荷位置插入了 projector 向量:
88
+
89
+ ```python
90
+ buffer = io.BytesIO()
91
+ torch.save(prompt_embeds.cpu().contiguous(), buffer)
92
+ body = {
93
+ "model": "sage-sciperception",
94
+ "prompt_embeds": base64.b64encode(buffer.getvalue()).decode("ascii"),
95
+ "max_tokens": 4096,
96
+ "temperature": 0,
97
+ }
98
+ request = urllib.request.Request(
99
+ "http://127.0.0.1:8000/v1/completions",
100
+ data=json.dumps(body).encode("utf-8"),
101
+ headers={"Content-Type": "application/json"},
102
+ )
103
+ ```
104
+
105
+ Completions 接口直接消费组装后的完整嵌入。构造请求时沿用 checkpoint 的 system prompt、模板参数及科学输入表示。[组件索引](https://huggingface.co/internlm/Sage-SciPerception/blob/main/projectors/glm-5.3-flash/README.md#scientific-inputs)列出了当前可用输入;晶体示例使用该任务自己的输入格式。服务接口见 [vLLM prompt embeddings 文档](https://docs.vllm.ai/en/v0.32.0/features/prompt_embeds/)。
106
+
107
+ 科学编码器权重和预处理运行脚本是��立依赖。其中 DNA、MPBind 和 ncRNA 所需的任务适配科学模型尚未在此发布。上述推理示例从已准备好的真实科学特征开始。
108
+
109
+ ### 可选:在 CPU 上检查 projector 加载
110
+
111
+ 在同一下载目录中,可以用 CPU 检查 projector 的参数量与输出维度,无需启动语言模型服务:
112
+
113
+ ```python
114
+ from load_projector import load_projector
115
+
116
+ projector, config = load_projector(
117
+ "projectors/glm-5.3-flash/cif/jarvis", device="cpu"
118
+ )
119
+ print(config["task"])
120
+ print(sum(p.numel() for p in projector.parameters()))
121
+ print(config["output_dim"])
122
+ ```
123
+
124
+ 预期输出:
125
+
126
+ ```text
127
+ cif/jarvis
128
+ 4314304
129
+ 4096
130
+ ```
131
+
132
+ 加载其他任务时,请从[组件索引](https://huggingface.co/internlm/Sage-SciPerception/blob/main/projectors/glm-5.3-flash/README.md)下载对应权重和配置。各任务前向所需的输入不同,准备预测时请查看其科学输入说明。
133
 
134
  ## 整体框架
135
 
136
  <p align="center">
137
+ <img src="assets/framework.gif" alt="科学输入经科学表征与可训练投影模块,接入语言模型。" width="100%">
138
  </p>
139
 
140
+ 任务专用 projector 将科学特征映射到语言模型的嵌入维度。在语言映射训练阶段,科学模型和语言模型保持冻结,只训练 projector。部分任务会先对科学模型进行任务适配,或将编码器状态与科学直接读出结合。
141
+
142
+ ## 反馈与后续
143
 
144
+ 如果你正在接入自己的科学流程、缺少配套文件,或希望看到具体示例,可以[提交 GitHub issue](https://github.com/InternLM/Sage-SciPerception/issues/new),附上任务、科学输入格式和想运行的步骤。发布相关问题也可以在 [HF 社区页](https://huggingface.co/internlm/Sage-SciPerception/discussions)讨论;关注 [InternLM](https://huggingface.co/internlm) 可接收后续更新。
145
 
146
+ 本次发布尚未指定许可证元数据。
 
 
 
 
 
 
 
examples/vllm_cif.py ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Send a crystal projector's scientific embeddings to a matching vLLM server.
2
+
3
+ Input: a CPU-loadable tensor [num_atoms, 64] containing the CHGNet atom states
4
+ specified by the cif/jarvis checkpoint. The language-model directory supplies
5
+ its tokenizer, config, and sharded safetensors input embedding table.
6
+ """
7
+ import argparse
8
+ import base64
9
+ import io
10
+ import json
11
+ from pathlib import Path
12
+ import sys
13
+ import urllib.request
14
+
15
+ import torch
16
+ from safetensors import safe_open
17
+
18
+ sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
19
+ from load_projector import load_projector
20
+
21
+ MARKER = "￰SAGE_PAYLOAD￱"
22
+
23
+
24
+ def build_prompt_embeds(projector, config, features, tokenizer, base_model, question):
25
+ """Use the checkpoint's native template and replace its scientific span."""
26
+ with torch.inference_mode():
27
+ scientific = projector(features.float(), torch.arange(len(features)))
28
+ spec = config["prompt"]
29
+ name = spec["names"][0][0]
30
+ messages = [
31
+ {"role": "system", "content": spec["system"]},
32
+ {"role": "user", "content": f"{name}:\n{MARKER}\n\nQuestion: {question}"},
33
+ ]
34
+ prompt = tokenizer.apply_chat_template(
35
+ messages, tokenize=False, add_generation_prompt=True, **spec["template_kwargs"]
36
+ )
37
+ before, after = prompt.split(MARKER)
38
+ prefix_ids = tokenizer(before, add_special_tokens=False)["input_ids"]
39
+ suffix_ids = tokenizer(after, add_special_tokens=False)["input_ids"]
40
+
41
+ # Text rows must come from the exact embedding table used by the server.
42
+ weight_map = json.loads((base_model / "model.safetensors.index.json").read_text())["weight_map"]
43
+ key = next(name for name in weight_map if name.endswith("embed_tokens.weight"))
44
+ with safe_open(base_model / weight_map[key], framework="pt", device="cpu") as weights:
45
+ table = weights.get_slice(key)
46
+ rows = {index: table[index:index + 1] for index in set(prefix_ids + suffix_ids)}
47
+ prefix = torch.cat([rows[index] for index in prefix_ids])
48
+ suffix = torch.cat([rows[index] for index in suffix_ids])
49
+ return torch.cat([prefix, scientific.to(prefix), suffix]).contiguous()
50
+
51
+
52
+ def complete(api_base, model, prompt_embeds, stop_token_ids, max_tokens):
53
+ """Completions receives the full templated sequence, including text rows."""
54
+ buffer = io.BytesIO()
55
+ torch.save(prompt_embeds.cpu().contiguous(), buffer)
56
+ body = {
57
+ "model": model,
58
+ "prompt_embeds": base64.b64encode(buffer.getvalue()).decode("ascii"),
59
+ "max_tokens": max_tokens,
60
+ "temperature": 0,
61
+ "stop_token_ids": stop_token_ids,
62
+ "skip_special_tokens": False,
63
+ }
64
+ request = urllib.request.Request(
65
+ api_base.rstrip("/") + "/completions",
66
+ data=json.dumps(body).encode("utf-8"),
67
+ headers={"Content-Type": "application/json"},
68
+ )
69
+ with urllib.request.urlopen(request, timeout=600) as response:
70
+ return json.load(response)["choices"][0]["text"]
71
+
72
+
73
+ def main():
74
+ parser = argparse.ArgumentParser(description=__doc__)
75
+ parser.add_argument("--component", type=Path, required=True)
76
+ parser.add_argument("--base-model", type=Path, required=True)
77
+ parser.add_argument("--features", type=Path, required=True)
78
+ parser.add_argument("--question", default="Predict the formation energy per atom in eV/atom.")
79
+ parser.add_argument("--api-base", default="http://127.0.0.1:8000/v1")
80
+ parser.add_argument("--model", default="sage-sciperception")
81
+ parser.add_argument("--max-tokens", type=int, default=4096)
82
+ args = parser.parse_args()
83
+
84
+ projector, config = load_projector(args.component, device="cpu")
85
+ if config["task"] != "cif/jarvis":
86
+ parser.error("This example uses the cif/jarvis input format and unnumbered crystal prompt.")
87
+ features = torch.load(args.features, map_location="cpu", weights_only=True)
88
+ from transformers import AutoTokenizer
89
+ tokenizer = AutoTokenizer.from_pretrained(args.base_model, local_files_only=True)
90
+ prompt_embeds = build_prompt_embeds(
91
+ projector, config, features, tokenizer, args.base_model, args.question
92
+ )
93
+ language_config = json.loads((args.base_model / "config.json").read_text())
94
+ text_config = language_config.get("text_config", language_config)
95
+ eos = text_config["eos_token_id"]
96
+ stop_ids = eos if isinstance(eos, list) else [eos]
97
+ print(complete(args.api_base, args.model, prompt_embeds, stop_ids, args.max_tokens))
98
+
99
+
100
+ if __name__ == "__main__":
101
+ main()
projectors/glm-5.3-flash/README.md CHANGED
@@ -1,29 +1,49 @@
1
- # GLM-5.3-Flash projectors
2
 
3
- This release contains nine task-specific projectors for `zai-org/GLM-5.3-Flash-BF16`.
4
 
5
- | Modality / task | Training step | Weights and configuration |
6
- |---|---:|---|
7
- | cif/jarvis | 2822 | [download](cif/jarvis/) |
8
- | protein-seq/mpbind | 100 | [download](protein-seq/mpbind/) |
9
- | spectra/qm9s | 8037 | [download](spectra/qm9s/) |
10
- | ecg/phu01 | 1068 | [download](ecg/phu01/) |
11
- | dna/splice | 50 | [download](dna/splice/) |
12
- | eeg/neu06 | 4688 | [download](eeg/neu06/) |
13
- | rna/ncrna | 200 | [download](rna/ncrna/) |
14
- | xrd/simxrd | 500 | [download](xrd/simxrd/) |
15
- | protein-struct/psr | 200 | [download](protein-struct/psr/) |
16
 
17
- ## Loading a projector
 
 
 
 
 
 
 
 
 
 
18
 
19
- Download this repository (or the selected component plus the two root Python modules), then install `torch` and `safetensors`.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
  ```python
22
  from load_projector import load_projector
23
 
24
- model, config = load_projector("projectors/glm-5.3-flash/cif/jarvis")
25
  ```
26
 
27
- The loader returns the projector module and its configuration. Supply the scientific representation declared in `scientific_inputs`, and use the exact language backbone revision and prompt declared in `config.json`.
28
 
29
- Scientific encoder weights and the language backbone are separate dependencies. Task-adapted encoder weights referenced by these configurations are not included in this projector-only release. The loader does not provide an end-to-end scientific input processing or generation pipeline.
 
1
+ # Projector index
2
 
3
+ Available checkpoints are organized by modality, task, and language-model version. Scientific modalities, tasks, and language-model support will continue to expand. See the [English model card](https://huggingface.co/internlm/Sage-SciPerception#inference) or [中文模型卡](https://huggingface.co/internlm/Sage-SciPerception/blob/main/README_zh.md#推理使用) for inference setup, a vLLM client example, and an optional CPU loading check.
4
 
5
+ Each task directory contains `projector.safetensors` and `config.json`. The configuration declares the architecture, output dimension, scientific inputs, prompt, backbone revision, and training step. Scientific encoder weights and the language backbone are separate dependencies.
 
 
 
 
 
 
 
 
 
 
6
 
7
+ | Task directory | Training step | Weights | Configuration |
8
+ |---|---:|---|---|
9
+ | `cif/jarvis` | 2822 | [Weights](https://huggingface.co/internlm/Sage-SciPerception/resolve/main/projectors/glm-5.3-flash/cif/jarvis/projector.safetensors?download=true) | [config.json](https://huggingface.co/internlm/Sage-SciPerception/blob/main/projectors/glm-5.3-flash/cif/jarvis/config.json) |
10
+ | `protein-seq/mpbind` | 100 | [Weights](https://huggingface.co/internlm/Sage-SciPerception/resolve/main/projectors/glm-5.3-flash/protein-seq/mpbind/projector.safetensors?download=true) | [config.json](https://huggingface.co/internlm/Sage-SciPerception/blob/main/projectors/glm-5.3-flash/protein-seq/mpbind/config.json) |
11
+ | `spectra/qm9s` | 8037 | [Weights](https://huggingface.co/internlm/Sage-SciPerception/resolve/main/projectors/glm-5.3-flash/spectra/qm9s/projector.safetensors?download=true) | [config.json](https://huggingface.co/internlm/Sage-SciPerception/blob/main/projectors/glm-5.3-flash/spectra/qm9s/config.json) |
12
+ | `ecg/phu01` | 1068 | [Weights](https://huggingface.co/internlm/Sage-SciPerception/resolve/main/projectors/glm-5.3-flash/ecg/phu01/projector.safetensors?download=true) | [config.json](https://huggingface.co/internlm/Sage-SciPerception/blob/main/projectors/glm-5.3-flash/ecg/phu01/config.json) |
13
+ | `dna/splice` | 50 | [Weights](https://huggingface.co/internlm/Sage-SciPerception/resolve/main/projectors/glm-5.3-flash/dna/splice/projector.safetensors?download=true) | [config.json](https://huggingface.co/internlm/Sage-SciPerception/blob/main/projectors/glm-5.3-flash/dna/splice/config.json) |
14
+ | `eeg/neu06` | 4688 | [Weights](https://huggingface.co/internlm/Sage-SciPerception/resolve/main/projectors/glm-5.3-flash/eeg/neu06/projector.safetensors?download=true) | [config.json](https://huggingface.co/internlm/Sage-SciPerception/blob/main/projectors/glm-5.3-flash/eeg/neu06/config.json) |
15
+ | `rna/ncrna` | 200 | [Weights](https://huggingface.co/internlm/Sage-SciPerception/resolve/main/projectors/glm-5.3-flash/rna/ncrna/projector.safetensors?download=true) | [config.json](https://huggingface.co/internlm/Sage-SciPerception/blob/main/projectors/glm-5.3-flash/rna/ncrna/config.json) |
16
+ | `xrd/simxrd` | 500 | [Weights](https://huggingface.co/internlm/Sage-SciPerception/resolve/main/projectors/glm-5.3-flash/xrd/simxrd/projector.safetensors?download=true) | [config.json](https://huggingface.co/internlm/Sage-SciPerception/blob/main/projectors/glm-5.3-flash/xrd/simxrd/config.json) |
17
+ | `protein-struct/psr` | 200 | [Weights](https://huggingface.co/internlm/Sage-SciPerception/resolve/main/projectors/glm-5.3-flash/protein-struct/psr/projector.safetensors?download=true) | [config.json](https://huggingface.co/internlm/Sage-SciPerception/blob/main/projectors/glm-5.3-flash/protein-struct/psr/config.json) |
18
 
19
+ ## Scientific inputs
20
+
21
+ The following is an interface summary. Exact feature extraction and preprocessing must match each checkpoint's `scientific_inputs`; arbitrary tensors with the same shape do not reproduce its scientific behavior.
22
+
23
+ | Task | Input to the projector | Scientific dependency |
24
+ |---|---|---|
25
+ | `cif/jarvis` | 64-dimensional state per atom, plus per-atom position indices | CHGNet 0.3.0 states entering the energy MLP |
26
+ | `protein-seq/mpbind` | 1,280-dimensional state per residue; 2-dimensional side features; residue counts | ESM-2 states plus a task-adapted ESMC readout; the adapted weights and side-feature construction are not included |
27
+ | `spectra/qm9s` | 50-dimensional spectral patches, positions, and a 3-way spectrum-type index | DiffSpectra-style `log10(x + 1)` transform and patch geometry for IR, Raman, and UV-Vis |
28
+ | `ecg/phu01` | 768-dimensional cached position features | The ECG encoder/cache pipeline used for the released checkpoint; extraction runner is not included |
29
+ | `dna/splice` | One 3-dimensional probability readout | Task-adapted DNABERT-2; its scientific weights are not included |
30
+ | `eeg/neu06` | 512-dimensional patch states with matching electrode and time positions | REVE-base with the position and tail-window handling declared in the configuration |
31
+ | `rna/ncrna` | 640-dimensional RNA-FM state per nucleotide; 13-dimensional side input | RNA-FM plus a task-adapted RiNALMo ensemble readout; adapted weights and the full ensemble preprocessing are not included |
32
+ | `xrd/simxrd` | 110 convolutional states, each 512-dimensional | The legacy XRD CNN and its normalized 3,501-point, square-root input pipeline; scientific weights are not included |
33
+ | `protein-struct/psr` | 384-dimensional state per residue/bin | ProteinMPNN v48-020; concatenate its three encoder layers, then use at most 256 contiguous mean bins |
34
+
35
+ The task-adapted scientific checkpoint paths in the configurations describe dependencies; those paths are not downloadable encoder directories in this release. Some encoder metadata records an upstream component but not the complete preparation pipeline. The [vLLM crystal example](https://huggingface.co/internlm/Sage-SciPerception/blob/main/examples/vllm_cif.py) shows the serving path from prepared features; raw scientific inputs require the matching preprocessing pipeline.
36
+
37
+ ## Local loading
38
+
39
+ Install `torch` and `safetensors`. From a downloaded repository containing the two root modules:
40
 
41
  ```python
42
  from load_projector import load_projector
43
 
44
+ projector, config = load_projector("projectors/glm-5.3-flash/cif/jarvis", device="cpu")
45
  ```
46
 
47
+ This returns a frozen projector module in evaluation mode and its configuration. It does not load scientific encoders, the language backbone, or a complete generation pipeline. Consult the input table above before calling the projector for another task.
48
 
49
+ For integration questions or missing assets, [open a GitHub issue](https://github.com/InternLM/Sage-SciPerception/issues/new) with the task, input format, and the step you want to run.