# 通过 vLLM 部署科学投影

> 在客户端组装提示词嵌入，再通过 completions API 发送。

---

LLMS 索引： [llms.txt](/Sage-SciPerception/zh/llms.txt)

---

推理客户端在语言模型的嵌入空间中组装完整提示词。它先按 GLM 原生对话模板渲染提示词，再查找文本嵌入行、投影科学特征，并替换预留的载荷区间。vLLM 在 `/v1/completions` 端点通过 `prompt_embeds` 接收结果。

## 启动匹配的主干模型 {#serve}

使用所选检查点 `base_model` 字段指定的模型快照。客户端也需要同一快照来读取分词器和输入嵌入表。下面以八路张量并行为例，请根据部署主干模型的硬件设置并行度。

```bash
vllm serve /path/to/matching-base-model \
  --served-model-name sage-sciperception \
  --tensor-parallel-size 8 \
  --enable-prompt-embeds \
  --no-enable-prefix-caching \
  --generation-config vllm \
  --host 127.0.0.1 --port 8000
```

## 发送晶体提示词 {#crystal}

根据 [JARVIS 任务指南](/docs/tasks/cif-jarvis/)，按原子顺序准备形状为 `[num_atoms, 64]` 的 CHGNet 0.3.0 状态张量。沿用 [CPU 快速校验章节](/book/02-quickstart-cpu/)下载的检查点，将特征文件传给[晶体推理客户端](https://github.com/InternLM/Sage-SciPerception/blob/main/examples/vllm_cif.py)。

```bash
python -m pip install transformers
python examples/vllm_cif.py \
  --component ./checkpoints/projectors/glm-5.3-flash/cif/jarvis \
  --base-model /path/to/matching-base-model \
  --features /path/to/cif_features.pt \
  --api-base http://127.0.0.1:8000/v1 \
  --model sage-sciperception
```

客户端先用 PyTorch 序列化矩阵，再经 Base64 编码后发送。默认问题要求预测每原子形成能，单位为 eV/atom。可用 `--question` 传入其他问题。

## 为变长输入建立会话 {#session}

[`evalkit.glm_prompt_embeds`](https://github.com/InternLM/Sage-SciPerception/blob/main/evalkit/src/evalkit/glm_prompt_embeds.py) 提供两种适配器。`GlmProjectorPrompt` 在构造时接收固定的问题和载荷布局，并复用对应的文本嵌入。`GlmProjectorSession` 则复用投影模块、分词器和嵌入查找器，同时为每次请求重新渲染问题及载荷区间。

处理多个对象时，按对象顺序拼接特征，通过 `payload_tokens` 传入各对象的行数，例如用 `[3, 5]` 表示共八行。启用 `atom_numbering` 的检查点会在提示词中渲染带编号的载荷位置，可按对象分组传入 `payload_labels` 来指定标签。根据检查点配置提供 `discrete` 或 `side` 输入。若投影模块需要 `counts`，适配器默认使用各对象的行数，也可由调用者显式传入计数。

[端到端评测章节](/book/04-end-to-end-eval/)介绍如何保存生成结果并使用固定参考答案评分。
