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

# CPU Servers

The document addresses how to set up the [SGLang](https://github.com/sgl-project/sglang) environment and run LLM inference on CPU servers.
SGLang is enabled and optimized on the CPUs equipped with Intel® AMX® Instructions,
which are 4th generation or newer Intel® Xeon® Scalable Processors.

A number of popular LLMs are optimized and run efficiently on CPU,
including the most notable open-source models like Llama series, Qwen series,
and DeepSeek series like DeepSeek-R1 and DeepSeek-V3.1-Terminus.
Please check the [SGLang Cookbook pages](https://docs.sglang.io/cookbook/intro.md)
in which the support status and example commands can be found.

## Installation

### Install Using Docker

It is recommended to use Docker for setting up the SGLang environment.

#### Pull from Docker Hub

Pull the prebuilt docker image of SGLang package releases from `lmsysorg/sglang` repository.
The [CPU image tags](https://hub.docker.com/r/lmsysorg/sglang/tags?name=xeon) end with `xeon` suffix.
The image pulling command is like:

```bash Command theme={null}
docker pull lmsysorg/sglang:v0.5.13-xeon
```

#### Build from Dockerfile

A [Dockerfile](https://github.com/sgl-project/sglang/blob/main/docker/xeon.Dockerfile) is provided to facilitate the installation from latest source code.
Replace `<secret>` below with your [HuggingFace access token](https://huggingface.co/docs/hub/en/security-tokens).

```bash Command theme={null}
# Clone the SGLang repository
git clone https://github.com/sgl-project/sglang.git
cd sglang/docker

# Build the docker image
docker build -t sglang-cpu:latest -f xeon.Dockerfile .

# Initiate a docker container
docker run \
    -it \
    --privileged \
    --ipc=host \
    --network=host \
    -v /dev/shm:/dev/shm \
    -v ~/.cache/huggingface:/root/.cache/huggingface \
    -p 30000:30000 \
    -e "HF_TOKEN=<secret>" \
    sglang-cpu:latest /bin/bash
```

### Install From Source

If you prefer to install SGLang in a bare metal environment,
the setup process is as follows:

Please install the required packages and libraries beforehand if
they are not already present on your system.
You can refer to the Ubuntu-based installation commands in
[the Dockerfile](https://github.com/sgl-project/sglang/blob/main/docker/xeon.Dockerfile#L7)
for guidance.

1. Install `uv` package manager, then create and activate a virtual environment:

```bash Command theme={null}
# Taking '/opt' as the example uv env folder, feel free to change it as needed
cd /opt
curl -LsSf https://astral.sh/uv/install.sh | sh
source $HOME/.local/bin/env
uv venv --python 3.12
source .venv/bin/activate
```

2. Create a config file to direct the installation channel
   (a.k.a. index-url) of `torch` related packages:

```bash Command theme={null}
vim .venv/uv.toml
```

Press 'a' to enter insert mode of `vim`, paste the following content into the created file

```file theme={null}
[[index]]
name = "torch"
url = "https://download.pytorch.org/whl/cpu"

[[index]]
name = "torchvision"
url = "https://download.pytorch.org/whl/cpu"

[[index]]
name = "torchaudio"
url = "https://download.pytorch.org/whl/cpu"

[[index]]
name = "triton"
url = "https://download.pytorch.org/whl/cpu"

```

Save the file (in `vim`, press 'esc' to exit insert mode, then ':x+Enter'),
and set it as the default `uv` config.

```bash Command theme={null}
export UV_CONFIG_FILE=/opt/.venv/uv.toml
```

3. Clone the `sglang` source code and build the packages

```bash Command theme={null}
# Clone the SGLang code
git clone https://github.com/sgl-project/sglang.git
cd sglang
git checkout <YOUR-DESIRED-VERSION>

# Use dedicated toml file
cd python
cp pyproject_cpu.toml pyproject.toml
# Install SGLang dependent libs, and build SGLang main package
uv pip install --upgrade pip setuptools
uv pip install .  # If installing sgl-diffusion, please use: uv pip install ".[diffusion]"

# Build the CPU backend kernels
cd sglang/kernels/aot
cp pyproject_cpu.toml pyproject.toml
uv pip install .
```

4. Set the required environment variables

```bash Command theme={null}
export SGLANG_USE_CPU_ENGINE=1

# Set 'LD_LIBRARY_PATH' and 'LD_PRELOAD' to ensure the libs can be loaded by sglang processes
export LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu
export LD_PRELOAD=${LD_PRELOAD}:/opt/.venv/lib/libiomp5.so:${LD_LIBRARY_PATH}/libtcmalloc.so.4:${LD_LIBRARY_PATH}/libtbbmalloc.so.2
```

Notes:

* Note that the environment variable `SGLANG_USE_CPU_ENGINE=1`
  is required to enable the SGLang service with the CPU engine.

* If you encounter code compilation issues during the `sgl-kernel` building process,
  please check your `gcc` and `g++` versions and upgrade them if they are outdated.
  It is recommended to use `gcc-15` and `g++-15` as they have been verified
  in the official Docker container.

* The system library path is typically located in one of the following directories:
  `~/.local/lib/`, `/usr/local/lib/`, `/usr/local/lib64/`, `/usr/lib/`, `/usr/lib64/`
  and `/usr/lib/x86_64-linux-gnu/`. In the above example commands, `/usr/lib/x86_64-linux-gnu`
  is used. Please adjust the path according to your server configuration.

* It is recommended to add the following to your `~/.bashrc` file to
  avoid setting these variables every time you open a new terminal:

  ```bash Command theme={null}
  source .venv/bin/activate
  export SGLANG_USE_CPU_ENGINE=1
  export LD_LIBRARY_PATH=<YOUR-SYSTEM-LIBRARY-FOLDER>
  export LD_PRELOAD=<YOUR-LIBS-PATHS>
  ```

## Launch of the Serving Engine

Example command to launch SGLang serving:

```bash Launch Server theme={null}
sglang serve                          \
    --model-path <MODEL_ID_OR_PATH>   \
    --trust-remote-code               \
    --disable-overlap-schedule        \
    --device cpu                      \
    --host 0.0.0.0                    \
    --tp 6
```

Notes:

1. For running W8A8 quantized models, please add the flag `--quantization w8a8_int8`.

2. The flag `--tp 6` specifies that tensor parallelism will be applied using 6 ranks (TP6).
   The number of TP specified is how many TP ranks will be used during the execution.
   By default, each rank is bound to a group of physical CPU cores.
   SGLang reads `lscpu -p=CPU,Core,Socket,Node,Cache` and groups cores by Compute Building Block (CBB), identified by L3 cache ID, when there are more L3 cache IDs than NUMA nodes. Otherwise, it groups cores by NUMA node, including sub-NUMA clusters (SNCs) exposed as NUMA nodes.
   Each group is restricted to the process's allowed CPU affinity, and empty groups are excluded from rank assignment.

   Ranks use the first available groups in NUMA node or L3 cache ID order.
   Without an explicit binding, the total rank count (`dp_size * tp_size * pp_size`) cannot exceed the available group count.
   A CBB is a CPU binding group, not a separate NUMA memory node; multiple CBB groups can share one NUMA node.

   `SGLANG_CPU_OMP_THREADS_BIND` allows explicit control of CPU cores for each tensor parallel (TP) rank.

   **example 1**: Run SGLang service with TP=6, using the first 40 cores of each SNC on a Xeon® 6980P server,
   which has 43-43-42 cores on the 3 SNCs of a socket, we should set:

   ```bash Command theme={null}
   export SGLANG_CPU_OMP_THREADS_BIND="0-39|43-82|86-125|128-167|171-210|214-253"
   ```

   This configuration is equivalent to:

   * rank 0: `numactl -C 0-39 -m 0`
   * rank 1: `numactl -C 43-82 -m 1`
   * rank 2: `numactl -C 86-125 -m 2`
   * rank 3: `numactl -C 128-167 -m 3`
   * rank 4: `numactl -C 171-210 -m 4`
   * rank 5: `numactl -C 214-253 -m 5`

   **example 2**: Run SGLang service with TP=2, using 96 cores cross 3 SNCs on a Xeon® 6972P server,
   which has 32-32-32 cores on the 3 SNCs in a socket, we should set:

   ```bash Command theme={null}
   export SGLANG_CPU_OMP_THREADS_BIND="0-95|96-191"
   ```

   This configuration is equivalent to:

   * rank 0: `numactl -C 0-95 -m 0-2`
   * rank 1: `numactl -C 96-191 -m 3-5`

   Please beware that with SGLANG\_CPU\_OMP\_THREADS\_BIND set,
   the available memory amounts of the ranks may not be determined in prior.
   You may need to set proper `--max-total-tokens` to avoid the out-of-memory error.

3. A warmup step is automatically triggered when the service is started.
   The server is ready when you see the log `The server is fired up and ready to roll!`.

### CPU Graph for Decode and Prefill

On Intel AMX systems, `torch.compile` can reduce Python overhead for CPU graph
execution. Decode graph capture is enabled by default with
`--enable-torch-compile`; CPU prefill graph capture is opt-in because the full
prefill backend is experimental:

```bash Command theme={null}
sglang serve \
    --model-path <MODEL_ID_OR_PATH> \
    --trust-remote-code \
    --device cpu \
    --attention-backend intel_amx \
    --enable-torch-compile
```

`--enable-torch-compile` is the global compile switch. On CPU, decode defaults
to `full`, while prefill defaults to `disabled`. CPU decode graphs use
batch-size buckets; CPU prefill graphs use total-token buckets. To enable CPU
prefill explicitly, set its backend to `full` in the shared JSON format:

```bash Command theme={null}
sglang serve \
    --model-path <MODEL_ID_OR_PATH> \
    --trust-remote-code \
    --device cpu \
    --attention-backend intel_amx \
    --enable-torch-compile \
    --cuda-graph-config \
    '{"decode":{"backend":"full", "max_bs": 4},"prefill":{"backend":"full", "max_bs": 512}}'
```

The JSON format works on CPU as well as CUDA. On CPU, the fields mean:

* `decode.max_bs`: maximum decode batch size.
* `decode.bs`: explicit decode batch-size buckets.
* `prefill.max_bs`: maximum prefill total-token count.
* `prefill.bs`: explicit prefill total-token buckets.

For decode, `decode.bs` takes precedence over `decode.max_bs`; if both are
omitted, the legacy `--torch-compile-max-bs` value is used. `decode.max_bs` or
the legacy value then generates the default decode bucket list. For prefill,
`prefill.bs` is generated from `prefill.max_bs` when it is omitted.

To use custom buckets, set `bs` explicitly for each phase. In this example,
decode captures batch sizes 1, 2, 4, and 8, while prefill captures total-token
counts 128, 256, and 512:

```bash Command theme={null}
sglang serve \
    --model-path <MODEL_ID_OR_PATH> \
    --trust-remote-code \
    --device cpu \
    --attention-backend intel_amx \
    --enable-torch-compile \
    --cuda-graph-config \
    '{"decode":{"backend":"full", "bs": [1, 2, 4, 8]},"prefill":{"backend":"full", "bs": [128, 256, 512]}}'
```

When `bs` is provided, SGLang uses those buckets instead of generating them
from `max_bs`.

For workloads with batch sizes or prefill token counts that do not match the
configured buckets, an optional dynamic fallback graph can be enabled with
`SGLANG_TORCH_DYNAMIC_SHAPE=true`:

```bash Command theme={null}
SGLANG_TORCH_DYNAMIC_SHAPE=true \
sglang serve \
    --model-path <MODEL_ID_OR_PATH> \
    --trust-remote-code \
    --device cpu \
    --attention-backend intel_amx \
    --enable-torch-compile
```

Dynamic graph compilation requires `--enable-torch-compile` and is available
for both CPU decode and prefill. Exact configured buckets are used first;
dynamic graphs are compiled as a fallback when no exact or padded bucket can
serve the request. CPU prefill graphs currently target text-only requests;
multimodal prefill requests fall back to eager execution. Dynamic graphs may
increase startup compilation time.

`full` is required in the JSON to enable CPU prefill. Set either phase to
`disabled` to keep it on the eager path, for example:

```bash Command theme={null}
--enable-torch-compile \
--cuda-graph-config '{"decode":{"backend":"disabled"},"prefill":{"backend":"full"}}'
```

Unsupported phase backends such as `breakable` are rejected on CPU. Set a phase
backend to `disabled` to keep that phase on the eager path.

Legacy convenience parameters remain supported:

* `--torch-compile-max-bs`: decode-only maximum batch size. It is used only
  when explicit `decode.max_bs` and `decode.bs` are not provided.
* `--cuda-graph-bs-decode`: explicit decode batch-size buckets.
* `--cuda-graph-max-bs-decode`: maximum decode batch size.
* `--cuda-graph-bs-prefill`: explicit prefill total-token buckets.
* `--cuda-graph-max-bs-prefill`: maximum prefill total-token count on the CPU
  graph path. The name is shared with other devices for compatibility.

## Benchmarking with Requests

You can benchmark the performance via the `bench_serving` script.
Run the command in another terminal. An example command would be:

```bash Run Benchmark theme={null}
python -m sglang.benchmark.serving   \
    --dataset-name random        \
    --random-input-len 1024      \
    --random-output-len 1024     \
    --num-prompts 1              \
    --request-rate inf           \
    --random-range-ratio 1.0
```

Detailed parameter descriptions are available via the command:

```bash Benchmark Help theme={null}
python -m sglang.benchmark.serving -h
```

Additionally, requests can be formatted using
[the OpenAI Completions API](https://docs.sglang.io/docs/basic_usage/openai_api_completions.md)
and sent via the command line (e.g., using `curl`) or through your own scripts.

## Example Usage Commands

Large Language Models can range from fewer than 1 billion to several hundred billion parameters.
Dense models larger than 20B are expected to run on flagship 6th Gen Intel® Xeon® processors
with dual sockets and a total of 6 sub-NUMA clusters. Dense models of approximately 10B parameters or fewer,
or MoE (Mixture of Experts) models with fewer than 10B activated parameters, can run on more common
4th generation or newer Intel® Xeon® processors, or utilize a single socket of the flagship 6th Gen Intel® Xeon® processors.

### Example: Running DeepSeek-V3.1-Terminus

An example command to launch service of W8A8\_INT8 DeepSeek-V3.1-Terminus on a Xeon® 6980P server:

```bash W8A8_INT8 theme={null}
sglang serve                                                        \
    --model-path IntervitensInc/DeepSeek-V3.1-Terminus-Channel-int8 \
    --trust-remote-code                                             \
    --disable-overlap-schedule                                      \
    --device cpu                                                    \
    --quantization w8a8_int8                                        \
    --enable-torch-compile                                          \
    --torch-compile-max-bs 4                                        \
    --host 0.0.0.0                                                  \
    --tp 6
```

Similarly, an example command to launch service of FP8 DeepSeek-V3.1-Terminus would be:

```bash FP8 theme={null}
sglang serve                                         \
    --model-path deepseek-ai/DeepSeek-V3.1-Terminus  \
    --trust-remote-code                              \
    --disable-overlap-schedule                       \
    --device cpu                                     \
    --enable-torch-compile                           \
    --torch-compile-max-bs 4                         \
    --host 0.0.0.0                                   \
    --tp 6
```

Note: Please set `--torch-compile-max-bs` to the maximum desired batch size for your deployment.
The value `4` in the examples is illustrative.

### Example: Running Llama-3.2-3B

An example command to launch service of Llama-3.2-3B with BF16 precision:

```bash BF16 theme={null}
sglang serve                                         \
    --model-path meta-llama/Llama-3.2-3B-Instruct    \
    --trust-remote-code                              \
    --disable-overlap-schedule                       \
    --device cpu                                     \
    --enable-torch-compile                           \
    --torch-compile-max-bs 16                        \
    --host 0.0.0.0                                   \
    --tp 3
```

The example command to launch service of W8A8\_INT8 version of Llama-3.2-3B:

```bash W8A8_INT8 theme={null}
sglang serve                                            \
    --model-path RedHatAI/Llama-3.2-3B-quantized.w8a8   \
    --trust-remote-code                                 \
    --disable-overlap-schedule                          \
    --device cpu                                        \
    --quantization w8a8_int8                            \
    --enable-torch-compile                              \
    --torch-compile-max-bs 16                           \
    --host 0.0.0.0                                      \
    --tp 3
```

Note: The `--torch-compile-max-bs` and `--tp` settings are examples that should be adjusted for your setup.
For instance, use `--tp 3` to utilize 1 socket with 3 sub-NUMA clusters on an Intel® Xeon® 6980P server.

Once the server have been launched, you can test it using the `bench_serving` command or create
your own commands or scripts following [the benchmarking example](#benchmarking-with-requests).


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