全模态推理示例与通道指南
在线复用 vllm_projector.py 覆盖九种科学模态,以及 NEU06 从原始脑电到评测的完整示例。
仓库的 examples/ 目录提供三类开箱即用的推理与评测示例,覆盖单任务轻量客户端、九模态统一客户端,以及从原始信号提取特征的完整基准流程:
准备客户端环境
在公开仓库根目录安装客户端依赖、evalkit 与 trainkit,下载任意任务检查点,并按部署章节启动启用 --enable-prompt-embeds 的 vLLM 服务:
pip install "scipkit[infer]" # 或在源码根目录:pip install -e ".[infer]"
scip download glm-5.3-flash/spectra/qm9s --local-dir ./checkpoints
直接消费公开训练样例(--sample-dir)
internlm/Sage-SciPerception-Training 为全部九个已验证模态提供两行可运行的 sage-training-data-v1 切片。下载任意切片后,vllm_projector.py 会自动读取 nodes.npy、offsets.npy、可选的 modality.npy(discrete)或 side.npy(side)、payload_labels 与 question。
先加 --dry-run 在 CPU 上完成投影前向与提示词拼接自检,无需启动 vLLM 服务:
hf download internlm/Sage-SciPerception-Training --repo-type dataset \
--include "samples/spectra/qm9s/*" --local-dir ./training-samples
python examples/vllm_projector.py \
--component ./checkpoints/projectors/glm-5.3-flash/spectra/qm9s \
--base-model /path/to/GLM-5.3-Flash-BF16 \
--sample-dir ./training-samples/samples/spectra/qm9s \
--row 0 \
--dry-run
去掉 --dry-run 并指定服务地址即可发送请求:
python examples/vllm_projector.py \
--component ./checkpoints/projectors/glm-5.3-flash/spectra/qm9s \
--base-model /path/to/GLM-5.3-Flash-BF16 \
--sample-dir ./training-samples/samples/spectra/qm9s \
--row 0 \
--api-base http://127.0.0.1:8000/v1 \
--model sage-sciperception
九种模态的输入张量与附加通道
使用 --features 直接传入自有数组时,请与检查点 config.json 声明的通道和形状保持一致:
以下示例覆盖 discrete、side、payload_labels 与多对象拼接场景:
示例 6-1 使用 vllm_projector.py 运行光谱离散通道、RNA/蛋白侧输入与多对象比较。# 分子三谱(QM9S):连续谱片段 + 离散谱型索引 + 自动 atom_numbering
python examples/vllm_projector.py \
--component ./checkpoints/projectors/glm-5.3-flash/spectra/qm9s \
--base-model /path/to/GLM-5.3-Flash-BF16 \
--features /path/to/nodes.npy \
--discrete /path/to/modality.npy \
--question "Identify the molecule from its IR, Raman, and UV-Vis spectra."
# 非编码 RNA(BEACON ncRNA):逐核苷酸状态 + 广播后的 13 维概率侧输入
python examples/vllm_projector.py \
--component ./checkpoints/projectors/glm-5.3-flash/rna/ncrna \
--base-model /path/to/GLM-5.3-Flash-BF16 \
--features /path/to/nodes.npy \
--side /path/to/side.npy \
--question "Classify this non-coding RNA sequence into its Rfam family."
# 蛋白质界面位点(MPBind):逐残基状态 + 逐残基侧输入 + 1-based 残基编号
python examples/vllm_projector.py \
--component ./checkpoints/projectors/glm-5.3-flash/protein-seq/mpbind \
--base-model /path/to/GLM-5.3-Flash-BF16 \
--features /path/to/nodes.npy \
--side /path/to/side.npy \
--payload-labels '[[1, 2, 3, 4, 5]]' \
--question "Predict protein-protein interaction interface residues in positions 1 through 5."
# 多对象比较:按对象顺序拼接特征并用 --payload-tokens 传入各自长度
python examples/vllm_projector.py \
--component ./checkpoints/projectors/glm-5.3-flash/cif/jarvis \
--base-model /path/to/GLM-5.3-Flash-BF16 \
--features /path/to/two_crystals.pt \
--payload-tokens 12,18 \
--question "Compare the formation energies of the two crystals."
SciTS NEU06 完整示例(原始 EEG → 评测)
examples/neu06/ 展示在 SciTS NEU06(1,024 段 30 秒 Fpz-Cz 单通道脑电,分为 Wake、N1、N2、N3、REM 五类)上运行已发布 glm-5.3-flash/eeg/neu06 投影模块的完整链路。v0.1.0 发布成绩为宏平均 F1 72.01% / 准确率 76.46%;公开示例脚本独立重跑取得宏平均 F1 71.82% / 准确率 76.46%(两次全量均覆盖 1,024 题,为不同次运行,原运行逐题预测未保留)。
固定版本输入来源
仅对已有预测文件评分(CPU)
如果已有符合格式(每行含 eval_id 与 content)的 responses.jsonl,只需 Python 3.12+ 与 uv 即可在 CPU 上评分:
SCITS=/path/to/SciTS
RUN=/path/to/neu06-run
uvx --from huggingface-hub hf download OpenTSLab/SciTS meta_data.jsonl --repo-type dataset \
--revision 6ce690e904898cc8fd9014ea2e5bebdfa749c1d2 --local-dir "$SCITS"
uv run --project evalkit scip-eval score --task scits-neu06 \
--references "$SCITS/meta_data.jsonl" --responses "$RUN/responses.jsonl" --out-dir "$RUN/score"
从原始 EEG 波形重现特征、生成并评分
先在 CPU 环境准备依赖、拉取固定版本资产,并用 reve_features.py 提取 REVE-base 特征:
WORK=/path/to/neu06-work
SCITS=$WORK/SciTS
REVE=$WORK/reve-base
GLM=$WORK/GLM-5.3-Flash-BF16
PROJECTOR=./checkpoints/projectors/glm-5.3-flash/eeg/neu06
RUN=$WORK/run
python3.12 -m venv "$WORK/venv"
. "$WORK/venv/bin/activate"
python -m pip install torch==2.15.0 transformers==5.24.1 scipy==1.18.1 safetensors numpy einops huggingface_hub
python -m pip install ./evalkit
hf download OpenTSLab/SciTS --repo-type dataset --revision 6ce690e904898cc8fd9014ea2e5bebdfa749c1d2 \
--include meta_data.jsonl --include "Neuroscience-Sleep-Sleep_staging-Classification/*" --local-dir "$SCITS"
hf download brain-bzh/reve-base --revision 33841986f6cc1438d9dcdbca5a2137d60f6007d9 --local-dir "$REVE"
hf download brain-bzh/reve-positions positions.json --revision befa5b57a455b77cf302daf610c2e9ed8140bace \
--local-dir "$WORK/reve-positions"
hf download zai-org/GLM-5.3-Flash-BF16 --revision f9fed3bbc82291073373d67452e9f25317ef7577 --local-dir "$GLM"
python load_projector.py glm-5.3-flash/eeg/neu06 --revision 7c228fc03394027fed19bda1ff26388394b0031a \
--local-dir ./checkpoints
python examples/neu06/reve_features.py --scits "$SCITS" --reve "$REVE" \
--positions "$WORK/reve-positions/positions.json" --out "$RUN/features"
在八张 GPU 上使用 vLLM 0.32.0 启动底座服务(参数与重跑实测一致):
vllm serve "$GLM" \
--served-model-name sage-sciperception \
--tensor-parallel-size 8 \
--dtype bfloat16 \
--max-model-len 98304 \
--max-num-seqs 256 \
--max-num-batched-tokens 16384 \
--gpu-memory-utilization 0.88 \
--enable-chunked-prefill \
--no-enable-prefix-caching \
--enable-prompt-embeds \
--generation-config vllm \
--seed 20261018 \
--trust-remote-code \
--logprobs-mode raw_logprobs \
--no-enable-flashinfer-autotune \
--reasoning-parser glm47 \
--tool-call-parser glm47 \
--enable-auto-tool-choice \
--host 127.0.0.1 --port 8000
最后运行 generate_neu06.py 并交由 EvalKit 评分(贪心解码,最大生成 8,192 tokens;首次试跑可传 --limit 16 并在评分时加 --only-responded):
python examples/neu06/generate_neu06.py --features "$RUN/features" --projector "$PROJECTOR" \
--projector-code modeling_projector.py --base-model "$GLM" \
--api-base http://127.0.0.1:8000/v1 --model sage-sciperception --out "$RUN/responses.jsonl"
uv run --project evalkit scip-eval score --task scits-neu06 \
--references "$SCITS/meta_data.jsonl" --responses "$RUN/responses.jsonl" --out-dir "$RUN/score"