Fix DFlash sliding attention causality defaults (#34524)
This commit is contained in:
@@ -28,6 +28,7 @@ _ARCH = "muse-glimmer"
|
|||||||
class MuseGlimmerAssistantConfig(PretrainedConfig):
|
class MuseGlimmerAssistantConfig(PretrainedConfig):
|
||||||
|
|
||||||
model_type = "muse_glimmer_assistant"
|
model_type = "muse_glimmer_assistant"
|
||||||
|
is_causal = False
|
||||||
# The DFlash draft has no head; draft_worker_common borrows the target's.
|
# The DFlash draft has no head; draft_worker_common borrows the target's.
|
||||||
vocab_size = None
|
vocab_size = None
|
||||||
|
|
||||||
|
|||||||
@@ -43,14 +43,13 @@ if _is_npu:
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def _get_dflash_attention_type(config) -> AttentionType:
|
def _get_dflash_attention_type(config, *, default: AttentionType) -> AttentionType:
|
||||||
"""Bidirectional over the draft block unless the checkpoint says causal."""
|
"""Honor explicit causality while preserving legacy layer defaults."""
|
||||||
text_config = getattr(config, "text_config", None) or config
|
text_config = config.get_text_config()
|
||||||
return (
|
is_causal = getattr(text_config, "is_causal", None)
|
||||||
AttentionType.DECODER
|
if is_causal is None:
|
||||||
if getattr(text_config, "is_causal", False)
|
return default
|
||||||
else AttentionType.ENCODER_ONLY
|
return AttentionType.DECODER if is_causal else AttentionType.ENCODER_ONLY
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def _get_dflash_layer_attention_params(
|
def _get_dflash_layer_attention_params(
|
||||||
@@ -67,12 +66,15 @@ def _get_dflash_layer_attention_params(
|
|||||||
|
|
||||||
layer_type = layer_types[layer_id]
|
layer_type = layer_types[layer_id]
|
||||||
if layer_type == "full_attention":
|
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":
|
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)
|
sliding_window_size = get_dflash_attention_sliding_window_size(config)
|
||||||
assert sliding_window_size is not None
|
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(
|
raise ValueError(
|
||||||
"Unsupported DFLASH draft layer type. "
|
"Unsupported DFLASH draft layer type. "
|
||||||
f"layer_types[{layer_id}]={layer_type!r}."
|
f"layer_types[{layer_id}]={layer_type!r}."
|
||||||
|
|||||||
Reference in New Issue
Block a user