Add switchable DIFF V1 attention

This commit is contained in:
2026-08-21 11:48:16 +08:00
parent 75c9f06114
commit bf5cae8758
7 changed files with 453 additions and 4 deletions

26
attention_types.py Normal file
View File

@@ -0,0 +1,26 @@
"""Attention implementation identifiers and validation helpers."""
STANDARD_ATTENTION = "standard"
DIFF_ATTENTION = "diff"
DEFAULT_ATTENTION_TYPE = STANDARD_ATTENTION
SUPPORTED_ATTENTION_TYPES = (
STANDARD_ATTENTION,
DIFF_ATTENTION,
)
def resolve_attention_type(attention_type: str | None = None) -> str:
"""Resolve an attention selector, defaulting old configs to standard."""
resolved = DEFAULT_ATTENTION_TYPE if attention_type is None else attention_type
if not isinstance(resolved, str):
raise ValueError(
"attention_type must be one of "
f"{SUPPORTED_ATTENTION_TYPES}, got {resolved!r}"
)
if resolved not in SUPPORTED_ATTENTION_TYPES:
raise ValueError(
f"Unsupported attention_type={resolved!r}; "
f"expected one of {SUPPORTED_ATTENTION_TYPES}."
)
return resolved