[PR #4845] [Engine] dense qwen35 family: recognition, loader, layer path, and the split-K partials' size #5210

Open
opened 2026-11-07 16:33:29 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/4845
Author: @FurBlood344324
Created: 10/31/2026
Status: 🔄 Open

Base: main ← Head: dense-qwen35


📝 Commits (5)

  • f886ae0 docs: plan for a dense qwen35 (Qwen3.5/3.8-4B) family
  • ca653c2 qwen35: the dense family — guard, geometry, layout tables, family switch (M0)
  • fc4a228 qwen35 dense: loader, dense layer path, tied head, 4 GB card memory (M1)
  • b952f39 qwen35 dense: fix the split-K partials' size, which was a router's width
  • 106fd2f qwen35 dense: drop the stale warm-up note and the allocation trace

📊 Changes

8 files changed (+475 additions, -51 deletions)

View changed files

➕ docs/DENSE_QWEN35.md (+149 -0)
📝 include/strata/artifact/gguf_reader.hpp (+28 -0)
📝 include/strata/artifact/model_family.hpp (+9 -0)
📝 include/strata/core/family_layout.hpp (+40 -16)
📝 src/program/generate.cpp (+6 -4)
📝 src/qwen35/q36_engine.cu (+151 -23)
📝 src/qwen35/q36ref.cu (+15 -3)
📝 tests/core/model_family_test.cpp (+77 -5)

📄 Description

Draft, opened so the diff can be read next to #4843 — I will keep it draft until the scope in that issue is
agreed, and I am not asking for review before then.

Problem

GGUFs whose general.architecture is qwen35 with a dense FFN (unsloth/Qwen3.5-4B-GGUF, Qwen3.8-4B
distills such as empero-ai/Qwen3.8-4B-Distill-GGUF) are refused at load:

architecture is 'qwen35', this engine requires 'qwen4exp'

Their 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 — and the MoE path's shared expert
is already a dense MLP. So the GPU work exists; what is missing is recognition and routing the dense MLP into the
path the shared expert takes. No kernel is touched.

What the change does

  • Recognition (model_family.hpp, gguf_reader.hpp, family_layout.hpp, generate.cpp): ModelFamily::Qwen35,
    check_architecture_qwen35 (no expert_* keys, nextn_predict_layers optional), geometry
    (n_ff = feed_forward_length, n_expert = 0, n_ff_shexp = n_ff, no router tables), a dense layout table
    (ffn_gate/up/down.weight instead of ffn_*_inp/_shexp/_exps), and TensorWant.optional so a file without
    output.weight still completes its table.
  • Loader (q36_engine.cu): sh_gate/up/down ← ffn_*, no router / expert blobs, and a tied head reuses
    token_embd.weight as the head (same [n_embd, n_vocab] shape — no second 497 MiB copy on a small card). The
    host-side f32 path now dequantizes K-quant blocks, because this distill stores ssm_alpha / ssm_beta as Q4_K.
  • Layer: after add_rms_post the dense family computes SwiGLU + sh_down and adds the residual with the next
    layer's norm. k_moe_out cannot serve it: it always reads its first expert's row.
  • place_experts() returns for n_expert == 0 (it divided by the expert count: SIGFPE).
  • sk_part sizing: the split-K partials of the F32 projections are [kSplitK][T][n_out] and were sized
    kSplitK * T * (n_expert + 1) — the router's width in a MoE file (257) and 1 in a dense family, while the GDN
    alpha / beta projections that share the buffer have ssm_v_heads (32) rows. Every chunked prompt wrote 32 rows
    per row past the end. Sized by max(n_expert + 1, ssm_v_heads) now; for a MoE file this is the same value as
    before (max(257, 32) = 257), so the change is a no-op there.
  • Small-card behaviour (a 4 GB GTX 1650 is what I have): the dense family takes a 512-row prompt chunk (the
    auto rule budgets for expert weights that are not there and picked 2048 rows, which OOMed), skips the prompt
    GEMM's 45 MB dequant scratch below 640 MB free — apply()/prep() then read prompts on the native MMVQ in
    8-column steps — and starts the attention-score buffer at 16 MB. All of it applies only to the dense family; the
    MoE path's defaults are untouched.
  • One diagnostic line at the end of init(): weights / cache+state+buffers / free VRAM, measured with
    cudaMemGetInfo. It is what showed that the weights alone are 2.59 GiB of this card's 3.64 GiB.

Validation I actually ran

Environment: CachyOS, Linux 7.2.11, driver 615.78.08, CUDA 13.4.92, one GTX 1650 (4096 MiB, sm_75), engine built
from this branch with -DCMAKE_CUDA_ARCHITECTURES=75. Model: Qwen3.8-4B-Q4_K_M.gguf (2 783 446 304 B).
Reference engines: llama.cpp b10387 (llama-server, temp 0) and this tree's own strata-q36ref (one token at a
time, no chunked path) — both on the same machine.

Passed

  • model_family_test: 37 checks, ALL PASSED, including the new dense cases (a qwen35 file with expert_*
    keys is refused, the dense layout table, the optional head).

  • Greedy parity, ctx 1024, chunk 512, warm-up and CUDA graph capture on:

    prompt this branch reference
    The (1 token) 2614 llama.cpp 2614
    The capital of France is (5) " 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 strata-q36ref 760
    ×140 (700 tokens, crosses the 512-row chunk boundary) 760 6511 314 strata-q36ref 760
  • Layer-by-layer A/B against strata-q36ref (residual after every layer, one prompt): max relative difference
    0.02 over the 32 trunk layers.

Failed, then fixed in this branch — the sk_part overflow above. Symptoms were an illegal memory access on a
300-token prompt and a warm-up (which is just a 512-row prompt chunk) leaving the next sequence wrong. With the
fix, both are gone and the warm-up and the graph capture are on.

Not run

  • Any backend other than CUDA: no ROCm, Metal or SYCL build, no non-sm_75 CUDA arch.
  • serve / the chat template, speculative decoding and the MTP block (loaded, unused: load() ignores
    want_mtp and the MTP block costs 71 MiB), --batch, layer split / multi-GPU.
  • Any quantization of this family other than Q4_K_M, and any context beyond 3K cells (this card's ceiling:
    weights 2.59 GiB of 3.64 GiB usable, 3072 cells fit, 3584 OOM).

Compatibility

Existing families behave as before: the new geometry and layout rows are keyed by the family, and the one shared
line (sk_part) is unchanged for a MoE file. No kernel, no default and no CLI flag changes.

I could not test on a bigger card; a review of the VRAM thresholds for the dense family on 8 GB+ would be
welcome, since the 640 MB prompt-GEMM gate and the 16 MB score buffer were both chosen for a 4 GB card.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/4845 **Author:** [@FurBlood344324](https://github.com/FurBlood344324) **Created:** 10/31/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `dense-qwen35` --- ### 📝 Commits (5) - [`f886ae0`](https://github.com/Niko1221/Strata/commit/f886ae0314679e722dd14cb1561ac0fedf9056e3) docs: plan for a dense qwen35 (Qwen3.5/3.8-4B) family - [`ca653c2`](https://github.com/Niko1221/Strata/commit/ca653c22b311354b4a65950ec5e726821a31f199) qwen35: the dense family — guard, geometry, layout tables, family switch (M0) - [`fc4a228`](https://github.com/Niko1221/Strata/commit/fc4a228c738f39d20a6071fa5f93e37726ba051e) qwen35 dense: loader, dense layer path, tied head, 4 GB card memory (M1) - [`b952f39`](https://github.com/Niko1221/Strata/commit/b952f398c3d84e2ab7fa9a60ad9d8664f1893f8b) qwen35 dense: fix the split-K partials' size, which was a router's width - [`106fd2f`](https://github.com/Niko1221/Strata/commit/106fd2f25bfc69c0c0719ae4285620d78b6c4ea9) qwen35 dense: drop the stale warm-up note and the allocation trace ### 📊 Changes **8 files changed** (+475 additions, -51 deletions) <details> <summary>View changed files</summary> ➕ `docs/DENSE_QWEN35.md` (+149 -0) 📝 `include/strata/artifact/gguf_reader.hpp` (+28 -0) 📝 `include/strata/artifact/model_family.hpp` (+9 -0) 📝 `include/strata/core/family_layout.hpp` (+40 -16) 📝 `src/program/generate.cpp` (+6 -4) 📝 `src/qwen35/q36_engine.cu` (+151 -23) 📝 `src/qwen35/q36ref.cu` (+15 -3) 📝 `tests/core/model_family_test.cpp` (+77 -5) </details> ### 📄 Description Draft, opened so the diff can be read next to #4843 — I will keep it draft until the scope in that issue is agreed, and I am not asking for review before then. ## Problem GGUFs whose `general.architecture` is `qwen35` with a **dense** FFN (`unsloth/Qwen3.5-4B-GGUF`, `Qwen3.8-4B` distills such as `empero-ai/Qwen3.8-4B-Distill-GGUF`) are refused at load: ``` architecture is 'qwen35', this engine requires 'qwen4exp' ``` Their 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` — and the MoE path's *shared expert* is already a dense MLP. So the GPU work exists; what is missing is recognition and routing the dense MLP into the path the shared expert takes. No kernel is touched. ## What the change does - **Recognition** (`model_family.hpp`, `gguf_reader.hpp`, `family_layout.hpp`, `generate.cpp`): `ModelFamily::Qwen35`, `check_architecture_qwen35` (no `expert_*` keys, `nextn_predict_layers` optional), geometry (`n_ff = feed_forward_length`, `n_expert = 0`, `n_ff_shexp = n_ff`, no router tables), a dense layout table (`ffn_gate/up/down.weight` instead of `ffn_*_inp/_shexp/_exps`), and `TensorWant.optional` so a file without `output.weight` still completes its table. - **Loader** (`q36_engine.cu`): `sh_gate/up/down ← ffn_*`, no router / expert blobs, and a tied head reuses `token_embd.weight` as the head (same `[n_embd, n_vocab]` shape — no second 497 MiB copy on a small card). The host-side f32 path now dequantizes K-quant blocks, because this distill stores `ssm_alpha` / `ssm_beta` as Q4_K. - **Layer**: after `add_rms_post` the dense family computes SwiGLU + `sh_down` and adds the residual with the next layer's norm. `k_moe_out` cannot serve it: it always reads its first expert's row. - **`place_experts()`** returns for `n_expert == 0` (it divided by the expert count: SIGFPE). - **`sk_part` sizing**: the split-K partials of the F32 projections are `[kSplitK][T][n_out]` and were sized `kSplitK * T * (n_expert + 1)` — the router's width in a MoE file (257) and `1` in a dense family, while the GDN alpha / beta projections that share the buffer have `ssm_v_heads` (32) rows. Every chunked prompt wrote 32 rows per row past the end. Sized by `max(n_expert + 1, ssm_v_heads)` now; for a MoE file this is the same value as before (`max(257, 32) = 257`), so the change is a no-op there. - **Small-card behaviour** (a 4 GB GTX 1650 is what I have): the dense family takes a 512-row prompt chunk (the auto rule budgets for expert weights that are not there and picked 2048 rows, which OOMed), skips the prompt GEMM's 45 MB dequant scratch below 640 MB free — `apply()`/`prep()` then read prompts on the native MMVQ in 8-column steps — and starts the attention-score buffer at 16 MB. All of it applies only to the dense family; the MoE path's defaults are untouched. - **One diagnostic line** at the end of `init()`: weights / cache+state+buffers / free VRAM, measured with `cudaMemGetInfo`. It is what showed that the weights alone are 2.59 GiB of this card's 3.64 GiB. ## Validation I actually ran Environment: CachyOS, Linux 7.2.11, driver 615.78.08, CUDA 13.4.92, one GTX 1650 (4096 MiB, sm_75), engine built from this branch with `-DCMAKE_CUDA_ARCHITECTURES=75`. Model: `Qwen3.8-4B-Q4_K_M.gguf` (2 783 446 304 B). Reference engines: `llama.cpp` b10387 (`llama-server`, temp 0) and this tree's own `strata-q36ref` (one token at a time, no chunked path) — both on the same machine. **Passed** - `model_family_test`: 37 checks, `ALL PASSED`, including the new dense cases (a `qwen35` file with `expert_*` keys is refused, the dense layout table, the optional head). - Greedy parity, ctx 1024, chunk 512, warm-up and CUDA graph capture on: | prompt | this branch | reference | |---|---|---| | `The` (1 token) | `2614` | llama.cpp `2614` | | `The capital of France is` (5) | " 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` | `strata-q36ref` `760` | | ×140 (700 tokens, crosses the 512-row chunk boundary) | `760 6511 314` | `strata-q36ref` `760` | - Layer-by-layer A/B against `strata-q36ref` (residual after every layer, one prompt): max relative difference 0.02 over the 32 trunk layers. **Failed, then fixed in this branch** — the `sk_part` overflow above. Symptoms were an illegal memory access on a 300-token prompt and a warm-up (which is just a 512-row prompt chunk) leaving the next sequence wrong. With the fix, both are gone and the warm-up and the graph capture are on. **Not run** - Any backend other than CUDA: no ROCm, Metal or SYCL build, no non-sm_75 CUDA arch. - `serve` / the chat template, speculative decoding and the MTP block (loaded, unused: `load()` ignores `want_mtp` and the MTP block costs 71 MiB), `--batch`, layer split / multi-GPU. - Any quantization of this family other than `Q4_K_M`, and any context beyond 3K cells (this card's ceiling: weights 2.59 GiB of 3.64 GiB usable, 3072 cells fit, 3584 OOM). ## Compatibility Existing families behave as before: the new geometry and layout rows are keyed by the family, and the one shared line (`sk_part`) is unchanged for a MoE file. No kernel, no default and no CLI flag changes. I could not test on a bigger card; a review of the VRAM thresholds for the dense family on 8 GB+ would be welcome, since the 640 MB prompt-GEMM gate and the 16 MB score buffer were both chosen for a 4 GB card. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#5210
No description provided.