Skip to main content

Achieving high throughput for offline batch inference

Achieving a large batch size is the most important thing for attaining high throughput in offline batch inference. When the server is running at full load in a steady state, look for the following in the log:
Output

Adjust the request submission speed to control #queue-req

#queue-req indicates the number of requests in the queue. If you frequently see #queue-req: 0, it suggests that your client code is submitting requests too slowly. A healthy range for #queue-req is 100 - 2000. However, avoid making #queue-req too large, as this will increase the scheduling overhead on the server.

Achieve a high token usage

token usage indicates the KV cache memory utilization of the server. token usage > 0.9 means good utilization. If you frequently see token usage < 0.9 and #queue-req > 0, it means the server is too conservative about taking in new requests. You can decrease --schedule-conservativeness to a value like 0.3. The case of a server being too conservative can happen when users send many requests with a large max_new_tokens but the requests stop very early due to EOS or stop strings. On the other hand, if you see token usage very high and you frequently see warnings like KV cache pool is full. Retract requests. #retracted_reqs: 1, #new_token_ratio: 0.9998 -> 1.0000, you can increase --schedule-conservativeness to a value like 1.3. If you see KV cache pool is full. Retract requests. occasionally but not frequently (~1 time per minute), it is okay.

Tune --mem-fraction-static to increase KV cache pool capacity

SGLang allocates memory as follows: Total memory usage = model weights + KV cache pool + CUDA graph buffers + activations The --mem-fraction-static parameter determines how much memory is allocated to the first two components: mem_fraction_static = (model weights + KV cache pool) / GPU memory capacity To support higher concurrency, you should maximize the KV cache pool capacity by setting --mem-fraction-static as high as possible while still reserving enough memory for activations and CUDA graph buffers. SGLang uses simple heuristics to set the default value of --mem-fraction-static, but you can optimize it for your use cases. As a rule of thumb, reserving 5–8 GB of memory for activations is typically sufficient. You can check this by inspecting the logs just before the server is ready. Look for log entries like this:
Output
Check the available_gpu_mem value.
  • If it is between 5–8 GB, the setting is good.
  • If it is too high (e.g., 10 - 20 GB), increase --mem-fraction-static to allocate more memory to the KV cache.
  • If it is too low, you risk out-of-memory (OOM) errors later, so decrease --mem-fraction-static.
Another straightforward approach is to increase --mem-fraction-static in increments of 0.01 until you encounter OOM errors for your workloads.

Avoid out-of-memory errors by tuning --chunked-prefill-size, --mem-fraction-static, and --max-running-requests

If you encounter out-of-memory (OOM) errors, you can adjust the following parameters:
  • If OOM occurs during prefill, try reducing --chunked-prefill-size to 4096 or 2048. This saves memory but slows down the prefill speed for long prompts.
  • If OOM occurs during decoding, try lowering --max-running-requests.
  • You can also reduce --mem-fraction-static to a smaller value, such as 0.8 or 0.7. This decreases the memory usage of the KV cache memory pool and helps prevent OOM errors during both prefill and decoding. However, it limits maximum concurrency and reduces peak throughput.

Tune --cuda-graph-max-bs-decode

By default, CUDA graph is enabled only for small batch sizes (e.g., less than 160 or 256). However, for some models, especially at large tensor parallelism sizes, CUDA graph can be useful for batch sizes up to 512 or 768. Therefore, it may be beneficial to increase --cuda-graph-max-bs-decode to a larger value. Note that CUDA graph consumes more memory, so you may need to reduce --mem-fraction-static at the same time.

Tune --dp-size and --tp-size

Data parallelism is better for throughput. When there is enough GPU memory, always favor data parallelism for throughput. Refer to DP, DPA and sgl-router for a better data parallelism with separate servers behind sgl-router rather than using dp_size parameter.

Try other options

  • torch.compile accelerates small models on small batch sizes. You can enable it with --enable-torch-compile.
  • Try other quantization (e.g. FP8 quantization with --quantization fp8)
  • Try other parallelism strategies (e.g. expert parallelism) or DP attention for deepseek models (with --attn-dp-size 8).
  • If the workload has many shared prefixes, try --schedule-policy lpm. Here, lpm stands for longest prefix match. It reorders requests to encourage more cache hits but introduces more scheduling overhead.

LPM under long waiting queues

With prefix caching enabled, lpm keeps its existing matching and sorting behavior for queues of at most 128 requests. Above 128, it checks the first 64 waiting requests for a prefix-reuse opportunity on the first eligible scheduling pass and every 32 eligible passes thereafter. A pass is eligible when the queue exceeds 128 and no committed batch remains. This deterministic cadence keeps ranks sharing the queue independent of local clock differences. The gate requires threatened reuse of at least 1.5 times the KV capacity. Candidate requests are grouped by cache namespace and their first 4096 tokens. Threatened reuse counts long shared prefixes whose intervening unique input working set, including the reusable prefix, exceeds the KV capacity. This is a heuristic input-based signal, not a guarantee of cache savings or latency improvement. If the gate rejects, LPM retains its FCFS fallback. Otherwise, it selects a fixed batch of up to 64 waiting requests. Each pass rematches and reorders the remaining members. Members are not replenished, and the batch finishes admission or cancellation before the queue threshold is evaluated again. Temporarily skipped members (prefetch, staging, LoRA availability, or pooling compatibility) may allow one additional fixed batch of up to 64 requests to be attempted. Resource and budget breaks still end the pass. This additional batch is never replenished while the current batch remains active; its survivors are promoted when the current batch clears. All committed batches must drain before short-queue LPM resumes. This bounds the set of later requests considered during temporary blocking, not their execution time. The gate currently supports ordinary RadixCache and FULL-only UnifiedRadixCache configurations. Hierarchical, session, sliding-window, Mamba, and other unsupported cache modes retain the existing fallback. Non-members retain the existing periodic, capped prefix refresh. dLLM retains the original LPM large-queue FCFS fallback because its separate transfer path does not use this admission loop. Disabling prefix caching still uses FCFS. No new policy name or server argument is required.

Reduce tail latency with --schedule-policy uniboost

For mixed prompt lengths, such as agentic RL rollouts, uniboost admits requests with little uncached prefill work ahead of long ones. Each request gets a bounded boost, so long requests keep their place in line and are not starved.
  • --uniboost-gamma (default 10.0) sets the boost decay rate. Lower values behave more like shortest-job-first; higher values behave more like fcfs.
  • --enable-uniboost-gamma-ada tunes gamma online from the observed p95/p99 latency, so you do not have to pick it per workload.
  • With --tp-size or --pp-size above 1, a request’s arrival is measured in prefill tokens processed before it was queued, not wall time, so every rank admits the same batch.