Skip to content

qwen4exp: Qwen3.8-Flash-Next on HRX (clean rebase; IMROPE->NEOX + CPU-route experts) - #142

Merged
bong-water-water-bong merged 3 commits into
1bit/hrx-vulkan-patchedfrom
1bit/hrx-qwen4exp
Oct 25, 2026
Merged

bong-water-water-bong merged 3 commits into
1bit/hrx-vulkan-patchedfrom
1bit/hrx-qwen4exp

Conversation

@bong-water-water-bong

@bong-water-water-bong bong-water-water-bong commented Oct 25, 2026 •

Copy link
Copy Markdown

Supersedes the draft #141 with a clean, rebased version on the current 1bit/hrx-vulkan-patched tip (d65a7e5).

What this does

Brings Qwen3.8-Flash-Next (qwen4exp) onto the HRX (gfx1151) backend — first full forward pass + llama-perplexity + coherent decode on -dev HRX0. Three commits:

  1. materialize view inputs to HRX rms_norm — build_gdn_l2_norm and build_norm fed a non-contiguous VIEW into HRX rms_norm; added a ggml_cont guard + the matching dispatch-rmsnorm acceptance. Clears the unsupported HRX node 48: RMS_NORM<-VIEW[128,16,T]->SCALE abort. No-op for 27B/other arches.
  2. decode Flash-Next on HRX (IMROPE->NEOX rope, route problem experts to CPU)
    • Rope: IMROPE (mode 40) with a 4-section position tensor collapses to NEOX for this model (sections=[11,11,10,0], text decode) — matcher accepts the collapsible case and reuses the existing rope_f32 kernel. Bit-exact by construction, no new kernel.
    • MoE mul_mat_id fallback for the Loom-only path.
  3. defer routed-expert MUL_MAT_ID to the HIP add-on when built (CPU only for IQ2_S) — gated on GGML_HRX_HIP_ADDON: with the add-on built (the engine's normal build), route to CPU only IQ2_S; IQ4_NL/IQ3_S/Q5_1/Q8_0 (and the 640-wide ffn_down) run on HRX via the add-on's prefill+decode mmid. Without the add-on, unchanged Loom-only CPU-routing.

New logic in our own Apache-headed ggml/src/ggml-hrx/qwen4exp-hrx-support.h; AMD files get minimal hooks.

Correctness and KLD (strixhalo HRX0, 12 chunks wikitext-2; Loom-only build, experts on CPU)

  • HRX0 PPL 1.7997 +/- 0.0507 vs CPU 1.8202 +/- 0.0527 (~1.1%, overlapping error bars) — benign f16-WMMA rounding. HRX kernels confirmed numerically correct.
  • KLD of UD-IQ3_XXS against UD-IQ4_XS: mean 0.3118, median 0.0179, 99.9% 6.08, max 9.24; Same-top-p 87.42%; PPL ratio 1.093 (+9.3%). Measured vs IQ4_XS (not 16-bit; box can't hold ~350 GB BF16), 12 chunks; not comparable to Paiton's vs-16-bit W3A8.

GGUF expert layout (all 3 shards)

Merge gating (per RC coordination)

  • The initial KLD above was a Loom-only build (experts on CPU, ~28 s/tok decode) and understates HRX. The add-on build (hrx-system 82804197bcbe + gpu-kernels 4b8b9d0d6) is being verified now to confirm the defer-to-HIP guard runs UD-IQ4_XS experts fully on HRX.
  • This PR merges into 1bit/hrx-vulkan-patched only after that add-on build shows the defer-to-HIP behaviour green (expert placement from the dispatch log + prefill/decode tok/s). Until then it stays a draft.
  • Flash-Next reaches the engine through the RC's coordinated pin bump after candidate 3 ships (llama.cpp + hrx-system + gpu-kernels together, one engine PR, full re-gate) — not a manual bump.

🤖 Generated with Claude Code

bong-water-water-bong and others added 2 commits October 24, 2026 23:06
…d_norm)

HRX rms_norm requires a materialized (non-view) input. qwen4exp feeds
strided ggml_view slices into normalization: the gated-delta-net L2-norm
of q_conv/k_conv (build_gdn_l2_norm) and the per-head q/k norms via
build_norm. Insert ggml_cont for non-contiguous / view-op inputs. No-op
for the contiguous residual-stream tensors other arches (e.g. qwen35 27B)
pass, so their HRX path is unchanged.

Clears the "unsupported HRX node: RMS_NORM<-VIEW" abort on
Qwen3.8-Flash-Next. Remaining HRX blockers (IMRoPE mode 40, MoE
mul_mat_id input_size=640) are separate kernel work.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…IQ4_NL/IQ2_S/640-wide experts to CPU)

Make the full Qwen3.8-Flash-Next (arch qwen4exp) forward pass complete on the
HRX backend so llama-perplexity runs and a KLD can be measured.

Two blockers fixed, logic in a new owned header (qwen4exp-hrx-support.h), with
only minimal one-line hooks into the AMD matcher/backend files:

1) ROPE matcher rejected qwen4exp's GGML_ROPE_TYPE_IMROPE (mode 40) + 4-section
   positions. For text decode llama.cpp sets p_t==p_h==p_w==token pos, p_e==0; for
   this model's sections [11,11,10,0] (sect_dims 32 = n_dims/2) ggml_mrope_cache_init
   never selects p_e, so the interleaved rotation collapses to a plain NEOX rotation
   on the shared position -- which the existing rope_f32 kernel computes bit-exactly.
   The matcher now accepts a collapsible IMROPE, admits the 4*token_count positions
   layout, and hands the kernel NEOX mode. No kernel change (proven bit-exact).

2) MUL_MAT_ID routed-expert GEMM could not run on HRX: UD-IQ4_XS gate/up experts are
   IQ4_NL (shared f16 dequant mis-applies the XOR-12 nibble remap -> garbage),
   UD-IQ3_XXS experts are IQ2_S (no HRX MUL_MAT_ID path), and the Q8_0 down-proj has a
   640-wide contraction that violates the kernel's 256-multiple input_size constraint
   ("value 640 violates constraint 'mul'"). device_supports_op now keeps every such
   MUL_MAT_ID (bad weight type, or input_size % 256 != 0) on CPU, so the forward pass
   completes correctly instead of failing JIT link with no fallback.

Measured (strixhalo, performance mode, power_mode=performance, HRX0, 12 chunks, -c 512
-b 512 -ngl 99 -fa on, wikitext-2 test; MoE experts on CPU):
  * "Paris" generation on HRX0: coherent ("...directly state Paris as the answer").
  * Correctness vs CPU (UD-IQ4_XS): HRX0 PPL 1.7997 +/- 0.0507 vs CPU PPL 1.8202 +/-
    0.0527 (~1.1%, within error bars; benign f16-WMMA rounding, not a bug).
  * KLD UD-IQ3_XXS vs UD-IQ4_XS reference (both HRX0): mean 0.3118 +/- 0.0138,
    median 0.0179, 99% 3.950, 99.9% 6.076, max 9.243, Same-top-p 87.42%,
    PPL(Q)/PPL(base) 1.0927, PPL(Q)-PPL(base) 0.1665.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
… (CPU only for IQ2_S)

Refine ggml::hrx::mul_mat_id_weight_type_requires_cpu / mul_mat_id_requires_cpu in
qwen4exp-hrx-support.h so the device_supports_op guard defers to the gpu-kernels HIP
add-on (addons/hip-hrx) when it is compiled in (GGML_HRX_HIP_ADDON):

  * add-on built  -> route to CPU ONLY IQ2_S (no add-on mmid path); IQ4_NL / IQ3_S /
                     Q5_1 / Q8_0 (and the K-quant / MXFP4 / NVFP4 / Q2_0 formats) run
                     on HRX via the add-on's decode + prefill mmid, which carry the real
                     GGUF code books. The 640-wide (K%256!=0) restriction also lifts:
                     the add-on mmid handles input_size % 32.
  * add-on absent -> unchanged (the Loom WMMA mmid mis-applies the IQ4_NL XOR-12 remap
                     and rejects K%256!=0), so IQ4_NL + IQ2_S + K%256!=0 stay on CPU.

Rope IMROPE->NEOX and the rms_norm view-materialization fix are untouched.

NOT YET VERIFIED ON DEVICE: building this tree with the add-on is blocked by a stale
hrx-system pin (see report) -- the base d65a7e5 corpus needs the Loom 'multiple_of'
predicate (hrx-system >= Oct-18), but HRX_SOURCE_DIR resolves to the Sept-23 51b1739ae
whose loom-link/runtime lacks it. The guard change itself is a compile-time no-op unless
GGML_HRX_HIP_ADDON is defined.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@bong-water-water-bong

Copy link
Copy Markdown
Author

Verified on device — defer-to-HIP guard green ✅

Built this branch (incl. 7b38b9149) with the HIP add-on (GGML_HRX_HIP_ADDON_DIR → gpu-kernels 4b8b9d0d6, hrx-system 82804197, no deps regen) and measured on HRX0 (12-chunk perplexity -c512 -b512 -ngl99 -fa on wikitext-2; llama-bench pp512/tg128; GGML_HRX_LOG_DISPATCH for placement):

model PPL (12ch) prefill pp512 decode tg128 expert placement
UD-IQ4_XS (87 GiB) 1.8090 ± 0.052 286.8 t/s 23.97 t/s all experts on HRX via HIP
UD-IQ3_XXS (76 GiB) 1.9634 ± 0.060 85.4 t/s 12.82 t/s HRX via HIP except IQ2_S gate/up on CPU
  • Dispatch log confirms the add-on mmid (hip.mul_mat_id_swiglu_prefill, hip.moe_tokens.mmid/.swiglu, hip.moe_decode.mmid/.swiglu, hip.moe_weighted_sum) runs IQ3_S gate/up + IQ4_NL/Q8_0 down (K=640). A Loom mul_mat_id_swiglu.f32_f32_wmma fires only for IQ3_S at K%256 below the HIP prefill floor — not IQ4_NL, so no XOR-12 risk.
  • Correctness: PPLs match the non-add-on references within noise (IQ4_XS 1.8090 vs CPU 1.8202 / Loom-only-HRX 1.7997). The sane IQ3_XXS PPL proves IQ2_S ran correctly on CPU, not wrongly on HRX. No Compute/Loom-root errors, no NaN.
  • Speed: vs the earlier all-CPU-route (~28 s/tok ≈ 0.036 t/s) this is a ~670× / ~360× decode gain; prefill 92 → 286.8 t/s (≈3.1×). Still below the field's reported 33–60 decode / 500–2400 prefill on this 177B-A3B MoE on gfx1151 unified memory; the IQ2_S-on-CPU fallback is the remaining IQ3_XXS drag → the fn-iq2s-mmid GEAK follow-up.

The guard now correctly defers to the HIP add-on (CPU only for IQ2_S). This PR should pin as "Flash-Next experts on HRX via HIP." Merge timing into 1bit/hrx-vulkan-patched is coordinated with the RC (candidate 3 is gating off this branch tonight); Flash-Next reaches the engine via the RC's coordinated pin bump.

@bong-water-water-bong
bong-water-water-bong marked this pull request as ready for review October 25, 2026 04:43
@bong-water-water-bong
bong-water-water-bong merged commit a25b4b8 into 1bit/hrx-vulkan-patched Oct 25, 2026
bong-water-water-bong added a commit that referenced this pull request Oct 25, 2026
…ts the kernels (#144)

The #142 guard sends IQ2_S MUL_MAT_ID to HRX when the embedded hrx_prefill_gemm code object exports the IQ2_S kernels (names looked up in the code object), every batch incl. one token (GGML_HRX_HIP_IQ2S_MIN_TOKENS, default 1): a CPU decode reading experts the loader had moved into HRX memory collapsed to 0.64 tok/s. Flash-Next UD-IQ3_XXS on HRX0 with gpu-kernels #38: PPL 1.9514, pp512 297, tg128 25.2.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
bong-water-water-bong added a commit that referenced this pull request Oct 25, 2026
…e-token decode back on the fused GDN kernel) (#152)

#142 (a25b4b8) made build_norm wrap every view / reshape input in a CONT for all arches. On qwen35
(Qwen3.5 / 3.8, Ternary-Bonsai) the CONT before RMS_NORM(VIEW(gated-delta-net output)) broke the HRX
add-on's fused one-token GDN match (hip.q36.gdn_decode): decode fell back to the Loom
llm_gated_delta_net_f32_wmma_head128 path plus 112 copies, 1432 -> 1608 dispatches per token. The CONT
now applies to LLM_ARCH_QWEN4EXP only, the arch it was added for.

HRX dispatch profile, Ternary-Bonsai-2-27B PQ2_0, one-token decode, 31 steps, medians (fork 6ded110 +
gpu-kernels 2b626798a -> this): 1608 -> 1432 dispatches, step period 50.20 -> 48.05 ms (GDN 1.24 ms Loom ->
0.51 ms q36_gdn_decode_f32; state get_rows 2.18 -> 1.06 ms; copy_f32 0.51 ms -> gone).
llama-bench tg128 -r 3, three interleaved rounds (performance mode): PQ2_0 20.17 / 20.36 / 20.46 ->
20.94 / 21.31 / 21.31 tok/s; Qwen3.8-27B UD-Q4_K_XL 11.70 / 11.79 / 11.78 -> 12.13 / 11.89 / 12.11.
KLD vs the Bonsai F16 CPU logits (8 x 512): -ub 1 0.000000 (same top 100%, as before); -ub 8 0.000074.
No kernel changed (gpu-kernels 2b626798a in both builds).

Co-authored-by: bong-water-water-bong <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
@bong-water-water-bong
bong-water-water-bong deleted the 1bit/hrx-qwen4exp branch November 12, 2026 21:15
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