Skip to content

add safety checks for varlen - #2179

Merged
liangel-02 merged 1 commit into
mainfrom
checks
Dec 26, 2025
Merged

liangel-02 merged 1 commit into
mainfrom
checks

Conversation

@liangel-02

Copy link
Copy Markdown
Contributor

since varlen attn is not supported for deepseek v3 and llama4, we should raise an error if someone attempts to use it

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Dec 26, 2025
@wwwjn

wwwjn commented Dec 26, 2025

Copy link
Copy Markdown
Contributor

Thank you! Can we also change llama3 to align with other models: https://github.com/pytorch/torchtitan/blob/main/torchtitan/models/llama3/model/model.py#L228

@wwwjn wwwjn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@liangel-02
liangel-02 merged commit 5077be6 into main Dec 26, 2025
@tianyu-l
tianyu-l deleted the checks branch December 26, 2025 21:10
@jquesnelle

Copy link
Copy Markdown
Contributor

@wwwjn what's the barrier to varlen support for DSv3? from a cursory glance using the existing VarlenAttentionWrapper as in Qwen3 ought to work?

@liangel-02

liangel-02 commented Jan 26, 2026 •

Copy link
Copy Markdown
Contributor Author

@jquesnelle the underlying flash attention kernel expects Q, K, V to have the same head dimensions
https://github.com/Dao-AILab/flash-attention/blob/main/csrc/flash_attn/flash_api.cpp#L611-L620 but DSv3 uses different dims for Q/K and V

q = q.transpose(1, 2) # (bsz, n_heads, seqlen, qk_head_dim)
k = k.transpose(1, 2) # (bsz, n_heads, seqlen, qk_head_dim)
v = v.transpose(1, 2) # (bsz, n_heads, seqlen, v_head_dim)

cc @drisspg

xrsrke pushed a commit to NousResearch/torchtitan that referenced this pull request Feb 13, 2026
since varlen attn is not supported for deepseek v3 and llama4, we should
raise an error if someone attempts to use it
TXacs pushed a commit to McmillanTAC/torchtitan that referenced this pull request Apr 13, 2026
since varlen attn is not supported for deepseek v3 and llama4, we should
raise an error if someone attempts to use it
ACharacterInASimulation pushed a commit to ACharacterInASimulation/torchtitan that referenced this pull request Apr 21, 2026
since varlen attn is not supported for deepseek v3 and llama4, we should
raise an error if someone attempts to use it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/8gpu CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants