# Optimizing GLM-4.x Throughput on NVIDIA H100 GPUs

## Conclusion

Recommended configuration for optimizing throughput of GLM-4.x (4.5, 4.6 and 4.7) on H100 GPUs:

???+ tip "Serving Command"
    ```bash
    python3 -m sglang.launch_server --model zai-org/GLM-4.6-FP8 --tp-size 8 --ep-size 8 --tool-call-parser glm --reasoning-parser glm45
    ```

!!! note
    1. Our benchmark tests do not cover all possible optimization combinations. For example, we select the inference engine that performs best under its default configuration as the starting point for further tuning. This pruning approach yields a local optimum, which may not be the global optimum.
    2. There are other optimization methods that depend on specific user scenarios, including max batch size, schedule configuration, extended KV cache, CUDA graph, etc. The conclusions in this document can serve as a starting point for more targeted optimizations.
    3. The tests are conducted on specific hardware and software setups. Advances in the inference engine may lead to new conclusions.
    4. Although using quantization may impact accuracy. FP8 quantization can achieves less than 1% accuracy drop for most models. See the [evaluation results](https://github.com/Tencent/AngelSlim/blob/main/README_en.md#-benchmark) for more details. Therefore, it is highly recommended to use FP8 quantization for high-throughput serving scenarios.

If there are any missing points or updates reflecting new changes, please [let us know](https://github.com/gpustack/gpustack/issues/new/choose).

## Optimization Objective

Achieve high throughput under high-concurrency request scenarios.

## Experimental Setup

### Model

zai-org/GLM-4.6

### Hardware

8 × NVIDIA H100 SXM GPUs on a single node.

### Engine Version

- vLLM: v0.11.0
- SGLang: v0.5.3
- TensorRT-LLM: v1.0.0

### Benchmark Dataset

1. ShareGPT
2. Random dataset with varying sequence lengths:
    - Very long prompt: 32000 input tokens, 100 output tokens
    - Long prompt: 4000 input tokens, 200 output tokens
    - Medium prompt: 2000 input tokens, 100 output tokens
    - Short prompt: 128 input tokens, 4 output tokens

### Benchmark Script

We use the **vLLM bench CLI** tool to benchmark the model performance. The following command is used to run the benchmark:

```bash
# Prepare the ShareGPT dataset
wget https://huggingface.co/datasets/anon8231489123/ShareGPT_Vicuna_unfiltered/resolve/main/ShareGPT_V3_unfiltered_cleaned_split.json

# Benchmark on ShareGPT dataset
vllm bench serve --model zai-org/GLM-4.6 --backend openai-chat --endpoint /v1/chat/completions --dataset-name sharegpt --dataset-path ShareGPT_V3_unfiltered_cleaned_split.json --num-prompts 1000

# Benchmark on random dataset (fixed seed for reproducibility)
vllm bench serve --model zai-org/GLM-4.6 --backend openai-chat --endpoint /v1/chat/completions --dataset-name random --random-input-len 4000 --random-output-len 200 --num-prompts 500 --seed 42
```

## Experiment Results

The original BF16 precision model cannot be served on a single server with NVIDIA H100 GPUs due to memory limitations. Therefore, we focus on serving the FP8 quantization model.

### 1. Choosing the Inference Engine

vLLM
??? info "Serving script"
    ```bash
    vllm serve zai-org/GLM-4.6-FP8 -tp 8 --gpu-memory-utilization 0.85
    ```

??? info "Benchmark result"
    ```
    ============ Serving Benchmark Result ============
    Successful requests:                     1000
    Benchmark duration (s):                  130.81
    Total input tokens:                      214465
    Total generated tokens:                  199904
    Request throughput (req/s):              7.64
    Output token throughput (tok/s):         1528.16
    Peak output token throughput (tok/s):    3935.00
    Peak concurrent requests:                1000.00
    Total Token throughput (tok/s):          3167.63
    ---------------Time to First Token----------------
    Mean TTFT (ms):                          26751.30
    Median TTFT (ms):                        26848.82
    P99 TTFT (ms):                           45890.42
    -----Time per Output Token (excl. 1st token)------
    Mean TPOT (ms):                          508.88
    Median TPOT (ms):                        273.93
    P99 TPOT (ms):                           1362.12
    ---------------Inter-token Latency----------------
    Mean ITL (ms):                           222.86
    Median ITL (ms):                         149.69
    P99 ITL (ms):                            1365.56
    ==================================================
    ```

SGLang
??? info "Serving script"
    ```bash
    python3 -m sglang.launch_server --model-path zai-org/GLM-4.6-FP8 --host 0.0.0.0 --port 8000 --tp-size 8
    ```

??? info "Benchmark result"
    ```
    ============ Serving Benchmark Result ============
    Successful requests:                     1000
    Benchmark duration (s):                  109.16
    Total input tokens:                      214465
    Total generated tokens:                  199904
    Request throughput (req/s):              9.16
    Output token throughput (tok/s):         1831.30
    Peak output token throughput (tok/s):    5614.00
    Peak concurrent requests:                1000.00
    Total Token throughput (tok/s):          3796.00
    ---------------Time to First Token----------------
    Mean TTFT (ms):                          17555.93
    Median TTFT (ms):                        17493.70
    P99 TTFT (ms):                           32706.51
    -----Time per Output Token (excl. 1st token)------
    Mean TPOT (ms):                          684.10
    Median TPOT (ms):                        252.95
    P99 TPOT (ms):                           4790.60
    ---------------Inter-token Latency----------------
    Mean ITL (ms):                           208.76
    Median ITL (ms):                         129.94
    P99 ITL (ms):                            514.51
    ==================================================
    ```

Result: SGLang(3796.00 tok/s) > vLLM (3167.63 tok/s) > TensorRT-LLM (Not supported)

### 2. Parallelism in SGLang

TP8EP8
??? info "Serving script"
    ```bash
    python3 -m sglang.launch_server --model-path zai-org/GLM-4.6-FP8 --host 0.0.0.0 --port 8000 --tp-size 8 --ep-size 8
    ```
??? info "Benchmark result"
    ```
    ============ Serving Benchmark Result ============
    Successful requests:                     1000
    Benchmark duration (s):                  107.44
    Total input tokens:                      214465
    Total generated tokens:                  199904
    Request throughput (req/s):              9.31
    Output token throughput (tok/s):         1860.58
    Peak output token throughput (tok/s):    6492.00
    Peak concurrent requests:                1000.00
    Total Token throughput (tok/s):          3856.69
    ---------------Time to First Token----------------
    Mean TTFT (ms):                          18994.85
    Median TTFT (ms):                        18941.03
    P99 TTFT (ms):                           34437.71
    -----Time per Output Token (excl. 1st token)------
    Mean TPOT (ms):                          677.30
    Median TPOT (ms):                        237.99
    P99 TPOT (ms):                           4817.75
    ---------------Inter-token Latency----------------
    Mean ITL (ms):                           200.86
    Median ITL (ms):                         123.73
    P99 ITL (ms):                            502.84
    ==================================================
    ```

### Summary of Optimization Options
| Optimization Option               | Throughput Improvement               |
|-----------------------------|-------------------------------------|
| Engine Selection            | <span style="background-color:lightgreen;">+19.8%</span>                             |
| Parallelism                 | <span style="background-color:lightgreen;">+1.6%</span>                                   |
