[GH-ISSUE #4843] [Engine] support the dense qwen35 family (Qwen3.5-4B, Qwen3.8-4B distills) #2225

Open
opened 2026-11-04 01:57:41 +07:00 by bsakaguchi · 0 comments
Owner

Originally created by @FurBlood344324 on GitHub (Oct 31, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/4843

What I want to do

Run and serve GGUFs that carry general.architecture = qwen35 but a dense FFN — unsloth/Qwen3.5-4B-GGUF
and the Qwen3.8-4B distills (empero-ai/Qwen3.8-4B-Distill-GGUF) — on the q36 path. Today the engine refuses
them at load: architecture is 'qwen35', this engine requires 'qwen4exp' (0.1.55, upstream c62d5e3a).

The skeleton is the one the engine already runs for qwen35moe: same GDN keys (conv_kernel 4, state_size 128,
group_count 16, time_step_rank 32, inner_size 4096), full_attention_interval 4, embedding_length 2560,
attention.head_count 16 / kv 4, head_dim 256. Only the FFN differs:

qwen35moe (runs today) qwen35 dense
FFN 256 experts, top-8 + shared expert one dense MLP, ffn_gate/up/down.weight, 9216
router ffn_gate_inp.weight none
MTP block blk.<n>.nextn.* same keys, present in the 3.8-4B distill (nextn_predict_layers = 1)
head output.weight absent (tied) in the 3.8-4B distill → token_embd.weight

So the GPU work exists already: the MoE path's shared expert is a dense MLP and the kernels are runtime-shaped.
I am asking for scope before opening the PR, as CONTRIBUTING asks.

What I did today, on a fork

FurBlood344324/strata-dense, branch dense-qwen35 (private copy of this tree, upstream stays its remote).
Diff against main: 8 files, +465/−52, no kernel changes.

  • ModelFamily::Qwen35, check_architecture_qwen35, geometry (n_ff = feed_forward_length, n_expert = 0,
    n_ff_shexp = n_ff), a dense layout table, TensorWant.optional for the tied head, the family switch.
  • loader: the dense MLP goes into the shared-expert slot, router/expert blobs are skipped, a tied head reuses
    token_embd.weight as the head (same [n_embd, n_vocab]; no second 497 MiB copy), and the host-side f32 path
    dequantizes K-quant blocks (this distill stores ssm_alpha/ssm_beta as Q4_K).
  • layer(): a dense branch after add_rms_post (SwiGLU + down, then the residual and the next layer's norm);
    k_moe_out cannot be reused, it always reads its first expert's row.
  • place_experts() returns for n_expert == 0 (it divided by the expert count: SIGFPE).

Measurements (GTX 1650 4 GB, CUDA 13.4, sm_75, ctx 1024, chunk 512, warm-up and capture on)

Greedy, Qwen3.8-4B-Q4_K_M.gguf, llama.cpp b10387 as the reference engine (llama-server, temp 0):

prompt strata reference
The 2614 llama.cpp 2614
The capital of France is " Paris. The capital of Germany is Berlin. The capital of Italy is Rome." llama.cpp: the same 16 tokens
×60 (300 tokens) 760 6511 314 9338 my host-side reference kernel path (strata-q36ref): 760
×140 (700 tokens, crosses the 512-row chunk boundary) 760 6511 314 strata-q36ref: 760

Prefill 700 tokens in 7.2 s (~97 tok/s, the native MMVQ — this card has no room for the prompt GEMM's scratch),
decode 37.5 tok/s. VRAM, measured with cudaMemGetInfo: weights 2.59 GiB of the card's 3.64 GiB usable (32 trunk
layers 2.03, token_embd/tied head 0.49, MTP block 71 MiB), state + buffers 0.69 GiB at ctx 3072, so the practical
context ceiling on a 4 GB card is ~3K (2560 with room to spare, 3584 OOM).

One sizing bug that this family exposes, worth fixing whatever you decide about the port

init() sizes the F32 projections' split-K partials as

sk_part = dalloc((size_t) kSplitK * T * (g.n_expert + 1));   // origin/main, q36_engine.cu:1369

The buffer is laid out [kSplitK][T][n_out]. n_expert + 1 is the router's width (257 for a MoE file) and it
happens to be ≥ the other user of this buffer, the GDN alpha / beta projections, which have ssm_v_heads (32)
rows. A dense family has no router, so n_expert + 1 = 1 and every chunked prompt writes 32 rows per row past
the end, over whatever the allocator placed next. Its symptoms looked like two unrelated bugs: a warm-up (which is
just a 512-row prompt chunk) left the next sequence wrong, and a 300-token prompt raised an illegal memory access.
max(n_expert + 1, ssm_v_heads) fixed both.

Note on reproduction status: on the current tree this is unreachable, because the family is refused before the
engine starts. I hit it through my branch, so I state it as a latent sizing bug this family exposes, not as an
existing crash — the MoE path is insulated only by the router being wider than the GDN projections.

Scope I would like agreed

  1. family recognition, geometry, layout tables, family switch, and the layout unit tests (my model_family_test
    grows to 37 checks, all pass);
  2. the loader and the dense layer path;
  3. the sk_part sizing line above.

Not in that PR unless you want them: MTP drafting for a dense nextn block (it is loaded but unused; a
community distill's block may be a donor head), serve plumbing (the chat template should come from
tokenizer.chat_template in the file rather than a hardcoded jinja), setup.py's family entry, and honouring
want_mtp in load() (today the MTP block is loaded even when drafting is off — 71 MiB on a 4 GB card).

What I did not test

Only CUDA on sm_75 (a 4 GB GTX 1650). No ROCm, Metal, SYCL or Blackwell run, no other quantization of the same
family, no multi-GPU / layer split, and no long-context run past 3K cells. The spec-decode and serve paths were
not exercised at all.

Reproduction status: measured locally. Happy to open the PR with the exact commands and logs if the scope is
acceptable.

Originally created by @FurBlood344324 on GitHub (Oct 31, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/4843 ## What I want to do Run and serve GGUFs that carry `general.architecture = qwen35` but a **dense** FFN — `unsloth/Qwen3.5-4B-GGUF` and the `Qwen3.8-4B` distills (`empero-ai/Qwen3.8-4B-Distill-GGUF`) — on the q36 path. Today the engine refuses them at load: `architecture is 'qwen35', this engine requires 'qwen4exp'` (0.1.55, upstream `c62d5e3a`). The skeleton is the one the engine already runs for `qwen35moe`: same GDN keys (`conv_kernel 4`, `state_size 128`, `group_count 16`, `time_step_rank 32`, `inner_size 4096`), `full_attention_interval 4`, `embedding_length 2560`, `attention.head_count 16 / kv 4`, `head_dim 256`. Only the FFN differs: | | `qwen35moe` (runs today) | `qwen35` dense | |---|---|---| | FFN | 256 experts, top-8 + shared expert | one dense MLP, `ffn_gate/up/down.weight`, 9216 | | router | `ffn_gate_inp.weight` | none | | MTP block | `blk.<n>.nextn.*` | same keys, present in the 3.8-4B distill (`nextn_predict_layers = 1`) | | head | `output.weight` | absent (tied) in the 3.8-4B distill → `token_embd.weight` | So the GPU work exists already: the MoE path's *shared expert* is a dense MLP and the kernels are runtime-shaped. I am asking for scope before opening the PR, as CONTRIBUTING asks. ## What I did today, on a fork `FurBlood344324/strata-dense`, branch `dense-qwen35` (private copy of this tree, upstream stays its remote). Diff against `main`: **8 files, +465/−52, no kernel changes.** - `ModelFamily::Qwen35`, `check_architecture_qwen35`, geometry (`n_ff = feed_forward_length`, `n_expert = 0`, `n_ff_shexp = n_ff`), a dense layout table, `TensorWant.optional` for the tied head, the family switch. - loader: the dense MLP goes into the shared-expert slot, router/expert blobs are skipped, a tied head reuses `token_embd.weight` as the head (same `[n_embd, n_vocab]`; no second 497 MiB copy), and the host-side f32 path dequantizes K-quant blocks (this distill stores `ssm_alpha`/`ssm_beta` as Q4_K). - `layer()`: a dense branch after `add_rms_post` (SwiGLU + down, then the residual and the next layer's norm); `k_moe_out` cannot be reused, it always reads its first expert's row. - `place_experts()` returns for `n_expert == 0` (it divided by the expert count: SIGFPE). ## Measurements (GTX 1650 4 GB, CUDA 13.4, sm_75, ctx 1024, chunk 512, warm-up and capture on) Greedy, `Qwen3.8-4B-Q4_K_M.gguf`, `llama.cpp` b10387 as the reference engine (`llama-server`, temp 0): | prompt | strata | reference | |---|---|---| | `The` | `2614` | llama.cpp `2614` | | `The capital of France is` | " Paris. The capital of Germany is Berlin. The capital of Italy is Rome." | llama.cpp: the same 16 tokens | | ×60 (300 tokens) | `760 6511 314 9338` | my host-side reference kernel path (`strata-q36ref`): `760` | | ×140 (700 tokens, crosses the 512-row chunk boundary) | `760 6511 314` | `strata-q36ref`: `760` | Prefill 700 tokens in 7.2 s (~97 tok/s, the native MMVQ — this card has no room for the prompt GEMM's scratch), decode 37.5 tok/s. VRAM, measured with `cudaMemGetInfo`: weights 2.59 GiB of the card's 3.64 GiB usable (32 trunk layers 2.03, `token_embd`/tied head 0.49, MTP block 71 MiB), state + buffers 0.69 GiB at ctx 3072, so the practical context ceiling on a 4 GB card is ~3K (2560 with room to spare, 3584 OOM). ## One sizing bug that this family exposes, worth fixing whatever you decide about the port `init()` sizes the F32 projections' split-K partials as ```cpp sk_part = dalloc((size_t) kSplitK * T * (g.n_expert + 1)); // origin/main, q36_engine.cu:1369 ``` The buffer is laid out `[kSplitK][T][n_out]`. `n_expert + 1` is the router's width (257 for a MoE file) and it happens to be ≥ the other user of this buffer, the GDN alpha / beta projections, which have `ssm_v_heads` (32) rows. A dense family has no router, so `n_expert + 1 = 1` and every **chunked** prompt writes 32 rows per row past the end, over whatever the allocator placed next. Its symptoms looked like two unrelated bugs: a warm-up (which is just a 512-row prompt chunk) left the next sequence wrong, and a 300-token prompt raised an illegal memory access. `max(n_expert + 1, ssm_v_heads)` fixed both. Note on reproduction status: on the current tree this is unreachable, because the family is refused before the engine starts. I hit it through my branch, so I state it as a latent sizing bug this family exposes, not as an existing crash — the MoE path is insulated only by the router being wider than the GDN projections. ## Scope I would like agreed 1. family recognition, geometry, layout tables, family switch, and the layout unit tests (my `model_family_test` grows to 37 checks, all pass); 2. the loader and the dense layer path; 3. the `sk_part` sizing line above. **Not in that PR** unless you want them: MTP drafting for a dense `nextn` block (it is loaded but unused; a community distill's block may be a donor head), `serve` plumbing (the chat template should come from `tokenizer.chat_template` in the file rather than a hardcoded jinja), `setup.py`'s family entry, and honouring `want_mtp` in `load()` (today the MTP block is loaded even when drafting is off — 71 MiB on a 4 GB card). ## What I did not test Only CUDA on sm_75 (a 4 GB GTX 1650). No ROCm, Metal, SYCL or Blackwell run, no other quantization of the same family, no multi-GPU / layer split, and no long-context run past 3K cells. The spec-decode and `serve` paths were not exercised at all. Reproduction status: measured locally. Happy to open the PR with the exact commands and logs if the scope is acceptable.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#2225
No description provided.