Skip to content

Tutorial

Load, serve, evaluate, and train a Sage-SciPerception projector.

Start with the projector architecture and run a CPU smoke check. Then serve a crystal example through vLLM and follow a full EEG evaluation. The final chapter uses TrainKit to prepare training and explains how to add an evaluation dataset.

Contents

Figures

  1. Figure 1-1 — From scientific inputs to language-model embeddings.

Tables

  1. Table 1-1 — Scientific input for each released checkpoint.

Examples

  1. Example 2-1 — Run a synthetic two-row projection on CPU.

1 Scientific perception and projector architecture

How scientific representations become GLM-5.3-Flash prompt embeddings.

A Sage-SciPerception checkpoint connects one scientific task to a frozen GLM-5.3-Flash backbone. A frozen scientific encoder or a fixed preprocessing pipeline produces task-specific feature rows. The trained atom projector maps those rows and their positions to the backbone’s embedding width. The client inserts the projected rows into a chat-templated prompt so that GLM processes them together with text.

Scientific representations pass through projectors into the language model
Figure 1-1 From scientific inputs to language-model embeddings.

What a checkpoint contains

The Hugging Face repository’s root config.json maps component IDs to directories. In each component directory, a second config.json describes the sage-projector-v1 component and names its projector.safetensors weights. Read these fields before preparing inputs:

  • scientific_inputs specifies the encoder, preprocessing, feature width and any scientific readout or side inputs.
  • projector specifies the architecture and any optional inputs. output_dim sets the target embedding width.
  • base_model pins the language-model repository and revision. prompt describes how to lay out the scientific payload in the chat template.
  • task identifies the task and training_step records the exported training step. TrainKit exports can also include a training provenance block.

See the configuration reference for field definitions.

The nine released modalities

Each suffix below is used with the prefix glm-5.3-flash/. A row can represent an atom, residue, patch, or another unit defined by the task.

Component suffixScientific representationTask
cif/jarvisCHGNet 0.3.0 atom statesFormation energy
protein-seq/mpbindESM-2 residue states and a task-adapted ESMC readoutInterface sites
spectra/qm9sIR, Raman, and UV–Vis patches with spectrum-type indicesMolecular structure identification
ecg/phu01Cached ECG position featuresECG classification
dna/spliceTask-adapted DNABERT-2 probability readoutSplice-site classification
eeg/neu06REVE-base patch states and matching positionsSleep staging
rna/ncrnaRNA-FM states and a task-adapted RiNALMo ensemble readoutRNA family classification
xrd/simxrdXRD CNN convolutional statesCrystal-system classification
protein-struct/psrProteinMPNN residue states or contiguous mean binsProtein structure ranking
Table 1-1 Scientific input for each released checkpoint.

Check the task pages for the exact representation before generating predictions. Several checkpoints depend on separately obtained scientific encoders or task-adapted weights.

2 Download and verify a projector on CPU

Pin the CIF checkpoint, inspect its configuration, and check a synthetic forward pass.

Use the public JARVIS formation-energy checkpoint for a small test of the download, weight loading, and tensor interface. The commands require Python and run without a language-model download or a GPU.

Download from the pinned snapshot

git clone https://github.com/InternLM/Sage-SciPerception.git
cd Sage-SciPerception
python -m pip install -r requirements.txt
python load_projector.py glm-5.3-flash/cif/jarvis \
  --revision 7c228fc03394027fed19bda1ff26388394b0031a \
  --local-dir ./checkpoints

load_projector.py resolves the ID in the Hugging Face repository index, then downloads the component configuration and weights from the same snapshot. With --local-dir, the command also copies the index into ./checkpoints and prints the local component directory. Browse the pinned snapshot.

Load and exercise the module

Save or run the following Python code from the repository root. load_projector calls modeling_projector.build with the architecture and output width declared in the component configuration. It loads the weights strictly and returns a frozen module in evaluation mode.

Example 2-1 Run a synthetic two-row projection on CPU.
import torch

from load_projector import load_projector

projector, config = load_projector(
    "checkpoints/projectors/glm-5.3-flash/cif/jarvis", device="cpu"
)
with torch.inference_mode():
    features = torch.zeros(2, config["projector"]["feature_dim"])
    payload = projector(features, torch.arange(features.shape[0]))

assert config["task"] == "cif/jarvis"
assert payload.shape == (2, 4096)
assert torch.isfinite(payload).all()
print(config["task"], tuple(payload.shape))

Expect cif/jarvis (2, 4096). The two zero rows exercise only the projector. For formation-energy inference, prepare real CHGNet states with 64 features per atom in atom order, then follow the vLLM chapter.

3 Serve projected inputs with vLLM

Build an embedding prompt on the client and send it through the completions API.

The inference client builds the entire prompt in the language model’s embedding space. It renders the native GLM chat template, looks up text embedding rows, projects the scientific features, and replaces the designated payload spans. vLLM receives the result as prompt_embeds on /v1/completions.

Serve the matching backbone

Use the model snapshot declared by base_model in the selected checkpoint. The client needs that same snapshot locally for the tokenizer and input embedding table. The example uses eight-way tensor parallelism. Set it for the hardware serving the backbone.

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

Send a crystal prompt

Prepare a tensor of shape [num_atoms, 64] with the CHGNet 0.3.0 states described in the JARVIS task guide. Preserve atom order. Use the checkpoint from the CPU chapter and pass the feature file to the crystal client.

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

The client sends the matrix serialized with PyTorch and encoded as Base64. The default question asks for formation energy per atom in eV/atom. Use --question to pass another question.

Build a session for variable-length inputs

evalkit.glm_prompt_embeds provides two adapters. GlmProjectorPrompt takes a fixed question and payload layout at construction and reuses their text embeddings. GlmProjectorSession reuses the projector, tokenizer and embedding lookup while rendering the question and payload spans for each request.

For multiple objects, concatenate the feature rows in object order and pass their lengths as payload_tokens, for example [3, 5] for eight rows. If the checkpoint uses atom_numbering, the chat prompt renders numbered payload positions. To supply labels for those positions, pass payload_labels grouped per object. Follow the checkpoint configuration for discrete or side inputs. If the projector needs counts, the adapter uses the per-object lengths unless the caller supplies counts explicitly.

The evaluation chapter shows how to save generation results and score them alongside frozen references.

4 Run an end-to-end evaluation with EvalKit

Generate SciTS NEU06 predictions, resume a run, and score the saved answers on CPU.

A SciTS NEU06 run goes from raw EEG to REVE-base features, then through the released EEG projector to GLM completions. EvalKit joins saved answers to a frozen reference set and scores them on CPU. Generation and scoring use the same eval_id, prefixed with NEU06: for this dataset.

Generate a prediction file

Follow the NEU06 example to install the client dependencies and download the pinned SciTS, REVE, position table, GLM, and projector inputs. Start the vLLM service using the example’s arguments. Then run these commands from the repository root with paths pointing to your downloads. Feature extraction runs on CPU. For an initial smoke run, add --limit 16 and use a separate --out path.

SCITS=./SciTS
RUN=./neu06-run
REVE=/path/to/reve-base
POSITIONS=/path/to/reve-positions/positions.json
GLM=/path/to/matching-base-model
PROJECTOR=./checkpoints/projectors/glm-5.3-flash/eeg/neu06

python examples/neu06/reve_features.py --scits "$SCITS" --reve "$REVE" \
  --positions "$POSITIONS" --out "$RUN/features"
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"

The generator saves a run_id on each response and the corresponding run identity in responses.jsonl.run.json. Run the same command against the same file to skip IDs already written. A different identity, including changed ordered inputs or decoding settings, needs a new output path. Keep a single writer per file.

Score the saved answers on CPU

Use Python 3.12 or later and uv. From the public repository root, fetch the pinned reference metadata and pass it with the response log to scip-eval.

SCITS=./SciTS
RUN=./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"

The NEU06 loader checks the count and SHA-256 of its frozen reference pairs. Scores include macro-F1 and accuracy over Wake, N1, N2, N3, and REM. Read the aggregate summary.json and per-item scores.jsonl in the output directory. The default scores the whole reference set, treating missing predictions as empty. Add --only-responded to score the smoke run on just the IDs with response records. The output marks this as a subset.

Choose another dataset

Use --dataset as an alias for --task. Pass --workers to set the number of processes for metrics that support parallel scoring, such as QM9S. Install any additional packages into the scoring environment for the corresponding task.

Dataset IDEvaluation taskAdditional CPU dependencies
scits-neu06Sleep staging—
scits-phu01ECG classification—
llm4mat-jarvisCrystal formation energy—
qm9s-allspectraThree-spectrum molecular structure identificationrdkit, myopic-mces, pulp
atom3d-psrProtein structure rankingscipy
gue-spliceSplice-site classification—
beacon-ncrnaRNA family classification—
mpbind-ba1Protein interface sites—
simxrd-olCrystal-system classification—

Reference formats and protocol versions are linked from the evaluation guide.

5 Train a projector and extend evaluation

Prepare a feature export, check XTuner packing, and register a new evaluation dataset.

TrainKit leaves feature extraction upstream and trains the projector against a frozen GLM-5.3-Flash backbone. XTuner provides the trainer, FSDP, packing, optimizer, and loss. TrainKit supplies the prompt, supervision mask, and insertion of projected payloads into the packed sequence.

Read a training export

The public sample dataset includes an NEU06 example under samples/eeg/neu06/. In a sage-training-data-v1 export:

  • dataset.json declares the schema, split JSONL files, and the path to features.json. Resolve paths relative to the manifest.
  • A split row describes a training example. Its array_index identifies objects in the frozen feature cache, in prompt order.
  • features.json describes the cache. offsets.npy locates each object’s span in nodes.npy, which holds its features. Some components also require discrete columns or side features.

Use the component’s scientific_inputs and prompt to decide what your export must contain. The TrainKit reader shows how the manifest and cache are opened.

Check packing before training

Start from the public repository root. Install the pinned XTuner checkout and dependencies, set XTUNER to that checkout, and set GLM to the matching local backbone directory. These commands also use hf from huggingface_hub and the root projector requirements from the CPU chapter. The preflight reads the projector configuration. The downloaded component weights are available for an optional warm start.

WORK=./training-work
DATA=$WORK/training-samples/samples/eeg/neu06
COMPONENT=./checkpoints/projectors/glm-5.3-flash/eeg/neu06

python -m pip install ./evalkit ./trainkit
hf download internlm/Sage-SciPerception-Training --repo-type dataset \
  --include "samples/eeg/neu06/*" --local-dir "$WORK/training-samples"
python load_projector.py glm-5.3-flash/eeg/neu06 \
  --revision 7c228fc03394027fed19bda1ff26388394b0031a --local-dir ./checkpoints

PYTHONPATH="$XTUNER" scip-train preflight \
  --manifest "$DATA/dataset.json" --model "$GLM" \
  --projector-config "$COMPONENT/config.json" --work-dir "$WORK/preflight" \
  --pack-max-length 2048 --global-batch-size 2 \
  --total-epoch 1 --sp-size 8 --pack-chunk-size 1

The preflight runs the recipe’s dataset, sampler, and collator on CPU. Read sizing in preflight.json for pack count, steps, warmup, and dropped tail packs. For training, the world size must be divisible by the sequence-parallel size (SP), and the data-parallel size (DP) is world_size / SP. Keep pack_max_length divisible by SP and global_batch_size divisible by DP. With round_up=False, steps per epoch are packs // global_batch_size. The sample uses one row per packing chunk so its two rows yield two packs and fill a global batch of two.

Choose a recipe and export

Use recipes/projector_sft.py for the common path across all nine published atom modalities. Use recipes/neu06_projector.py when you need strict NEU06 checks. Follow the training guide to pass the preflight sizing to XTuner. The exported config.json and projector.safetensors use the same component interface as the public checkpoints, so compatible serving clients can load the export and EvalKit can score the resulting predictions.

Add an evaluation dataset

Implement an EvalDataset subclass in the relevant EvalKit suite. Give it a unique name and versioned protocol. Implement load for frozen references keyed by eval_id, metadata for provenance and scoring rules, and score_items for parsing and metrics. Use the shared answer_span where its extraction rules match the protocol. Register the subclass in datasets/__init__.py and add fixed fixtures for reference validation, missing responses, and scoring. The dataset contract test shows how a new implementation reaches the existing CLI and scorer.