Skip to content

[model] refactor qwen3.5 GDN to use FLA causal conv1d and cu_seq_lens_q - #176

Merged
hjh0119 merged 3 commits into
modelscope:mainfrom
ys2025-AI:main
Sep 7, 2026
Merged

[model] refactor qwen3.5 GDN to use FLA causal conv1d and cu_seq_lens_q#176
hjh0119 merged 3 commits into
modelscope:mainfrom
ys2025-AI:main

Conversation

@ys2025-AI

Copy link
Copy Markdown
Contributor

Fix

src/mcore_bridge/model/mm_gpts/qwen3_5.py

  1. __init__ hybrid-arch adaptation: auto-derive config.layer_types from linear_attention_freq (int → per-layer list); pass layer_number - 1 to the HF parent (0-based layer_idx).
  2. Varlen conv: override self.causal_conv1d_fn = self._fla_conv_fn, which routes FLA causal_conv1d(..., cu_seqlens=self._cur_cu_seqlens) — gives the conv sequence-boundary isolation in varlen (solves cross-sample state leakage that attention_mask cannot fully prevent on GDN's recurrent state).
  3. Varlen forward: thd path keeps packed [1, total, D] and passes cu_seq_lens_q to super().forward(...) instead of un-padding to a padded batch + repacking after. Verified the parent Qwen3_5MoeGatedDeltaNet.forward (transformers ≥5.14.1, modeling_qwen3_5_moe.py:546) consumes kwargs["cu_seq_lens_q"]chunk_gated_delta_rule(cu_seqlens=...), and FLA causal_conv1d supports cu_seqlens (signature verified), so both conv and delta-rule run varlen.

- Add FLA causal_conv1d as the conv function for packed sequences
- Pass cu_seq_lens_q directly to forward, removing manual padding/unpadding
- Derive layer_types from linear_attention_freq in __init__
- Use layer_number-1 to match HF indexing
Comment thread src/mcore_bridge/model/mm_gpts/qwen3_5.py Outdated
Comment thread src/mcore_bridge/model/mm_gpts/qwen3_5.py Outdated
Comment thread src/mcore_bridge/model/mm_gpts/qwen3_5.py Outdated
Comment thread src/mcore_bridge/model/mm_gpts/qwen3_5.py
@ys2025-AI
ys2025-AI requested a review from hjh0119 September 3, 2026 09:40
@hjh0119

hjh0119 commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator

thanks, can you resolve the conflicts?

Conflict in src/mcore_bridge/model/mm_gpts/qwen3_5.py resolved by keeping
the PR's varlen forward path (FLA causal_conv1d + cu_seq_lens_q). The
upstream change to this file only replaced packed_seq_params.num_samples
with get_num_samples(packed_seq_params) in the manual padding block,
which the PR removes entirely in favor of the packed varlen path.
@ys2025-AI

Copy link
Copy Markdown
Contributor Author

thanks, can you resolve the conflicts?

@hjh0119 Conflicts resolved, ready for another look. Thanks!

@hjh0119
hjh0119 merged commit 09e3066 into modelscope:main Sep 7, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants