Repository navigation
feat(qwen4): add optional Looped-Qwen4 recurrent-depth sidecar support - #1270
Open
This-Is-NPC wants to merge 2 commits into
Open
This-Is-NPC wants to merge 2 commits into
This-Is-NPC wants to merge 2 commits into
Conversation
This was referenced Dec 6, 2026
This branch has not been deployed
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.
Summary
Adds optional Open-Channel v4 recurrent-depth ("Looped-Qwen4") support to the
qwen4_moe_npu(q4m) engine — enablingT = 2orT = 3recurrent passes over the middle 16 layers (L12..L27) using the pure-recurrence, zero-LoRA 22.8 MiB.safetensorssidecar fromsliderforthewin/Looped-Qwen4-35B-A3B(MIT, blog).model.q4nxor NPU xclbins: works directly on top of the officialFastFlowLM/Qwen4-35B-A3B-NPU2checkpoint,decode.xclbin,prefill_overlay.xclbin, vision tower, andcausal_lmvtable ABI (_ZTV13qwen4_moe_npu == 144bytes unchanged).FLM_QWEN4_LOOP_PASSES=1),loop_->active()isfalse, no extra KV/GDN pass caches are allocated, andmodel::forwardexecutes the exact upstream single-pass loop.q4nx_file(zero pickle, zero script execution), strictly validating shapes, dtypes, andPLE_LAYER < core_start < core_end <= NL.Key Changes
qwen4_moe_loop.hpp/qwen4_moe_loop.cpp):<model_dir>/looped.safetensorsor<model_dir>/loop/loop_adapter_mlx.safetensors, or loads an explicit path viaFLM_QWEN4_LOOP_ADAPTER.Looped-Qwen4-35B-A3Bsidecar layouts (loop/,sushi/default_t{2,3}, andmlx/default_t{2,3}with*_tanhkeys +delta_rms_match: true).HCWorkspaceEntry,HCCrossPassMixer(L15, L19, L23, L27), and optionalLoopCD-Hiddenextrapolation (FLM_QWEN4_LOOP_CD_OMEGA, default0.0) using BF16 AVX-512 low-rank projections (0.72 ms/tokentotal overhead for all 5 mixers combined).qwen4_moe_host.{hpp,cpp},qwen4_moe_forward.cpp):pass_swap_guard) around core passesp = 1 .. T - 1soattn_blockandgdn_blockstay untouched.snapshot(model::save/load/load_rows) so prefix caching (flm_state_api) works seamlessly with looped inference.#include <climits>innpu_cmd.hppand overridableCXX ?= g++-13inMakefile.Usage (Zero 42 GB Model Duplication)
Verification
SUSHI_QWEN4_35B.md/vllm_looped_qwen38on realloop_adapter_mlx.safetensors, SHA-256c589e2b9...):workspace_entry(p=1):max_abs = 2.384e-07,rel_l2 = 1.034e-08workspace_entry(p=2):max_abs = 2.384e-07,rel_l2 = 1.258e-08cross_pass_mix(p=1, L15):max_abs = 1.192e-07,rel_l2 = 4.352e-08cross_pass_mix(p=2, L27):max_abs = 1.192e-07,rel_l2 = 4.461e-08apply_loop_cd(w=0.15):max_abs = 7.153e-07,rel_l2 = 7.528e-080.719 mslibqwen4_moe_npu.soandsrc/build/flmcleanly with zero errors.readelf -sW_ZTV13qwen4_moe_npu == 144bytes (exact ABI match)./dev/accel/accel0, officialFastFlowLM/Qwen4-35B-A3B-NPU2):FLM_QWEN4_LOOP_PASSES=3(72 effective layers/token) across bothprefill_overlay.xclbin(66 tokens,7.69 tok/s, TTFT8.72 s) and persistentdecode.xclbinwith clean output ("The ball costs $0.05 (since the bat costs $1.05, making the total $1.10 and the difference $1.00).").