Use AIUnderstand AIBuild with AI
Build with AI·Model deep dive·· 4 min read

Run Spark-X2.6-4B: a 4B On-Device Model with Adjustable Thinking

Spark-X2.6-4B is an Apache-2.0 4B model for agents, coding and long context. Run it with Transformers, SGLang, vLLM or Ollama, per the model card.

The code in this post comes from the model's docs and hasn't been run in our CI yet. If something breaks, let us know.

Spark-X2.6-4B is a compact language model from XHToken (the SparkLLM team), aimed at on-device agents. It keeps exactly the same architecture as Spark-X2.5-4B and gets its gains from improved post-training. The card says that brings improvements in coding, agent work, long context, multilingual use and reasoning, and it reports state-of-the-art results among similarly sized open models, in some cases matching or surpassing models of about 9B parameters. The benchmark tables on the card are images, so this post doesn’t repeat specific scores. Check the card’s charts before you rely on a comparison.

Key specs

Property Value
Size ~4B (per the model name)
Base model XHToken/Spark-X2.6-4B-Base
Languages English, Chinese
Library Transformers (trust_remote_code=True required)
Context in the card’s server examples 1,048,576 tokens
Thinking levels none, low, high
License Apache-2.0

The card’s two headline features are stronger agentic and long-context behavior, and a controllable thinking budget. The thinking levels are meant to let an application trade off reasoning quality, latency and cost.

Install

The card pins a specific Transformers version:

Terminal window
pip install transformers==4.57.1

For serving, the card uses a prebuilt SGLang Docker image (NVIDIA GPUs) or the vllm/vllm-openai:latest image. Both expect a local checkpoint directory:

Terminal window
export MODEL_PATH=/absolute/path/to/Spark-X2.6-4B
docker pull lmsysorg/sglang:nightly-dev-cu13-20260827-20621aa1

Run it with Transformers

This is the card’s quickstart, unchanged. enable_thinking=True turns on the thinking mode in the chat template.

quickstart.py
from transformers import AutoModelForCausalLM, AutoTokenizer
model_id = "XHToken/Spark-X2.6-4B"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
trust_remote_code=True,
torch_dtype="auto",
device_map="auto",
)
messages = [{"role": "user", "content": "What is the capital of Anhui Province?"}]
inputs = tokenizer.apply_chat_template(
messages,
tokenize=True,
add_generation_prompt=True,
enable_thinking=True,
return_dict=True,
return_tensors="pt",
).to(model.device)
outputs = model.generate(
**inputs,
max_new_tokens=131072,
do_sample=True,
temperature=1.0,
top_p=0.95,
top_k=0,
)
print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:], skip_special_tokens=True))

The card’s Transformers example samples with temperature 1.0, top_p 0.95 and top_k 0. Its server examples use temperature 1, top_p 0.95 and top_k -1, which is how those APIs disable top-k.

Serve it with SGLang

The card starts an OpenAI-compatible server on port 30000 with a tool-call parser (spark25) and a reasoning parser (qwen3):

Terminal window
docker run --rm -it \
--gpus '"device=0"' \
--ipc=host \
-p 30000:30000 \
-v "$MODEL_PATH:/root/Spark-X2.6-4B:ro" \
lmsysorg/sglang:nightly-dev-cu13-20260827-20621aa1 \
python -m sglang.launch_server \
--model-path /root/Spark-X2.6-4B \
--served-model-name spark2.6 \
--tool-call-parser spark25 \
--reasoning-parser qwen3 \
--tp-size 1 \
--mem-fraction-static 0.8 \
--context-length 1048576 \
--chat-template /root/Spark-X2.6-4B/chat_template.jinja \
--host 0.0.0.0 \
--port 30000

Thinking is on by default, from both the chat template and the Qwen3 reasoning parser. To switch it off for one request, pass "chat_template_kwargs": {"enable_thinking": false}. The card’s client example (it sends the question in Chinese; the English prompt below is the same question):

Terminal window
curl -s http://localhost:30000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "spark2.6",
"messages": [{"role": "user", "content": "What is the capital of Anhui Province?"}],
"max_tokens": 131072,
"temperature": 1,
"top_k": -1,
"top_p": 0.95,
"repetition_penalty": 1,
"presence_penalty": 0,
"frequency_penalty": 0
}'

Serve it with vLLM

For NVIDIA GPUs the card uses the official vLLM image:

Terminal window
docker run --rm --gpus all \
--ipc=host \
-p 30000:30000 \
-v "$MODEL_PATH:/models/Spark-X2.6-4B:ro" \
vllm/vllm-openai:latest \
--model /models/Spark-X2.6-4B \
--port 30000 \
--trust-remote-code \
--served-model-name spark25 \
--tensor-parallel-size 1 \
--gpu-memory-utilization 0.7 \
--enable-prefix-caching \
--chat-template /models/Spark-X2.6-4B/chat_template.jinja

Note that the served name here is spark25, so the client request must use "model": "spark25":

Terminal window
curl -s http://127.0.0.1:30000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "spark25",
"messages": [{"role": "user", "content": "What is the capital of Anhui Province?"}],
"temperature": 1.0,
"top_k": -1,
"top_p": 0.95
}'

Other ways to run it

The card also lists these routes. It gives the commands below and no more detail:

  • Ollama (v0.34.1 or later): ollama run SparkLLM/Spark-X2.6-4B
  • LM Studio (0.4.0 or later): search for “Spark-X2.6”, or use lms chat spark-x2.6
  • Spark-MLX-LLM, which runs the original checkpoints on Apple silicon, Linux CPU or NVIDIA CUDA on Linux:
Terminal window
spark-mlx-generate \
--device gpu \
--dtype bfloat16 \
--model XHToken/Spark-X2.6-4B \
--prompt "What is the capital of Anhui Province?" \
--max-tokens 512 \
--temp 0
  • llama.cpp: native spark2_5 support needs build b10828 or later (llama cli -m /path/to/Spark-X2.6-4B-GGUF).
  • Fine-tuning: the card recommends Llama-Factory.

Gotchas

  • Memory. The server examples set a 1,048,576-token context. The card warns this needs sufficient device memory and says to lower --context-length when necessary.
  • Remote code. Both the Transformers and vLLM examples use trust_remote_code. Read what you’re enabling before you run it on a shared machine.
  • Naming. The architecture and tool parser are called spark25 / spark2_5 even for X2.6 (the card says the architecture is unchanged from X2.5). The served model name differs between the card’s SGLang (spark2.6) and vLLM (spark25) examples.
  • Ascend NPUs. The card’s vLLM route for Ascend hardware has an extra step: install the Spark plugin from github.com/XHToken/Spark-plugin inside the container.
  • Version pins. The SGLang image tag is a dated nightly build, and the Transformers version is pinned to 4.57.1. Expect to use those versions.
  • Thinking. It’s on by default. If you want quick, short replies, disable it per request as shown above. The card doesn’t show how to select the low or high levels, so check the chat template before relying on them.
  • Untested. We didn’t run these commands; they are taken from the card.

When to pick it

Pick Spark-X2.6-4B if you want a permissively licensed (Apache-2.0) small model for on-device or low-cost agent and coding work, with English and Chinese support, and you like the idea of a thinking switch you can turn down for latency. It also has many ready-made routes, from Transformers to Ollama.

Skip it, or test it first, if you need a language beyond English and Chinese (the card lists only those two), if you can’t afford the memory for very long contexts, or if you need figures you can verify yourself: the card’s comparisons are in charts, and “best-in-class among similar sizes” is the authors’ claim. Run it on your own tasks before you commit.

Related