# Inference with vLLM

> Insert projected scientific vectors into prompt embeddings and generate with vLLM.

---

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

---

The serving path inserts projected scientific vectors into a language model's full templated prompt embeddings and sends them to vLLM through `prompt_embeds` at `/v1/completions`. Scientific features and projection are prepared in the client; the language-model service generates the answer.

## Start the language-model service {#serve}

Install [vLLM](https://docs.vllm.ai/en/latest/getting_started/installation/) in a compatible inference environment. Run it on suitable GPUs and set tensor parallelism for that model and hardware. This command shows an eight-way deployment example:

```bash
vllm serve /path/to/matching-base-model \
  --served-model-name sage-sciperception \
  --enable-prompt-embeds \
  --tensor-parallel-size 8 \
  --generation-config vllm \
  --max-model-len 8192 \
  --host 127.0.0.1 --port 8000
```

> [!WARNING] Use the exact snapshot the checkpoint declares
> Serve the language-model snapshot named in the selected checkpoint's `config.json`. A different snapshot changes the embedding table the client reads from.

## Generate from prepared crystal features {#crystal}

The [crystal client](https://github.com/InternLM/Sage-SciPerception/blob/main/examples/vllm_cif.py) renders the checkpoint's native chat template, looks up text embeddings, inserts scientific vectors, and sends the completed prompt embeddings to the server.

Prepare `cif_features.pt` as a tensor of shape `[num_atoms, 64]`, containing the real CHGNet 0.3.0 atom states specified in [`cif/jarvis`](/docs/tasks/cif-jarvis/), in atom order. Once the server is ready, run:

```bash
python -m pip install --upgrade 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 local language-model directory supplies the tokenizer, configuration, and sharded input embedding table used by the server. The client reads the needed text embedding rows without loading the full language model.

## Other tasks {#other-tasks}

Scientific feature extraction and task-adapted scientific models are separate dependencies; some adapted scientific weights are not yet included in the release. Match each task's `scientific_inputs` before preparing predictions. The crystal example starts from prepared features, while other tasks require their corresponding input preparation and prompt assembly.

For a second worked path, including feature extraction from raw signals, see the [NEU06 example](https://github.com/InternLM/Sage-SciPerception/blob/main/examples/neu06/README.md).

## References {#references}

- [vLLM prompt embedding interface](https://docs.vllm.ai/en/latest/features/prompt_embeds/)
- [HF inference guide](https://huggingface.co/internlm/Sage-SciPerception#inference)
