# Inference examples and channel guide

> Unified nine-modality inference with vllm_projector.py and the full raw-EEG-to-evaluation walkthrough for NEU06.

---

LLMS index: [llms.txt](/Sage-SciPerception/llms.txt)

---

The [`examples/`](https://github.com/InternLM/Sage-SciPerception/tree/main/examples) directory provides three runnable client workflows covering standalone single-task serving, unified nine-modality serving, and raw-signal feature extraction plus benchmark scoring:

| Example | Scope | Key features |
| --- | --- | --- |
| [`examples/vllm_cif.py`](https://github.com/InternLM/Sage-SciPerception/blob/main/examples/vllm_cif.py) | Standalone crystal (`cif/jarvis`) client | Self-contained (`load_projector.py` + `modeling_projector.py`), no `evalkit`/`trainkit` install required |
| [`examples/vllm_projector.py`](https://github.com/InternLM/Sage-SciPerception/blob/main/examples/vllm_projector.py) | Unified 9-modality client | Uses `GlmProjectorSession`; supports `discrete`, `side`, `counts`, `atom_numbering`, `payload_labels`, multi-object payloads, and `--sample-dir` |
| [`examples/neu06/`](https://github.com/InternLM/Sage-SciPerception/blob/main/examples/neu06/README.md) | Full SciTS NEU06 benchmark loop | Raw EEG extraction (`reve_features.py`), resumable batched generation (`generate_neu06.py`), and CPU scoring |

## Install client dependencies {#setup}

From the repository root, install the client requirements alongside `evalkit` and `trainkit`, download any task projector, and start a matching vLLM server with `--enable-prompt-embeds` as shown in the [vLLM serving chapter](/book/03-vllm-serving/):

```bash
pip install "scipkit[infer]"   # or from a local checkout: pip install -e ".[infer]"

scip download glm-5.3-flash/spectra/qm9s --local-dir ./checkpoints
```

## Run directly from public training samples (`--sample-dir`) {#sample-dir}

Two-row `sage-training-data-v1` slices for all nine verified modalities are hosted at [`internlm/Sage-SciPerception-Training`](https://huggingface.co/datasets/internlm/Sage-SciPerception-Training). After downloading a slice, `vllm_projector.py` automatically loads `nodes.npy`, `offsets.npy`, optional `modality.npy` (`discrete`) or `side.npy` (`side`), `payload_labels`, and `question`.

Run `--dry-run` first to verify projector loading, channel shapes, and prompt assembly on CPU without starting vLLM:

```bash
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
```

Drop `--dry-run` to send the assembled `prompt_embeds` to a running vLLM endpoint:

```bash
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
```

## Input shapes and extra channels across all 9 modalities {#channels}

When supplying your own prepared arrays with `--features`, match the input channels declared in the checkpoint's `config.json`:

| Task | Projector ID | `--features` shape | Extra CLI flags |
| --- | --- | --- | --- |
| Crystal formation energy | `glm-5.3-flash/cif/jarvis` | `[num_atoms, 64]` | — |
| ECG classification | `glm-5.3-flash/ecg/phu01` | `[360, 768]` | — |
| EEG sleep staging | `glm-5.3-flash/eeg/neu06` | `[34, 512]` | See [Full NEU06 walkthrough](#neu06) below |
| DNA splice classification | `glm-5.3-flash/dna/splice` | `[1, 3]` | — |
| Protein structure ranking | `glm-5.3-flash/protein-struct/psr` | `[<=256, 384]` | — |
| XRD crystal system | `glm-5.3-flash/xrd/simxrd` | `[110, 512]` | — |
| Molecular spectra | `glm-5.3-flash/spectra/qm9s` | `[347, 50]` | `--discrete modality.npy` (`[347, 1]`, values `0`/`1`/`2`) |
| RNA family classification | `glm-5.3-flash/rna/ncrna` | `[len_seq, 640]` | `--side side.npy` (`[len_seq, 13]` broadcast per nucleotide) |
| Protein interface sites | `glm-5.3-flash/protein-seq/mpbind` | `[len_win, 1280]` | `--side side.npy` (`[len_win, 2]`) and optional `--payload-labels` |

The examples below cover `discrete`, `side`, `payload_labels`, and multi-object inputs:

**Example 6-1.** Run spectra discrete channels\, RNA\/protein side channels\, and multi\-object prompts with vllm\_projector\.py\.

```bash
# Spectra (QM9S): continuous patches + discrete spectrum-type column + automatic 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): per-nucleotide states + broadcast 13-class side probabilities
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."

# Protein sequence (MPBind): per-residue states + per-residue side features + 1-based residue labels
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."

# Multi-object comparison: concatenate features in object order and pass --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."
```

## Full SciTS NEU06 walkthrough (raw EEG to EvalKit) {#neu06}

[`examples/neu06/`](https://github.com/InternLM/Sage-SciPerception/blob/main/examples/neu06/README.md) evaluates the released `glm-5.3-flash/eeg/neu06` projector on [SciTS](https://huggingface.co/datasets/OpenTSLab/SciTS) NEU06: 1,024 single-channel Fpz-Cz EEG segments of 30 seconds labelled Wake, N1, N2, N3, or REM. The released v0.1.0 scores are **72.01%** Macro-F1 / **76.46%** Accuracy; an independent rerun with these scripts reaches **71.82%** Macro-F1 / **76.46%** Accuracy across all 1,024 items (per-item predictions of the released run are not available).

### Pinned inputs

| Input | Source | Revision | License |
| --- | --- | --- | --- |
| SciTS | [`OpenTSLab/SciTS`](https://huggingface.co/datasets/OpenTSLab/SciTS) | `6ce690e904898cc8fd9014ea2e5bebdfa749c1d2` | CC BY-NC-SA 4.0 |
| REVE-base | [`brain-bzh/reve-base`](https://huggingface.co/brain-bzh/reve-base) | `33841986f6cc1438d9dcdbca5a2137d60f6007d9` | REVE Responsible Use License v1.0 |
| `positions.json` | [`brain-bzh/reve-positions`](https://huggingface.co/brain-bzh/reve-positions) | `befa5b57a455b77cf302daf610c2e9ed8140bace` | Not stated upstream |
| GLM-5.3-Flash-BF16 | [`zai-org/GLM-5.3-Flash-BF16`](https://huggingface.co/zai-org/GLM-5.3-Flash-BF16) | `f9fed3bbc82291073373d67452e9f25317ef7577` | See upstream |
| NEU06 projector | [`internlm/Sage-SciPerception`](https://huggingface.co/internlm/Sage-SciPerception/tree/main/projectors/glm-5.3-flash/eeg/neu06) | `7c228fc03394027fed19bda1ff26388394b0031a` | Apache-2.0 |

### Score existing predictions on CPU

Scoring an existing `responses.jsonl` (`eval_id` and `content` per line) requires only Python 3.12+ and `uv`:

```bash
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"
```

### Extract REVE features, serve, generate, and score

Prepare the client environment on CPU, download the pinned inputs, and extract features with [`reve_features.py`](https://github.com/InternLM/Sage-SciPerception/blob/main/examples/neu06/reve_features.py):

```bash
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"
```

Start the language model with vLLM 0.32.0 on eight GPUs (the exact arguments of the rerun):

```bash
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
```

Run [`generate_neu06.py`](https://github.com/InternLM/Sage-SciPerception/blob/main/examples/neu06/generate_neu06.py) and score with EvalKit (greedy decoding, up to 8,192 output tokens; add `--limit 16` with `--only-responded` to try a small batch first):

```bash
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"
```
