From 0dab252ffcfed49fb73aece51c960c37c5cf67ef Mon Sep 17 00:00:00 2001 From: Mohammad Miadh Angkad <176301910+mmangkad@users.noreply.github.com> Date: Wed, 12 Aug 2026 14:05:55 +0800 Subject: [PATCH] Fix DFlash sliding attention causality defaults (#34524) --- python/sglang/srt/configs/muse_glimmer.py | 1 + python/sglang/srt/models/dflash.py | 24 ++++++++++++----------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/python/sglang/srt/configs/muse_glimmer.py b/python/sglang/srt/configs/muse_glimmer.py index 40866764c..468d0f89b 100644 --- a/python/sglang/srt/configs/muse_glimmer.py +++ b/python/sglang/srt/configs/muse_glimmer.py @@ -28,6 +28,7 @@ _ARCH = "muse-glimmer" class MuseGlimmerAssistantConfig(PretrainedConfig): model_type = "muse_glimmer_assistant" + is_causal = False # The DFlash draft has no head; draft_worker_common borrows the target's. vocab_size = None diff --git a/python/sglang/srt/models/dflash.py b/python/sglang/srt/models/dflash.py index 4adc9990d..75aaddf4f 100644 --- a/python/sglang/srt/models/dflash.py +++ b/python/sglang/srt/models/dflash.py @@ -43,14 +43,13 @@ if _is_npu: logger = logging.getLogger(__name__) -def _get_dflash_attention_type(config) -> AttentionType: - """Bidirectional over the draft block unless the checkpoint says causal.""" - text_config = getattr(config, "text_config", None) or config - return ( - AttentionType.DECODER - if getattr(text_config, "is_causal", False) - else AttentionType.ENCODER_ONLY - ) +def _get_dflash_attention_type(config, *, default: AttentionType) -> AttentionType: + """Honor explicit causality while preserving legacy layer defaults.""" + text_config = config.get_text_config() + is_causal = getattr(text_config, "is_causal", None) + if is_causal is None: + return default + return AttentionType.DECODER if is_causal else AttentionType.ENCODER_ONLY def _get_dflash_layer_attention_params( @@ -67,12 +66,15 @@ def _get_dflash_layer_attention_params( layer_type = layer_types[layer_id] if layer_type == "full_attention": - return -1, _get_dflash_attention_type(config) + return -1, _get_dflash_attention_type( + config, default=AttentionType.ENCODER_ONLY + ) if layer_type == "sliding_attention": - # Windowing is orthogonal to causality (mask is p1 - p0 >= window). sliding_window_size = get_dflash_attention_sliding_window_size(config) assert sliding_window_size is not None - return sliding_window_size, _get_dflash_attention_type(config) + return sliding_window_size, _get_dflash_attention_type( + config, default=AttentionType.DECODER + ) raise ValueError( "Unsupported DFLASH draft layer type. " f"layer_types[{layer_id}]={layer_type!r}."