Repository navigation
Description
--dflash with the CI pair (mlx-community/Qwen3.5-4B-4bit + z-lab/Qwen3.5-4B-DFlash) produces text that starts right and collapses after a few tokens on every prompt, at temperature 0. main @ ce9b717, mlx-swift-lm 69346d0, M1 Max.
What comes out
Same prompts, plain server vs. --dflash (Block 16), greedy:
| prompt | plain | --dflash |
|---|---|---|
| List five European capitals with their countries, one per line. | Paris, France\nBerlin, Germany\nMadrid, Spain\nRome, Italy\nVienna, Austria |
Paris,\n,\n,\n,\n,\n,\n,… (runs to max_tokens) |
| Explain in three sentences why the sky is blue. | Sunlight appears white but is actually composed… (72 tokens) |
Sunlight appears blue. |
| Translate to French: The committee reviews the quarterly budget on Monday. | Le comité examine le budget trimestriel le lundi. |
Le comité examine le comité |
| 17 × 23 with thinking on | Thinking Process:\n\n1. **Analyze the Request:**… |
Thinking Process the followed by spaces |
The DFlash summary lines report 69-91 % acceptance while this happens. CI's test-dflash.sh asks for "ok", "2" and "three fruits" and only checks that something came back (Here are three common fruits are sweet, juicy, passes), so the job is green.
With --dflash-block-size 1 the output is byte-identical to the plain server on every prompt I tried, hence the target forward is fine; what breaks is the rollback after a verify of a drafted block.
Why
Qwen3.5 is hybrid: most layers are gated delta net with a recurrent state in a MambaCache. The DFlash verify pass runs the whole block through them. When only part of the block is accepted, the state has to go back; it never does:
- Every
DFlashTargetModelconformance declaresdflashIsHybridGDN = false(Qwen35+DFlash.swift:39 and all the others), somakeTargetCacheleaves those layers on a plainMambaCache. restoreTargetCacheAfterAcceptancethen takes the branch commented "Plain MambaCache (non-rollback)… we can't undo them. Only update the offset" (DFlashRuntime.swift ≈205). The rejected drafts stay in the state and the next cycle verifies against a prefix that the model never produced. Block size 1 drafts nothing, therefore, there's nothing to undo.- The hybrid path would not help as it is:
RecurrentRollbackCachereplays an innovation tape thatrecordTapehas to fill, and nothing in mlx-swift-lm's layers calls it.
mlx-swift-lm already handles this case in its draft-model speculative loop (Evaluate.swift ≈1773): on a rejection with recurrent layers it trims every layer back by the verified count, which makes a MambaCache restore the checkpoint() it took before the round and re-feeds the kept tokens. Its MTP path never needs that, since Qwen3.5 advertises a native rewind depth of 1 and MTP drafts one token.
I think the README's note that DFlash on Qwen3.6-35B-A3B "locks into low-entropy attractors" and is unsuitable for production is this same thing, seen through a bigger model: the degenerate output above is what a corrupted recurrent state looks like under greedy decoding, not a sampling artifact.
Fix
Doing what the library's own loop does: checkpoint the plain MambaCache layers when the verify is armed and on a partial acceptance restore them; trim the attention layers to the pre-verify prefix and run the committed tokens (the staged first token plus the accepted drafts) through the target once more. Full acceptance and the no-draft case stay as they are. The hidden states the next draft conditions on still come from the verify pass - which is exact at the accepted positions.
With that, the 8 prompts I compared match the plain server to the last char (apart from DFlash emitting the model's trailing newline before <|im_end|> where the plain path stops at the end token), tool calls and thinking come out right, and the existing E2E script passes. It costs one extra target forward of the committed tokens per partially accepted cycle; on my Macbook Pro M1 Max with the 4B model that puts DFlash below plain decoding (around 24 vs. 66 tok/sec) which is the price of a correct answer until the library can roll a GDN state back per position.
PR coming shortly, with a unit test on the real cache classes and a coherence check in test-dflash.sh.
Activity
solderzzc commentedon Nov 6, 2026
Thanks for the detailed report. I checked the root cause against origin/main:
dflashIsHybridGDNis false for Qwen3.5, the plainMambaCachebranch only moves the offset, andrecordTapehas no call sites. The table of outputs and the block-size-1 control made it easy to confirm. A PR would be very welcome, and the coherence check intest-dflash.shyou described is a good idea.