[v1] support GDN Ulysses cp - #10727
Merged
Merged
Conversation
Removed unsupported model check for qwen3.5 in sequence parallel implementation.
Collaborator
|
gdn适配好fla,如果还没准备好,可以先转draft |
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.
What does this PR do?
Summary
Add Ulysses-style Context Parallel (CP) support for GDN (Gated Delta Network) linear attention layers in Qwen3.5 models, including Pack (cu_seqlens) support for improved GPU utilization.
Motivation
Qwen3.5 models mix two attention types:
full_attention(standard Flash Attention) andlinear_attention(GDN). The existing Ulysses CP implementation only handlesfull_attentionlayers. GDN layers were silently running without CP, causing:cp_size > 1(GDN layers processed only 1/cp of the sequence without all_to_all)Additionally, GDN layers lacked Pack (cu_seqlens) support, preventing multi-sample packing for higher GPU utilization under CP.
What This PR Does
New file:
gdn_attention.pyCore implementation with 4 functions:
is_gdn_layer()— identifies GDN layers bylayer_type == "linear_attention"orblock_type == "linear_attention"_get_gdn_module()— resolves the actual GDN module from either aQwen3_5GatedDeltaNetor aQwen3_5DecoderLayerget_parameter_local_cp()— slices model parameters (conv1d weight/bias, A_log, dt_bias) for the current CP rank, withsplit_sectionssupport to ensure proportional slicing of each Q/K/V sub-groupgdn_forward_with_cp()— replaces the GDN forward whencp_size > 1, falls back toself.original_forwardwhencp_size <= 1. Supports Pack mode via cu_seqlens derived from position_ids.Modified file:
sequence_parallel.pyAdded GDN forward registration in
apply_sequence_parallel(): whencp_size > 1, iterates over model modules, identifies GDN layers, and replaces their forward method withgdn_forward_with_cp.Design
Reuses
SeqAllToAll4D(same all_to_all primitive as UlyssesAttention). Each GDN component (Q/K/V/z/b/a) is independently reshaped to 4D and all_to_all'd with scatter heads / gather seq, then Q/K/V are concatenated for conv1d. Afterchunk_gated_delta_rule+ norm in HP layout, the output is all_to_all'd back to CP layout.Key decisions:
get_parameter_local_cpwithsplit_sectionsensures conv1d weight/bias, A_log, dt_bias are proportionally sliced for each CP rankself.original_forwardposition_idsviaprepare_fa_kwargs_from_position_idsafter all_gather, consistent with UlyssesAttention's position_ids handlingcausal_conv1d_fn(FLA) to prevent cross-sample information leakage; F.conv1d fallback is disabled when cu_seqlens is not Nonecausal_conv1d_fnandchunk_gated_delta_rulecu_seqlens support depend on FLA Triton kernels, which are GPU-onlyTesting
Model
Qwen3.5-4B with
num_hidden_layersreduced from 32 to 8 for fast single-node verification. Model weights fully downloaded.Precision
Memory
Before submitting
No more tests needed