This document is relevant for: Trn3
Quickstart: Serve Qwen3-8B with SGLang-Neuron#
Note
SGLang-Neuron is in public preview. Features, APIs, and supported models can change in later releases.
Applies to: trn3.48xlarge
In this quickstart, you start the SGLang-Neuron container image on one trn3.48xlarge instance, serve Qwen3-8B on four NeuronCores, and send a chat request to the server. Then you stop the server.
This quickstart takes approximately 30 minutes. The first start of the model compiles its programs, which takes most of that time.
Prerequisites#
Before you begin, make sure that you have:
A trn3.48xlarge instance with Docker Engine.
The Neuron driver of Neuron SDK 2.33.0 (
aws-neuronx-dkms2.31.7.0 or later) on the host.A bash shell. The commands rely on bash to split
$DEVICESinto separate arguments. zsh does not do this.Internet access from the instance, to pull the image and download the checkpoint.
Approximately 50 GB of free disk space for the container image and the Qwen3-8B checkpoint.
Step 1: Check the host#
In this step, you make sure that the Neuron driver is ready.
On the host, list the Neuron devices:
ls /dev/neuron*
The command lists one device for each Neuron chip. If it lists no devices, install or load the Neuron driver. On a host that just started, the driver can need a few minutes before it is ready.
Step 2: Set the variables and pull the image#
In this step, you set the shell variables that the next steps use, and you pull the container image.
Set the variables. Replace
/path/to/modelsand/path/to/cachewith directories on the host:IMAGE=public.ecr.aws/neuron/pytorch-inference-sglang-neuron:v0.1.0-neuron-py314-sdk-2.33.0-ubuntu26.04 MODELS=/path/to/models # the checkpoints, mounted at /models CACHE=/path/to/cache # the compile cache: persistent and local, one directory per image version DEVICES=$(for d in /dev/neuron*; do printf -- '--device %s ' "$d"; done)
Pull the image:
docker pull $IMAGE
Make sure that the container finds the Neuron devices:
docker run --rm $DEVICES $IMAGE neuron-ls
neuron-lslists the same devices asls /dev/neuron*on the host.
Step 3: Download the checkpoint#
In this step, you download the Qwen3-8B checkpoint from Hugging Face with the hf CLI in the image:
docker run --rm -v $MODELS:/models $IMAGE hf download Qwen/Qwen3-8B --local-dir /models/Qwen3-8B
Step 4: Start the server#
In this step, you start the server in a container. The container runs the Qwen3-8B example script from the image, run_server.sh. The script starts one server that does both prefill and decode, at tensor parallelism 4 (TP4) on four NeuronCores.
Start the container:
docker run -d --name qwen3-8b --init --ipc=host --cap-add SYS_NICE $DEVICES \ -v $MODELS:/models:ro -v $CACHE:/cache -p 127.0.0.1:30000:30000 -e HOST=0.0.0.0 \ $IMAGE /opt/sglang-neuron/examples/qwen3_8b/run_server.sh
-p 127.0.0.1:30000:30000publishes the server port on the loopback address of the host only.HOST=0.0.0.0lets the published port reach the server in the container.Wait until the server answers
/health:until curl -sf http://127.0.0.1:30000/health; do [ "$(docker inspect -f '{{.State.Running}}' qwen3-8b)" = true ] || { echo "exited: docker logs qwen3-8b"; break; } sleep 10; done
The first start on a new compile cache compiles the model programs. To see the progress, run
docker logs -f qwen3-8bin a different shell. The server is ready when its log showsThe server is fired up and ready to roll!.
Step 5: Send a chat request#
In this step, you send a request to the OpenAI-compatible /v1/chat/completions endpoint. The request turns off the thinking mode of Qwen3:
curl -s http://127.0.0.1:30000/v1/chat/completions -H 'Content-Type: application/json' -d '{
"model": "/models/Qwen3-8B", "temperature": 0, "max_tokens": 64,
"chat_template_kwargs": {"enable_thinking": false},
"messages": [{"role": "user", "content": "What is 17 * 23? Answer with the number."}]}'
The request sets temperature to 0, because the plug-in samples greedily by default. To serve sampled requests, see the SGLANG_NEURON_SAMPLER variable in Reference: SGLang-Neuron configuration.
Confirmation#
The answer contains this text:
17 * 23 = 391
To check the accuracy of the server, run the GSM8K check from the image. The check sends the first 100 GSM8K questions to the server and prints Accuracy. For Qwen3-8B, expect an accuracy of approximately 0.92:
docker run --rm --network host -e PORT=30000 $IMAGE /opt/sglang-neuron/examples/qwen3_8b/run_gsm8k.sh
Common issues#
The server exits at start with
the compile cache ... was built from other NKI kernel sources. The cache directory belongs to a different image version. Give this image its own cache directory.The server fails with
Failed to load the backend extension: torch_neuronx. A volume is mounted at/workspace. Mount your data at a different path.Neuron runtime errors on a host that just started. The Neuron driver is not ready. Wait until
ls /dev/neuron*lists the devices.
For more problems and fixes, see Troubleshooting: SGLang-Neuron.
Clean up#
Stop and remove the container:
docker stop -t 120 qwen3-8b && docker rm qwen3-8b
The server drains and stops every rank when it gets the stop signal. The default Docker timeout of 10 seconds can be too short, so the command sets 120 seconds.
The compile cache stays in $CACHE. The next start of Qwen3-8B with the same cache directory loads the compiled programs.
Next steps#
Further reading#
This document is relevant for: Trn3