Repository navigation
Conversation
5 of 11 tasks
…rallelism With sequence parallelism the policy replaces the attention forward, whose non-flash path needs an explicit 4d causal mask and skips masking when it gets None. The Qwen2 / Qwen3 pipeline forward however built the mask for the transformers attention implementation; for sdpa and an all-ones padding mask that is None, so with pipeline + sequence parallelism and flash attention off, the attention silently became bidirectional. Always build the 4d causal mask when sequence parallelism is on without flash attention, which is exactly when the attention forward is replaced. Add a pp 2 + sp 2 (all_to_all) config without flash attention to the qwen2 and qwen3 tests. (The mask length on later pipeline stages, the other bug originally fixed here, has been fixed on main by 641cda4.)
LiRunGuo
force-pushed
the
fix/qwen-pp-sp-attn-mask
branch
from
October 14, 2026 00:56
c0f86bf to
6ee408e
Compare
Author
|
cc @richardoo-707: 641cda4 fixed the mask-length part of this PR in the same way (thanks!), so I rebased and dropped it. What remains is the Qwen2/Qwen3 counterpart of the LLaMA non-flash mask change in 641cda4: with pipeline + sequence parallelism and flash attention off, the Qwen pipeline forward still passes |
Open
8 of 11 tasks
for more information, see https://pre-commit.ci
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📌 Checklist before creating the PR
[doc/gemini/tensor/...]: A concise descriptionpip install pre-commit && pre-commit install(ran the pinned hooks manually instead: black 24.10.0--line-length=120, isort 5.13.2--profile black, autoflake 2.3.1, all clean)🚨 Issue number
No existing issue; described below.
📝 What does this PR do?
Bug: with pipeline + sequence parallelism and flash attention off, Qwen2 / Qwen3 silently use bidirectional attention.
With SP the policy replaces the attention forward (
get_qwen{2,3}_flash_attention_forward), whose non-flash branch needs an explicit 4d causal mask and skips masking when it getsNone. The pipeline forward (Qwen{2,3}PipelineForwards.qwen{2,3}_model_forward) however builds the mask for the transformers attention implementation; forsdpa(the default) and an all-ones padding mask,_prepare_4d_causal_attention_mask_for_sdpareturnsNone, so every token attends to the whole sequence. Training runs without errors; outputs and gradients are wrong.(641cda4 fixed the same class of bug for LLaMA by always building the 4d mask in the non-flash path; the Qwen2/Qwen3 pipeline forwards were not changed.)
Fix. When SP is enabled and flash attention is not — exactly when the policy replaces the attention forward — build the 4d causal mask over the full sequence with
_prepare_4d_causal_attention_mask. Without SP the transformers attention is used, and its mask handling is unchanged.Test. Added a "Ulysses without flash attention" config (
tp 1, pp 2, sp 2, all_to_all, enable_flash_attention=False) torun_qwen2_testandrun_qwen3_test. The existing SP configs all enable flash attention, which is why this was not caught.Results (4x H200, torch 2.5.1+cu124, transformers 4.51.3, no
flash_attn; the repo's owncheck_forward_backward, which compares loss, outputs and grads with the unsharded model)test_shard_qwen3.py::test_qwen3(incl. the new config)test_shard_qwen2.py::test_qwen2(incl. the new config)💥 Checklist before requesting a review
⭐️ Do you enjoy contributing to Colossal-AI?