Tutorial
Tutorial
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
Tables
Examples
1 Scientific perception and projector architecture
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.

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_inputsspecifies the encoder, preprocessing, feature width and any scientific readout or side inputs.projectorspecifies the architecture and any optional inputs.output_dimsets the target embedding width.base_modelpins the language-model repository and revision.promptdescribes how to lay out the scientific payload in the chat template.taskidentifies the task andtraining_steprecords the exported training step. TrainKit exports can also include atrainingprovenance 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 suffix | Scientific representation | Task |
|---|---|---|
cif/jarvis | CHGNet 0.3.0 atom states | Formation energy |
protein-seq/mpbind | ESM-2 residue states and a task-adapted ESMC readout | Interface sites |
spectra/qm9s | IR, Raman, and UV–Vis patches with spectrum-type indices | Molecular structure identification |
ecg/phu01 | Cached ECG position features | ECG classification |
dna/splice | Task-adapted DNABERT-2 probability readout | Splice-site classification |
eeg/neu06 | REVE-base patch states and matching positions | Sleep staging |
rna/ncrna | RNA-FM states and a task-adapted RiNALMo ensemble readout | RNA family classification |
xrd/simxrd | XRD CNN convolutional states | Crystal-system classification |
protein-struct/psr | ProteinMPNN residue states or contiguous mean bins | Protein structure ranking |
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
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
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.
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
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.
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.
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
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.
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.
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 ID | Evaluation task | Additional CPU dependencies |
|---|---|---|
scits-neu06 | Sleep staging | — |
scits-phu01 | ECG classification | — |
llm4mat-jarvis | Crystal formation energy | — |
qm9s-allspectra | Three-spectrum molecular structure identification | rdkit, myopic-mces, pulp |
atom3d-psr | Protein structure ranking | scipy |
gue-splice | Splice-site classification | — |
beacon-ncrna | RNA family classification | — |
mpbind-ba1 | Protein interface sites | — |
simxrd-ol | Crystal-system classification | — |
Reference formats and protocol versions are linked from the evaluation guide.
5 Train a projector and extend evaluation
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.jsondeclares the schema, split JSONL files, and the path tofeatures.json. Resolve paths relative to the manifest.- A split row describes a training example. Its
array_indexidentifies objects in the frozen feature cache, in prompt order. features.jsondescribes the cache.offsets.npylocates each object’s span innodes.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.
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.