Add Llama4 attention backend auto-selection (#13421)
Signed-off-by: jbernloehr <jbernloehr@nvidia.com>
This commit is contained in:
@@ -21,6 +21,15 @@ python3 -m sglang.launch_server \
|
|||||||
|
|
||||||
- **OOM Mitigation**: Adjust `--context-length` to avoid a GPU out-of-memory issue. For the Scout model, we recommend setting this value up to 1M on 8\*H100 and up to 2.5M on 8\*H200. For the Maverick model, we don't need to set context length on 8\*H200. When hybrid kv cache is enabled, `--context-length` can be set up to 5M on 8\*H100 and up to 10M on 8\*H200 for the Scout model.
|
- **OOM Mitigation**: Adjust `--context-length` to avoid a GPU out-of-memory issue. For the Scout model, we recommend setting this value up to 1M on 8\*H100 and up to 2.5M on 8\*H200. For the Maverick model, we don't need to set context length on 8\*H200. When hybrid kv cache is enabled, `--context-length` can be set up to 5M on 8\*H100 and up to 10M on 8\*H200 for the Scout model.
|
||||||
|
|
||||||
|
- **Attention Backend Auto-Selection**: SGLang automatically selects the optimal attention backend for Llama 4 based on your hardware. You typically don't need to specify `--attention-backend` manually:
|
||||||
|
- **Blackwell GPUs (B200/GB200)**: `trtllm_mha`
|
||||||
|
- **Hopper GPUs (H100/H200)**: `fa3`
|
||||||
|
- **AMD GPUs**: `aiter`
|
||||||
|
- **Intel XPU**: `intel_xpu`
|
||||||
|
- **Other platforms**: `triton` (fallback)
|
||||||
|
|
||||||
|
To override the auto-selection, explicitly specify `--attention-backend` with one of the supported backends: `fa3`, `aiter`, `triton`, `trtllm_mha`, or `intel_xpu`.
|
||||||
|
|
||||||
- **Chat Template**: Add `--chat-template llama-4` for chat completion tasks.
|
- **Chat Template**: Add `--chat-template llama-4` for chat completion tasks.
|
||||||
- **Enable Multi-Modal**: Add `--enable-multimodal` for multi-modal capabilities.
|
- **Enable Multi-Modal**: Add `--enable-multimodal` for multi-modal capabilities.
|
||||||
- **Enable Hybrid-KVCache**: Add `--hybrid-kvcache-ratio` for hybrid kv cache. Details can be seen in [this PR](https://github.com/sgl-project/sglang/pull/6563)
|
- **Enable Hybrid-KVCache**: Add `--hybrid-kvcache-ratio` for hybrid kv cache. Details can be seen in [this PR](https://github.com/sgl-project/sglang/pull/6563)
|
||||||
|
|||||||
@@ -1110,6 +1110,21 @@ class ServerArgs:
|
|||||||
self.disable_hybrid_swa_memory = True
|
self.disable_hybrid_swa_memory = True
|
||||||
|
|
||||||
elif "Llama4" in model_arch and self.device != "cpu":
|
elif "Llama4" in model_arch and self.device != "cpu":
|
||||||
|
# Auto-select attention backend for Llama4 if not specified
|
||||||
|
if self.attention_backend is None:
|
||||||
|
if is_sm100_supported():
|
||||||
|
self.attention_backend, platform = "trtllm_mha", "sm100"
|
||||||
|
elif is_sm90_supported():
|
||||||
|
self.attention_backend, platform = "fa3", "sm90"
|
||||||
|
elif is_hip():
|
||||||
|
self.attention_backend, platform = "aiter", "hip"
|
||||||
|
elif self.device == "xpu":
|
||||||
|
self.attention_backend, platform = "intel_xpu", "xpu"
|
||||||
|
else:
|
||||||
|
self.attention_backend, platform = "triton", "other platforms"
|
||||||
|
logger.warning(
|
||||||
|
f"Use {self.attention_backend} as attention backend on {platform} for Llama4 model"
|
||||||
|
)
|
||||||
assert self.attention_backend in {
|
assert self.attention_backend in {
|
||||||
"fa3",
|
"fa3",
|
||||||
"aiter",
|
"aiter",
|
||||||
@@ -1117,11 +1132,6 @@ class ServerArgs:
|
|||||||
"trtllm_mha",
|
"trtllm_mha",
|
||||||
"intel_xpu",
|
"intel_xpu",
|
||||||
}, f"fa3, aiter, triton, trtllm_mha or intel_xpu is required for Llama4 model but got {self.attention_backend}"
|
}, f"fa3, aiter, triton, trtllm_mha or intel_xpu is required for Llama4 model but got {self.attention_backend}"
|
||||||
if is_sm100_supported() and self.attention_backend is None:
|
|
||||||
self.attention_backend = "trtllm_mha"
|
|
||||||
logger.warning(
|
|
||||||
"Use trtllm_mha as attention backend on sm100 for Llama4 model"
|
|
||||||
)
|
|
||||||
if is_sm100_supported() and self.moe_runner_backend == "auto":
|
if is_sm100_supported() and self.moe_runner_backend == "auto":
|
||||||
if self.quantization in {"fp8", "modelopt_fp8"}:
|
if self.quantization in {"fp8", "modelopt_fp8"}:
|
||||||
self.moe_runner_backend = "flashinfer_trtllm"
|
self.moe_runner_backend = "flashinfer_trtllm"
|
||||||
|
|||||||
Reference in New Issue
Block a user