[Bugfix] Respect declared attention contract for ColQwen3.5 retrievers (#49372)

Signed-off-by: Athrael Soju <athrael.soju@gmail.com>
This commit is contained in:
Athrael Soju
2026-07-26 04:08:07 +00:00
committed by GitHub
parent 48ebd6f2f1
commit 1240c74c0a
2 changed files with 135 additions and 16 deletions
+32 -8
View File
@@ -769,17 +769,41 @@ class Qwen3_5ForConditionalGenerationConfig(VerifyAndUpdateConfig):
class ColQwen3_5Config(Qwen3_5ForConditionalGenerationConfig):
"""ColQwen3.5 (late-interaction retrieval) inherits Qwen3.5's mamba cache
handling and additionally serves BIDIRECTIONAL attention: ColPali-style
document/query encoding attends over the whole sequence, not causally. Set
is_causal=False so Qwen3NextAttention builds its full_attention layers with
AttentionType.ENCODER_ONLY (the linear_attention GatedDeltaNet layers are
unaffected). Generation arches keep the parent (causal) and are untouched.
"""
"""Apply the attention contract declared by a ColQwen3.5 checkpoint."""
@staticmethod
def verify_and_update_model_config(model_config: "ModelConfig") -> None:
model_config.hf_config.is_causal = False
configs = {
id(config): config
for config in (
model_config.hf_config,
model_config.hf_text_config,
)
}
declarations = [
contract
for config in configs.values()
if (contract := getattr(config, "retrieval_attention_contract", None))
is not None
]
supported = {"causal", "bidirectional"}
if not declarations:
raise ValueError(
"ColQwen3.5 checkpoints must declare "
"retrieval_attention_contract as 'causal' or 'bidirectional'"
)
if (
any(not isinstance(contract, str) for contract in declarations)
or any(contract not in supported for contract in declarations)
or len(set(declarations)) != 1
):
raise ValueError(
"unsupported or conflicting ColQwen3.5 "
f"retrieval_attention_contract declarations: {declarations!r}"
)
is_causal = declarations[0] == "causal"
for config in configs.values():
config.is_causal = is_causal
class SnowflakeGteNewModelConfig(VerifyAndUpdateConfig):