# Train a projector and extend evaluation

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

---

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

---

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 {#data}

The [public sample dataset](https://huggingface.co/datasets/internlm/Sage-SciPerception-Training) 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](https://github.com/InternLM/Sage-SciPerception/blob/main/trainkit/src/trainkit/dataset.py) shows how the manifest and cache are opened.

## Check packing before training {#preflight}

Start from the public repository root. Install the [pinned XTuner checkout and dependencies](/docs/guides/training/#install), 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](/book/02-quickstart-cpu/). The preflight reads the projector configuration. The downloaded component weights are available for an optional warm start.

```bash
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 {#train}

Use [`recipes/projector_sft.py`](https://github.com/InternLM/Sage-SciPerception/blob/main/trainkit/recipes/projector_sft.py) for the common path across all nine published `atom` modalities. Use [`recipes/neu06_projector.py`](https://github.com/InternLM/Sage-SciPerception/blob/main/trainkit/recipes/neu06_projector.py) when you need strict NEU06 checks. Follow the [training guide](/docs/guides/training/#train) 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 {#extend}

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](https://github.com/InternLM/Sage-SciPerception/blob/main/evalkit/tests/test_dataset_contract.py) shows how a new implementation reaches the existing CLI and scorer.
