Skip to main content

Why Deterministic Inference Matters

Deterministic inference ensures consistent LLM outputs across runs, which is critical for:
  • Reinforcement Learning: Ensures consistent logprobs across runs, reducing stochastic noise and making RL training more stable, reproducible, and debuggable.
  • Testing & Debugging: Enables reproducible validation
  • Production: Improves reliability and user experience
Even with temperature=0, standard LLM inference can produce different outputs due to dynamic batching and varying reduction orders in GPU kernels.

The Root Cause of Non-Determinism

The main source is varying batch sizes. Different batch sizes cause GPU kernels to split reduction operations differently, leading to different addition orders. Due to floating-point non-associativity ((a + b) + c ≠ a + (b + c)), this produces different results even for identical inputs.

SGLang’s Solution

Building on Thinking Machines Lab’s batch-invariant operators, SGLang achieves fully deterministic inference while maintaining compatibility with chunked prefill, CUDA graphs, radix cache, and non-greedy sampling. The development roadmap for deterministic inference features can be found in this issue.

Supported Backends

Deterministic inference is supported with the following attention backends: flashinfer, fa3, fa4, triton, ascend, and intel_xpu. Radix cache under deterministic inference is supported with fa3, fa4, triton, and ascend. On gfx950 (MI350X, MI355X), aiter is also accepted as --prefill-attention-backend or --decode-attention-backend (not as --attention-backend) for non-MLA models without speculative decoding. aiter prefill also needs a bf16 KV cache and a --chunked-prefill-size that is a multiple of 128, and it changes a page size that is not a multiple of 128 to 128. The following table shows feature compatibility for deterministic inference on the three most common backends:
Attention BackendCUDA GraphChunked PrefillRadix CacheNon-greedy Sampling (Temp > 0)
FlashInfer✅ Yes✅ Yes❌ No✅ Yes
FlashAttention 3 (FA3)✅ Yes✅ Yes✅ Yes✅ Yes
Triton✅ Yes✅ Yes✅ Yes✅ Yes

Usage

Basic Usage

Enable deterministic inference by adding the --enable-deterministic-inference flag:
Command

Server Arguments

ArgumentType/DefaultDescription
--enable-deterministic-inferenceflag; default: disabledEnable deterministic inference with batch-invariant operations
--attention-backendstring; default: platform-dependentChoose attention backend (flashinfer, fa3, fa4, triton, ascend, or intel_xpu). When unset, deterministic mode picks fa3 on Hopper and older GPUs, flashinfer or triton on Blackwell, triton on ROCm, and intel_xpu on XPU

Example Configurations

Qwen3-8B

Command

Llama Models

Command

Qwen3-30B-A3B (MoE Model)

Command

Deterministic Inference with Non-Greedy Sampling (Temperature > 0)

SGLang supports deterministic inference even with non-greedy sampling by using sampling seeds. This is particularly useful for reinforcement learning scenarios like GRPO (Group Relative Policy Optimization) where you need multiple diverse but reproducible responses. A sampling_seed in a request takes effect even without --enable-deterministic-inference. The flag adds the default seed described below and the batch-invariant operators, and it is still required for a seed to apply under speculative decoding.

Default Behavior

With --enable-deterministic-inference, SGLang uses a sampling seed of 42 for reproducible sampling:
Example

Generating Multiple Reproducible Responses

To sample different responses from the same prompt while maintaining reproducibility (e.g., for GRPO training), provide different sampling seeds in your requests:
Example
This approach ensures that:
  • Different seeds produce diverse responses
  • The same seed always produces the same response across different runs
  • Results are reproducible for debugging and evaluation

Verification

Run deterministic tests to verify consistent outputs:
Command
Expected result: All tests should show Unique samples: 1 (perfectly deterministic).