Skip to content

HRX Loom dequant: IQ4_NL nibble remap uses XOR-12 instead of kvalues_iq4nl (garbage mul_mat_id on Loom-only path) #559

Closed

Description

@bong-water-water-bong

Summary

The Loom-corpus shared f16 dequant for IQ4_NL mis-applies the XOR-12 nibble remap, producing garbage for IQ4_NL mul_mat_id (routed MoE experts) on the HRX Loom path. This is why Qwen3.8-Flash-Next (qwen4exp) routed experts had to be forced to CPU on a Loom-only build (see the CPU-route fallback in the qwen4exp-on-HRX work).

Where

  • Loom corpus motif: ggml/src/ggml-hrx/.../motifs/dequant.loom (the shared f16 dequant used by the Loom WMMA mul_mat_id).
  • Observed on IQ4_NL ffn_down_exps (ne0=640) of the Flash-Next UD-IQ4_XS / UD-IQ3_XXS GGUFs.

Detail

The nibble-to-value remap for IQ4_NL should use the real ggml kvalues_iq4nl codebook. The Loom dequant applies an XOR-12 on the nibble index instead, which does not reproduce the codebook ordering, so decoded weights are wrong. The gpu-kernels HIP add-on path (addons/hip-hrx, hrx_prefill_mmid_iq4_nl / moe_decode_mmid_iq4_nl) does this correctly (uses kvalues_iq4nl), so IQ4_NL experts are correct when llama.cpp is built with GGML_HRX_HIP_ADDON_DIR; the bug is specific to the Loom-only path.

Impact / workaround

  • With the HIP add-on built (the engine's normal build), IQ4_NL experts run correctly on HRX via HIP — no action needed for shipping.
  • On a Loom-only build, IQ4_NL mul_mat_id must be routed to CPU to avoid garbage (current qwen4exp fallback).

Fix

Correct the IQ4_NL nibble remap in the Loom dequant motif to match kvalues_iq4nl, then verify the Loom mul_mat_id matches the CPU double-precision reference (NMSE < 1e-10) on the Flash-Next IQ4_NL ffn_down (ne0=640).

Filed for the record per the HRX kernel-routing review; the HIP add-on carries IQ4_NL meanwhile.

Activity

  1. bong-water-water-bong commented on Oct 25, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Verified on the Loom-only path today (no HIP add-on in the build), because the premise does not reproduce — the dequant is already correct and a PR follows with the docs update rather than a code change.

    test-backend-ops -b HRX0        # engine's pinned fork source, -DGGML_HRX=ON, no GGML_HRX_HIP_ADDON_DIR
      MUL_MAT  iq4_nl  n=1..9 k=256 : OK        MUL_MAT  iq4_xs  same : OK
      GET_ROWS iq4_nl  be1=1        : OK        MUL_MAT_ID iq4_nl/iq4_xs : not supported (declined to CPU)
      0 FAIL, 2/2 backends passed
    

    motifs/dequant.loom builds the real kvalues_iq4nl table (-127 … 113) and reads it with vector.table.lookup; there is no XOR-12 on the IQ4_NL path in the corpus at all. Fork #41 is what fixed the two copies, and the engine's pinned source carries it.

    So what the Loom path does run is numerically correct, and what it does not run (MUL_MAT_ID for those types on a Loom-only build) is declined to the CPU rather than decoded wrongly. The shipped engine build carries the HIP add-on, whose routed-expert kernels handle IQ4_NL on HRX. The remaining not supported cases are shape coverage — k=32, GET_ROWS on a view, and the batched gather be1=7 that #390 already covers (where q8_0 fails identically, so the quant is not the variable).

  2. bong-water-water-bong commented on Oct 25, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Closed as already fixed, now verified and documented. The XOR-12 remap the report describes was removed by fork #41 (motifs/dequant.loom reads the real kvalues_iq4nl table through vector.table.lookup; no XOR-12 remains on the IQ4_NL path anywhere in the corpus), and the engine's pinned source carries it.

    Verifying run (2026-10-25, strixhalo, HRX0) on a Loom-only build — -DGGML_HRX=ON with no HIP add-on, so every case goes through the Loom corpus:

    test-backend-ops -b HRX0
      MUL_MAT  iq4_nl  n=1..9 k=256 : OK      MUL_MAT  iq4_xs  the same : OK
      GET_ROWS iq4_nl  be1=1        : OK      MUL_MAT_ID iq4_nl/iq4_xs  : not supported (declined to CPU)
      0 FAIL, 2/2 backends passed
    

    What runs is numerically correct; what does not run is declined, not garbage — MUL_MAT_ID for those types on a Loom-only build takes the CPU, and the shipped engine build carries the HIP add-on whose routed-expert kernels handle IQ4_NL on HRX. The remaining not supported cases are shape coverage (k=32, GET_ROWS view v=1, batched gather be1=7 — the #390 gap, where q8_0 fails identically).

    Docs updated in #567 (merged, 99040cea): the docs/hrx.md bullet moved from "Not yet" to done with these numbers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions