Skip to content

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

Open
ys2025-AI wants to merge 1 commit into
modelscope:mainfrom
ys2025-AI:main
Open

[model] refactor qwen3.5 GDN to use FLA causal conv1d and cu_seq_lens_q#176
ys2025-AI wants to merge 1 commit 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
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.

1 participant