> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sglang.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Amazon Ergo

> Deploy Amazon Ergo (1.1T / 55B active MoE, 1M context) with SGLang on NVIDIA GB300, Vera Rubin, B300, GB200, B200, and 2× DGX Station using MXFP4, MXFP8, BF16, and DSpark speculative decoding, and on AWS Trainium3 (trn3.48xlarge) with MXFP4 and prefill/decode disaggregation over EFA.

## Deployment

> [accordion] Install SGLang
>
> Use an SGLang build with Amazon Ergo support and `xgrammar>=0.2.9` (required for the CONTROL-token tool-call grammar). See the [SGLang installation guide](https://docs.sglang.io/docs/get-started/install.md) for host and CUDA prerequisites.
>
> > [tab] Docker
> >
> > Pull the Amazon Ergo container image:
> >
> > ```bash Command theme={null}
> > docker pull lmsysorg/sglang:ergo
> > ```
> >
> > Run the command panel's **Docker** output directly on the host, or start a shell inside `lmsysorg/sglang:ergo` and run the **Python** output inside the container. See [Install with Docker](https://docs.sglang.io/docs/get-started/install.md#method-3-using-docker) for container runtime setup.
>
> > [tab] Python (pip / uv)
> >
> > Install SGLang from a build that includes Amazon Ergo support alongside `xgrammar>=0.2.9`, then run the command panel's **Python** output in that environment:
> >
> > ```bash Command theme={null}
> > pip install --upgrade pip
> > pip install uv
> > uv pip install --prerelease=allow sglang "xgrammar>=0.2.9"
> > ```
>
> > [tab] AWS Trainium (trn3)
> >
> > Amazon Ergo runs on AWS Trainium3 through the [sglang-neuron](https://github.com/sgl-project/sglang-neuron) platform plugin instead of the image above. Install the plugin from source, then follow [AWS Trainium deployment](#trainium).

The selector opens on **GB300 · MXFP4 · Single Node · 4× GPU** (single-node 4× GB300, TP4 · EP4). Choose your GPU platform, checkpoint quantization, operating point, and optional overlays:

* **Single Node · 4× GPU** — smallest datacenter starting point on 1×4 GB300 (MXFP4, TP4 · EP4, DeepEP v2 + DeepGEMM).
* **Low Latency** — 8-GPU TP8 · EP8 All-Reduce EP (`--moe-a2a-backend none`) using FlashInfer MXFP4 (`--moe-runner-backend flashinfer_mxfp4`) on Blackwell, SM107 Prims-TS MXFP4 (`--moe-runner-backend auto`) on 2×4 Vera Rubin, or DeepGEMM on MXFP8 for lowest single-request and low-concurrency latency.
* **Balanced · MegaMoE** — 8-GPU TP8 · EP8 fused MegaMoE (`--moe-a2a-backend megamoe`) over NVLink/MNNVL on GB300, 2×4 Vera Rubin (`--prefill-decode-interval 48`), B300, GB200, and B200 for mid-to-high concurrency, or 2× DGX Station with host-backed experts.
* **High Throughput** — 16-GPU TP16 · EP16 · Attn-DP4 across 4×4 GB300 / GB200 or 2×8 B300 / B200 (MXFP4, MXFP8, and full BF16), or 2×4 Vera Rubin peak-throughput MegaMoE (`--prefill-decode-interval 2`, `--swa-full-tokens-ratio 0.05`).
* **Overlays** — enable **DSpark** speculative decoding ([`Amazon-FMR/Ergo-dspark`](https://huggingface.co/Amazon-FMR/Ergo-dspark)), switch KV cache to **FP8 (`fp8_e4m3`)**, or add **HiCache L1 + L2** host DRAM offload (`160 GiB/rank` on Vera Rubin, `120 GiB/rank` on Blackwell).
* **AWS Trainium3** — trn3.48xlarge serving (single node, or prefill/decode disaggregation over EFA up to 1M context) runs through the sglang-neuron plugin with its own launch commands; see [AWS Trainium deployment](#trainium).

A **Verified** badge means that exact platform and command passed serving, quality, and speed gates. **Final Verification In Progress** means the configuration has real-weight serving runs and awaits exact-command benchmark completion. **Not Verified** means the recipe is a supported starting point that needs workload validation on that platform.

## Playground

Use the Playground to explore additional controls on top of the active Deployment command and inspect the exact diff. Any modified command is unverified until tested on your hardware.

* **MoE Backend** — switch between `DeepEP v2 (DeepGEMM)`, `MegaMoE (Fused)`, `All-Reduce EP (DeepGEMM)` (`--moe-a2a-backend none`), `All-Reduce EP (FlashInfer MXFP4)` on Blackwell, and `All-Reduce EP (Auto / Prims-TS MXFP4)` on Vera Rubin.
* **DSpark Proposed Draft Tokens** — shown when **DSpark** is active; adjust `--speculative-dspark-block-size` (checkpoint default `8`, `3` on 2× DGX Station, or `7 / 6 / 4` to match Pareto operating points).
* **Prefill-Decode Interval & MegaMoE Implementation** — tune `--prefill-decode-interval` (paired with `--prefill-decode-interval-min-bs 8`) to trade interactivity for throughput, and switch `SGLANG_ERGO_MEGAMOE_IMPL` between `JIT` (stock `sgl-deep-gemm 0.2.9`) and `DeepGEMM` (baked kernel in `lmsysorg/sglang:ergo`).
* **Tool Schema Enforcement** — toggle `SGLANG_TOOL_STRICT_LEVEL=1` to enable structural-tag tool grammar across all tools while enforcing parameter schemas on tools that set `strict: true`.
* **Memory, Concurrency, and Scheduling** — tune `--max-running-requests` (auto by KV capacity standalone, `48` default under DSpark), `--mem-fraction-static`, `SGLANG_ERGO_GPU_EXPERT_LAYERS` (DGX Station), `--disable-prefill-cuda-graph`, `--deepep-v2-mode` (`direct` vs `hybrid`), `--tokenizer-worker-num`, adaptive prefill delayer, and `--hicache-write-policy` (when HiCache L2 is active).

## 1. Model introduction

**Amazon Ergo** (`ErgoForCausalLM`, `model_type: ergo`) is an open-weights reasoning and coding Mixture-of-Experts model from Amazon Frontier Model Research (FMR). It has **1.1 trillion total parameters** with **55 billion active parameters** per token, a **1M-token context window**, and up to **128K output tokens**.

Ergo interleaves 48 local sliding-window attention layers (512-token window, GPT-J RoPE) with 16 global NoPE attention layers (every 4th layer), bounding long-context KV cache growth to the 16 global layers. The feed-forward stack has 1 leading ReLU² dense layer and 63 MoE layers, each with 256 routed ReLU² experts (top-8 sigmoid routing with DeepSeek-style load balancing, routed scaling factor 2.83, and per-expert output RMSNorm) plus 1 shared ReLU² expert.

<table>
  <colgroup>
    <col />

    <col />
  </colgroup>

  <thead>
    <tr>
      <th>Attribute</th>
      <th>Specification</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>Developer & license</td>
      <td>Amazon Frontier Model Research (FMR) · [Amazon Ergo Open-Weights License](https://huggingface.co/Amazon-FMR/Ergo/blob/main/LICENSE.md)</td>
    </tr>

    <tr>
      <td>Parameters</td>
      <td>1.1T total / 55B active per token</td>
    </tr>

    <tr>
      <td>Architecture</td>
      <td>64 layers (1 dense ReLU² + 63 MoE), hidden size 8,192; 256 routed experts (top-8, intermediate 4,096) + 1 shared expert (intermediate 8,192)</td>
    </tr>

    <tr>
      <td>Attention</td>
      <td>GQA (64 query heads, 8 KV heads, head dim 128, QK-norm); 48 local SWA-512 layers + 16 global NoPE layers (every 4th layer)</td>
    </tr>

    <tr>
      <td>Modalities</td>
      <td>Text-only (non-text content parts are rejected)</td>
    </tr>

    <tr>
      <td>Context & output</td>
      <td>1,048,576-token context window (1M); 131,072-token max output (128K)</td>
    </tr>

    <tr>
      <td>Reasoning & sampling</td>
      <td>Fixed reasoning effort (reasons by default); `generation_config.json` defaults: `temperature=1.0`, `top_p=0.99`, `max_new_tokens=131072`</td>
    </tr>

    <tr>
      <td>Tokenizer & protocol</td>
      <td>262,144-token SentencePiece vocabulary (`ErgoTokenizer`) with token-level CONTROL framing for reasoning and tool calls</td>
    </tr>
  </tbody>
</table>

### Official checkpoints

<table>
  <colgroup>
    <col />

    <col />

    <col />

    <col />
  </colgroup>

  <thead>
    <tr>
      <th>Precision / Role</th>
      <th>Repository</th>
      <th>Download size</th>
      <th>Minimum NVIDIA GPU footprint</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>MXFP4 (primary)</td>
      <td>[`Amazon-FMR/Ergo`](https://huggingface.co/Amazon-FMR/Ergo)</td>
      <td>626 GB</td>
      <td>4× GB300, 8× Vera Rubin / B300 / B200 / GB200, or 2× DGX Station (host-backed)</td>
    </tr>

    <tr>
      <td>MXFP8</td>
      <td>[`Amazon-FMR/Ergo-mxfp8`](https://huggingface.co/Amazon-FMR/Ergo-mxfp8)</td>
      <td>1.17 TB</td>
      <td>8× GB300 / B300 / GB200 / B200</td>
    </tr>

    <tr>
      <td>BF16</td>
      <td>[`Amazon-FMR/Ergo-bf16`](https://huggingface.co/Amazon-FMR/Ergo-bf16)</td>
      <td>2.22 TB</td>
      <td>16× GB300 / B300 / GB200 / B200</td>
    </tr>

    <tr>
      <td>DSpark draft</td>
      <td>[`Amazon-FMR/Ergo-dspark`](https://huggingface.co/Amazon-FMR/Ergo-dspark)</td>
      <td>6.48 GB</td>
      <td>3.24B BF16 5-layer draft (pairs with any target precision)</td>
    </tr>
  </tbody>
</table>

**Resources:** [Hugging Face (`Amazon-FMR/Ergo`)](https://huggingface.co/Amazon-FMR/Ergo) · [Launch Blog](https://www.aboutamazon.com/amazon-ergo) · [License](https://huggingface.co/Amazon-FMR/Ergo/blob/main/LICENSE.md).

## 2. Configuration tips

### Automatic runtime defaults

SGLang applies Ergo-specific defaults automatically when you leave the corresponding flags unset:

* **Parsers and grammar:** `--reasoning-parser ergo`, `--tool-call-parser ergo`, `--grammar-backend xgrammar`, `--enable-strict-thinking`, and `thinking=True` on `/v1/chat/completions`. Leave both parser flags unset — `ErgoChatEncodingAdapter` reads CONTROL token IDs directly and rejects text-based parsers.
* **Attention and MoE runners:** `--moe-runner-backend deep_gemm`, `--moe-a2a-backend deepep_v2` whenever `--ep-size > 1`, `--attention-backend trtllm_mha` on standalone SM100/SM103/SM107 GPUs, and prefill CUDA graphs enabled by default.
* **Checkpoint auto-detection:** `Amazon-FMR/Ergo` (`mxfp4`) and `Amazon-FMR/Ergo-mxfp8` (`mxfp8`) declare `quantization_config` in `config.json`, so omit `--quantization`. Context length (`1048576`) is inherited from `config.json`, chunked prefill defaults to `16384` on >=160 GiB GPUs, and `--cuda-graph-max-bs-decode` is derived automatically from `--max-running-requests // --attn-dp-size`.
* **DSpark draft precision:** The model override keeps `Amazon-FMR/Ergo-dspark` unquantized (BF16) even when the target uses MXFP4 or MXFP8.

### Checkpoint precision and GPU sizing

Only the 256 routed experts are quantized in MXFP4 and MXFP8 checkpoints; attention projections, the leading dense layer, the shared expert, norms, router, embeddings, and `lm_head` stay in native precision.

<table>
  <colgroup>
    <col />

    <col />

    <col />

    <col />
  </colgroup>

  <thead>
    <tr>
      <th>Topology & precision</th>
      <th>Weights / GPU</th>
      <th>Parallelism</th>
      <th>When to pick</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>4× GB300 · MXFP4</td>
      <td>\~147 GiB</td>
      <td>TP4 · EP4</td>
      <td>Smallest single-node datacenter footprint (\~10.4M FP8 KV tokens)</td>
    </tr>

    <tr>
      <td>8× Vera Rubin / Blackwell · MXFP4</td>
      <td>\~74 GiB</td>
      <td>TP8 · EP8</td>
      <td>Best interactive latency and largest KV pool per GPU (2×4 Vera Rubin / GB300 / GB200 or 1×8 B300 / B200)</td>
    </tr>

    <tr>
      <td>8× Blackwell · MXFP8</td>
      <td>\~137 GiB</td>
      <td>TP8 · EP8</td>
      <td>Higher weight precision on 8 GPUs; use FP8 KV on 192 GB B200/GB200 for long context</td>
    </tr>

    <tr>
      <td>16× Blackwell · MXFP4 / MXFP8 / BF16</td>
      <td>\~40–135 GiB</td>
      <td>TP16 · EP16 · DP4</td>
      <td>High-concurrency cluster serving and the minimum topology for full BF16</td>
    </tr>

    <tr>
      <td>2× DGX Station · MXFP4</td>
      <td>38–40L GPU + host</td>
      <td>TP2 · EP2</td>
      <td>Workstation deployment over 400G RDMA using host-backed experts (32K context cap)</td>
    </tr>
  </tbody>
</table>

* **Equal TP and EP.** `ErgoMoEFeedForward` normalizes each expert output before summing routes across experts, so `--ep-size` must equal `--tp-size`.
* **Shared-expert sharding (`--enable-shared-experts-attn-tp`).** Shards the 15.75 GiB BF16 shared expert across the attention-TP group (freeing \~13.8 GiB/GPU at TP8 and \~8 GiB/GPU at TP2) and fuses the shared-expert reduction with the routed all-reduce during decode.
* **FP32 LM head (`--enable-fp32-lm-head`).** Computes output logits in FP32 across the 262,144-token vocabulary.
* **Quantizing from BF16.** If you start from [`Amazon-FMR/Ergo-bf16`](https://huggingface.co/Amazon-FMR/Ergo-bf16) or a custom BF16 fine-tune, you can quantize routed experts to MXFP8 on load with `--quantization mxfp8`, or convert offline once for faster startup:

> [accordion] Convert a local BF16 checkpoint to static MXFP4 or MXFP8
>
> ```bash Single-GPU conversion theme={null}
> python3 -m sglang.quantize_ergo_checkpoint \
>   ./Ergo-bf16 \
>   ./Ergo-mxfp4 \
>   --quantization mxfp4
> ```
>
> Pass `--quantization mxfp8` for static MXFP8. To parallelize across multiple GPUs, pass `--worker-id` and `--num-workers`:
>
> ```bash Multi-GPU conversion (4 GPUs) theme={null}
> for wid in 0 1 2 3; do
>   CUDA_VISIBLE_DEVICES=$wid python3 -m sglang.quantize_ergo_checkpoint \
>     ./Ergo-bf16 \
>     ./Ergo-mxfp4 \
>     --quantization mxfp4 \
>     --worker-id "$wid" --num-workers 4 &
> done
> wait
> ```

### MoE dispatch and runner choices

Select **Single Node · 4× GPU**, **Low Latency**, **Balanced · MegaMoE**, or **High Throughput** in Deployment, or swap MoE backends directly in the Playground:

* **All-Reduce EP (`--moe-a2a-backend none`).** Selected by **Low Latency** (and used on 2× DGX Station). Pairs with `--moe-runner-backend flashinfer_mxfp4` on Blackwell MXFP4, `--moe-runner-backend auto` (SM107 Prims-TS MXFP4) on Vera Rubin MXFP4, or DeepGEMM on MXFP8. Avoids symmetric-memory buffers using a gather-free indexed finalizer and fused shared+routed all-reduce for the lowest single-request and low-concurrency latency. Requires `TP == EP` with no attention DP.
* **MegaMoE (`--moe-a2a-backend megamoe`).** Selected by **Balanced · MegaMoE** (and Vera Rubin **High Throughput**). Runs a fused SM100/SM103/SM107 kernel over NVLink/MNNVL symmetric memory that combines dispatch, MXFP4/MXFP8 grouped GEMM, per-expert output RMSNorm, and combine inside unbroken prefill and decode CUDA graphs. Use **MegaMoE Implementation** in the Playground to switch `SGLANG_ERGO_MEGAMOE_IMPL`: `deepgemm` enables the baked DeepGEMM MegaMoE kernel in `lmsysorg/sglang:ergo` (enabled by default on Vera Rubin), while `jit` works out of the box on stock `sgl-deep-gemm 0.2.9`. Requires MXFP4 or MXFP8 weights (not BF16) and a single NVLink/IMEX domain.
* **DeepEP v2 + DeepGEMM (default when unset).** Selected by **Single Node · 4× GPU** (1×4 GB300) and 16-GPU **High Throughput** (TP16 · EP16 · Attn-DP4). Supports MXFP4, MXFP8, and BF16 across both single NVLink domains (`--deepep-v2-mode direct`, default) and multi-node RDMA clusters (`--deepep-v2-mode hybrid`). SGLang validates `SGLANG_DEEPEP_V2_NUM_MAX_DISPATCH_TOKENS_PER_RANK` (default `128`) at startup against `ceil(chunked_prefill_size / (tp_size / attn_dp_size))` and the decode CUDA graph verify budget — set `4096` for TP4 with 16K chunks, or `2048` for TP8 (16K chunks) and TP16 · Attn-DP4 (8K per-DP chunks).

### AgentX coding-trace Pareto operating points

For long-context agentic-coding workloads on 2×4 **Vera Rubin** or 2×4 **GB300** (TP8 · EP8, MXFP4), enable **DSpark** and **FP8 (`fp8_e4m3`)** KV cache in Deployment, turn on **HiCache L1 + L2** at mid-to-high concurrency (`160 GiB/rank` on Vera Rubin, `120 GiB/rank` on GB300), and tune **DSpark Proposed Draft Tokens**, **Prefill-Decode Interval** (`--prefill-decode-interval`, paired with `--prefill-decode-interval-min-bs 8`), **MegaMoE Implementation** (`SGLANG_ERGO_MEGAMOE_IMPL=deepgemm` in `lmsysorg/sglang:ergo`), and `--max-running-requests` to move along the latency–throughput frontier:

<table>
  <colgroup>
    <col />

    <col />

    <col />

    <col />

    <col />

    <col />
  </colgroup>

  <thead>
    <tr>
      <th>Platform & target c</th>
      <th>MRR</th>
      <th>DSpark block</th>
      <th>MoE backend (a2a + runner)</th>
      <th>PDI</th>
      <th>HiCache (GiB/rank)</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>2×4 Vera Rubin · c=1</td>
      <td>1</td>
      <td>7</td>
      <td>`none` + `auto` (Prims-TS MXFP4)</td>
      <td>Off</td>
      <td>Off</td>
    </tr>

    <tr>
      <td>2×4 Vera Rubin · c=24</td>
      <td>12</td>
      <td>7</td>
      <td>`megamoe` + `deep_gemm`</td>
      <td>48</td>
      <td>160</td>
    </tr>

    <tr>
      <td>2×4 Vera Rubin · c=56</td>
      <td>16</td>
      <td>7</td>
      <td>`megamoe` + `deep_gemm`</td>
      <td>48</td>
      <td>160</td>
    </tr>

    <tr>
      <td>2×4 Vera Rubin · c=80</td>
      <td>88</td>
      <td>6</td>
      <td>`megamoe` + `deep_gemm`</td>
      <td>22</td>
      <td>160</td>
    </tr>

    <tr>
      <td>2×4 Vera Rubin · c=112</td>
      <td>136</td>
      <td>6</td>
      <td>`megamoe` + `deep_gemm`</td>
      <td>2</td>
      <td>160</td>
    </tr>

    <tr>
      <td>2×4 GB300 · c=1</td>
      <td>1</td>
      <td>7</td>
      <td>`none` + `flashinfer_mxfp4`</td>
      <td>Off</td>
      <td>Off</td>
    </tr>

    <tr>
      <td>2×4 GB300 · c=8</td>
      <td>16</td>
      <td>6</td>
      <td>`none` + `flashinfer_mxfp4`</td>
      <td>64</td>
      <td>Off</td>
    </tr>

    <tr>
      <td>2×4 GB300 · c=16</td>
      <td>40</td>
      <td>4</td>
      <td>`megamoe` + `deep_gemm`</td>
      <td>48</td>
      <td>Off</td>
    </tr>

    <tr>
      <td>2×4 GB300 · c=46</td>
      <td>48</td>
      <td>6</td>
      <td>`megamoe` + `deep_gemm`</td>
      <td>40</td>
      <td>120</td>
    </tr>

    <tr>
      <td>2×4 GB300 · c=64</td>
      <td>72</td>
      <td>6</td>
      <td>`megamoe` + `deep_gemm`</td>
      <td>16</td>
      <td>120</td>
    </tr>
  </tbody>
</table>

Start from **Low Latency** (`c=1`–`8`), **Balanced · MegaMoE** (`c=16`–`80`), or **High Throughput** (`c=112` on Vera Rubin), layer **DSpark + FP8 KV** (plus **HiCache L1 + L2** for `c>=24` on Vera Rubin or `c>=46` on GB300), and adjust `--speculative-dspark-block-size`, `--prefill-decode-interval`, and `--max-running-requests` (`MRR`, also sizing `--swa-full-tokens-ratio 0.05` at `c>=46` on GB300 or `c>=80` on Vera Rubin). Setting `MRR < c` caps active decode batch size while queuing excess clients for smoother per-user interactivity.

### Hybrid SWA KV cache and 1M context

Only 16 of Ergo's 64 layers attend globally; the other 48 layers keep a fixed 512-token sliding window. SGLang's default `--swa-full-tokens-ratio` is `0.8`, which over-allocates the 512-token window pool at long contexts:

* **Datacenter 1M context:** Use `--swa-full-tokens-ratio 0.03` on TP4/TP8 and `0.05` on TP16 · Attn-DP4 or high-concurrency TP8 MegaMoE (`c>=46` on GB300, `c>=80` on Vera Rubin) so nearly all KV memory serves the 16 global layers.
* **2× DGX Station (32K context):** Use `--swa-full-tokens-ratio 0.3` so the smaller 9 GiB KV pool holds enough window tokens for up to 64 concurrent requests.
* **FP8 KV cache (`--kv-cache-dtype fp8_e4m3`):** Roughly doubles full-attention KV capacity (one 1M-token sequence uses \~32 GiB across the 16 global layers) and halves decode KV read bandwidth. Because KV quantization changes attention numerics, validate accuracy on your workload before enabling it in production.

### Speculative decoding with `Amazon-FMR/Ergo-dspark`

Toggle **Spec Decode → DSpark** in Deployment to enable [`Amazon-FMR/Ergo-dspark`](https://huggingface.co/Amazon-FMR/Ergo-dspark) (3.24B BF16, 5 sliding-attention layers with a 32K window).

* **Minimal flags:** On GB300 / Vera Rubin / B300 / GB200 / B200, SGLang reads `block_size: 8` (`gamma = 8`, verifying 9 draft tokens per step) directly from `Amazon-FMR/Ergo-dspark/config.json`, defaults `SGLANG_RAGGED_VERIFY_MODE=static`, and keeps draft weights in BF16 automatically. `--attention-backend trtllm_mha` is added explicitly because automatic attention selection falls back to FlashInfer under DSpark unless pinned.
* **Draft KV cache:** SGLang model overrides keep the DSpark draft KV cache in `bf16` automatically (`--speculative-draft-kv-cache-dtype bf16`) even when the target uses `--kv-cache-dtype fp8_e4m3`, so no extra flag is needed and the HiCache L2 draft host pool sizes accordingly.
* **Batch cap:** Standalone recipes leave `--max-running-requests` unset so SGLang admits dynamically up to the KV cache capacity. When DSpark is enabled, SGLang defaults to `--max-running-requests 48` (and derives decode CUDA graph capture up to `max_running_requests // attn_dp_size`); override `--max-running-requests` in the Playground when targeting a specific concurrency or Pareto operating point (or `64` on 2× DGX Station).
* **Trade-offs:** The draft KV pool uses \~24% of the KV budget and each verify step costs more compute than plain decode. DSpark gives the largest speedups on structured coding and math workloads at low-to-moderate concurrency; turn it off if high-concurrency batch jobs see low acceptance lengths. On 2× DGX Station, `--speculative-dspark-block-size 3` balances draft cost and acceptance.

### Host-backed experts on 2× NVIDIA DGX Station

On two DGX Stations (250 GiB GB300 HBM + 494 GiB coherent host RAM per node over 400G RDMA), a TP2/EP2 rank's MXFP4 routed experts (\~290 GiB) exceed one GPU's HBM. `SGLANG_ERGO_GPU_EXPERT_LAYERS` keeps the first `N` of 63 MoE layers in GPU HBM and pins the rest in page-locked host memory read in place by the GPU while keeping block scales, dense weights, and shared experts on GPU:

* Use `SGLANG_ERGO_GPU_EXPERT_LAYERS=38` with `--mem-fraction-static 0.846` standalone, or `40` with `--mem-fraction-static 0.862` and `--speculative-dspark-block-size 3` when DSpark is enabled (add `+0.016` per additional GPU-resident layer).
* Leave at least 1/16 of GPU HBM (\~24–31 GiB) free for host-mapped driver allocations; the loader refuses to map host memory below that threshold.
* Requires `--moe-runner-backend deep_gemm` (default) and a pre-quantized MXFP4/MXFP8 or BF16 checkpoint. Prefill CUDA graphs are disabled (`--disable-prefill-cuda-graph`) to save \~13.5 GiB of HBM per Station.

### Known deployment boundaries

* **Blackwell or Vera Rubin required for MXFP4 and MXFP8 on NVIDIA GPUs:** Both MXFP4 (`model_overrides/ergo.py`) and MXFP8 MoE kernels require NVIDIA SM100+ GPUs (Blackwell / Vera Rubin). AWS Trainium3 serves MXFP4 through its own kernels in the sglang-neuron plugin (see [AWS Trainium deployment](#trainium)).
* **No pipeline or context parallelism:** Scale across GPUs with `--tp-size` / `--ep-size` (kept equal) and `--attn-dp-size` with `--enable-dp-lm-head`.
* **No EPLB / redundant experts:** Do not enable `--enable-eplb` or `--ep-num-redundant-experts`; per-expert output RMSNorm slices scales by contiguous logical expert IDs.
* **Text-only:** Image, audio, and video content parts are rejected by the chat encoder.

## 3. Advanced usage

### 3.1 Reasoning

Amazon Ergo frames reasoning blocks with SentencePiece CONTROL token IDs and reasons by default on `/v1/chat/completions`. SGLang's built-in `ergo` adapter separates thinking into `message.reasoning_content` and the final answer into `message.content` automatically — do not pass a different `--reasoning-parser`.

Ergo uses fixed reasoning effort (there is no `reasoning_effort` tier control). To skip the reasoning block on an individual request, pass `extra_body={"chat_template_kwargs": {"thinking": False}}`.

> [accordion] Reasoning example (Python)
>
> ```python Reasoning example theme={null}
> from openai import OpenAI
>
> client = OpenAI(base_url="http://localhost:30000/v1", api_key="EMPTY")
>
> resp = client.chat.completions.create(
>     model="Amazon-FMR/Ergo",
>     messages=[{"role": "user", "content": "What is 15% of 240?"}],
> )
> msg = resp.choices[0].message
> print("finish_reason:", resp.choices[0].finish_reason)
> print("reasoning:", getattr(msg, "reasoning_content", None))
> print("content:", msg.content)
> ```

### 3.2 Tool calling

Tool calls are framed by CONTROL token IDs and parsed automatically into `message.tool_calls` with `finish_reason: "tool_calls"` — leave `--tool-call-parser` unset.

* **Schema-constrained tool grammar (`SGLANG_TOOL_STRICT_LEVEL=1`):** Set `SGLANG_TOOL_STRICT_LEVEL=1` (or enable **Tool Schema Enforcement → Function strict (Level 1)** in the Playground) to enable xgrammar structural-tag constraints on tool calls while respecting each tool definition's `strict: true` setting for full JSON-schema parameter enforcement.
* **Multi-turn history:** Append the full assistant message (preserving `reasoning_content`, `content`, and `tool_calls`) followed by `role: "tool"` messages carrying matching `tool_call_id` values.

> [accordion] Tool calling example (Python)
>
> ```python Tool calling example theme={null}
> import json
> from openai import OpenAI
>
> client = OpenAI(base_url="http://localhost:30000/v1", api_key="EMPTY")
>
> tools = [
>     {
>         "type": "function",
>         "function": {
>             "name": "get_weather",
>             "description": "Return the current weather for a city.",
>             "strict": True,
>             "parameters": {
>                 "type": "object",
>                 "properties": {
>                     "location": {
>                         "type": "string",
>                         "description": "City name, e.g. Seattle",
>                     },
>                 },
>                 "required": ["location"],
>             },
>         },
>     }
> ]
>
> messages = [{"role": "user", "content": "What is the weather in Seattle?"}]
> resp = client.chat.completions.create(
>     model="Amazon-FMR/Ergo",
>     messages=messages,
>     tools=tools,
> )
> choice = resp.choices[0]
> print("Turn 1 finish_reason:", choice.finish_reason)
> print("Turn 1 reasoning:", getattr(choice.message, "reasoning_content", None))
> print("Turn 1 tool_calls:", choice.message.tool_calls)
>
> if choice.message.tool_calls:
>     call = choice.message.tool_calls[0]
>     args = json.loads(call.function.arguments)
>     messages.append(choice.message.model_dump(exclude_none=True))
>     messages.append(
>         {
>             "role": "tool",
>             "tool_call_id": call.id,
>             "content": json.dumps({"location": args["location"], "temp_c": 12, "condition": "cloudy"}),
>         }
>     )
>     followup = client.chat.completions.create(
>         model="Amazon-FMR/Ergo",
>         messages=messages,
>         tools=tools,
>     )
>     fmsg = followup.choices[0].message
>     print("Turn 2 finish_reason:", followup.choices[0].finish_reason)
>     print("Turn 2 reasoning:", getattr(fmsg, "reasoning_content", None))
>     print("Turn 2 content:", fmsg.content)
> ```

### 3.3 HiCache (hierarchical KV caching)

For long-context multi-turn coding sessions, select **HiCache → L1 + L2 (host DRAM)** in Deployment to spill evicted KV pages into pinned host memory (`160 GiB` per GPU rank on Vera Rubin, `120 GiB` on Blackwell by default) instead of recomputing shared prefixes. Adjust `--hicache-size` to fit your node's available host RAM, and change `--hicache-write-policy` (`write_through`, `write_through_selective`, or `write_back`) in the Playground. See the [HiCache documentation](https://docs.sglang.io/docs/advanced_features/hicache.md) for storage-tier (L3) options.

### 3.4 AWS Trainium (trn3) deployment

Amazon Ergo runs on AWS Trainium3 through [sglang-neuron](https://github.com/sgl-project/sglang-neuron), the SGLang platform plugin for AWS Neuron. One trn3.48xlarge serves the MXFP4 checkpoint as a single `--tp-size 128` engine (16 Trainium3 devices × 8 NeuronCores at LNC1), either as one aggregated server or as prefill and decode servers on separate nodes that move the KV cache over NIXL on EFA. Every role accepts contexts up to 1M tokens.

> [!NOTE]
>
> Amazon Ergo support is not in a sglang-neuron release yet. Install the plugin from source at a revision with Ergo support.

#### Install

Follow the plugin's [installation from source](https://github.com/sgl-project/sglang-neuron#from-source) on every node: Neuron SDK 2.33.0 (driver `aws-neuronx-dkms` 2.31.7.0 or later), the SGLang commit the plugin pins (it stops the launch on any other revision), and, for prefill/decode disaggregation, NIXL 1.5.0 with the plugin's patches. Launch the instances with their EFA interfaces attached. Every command below runs with `SGLANG_PLATFORM=neuron`, which selects the plugin.

#### Prepare the weight packs

The Trainium kernels read pre-sharded per-rank operands instead of the Hugging Face shards. Pack the MXFP4 checkpoint once per node; the routed experts are repacked losslessly, as stored:

```bash Pack the checkpoint theme={null}
python3 -m sglang_neuron.models.ergo.pack_model \
  --ckpt <model-path> \
  --out <pack-dir>
```

For prefill/decode disaggregation, also write the decode node's expert-TP pack (every expert split across all 128 ranks, which balances decode MoE load across devices):

```bash Decode pack (P/D decode nodes) theme={null}
python3 -m sglang_neuron.models.ergo.pack_dec \
  --src <pack-dir> \
  --dst <decode-pack-dir>
```

Point `SGLANG_NEURON_ERGO_PACK` at the pack on every node and, on decode nodes, `SGLANG_NEURON_ERGO_DECODE_PACK` at the decode pack. `pack_model` writes every layer plus the LM head and embedding shards (`head/`, `emb/`); the launch checks every file of the pack and names any that are missing. Keep `--model-path` on the local checkpoint directory (config and tokenizer).

#### Single-node aggregated serving

```bash Aggregated (1× trn3.48xlarge) theme={null}
SGLANG_PLATFORM=neuron \
SGLANG_NEURON_ERGO_PACK=<pack-dir> \
python3 -m sglang.launch_server \
  --model-path <model-path> \
  --tp-size 128 \
  --chunked-prefill-size 16384 \
  --radix-cache-backend neuron-chunk \
  --max-running-requests 16 \
  --context-length 131072 \
  --host 0.0.0.0 \
  --port 30000
```

* **Slots and context size the caches.** `--max-running-requests` (1–128) is the number of cache slots and `--context-length` (up to `1048576`) their size; the plugin sets `--max-total-tokens` to every slot at full context and refuses any other value.
* **Automatic defaults.** The plugin fills in the decode batch buckets (`--cuda-graph-bs-decode`), enables the small-prompt prefill programs when HBM allows, and checks each rank's 18 GiB HBM budget at launch, refusing configurations that do not fit and naming the flag to change.
* **Prefix cache.** Ergo's prefix cache uses the chunk-keyed tree (`--radix-cache-backend neuron-chunk`, set automatically when the radix cache is on), which matches whole 16,384-token pages. Use `--disable-radix-cache` to turn it off.
* **First launch compiles.** The server compiles every prefill and decode program at startup and never compiles while serving. The first launch takes tens of minutes; later launches reuse the Neuron compile cache.

#### Prefill/decode disaggregation over EFA

Each prefill and decode node runs its own `--tp-size 128` server. The plugin moves the KV cache over NIXL and sets `SGLANG_DISAGGREGATION_NIXL_BACKEND=LIBFABRIC` (EFA) on both roles, and raises SGLang's bootstrap and waiting timeouts to 1800 s for long prompts. Each node sizes its own caches, so the prefill can hold fewer slots than the decode.

> [tab] 1P1D · 128K
>
> ```bash Decode node theme={null}
> SGLANG_PLATFORM=neuron \
> SGLANG_NEURON_ERGO_PACK=<pack-dir> \
> SGLANG_NEURON_ERGO_DECODE_PACK=<decode-pack-dir> \
> python3 -m sglang.launch_server \
>   --model-path <model-path> \
>   --disaggregation-mode decode \
>   --disaggregation-transfer-backend nixl \
>   --disaggregation-decode-extra-slots 0 \
>   --tp-size 128 \
>   --chunked-prefill-size 16384 \
>   --max-running-requests 16 \
>   --context-length 131072 \
>   --host 0.0.0.0 \
>   --port 30000
> ```
>
> ```bash Prefill node theme={null}
> SGLANG_PLATFORM=neuron \
> SGLANG_NEURON_ERGO_PACK=<pack-dir> \
> python3 -m sglang.launch_server \
>   --model-path <model-path> \
>   --disaggregation-mode prefill \
>   --disaggregation-transfer-backend nixl \
>   --disaggregation-bootstrap-port 8998 \
>   --tp-size 128 \
>   --chunked-prefill-size 16384 \
>   --radix-cache-backend neuron-chunk \
>   --max-running-requests 4 \
>   --context-length 131072 \
>   --host 0.0.0.0 \
>   --port 30000
> ```

> [tab] 1P1D · 1M
>
> ```bash Decode node theme={null}
> SGLANG_PLATFORM=neuron \
> SGLANG_NEURON_ERGO_PACK=<pack-dir> \
> SGLANG_NEURON_ERGO_DECODE_PACK=<decode-pack-dir> \
> python3 -m sglang.launch_server \
>   --model-path <model-path> \
>   --disaggregation-mode decode \
>   --disaggregation-transfer-backend nixl \
>   --disaggregation-decode-extra-slots 0 \
>   --tp-size 128 \
>   --chunked-prefill-size 16384 \
>   --max-running-requests 8 \
>   --context-length 1048576 \
>   --host 0.0.0.0 \
>   --port 30000
> ```
>
> ```bash Prefill node theme={null}
> SGLANG_PLATFORM=neuron \
> SGLANG_NEURON_ERGO_PACK=<pack-dir> \
> python3 -m sglang.launch_server \
>   --model-path <model-path> \
>   --disaggregation-mode prefill \
>   --disaggregation-transfer-backend nixl \
>   --disaggregation-bootstrap-port 8998 \
>   --tp-size 128 \
>   --chunked-prefill-size 16384 \
>   --radix-cache-backend neuron-chunk \
>   --max-running-requests 2 \
>   --context-length 1048576 \
>   --host 0.0.0.0 \
>   --port 30000
> ```

Then start the plugin's P/D balancer and send requests to its port. It sends each request to a prefill and a decode server (least outstanding requests when there are several):

```bash Balancer theme={null}
python3 -m sglang_neuron.disaggregation.balancer \
  --prefill http://<prefill-node-ip>:30000 \
  --decode http://<decode-node-ip>:30000 \
  --bootstrap-port 8998 \
  --host 0.0.0.0 \
  --port 8000
```

* **Scale out (e.g. 3P2D).** Repeat `--prefill` and `--decode` once per server. At 1M context, three prefill nodes (`--max-running-requests 2` each) feeding two decode nodes (`--max-running-requests 8` each) is the measured 1M layout: the prefill nodes set the cold 1M prompt rate, and each decode node adds decode throughput.
* **Decode role rules.** A decode launches with `--disaggregation-decode-extra-slots 0` (every request row is a cache slot) and without HiCache. With a decode pack and at most 32 slots it runs the expert-TP decode MoE automatically.
* **Decode prefix cache (optional).** `--disaggregation-decode-enable-radix-cache` keeps finished prompts' pages on the decode so that a session's next turn transfers only its new pages; it saves transfer bytes rather than TTFT.

#### HiCache for multi-turn and agentic long context

On an aggregated server or a P/D prefill, add the host tier to the chunk-keyed prefix cache so evicted pages are backed up to pinned host memory and loaded back on a hit instead of being recomputed:

```bash HiCache flags (aggregated or prefill) theme={null}
  --radix-cache-backend neuron-chunk \
  --enable-hierarchical-cache \
  --hicache-size 6
```

`--hicache-size` is GB **per rank**, and a node runs 128 ranks (`--hicache-size 6` pins \~768 GB of host memory); `--hicache-ratio` also works. The plugin sets the I/O backend and memory layout itself. HiCache is not supported on a decode node.

#### Cross-node prefill

To cut cold long-prompt TTFT, two or three prefill nodes can split one prompt's prefill by layers. The **head** runs the first layers and passes its activations to the next stage over NIXL on EFA; the **tail** runs the last layers, and every other stage merges its layers' KV into the tail's cache. The tail is the prefill server the balancer and decode see. Launch every stage with the same prefill command and packs, plus:

* **Head:** `SGLANG_NEURON_ERGO_XNODE=head` and `--skip-server-warmup` (the head takes no requests of its own).
* **Middle (three stages):** `SGLANG_NEURON_ERGO_XNODE=1` and `--skip-server-warmup`.
* **Tail:** `SGLANG_NEURON_ERGO_XNODE=tail`.
* **Peers:** every stage except the head sets `SGLANG_NEURON_ERGO_XNODE_PEER` to the addresses of all stages before the tail, head first: `<head-node-ip>` for two stages, `<head-node-ip>,<middle-node-ip>` for three.
* **Layer split:** `SGLANG_NEURON_ERGO_XNODE_SPLIT` on every stage gives the stages' boundaries in units of 4-layer segments: `8` (the default) for two stages, `6,11` for three.

Register only the tail with the balancer (`--prefill http://<tail-node-ip>:30000`). The output is identical to a one-node prefill, and a full prefix cache keeps the fresh-pool speed. On trn3.48xlarge, splitting a cold 1M-token prompt across two or three prefill stages substantially reduces time to first token.

#### Trainium deployment boundaries

* **Greedy decoding only.** The device heads select the greedy token, so sampling parameters such as `temperature` and `top_p` do not apply. Requests for logprobs or hidden states are rejected with HTTP 400.
* **Fixed parallelism.** `--tp-size 128` on one node per server, `--chunked-prefill-size 16384`; no `--ep-size`, pipeline parallelism, DP attention, mixed chunks, or speculative decoding (DSpark).
* **Parsers not yet validated.** The Trainium recipes were validated through SGLang's native `/generate` API; reasoning and tool-call parsing (sections 3.1 and 3.2) have not been validated on Trainium.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.