This document is relevant for: Trn3
Tutorial: Serve GPT-OSS-120B with prefill-decode disaggregation#
Note
SGLang-Neuron is in public preview. Features, APIs, and supported models can change in later releases.
Applies to: trn3.48xlarge (two instances)
Overview#
In this tutorial, you serve GPT-OSS-120B with prefill-decode (PD) disaggregation on two Trn3 nodes. A prefill server on one node computes the KV cache of each prompt. It sends the KV cache to a decode server on the other node with NIXL over Elastic Fabric Adapter (EFA). The decode server generates the answer. A balancer on the prefill node receives the client requests and sends each request to both servers.
You start the two servers and the balancer from the GPT-OSS-120B example scripts in the container image. Then you send a request whose answer you know, and you run the GSM8K accuracy check.
This tutorial takes about 15 minutes after the instances are ready, plus the download of the 65 GB checkpoint on each node. The first start of the prefill server compiles its programs, which takes most of that time.
Before you start#
Do the SGLang-Neuron quickstart first. This tutorial uses the same image, variables, and compile cache rules.
Model details#
GPT-OSS-120B is a mixture-of-experts (MoE) model with MXFP4 experts. In this layout:
Prefill server: five data-parallel replicas on the prefill node. Each replica runs attention at tensor parallelism 4 (TP4) and the experts at expert parallelism 2 (EP2).
Decode server: eight data-parallel attention replicas on the decode node, with attention TP8 and MoE EP64.
Context: the prompt and the answer of one request together can have up to 10,240 tokens.
Chat parsers: the servers run the SGLang GPT-OSS reasoning and tool-call parsers. A chat answer has its reasoning in
reasoning_contentand its tool calls intool_calls.
Prerequisites#
Two trn3.48xlarge instances with Docker Engine and the Neuron driver of Neuron SDK 2.33.0 (
aws-neuronx-dkms2.31.7.0 or later). In this tutorial, one instance is the prefill node and the other is the decode node.EFA devices on both instances (
/dev/infiniband/uverbs*).One security group for both instances that allows all traffic between its members. EFA needs this rule. The KV transfer of each rank also listens on a TCP port that the system selects, so a firewall that opens only ports 30000 and 8998 stops the transfer. To create the security group, see Prepare an EFA-enabled security group.
The GPT-OSS-120B checkpoint in a host directory on both nodes, at
<models dir>/gpt-oss-120b.The address of each node that the other node can reach. Do not use a loopback address.
Important
The server ports and the KV transfer ports accept any peer that can reach them. Keep them in the security group of the two nodes, and give clients access only to the balancer.
Prepare your environment#
Do these steps on both nodes.
Set the image variable:
IMAGE=public.ecr.aws/neuron/pytorch-inference-sglang-neuron:v0.1.0-neuron-py314-sdk-2.33.0-ubuntu26.04
Download the checkpoint to the host directory:
docker run --rm -v <models dir>:/models $IMAGE hf download openai/gpt-oss-120b --local-dir /models/gpt-oss-120b --exclude "original/*" --exclude "metal/*"
Start a container with the Neuron devices, the EFA devices, and the network of the node, and open a shell in it:
DEVICES=$(for d in /dev/neuron* /dev/infiniband/uverbs*; do printf -- '--device %s ' "$d"; done) docker run -it --rm --name sglang --init --ipc=host --network host \ --cap-add SYS_NICE --cap-add IPC_LOCK --ulimit memlock=-1 $DEVICES \ -v <models dir>:/models:ro -v <cache dir>:/cache $IMAGE bash
Replace
<models dir>and<cache dir>with host directories. Use one cache directory for each image version and node role.
To open more shells in the same container, run docker exec -it sglang bash on the host.
Step 1: Start the decode server#
In this step, you start the decode server. On the decode node, in the container shell, run:
HOST=<decode node address> bash /opt/sglang-neuron/examples/gpt_oss_120b/run_decode.sh # decode node
The server is ready when its log shows The server is fired up and ready to roll!. The first start compiles the programs of the server.
Step 2: Start the prefill server#
In this step, you start the prefill server. On the prefill node, in the container shell, run:
HOST=<prefill node address> bash /opt/sglang-neuron/examples/gpt_oss_120b/run_prefill.sh # prefill node
You can start the two servers in either order. Wait until both servers are ready before you go to the next step.
Step 3: Start the balancer#
In this step, you start the balancer. The balancer is the address that clients use for the PD pair. It needs no Neuron device.
On the prefill node, open a second shell in the container (docker exec -it sglang bash), and run:
# prefill node, second shell, once both servers are ready
PREFILL_URL=http://<prefill node address>:30000 DECODE_URL=http://<decode node address>:30000 \
bash /opt/sglang-neuron/examples/gpt_oss_120b/run_balancer.sh
The balancer listens on 127.0.0.1:8000. It serves /generate, /v1/completions, and /v1/chat/completions.
Step 4: Send a request#
In this step, you send one request whose answer you know. On the prefill node, open a third shell in the container, and run:
bash /opt/sglang-neuron/examples/gpt_oss_120b/run_client.sh
The script sends a chat request to the balancer. Then it sends a second request that asks for a tool call.
Confirmation#
The output of run_client.sh shows "content": "391", and then a get_weather tool call.
To check the accuracy, run the GSM8K check in the same shell:
bash /opt/sglang-neuron/examples/gpt_oss_120b/run_gsm8k.sh
The check sends the first 100 GSM8K questions through the balancer and prints Accuracy. For GPT-OSS-120B, expect an accuracy of approximately 0.89.
Common issues#
EFA or libfabric errors at start, or requests that stop in the KV transfer. The EFA devices,
IPC_LOCK, ormemlockare missing. Start the container with the command in Prepare your environment.The decode server cannot reach the prefill server, and requests fail or time out.
HOSTis wrong, or the security group blocks traffic between the nodes. Give each server an address that the other node can reach, and allow all traffic between the two nodes.A server refuses its peer at the first request. The two nodes run different image builds. Run the same image on both nodes.
The servers cannot download the tokenizer vocabulary. The node has no internet access. Download the vocabulary file on a different computer into the models directory:
curl -L -o <models dir>/tiktoken/o200k_base.tiktoken --create-dirs \ https://openaipublic.blob.core.windows.net/encodings/o200k_base.tiktoken
Then start both servers with
TIKTOKEN_ENCODINGS_BASE=/models/tiktoken HF_HUB_OFFLINE=1before the command.
For more problems and fixes, see Troubleshooting: SGLang-Neuron.
Clean up#
Stop the balancer first, and then the servers:
In the balancer shell, press Ctrl+C.
In the shell of each server, press Ctrl+C. The server drains and stops every rank. Wait until the shell prompt shows again.
Exit the container shells. The
--rmoption removes the containers.
Note
docker stop does not drain the servers in this layout. The servers run under the shell of the container, and the shell does not send the signal to them.
Next steps#
Further reading#
This document is relevant for: Trn3