.. meta::
   :description: Tutorial for SGLang-Neuron. Serve GPT-OSS-120B on two Trainium3 nodes with prefill-decode disaggregation, NIXL over EFA, and the SGLang-Neuron balancer.
   :keywords: SGLang, SGLang-Neuron, GPT-OSS-120B, prefill-decode disaggregation, disaggregated serving, NIXL, EFA, balancer, AWS Neuron, Trainium3, Trn3, trn3.48xlarge
   :date-modified: 2026-11-16

.. _sglang-neuron-gpt-oss-disaggregated-tutorial:

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 :ref:`SGLang-Neuron quickstart <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_content`` and its tool calls in ``tool_calls``.

Prerequisites
-------------

- Two trn3.48xlarge instances with Docker Engine and the Neuron driver of Neuron SDK 2.33.0 (``aws-neuronx-dkms`` 2.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 <https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/efa-start-nixl.html#nixl-start-base-setup>`__.
- 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.

.. _sglang-neuron-gpt-oss-prepare:

Prepare your environment
------------------------

Do these steps on **both** nodes.

1. Set the image variable:

   .. code-block:: bash

      IMAGE=public.ecr.aws/neuron/pytorch-inference-sglang-neuron:v0.1.0-neuron-py314-sdk-2.33.0-ubuntu26.04

2. Download the checkpoint to the host directory:

   .. code-block:: bash

      docker run --rm -v <models dir>:/models $IMAGE hf download openai/gpt-oss-120b --local-dir /models/gpt-oss-120b --exclude "original/*" --exclude "metal/*"

3. Start a container with the Neuron devices, the EFA devices, and the network of the node, and open a shell in it:

   .. code-block:: bash

      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:

.. code-block:: bash

   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:

.. code-block:: bash

   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:

.. code-block:: bash

   # 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:

.. code-block:: bash

   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:

.. code-block:: bash

   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``, or ``memlock`` are missing. Start the container with the command in :ref:`Prepare your environment <sglang-neuron-gpt-oss-prepare>`.
- **The decode server cannot reach the prefill server, and requests fail or time out.** ``HOST`` is 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:

  .. code-block:: bash

     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=1`` before the command.

For more problems and fixes, see :ref:`sglang-neuron-tshoot`.

Clean up
--------

Stop the balancer first, and then the servers:

1. In the balancer shell, press **Ctrl+C**.
2. In the shell of each server, press **Ctrl+C**. The server drains and stops every rank. Wait until the shell prompt shows again.
3. Exit the container shells. The ``--rm`` option 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
----------

- :ref:`Tutorial: Serve a multi-turn chat with Kimi-K3 <sglang-neuron-kimi-k3-multi-turn-tutorial>`
- :ref:`SGLang-Neuron feature compatibility <sglang-neuron-feature-compatibility-ref>`
- :ref:`SGLang-Neuron configuration reference <sglang-neuron-configuration-ref>`

Further reading
---------------

- :ref:`What is SGLang-Neuron? <sglang-neuron-overview>`
- `GPT-OSS-120B example in the sglang-neuron repository <https://github.com/sgl-project/sglang-neuron/tree/main/examples/gpt_oss_120b>`__
- `GPT-OSS model recipe in the sglang-neuron repository <https://github.com/sgl-project/sglang-neuron/blob/main/docs/model-recipes/gpt-oss.md>`__
