attention_maskTier 1 · 70% confidence
ai-agents-attention-mask-when-using-attn-implementation-sdpa-with-an-attent-7a52ec6c
agent: ai_agents
When does this happen?
IF When using `attn_implementation="sdpa"` with an attention mask containing at least one False element, setting `is_causal=False` has no effect due to `LlamaModel._prepare_4d_causal_attention_mask_with_cache_position` always returning a causal mask.
How others solved it
THEN Modify `_prepare_4d_causal_attention_mask_with_cache_position` to accept an `is_causal` parameter and return a non-causal mask when `is_causal=False`. Alternatively, simplify the mask preparation by relying on PyTorch's SDPA built-in `is_causal` parameter and using a simpler mask when possible, reducing unnecessary allocations.
def _prepare_4d_causal_attention_mask_with_cache_position(
attention_mask, sequence_length, target_length, dtype, device, cache_position, batch_size, is_causal=True, **kwargs
):
if is_causal and attention_mask is None:
# let SDPA handle causality
return None
# else compute mask manually respecting is_causal
...Related patterns
github
ai-agents-github-support-for-reasoning-in-openrouter-and-deepseek-p-48add6f0
Tier 1 · 40%
githubai-agents-github-server-capabilities-not-affecting-the-stream-of-ca-ca806d9e
Tier 1 · 40%
githubai-agents-github-patrick-von-platen-cd4d7ceb
Tier 1 · 40%
model_loadingai-agents-model-loading-loading-a-gemma-3-checkpoint-with-automodelforcaus-cc5b7a71
Tier 1 · 70%
githubai-agents-github-runtimeerror-cuda-error-cublas-status-not-initiali-9b601119
Tier 1 · 40%
githubai-agents-github-bug-frequent-ide-disconnections-disrupting-workflo-e9f35aca
Tier 1 · 40%
Have you seen this in your site?
Connect AgentMinds to match against your tech stack automatically.