Skip to content

fix(qwen): preserve GDN state during padded prefill - #4526

Merged
jundot merged 1 commit into
mainfrom
fix/qwen-gdn-padding-mask
Oct 14, 2026
Merged

jundot merged 1 commit into
mainfrom
fix/qwen-gdn-padding-mask

Conversation

@jundot

@jundot jundot commented Oct 14, 2026

Copy link
Copy Markdown
Owner

Summary

The pinned mlx-vlm Qwen SSM mask helper can return no mask when a newly merged batch has zero left padding but nonzero right padding. It can also drop one boundary when both padding bounds are present. Padded tokens then update the GDN recurrent state after the row's last valid token.

I added a small compatibility patch that intersects both bounds and keeps the existing no-mask path for unpadded calls. It is installed before loading Qwen3.5-family and Qwen4-Exp VLMs, independently of Lightning MTP or DFlash. Qwen4 resolves the shared helper through its module so import order cannot retain the old function.

This is an existing dependency defect identified while investigating the padding comment on #4508. It does not require changes to the GDN kernel or scheduler.

Validation

  • A tiny random-weight Qwen VLM with prompt lengths 3 and 7 reproduced GDN state errors of 0.006195 and 0.005253 in the shorter row's two recurrent layers. With the patch, both GDN and convolution states exactly matched separate unpadded runs for both rows.
  • The regression test compares padded prefill with separate unpadded GDN states, both in a single call and across chunks. It failed before the patch and passes afterward.
  • Mask tests cover both bounds together, a row with no valid tokens, and the unpadded fast path. Loader tests verify installation without speculative decoding enabled.

@jundot
jundot merged commit 0268dd1 into main Oct 14, 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.

1 participant