From 5a0c1e21e94ed8e5d807547093686c733ff4d382 Mon Sep 17 00:00:00 2001 From: Bingxu Chen Date: Wed, 16 Sep 2026 17:09:08 +0800 Subject: [PATCH] [AMD] Preserve deterministic inference when Lean Attention is enabled (#37740) --- python/sglang/srt/layers/attention/triton_backend.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/python/sglang/srt/layers/attention/triton_backend.py b/python/sglang/srt/layers/attention/triton_backend.py index 33f76e2a6..239b57103 100644 --- a/python/sglang/srt/layers/attention/triton_backend.py +++ b/python/sglang/srt/layers/attention/triton_backend.py @@ -2218,14 +2218,15 @@ class TritonAttnBackend(AttentionBackend): # would never activate on the default path. There we key the bake on capture-time-known # signals (batch, head-tiles, is_mla) via lean_capture_policy -- Lean's fixed persistent # grid still adapts to raggedness on-device at replay. In eager decode, real seq_lens - # are known, so lean_decode_seqlen_gate uses them. An explicit True/False override is - # respected; the SGLANG_DISABLE_LEAN_ATTENTION kill-switch forces the standard kernel. + # are known, so lean_decode_seqlen_gate uses them. Deterministic inference requires + # the batch-invariant standard path; the SGLANG_DISABLE_LEAN_ATTENTION kill-switch + # also forces that path. Otherwise, an explicit True/False override is respected. from sglang.srt.environ import envs from sglang.srt.model_executor.runner_utils.capture_mode import ( get_is_capture_mode, ) - if envs.SGLANG_DISABLE_LEAN_ATTENTION.get(): + if self.enable_deterministic or envs.SGLANG_DISABLE_LEAN_ATTENTION.get(): enable_lean = False else: enable_lean = self.enable_lean_attention