The results are not deterministic, even with a temperature of 0.
数值计算精度和舍入误差:因计算机数值精度有限(如用 32 位、16 位浮点数计算),会产生舍入误差及数值计算不确定性,且这些误差易在模型多层复杂计算中累积放大,致使相同输入时输出有微小差异。
多线程和并行计算影响:即使温度设置为 0,相同请求发送两次,引擎结果仍可能不同,主要原因在于动态批量处理(占 95%)和前缀缓存。动态批量处理中,不同批量大小致 PyTorch/CuBLAS 调用不同 CUDA 内核,产生细微数值差异,经多层累积,使输出结果不确定;启用前缀缓存也因不同内核实现带来数值差异,导致结果不确定。
CUDA 内核是 GPU 上并行执行的函数。
- 通用计算内核用于执行加法、乘法等通用计算任务,A100 的配置可高效处理大量线程,快速完成大规模数据处理;
- 张量内核专为深度学习张量运算设计,A100 的每个 SM 中有四个第三代张量核心,可加速深度学习训练和推理,提高计算性能且保持较低精度损失。
默认参数
- –model-path
- 要使用的 huggingface 模型的名称或路径。
- –dtype
- auto, half, float16, bfloat16, float, float32。默认值:auto。
- –context-length
- 模型上下文长度。如果未指定,将从模型配置中自动导出。
- –served-model-name
- API 中使用的名称。如果未指定,模型名称将与 –model-path 参数相同。
- –random-seed
- 随机种子。
- –quantization
- Sglang支持各种量化方法,包括离线量化和在线动态量化。
- 可能的量化方法:awq, fp8, gptq, marlin, gptq_marlin, awq_marlin, bitsandbytes, gguf, modelopt, modelopt_fp4, w8a8_int8, w8a8_fp8, moe_wna16
- –kv-cache-dtype
- 可能的缓存量化方法:auto, fp8_e5m2, fp8_e4m3。
- –chunked-prefill-size
- 分块预填充块大小。默认值:根据GPU显存,选择2048或者8192。
- –attention-backend
- 可能的attention方法:flashinfer, triton, torch_native, fa3, flashmla, cutlass_mla
- Non-Hopper架构的机器默认使用FlashInfer,Hopper架构使用FlashAttention 3
- python3 -m sglang.launch_server –tp 8 –model deepseek-ai/DeepSeek-V3 –trust-remote-code –attention-backend flashinfer
- python3 -m sglang.launch_server –tp 8 –model deepseek-ai/DeepSeek-V3 –trust-remote-code –attention-backend fa3
- –sampling-backend
- –grammar-backend
- 可能的解码方式:xgrammar、outlines、llguidance。默认值:xgrammar。
- Outlines: 支持 JSON 模式和正则表达式约束。
- XGrammar(默认): 支持JSON模式,正则表达和EBNF约束。
- Llguidance: 支持JSON模式,正则表达和EBNF约束。
Sglang支持解析推理内容,来”标准化”内容,例如DeepSeek R1。
- –reasoning-parser
- 可能的推理解析器:deepseek-r1、qwen3,为 OpenAI API 格式。
- python -m sglang.launch_server –model-path deepseek-ai/DeepSeek-R1-Distill-Qwen-7B –host 0.0.0.0 –reasoning-parser deepseek-r1
OpenAI Compatible API启动
- –tool-call-parser
- –pp-size, –pp
- 流水线并行,层间并行,对模型不同的 Transformer 层间进行分割。默认值为1。
- –tp-size, –tp
- 张量并行,层内并行,对模型 Transformer 层内进行分割。默认值为1。
- –dp-size, –dp
- 数据并行,默认值为1。
- –ep-size
- –mem-fraction-static
- 用于静态内存(如模型权重和 KV 缓存)的 GPU 可用内存的百分比。默认值:0.9。
- –max-running-requests
- 同时运行的最大请求数。
- –max-total-tokens
- 可存储在 KV 缓存中的令牌的最大数量。主要用于调试。
- –max-prefill-tokens
- 表示一次预填充批次可接受的token数量。默认值:16384。
- –scheduling-policy
- 可能的调度策略:lpm(longest prefix match), random, fcfs, dfs-weight,默认值:fcfs(first come first served)。
- –schedule-conservativeness
- 控制服务器接受新的预填充请求时的保守程度。默认值:1.0。
- –cpu-offload-gb
- –enable-torch-compile
- 开启torch.compile加速,加快了小批量小模型的速度。
- –disable-chunked-prefix-cache
- 禁用 DeepSeek 模型的分块前缀缓存。仅在 FA3 作为后端时使用。
- –speculative-algorithm
- 用于投机解码的算法。可选的参数:EAGLE, EAGLE3, NEXTN。
- –speculative-num-steps
- –disable-radix-cache,禁用 Radix 后端前缀缓存。默认值:False。
- –disable-cuda-graph,禁用 CUDA 图。在遇到 CUDA ECC 错误时使用。默认值:False。
- –disable-cuda-graph-padding,需要填充时禁用CUDA图;否则使用CUDA图。默认值:False。
- –disable-outlines-disk-cache,禁用outlines/grammar后端缓存。默认值:False。
- –disable-custom-all-reduce,禁用自定义all_reduce内核。默认值:False。
- –enable-p2p-check,关闭访问GPU时始终允许P2P检查的默认值。默认值:False。
Speculative Decoding
请参阅下面的内容,了解通过 EAGLE3 解码对 MT 基准上测试的 LLaMA-Instruct 3.1 8B 吞吐量的巨大改进。Method Throughput (tokens/s) SGLang (w/o speculative, 1x H100) 158.34 tokens/s SGLang + EAGLE-2 (1x H100) 244.10 tokens/s SGLang + EAGLE-3 (1x H100) 373.25 tokens/s EAGLE-3执行的脚本 - –speculative-draft-model-path: 指定draft模型。必填项。
- –speculative-num-steps: 自回归drafting的深度,增加推测范围。默认值:5。
- –speculative-eagle-topk: 每步分支系数,提高多样性。默认值:4。
- –speculative-num-draft-tokens: 最大并行验证能力。默认值:8。
1
python3 -m sglang.launch_server --model meta-llama/Llama-3.1-8B-Instruct --speculative-algorithm EAGLE3 --speculative-draft-model-path jamesliu1/sglang-EAGLE3-Llama-3.1-Instruct-8B --speculative-num-steps 5 --speculative-eagle-topk 8 --speculative-num-draft-tokens 32 --mem-fraction 0.6 --cuda-graph-max-bs 2 --dtype float16

