Skip to content

hrx: the Q8_1 alternate-value fallback kept the alias source's row shape - an ordered reshape takes the requested value's rows (engine#3380) - #508

Merged
bong-water-water-bong merged 1 commit into
1bit/hrx-vulkan-patchedfrom
fix/3380-alternate-value-ordered-reshape
Nov 24, 2026
Merged

bong-water-water-bong merged 1 commit into
1bit/hrx-vulkan-patchedfrom
fix/3380-alternate-value-ordered-reshape

Conversation

@bong-water-water-bong

Copy link
Copy Markdown

engine#3380 / engine#3383: the split-FA head96/value64 device rows regressed at 6164e5b. Fork #503 (c6c654c) is the cause: its Q8_1 layout comparison reads the alias source's row shape, and a split-FA alias source is shaped by its head size, not by the packed row width.

The defect

PR #503 replaced the alternate-value fallback's full-range comparison with layout comparison. For Q8_1 it calls
same_q8_1_x4_geometry(lhs, rhs), which requires both values' ne[0] to be 128-aligned
(ggml/src/ggml-hrx/dispatch/command-plan.h:91 at 6164e5b).

The rows build one token of split flash attention, then read the published Q8_1 x4 alternate through the consumer's
view of the output:

  • the split-FA dispatch publishes the alternate for match.output, whose shape is
    [value_head_size, heads, tokens] = [64, 32, 1]
    (ggml/src/ggml-hrx/dispatch_registration/common/dispatch-flash-attention.cpp:703);
  • the o_proj consumer reads ggml_reshape_2d(output, 32 * 64, tokens) = [2048, 1]
    (tests/hrx-ops-test.cpp:5398).

The reshape is a pure ordered range over the same bytes (contiguous, same storage/offset/byte_count/type/element
count). The alias source's ne[0] is 64, so same_q8_1_x4_geometry() is false even though the requested value's rows are
2048 elements (128-aligned), and find_alternate_value() returns nullptr. At the default head size 128 the source's
ne[0] is 128, so the identical lookup passes: that is why only ...masked.head96.value64 broke.

At the pin this shows up as both device failures reported by lane-dv2:

[FAIL] qwen_decode_split_flash_attention.query1.kv512.masked.head96.value64
       tests/hrx-ops-test.cpp:5440: requirement failed: q8_alternate != nullptr
[FAIL] qwen_decode_split_flash_attention.query4.kv513.masked.head96.value64
       tests/hrx-ops-test.cpp:5420: requirement failed: plan.dispatches.size() == query_token_count + 1

(the 4-query row loses its q8 next-projection dispatch, so it fails the plan-size assert first).

The fix

A Q8_1 x4 copy carries the requested value's rows - that is the row width the reader and the publisher both use, and
the alternate's byte_count is the same ordered range either way. q8_1_x4_rows_compatible() keeps the ordered-range
requirement (storage, offset, byte_count, type, element count, contiguity all equal, so a transposed view and a
write's storage are still refused exactly as #503 requires) and checks the 128-element row alignment on the requested
value instead of the alias source.

The two rows move to the host tier. Like the attention-output rows #506 moved, they build a graph and read the plan
back and never open a device; as device cases no host run could see this, and the pre-fix tree fails them on a host.

Cause proof: a plain #503 revert is not the fix

Rebuilt the fork at 6164e5b in a throwaway tree with ggml/src/ggml-hrx/dispatch/command-plan.h moved back to its
pre-#503 content (c6c654c^), same configure (add-on, -j 6):

tree the two rows (host tier) #503's host row support.alternate_value_alias_lookup
6164e5b with command-plan.h = c6c654c^ 2 passed FAIL through_reordered_alias == nullptr
this branch 2 passed PASS

So the regression is #503's comparator, but reverting #503 re-opens engine#3383. This change keeps both green.

Control: pre-fix vs this branch, host tier (device-free, CI-reachable)

Both trees are the same source and the same host-tier registration of the two rows.

# pre-fix = branch tip's tests, command-plan.h at 6164e5ba
[FAIL] 1/2 qwen_decode_split_flash_attention.query4.kv513.masked.head96.value64
       tests/hrx-ops-test.cpp:5420: requirement failed: plan.dispatches.size() == query_token_count + 1
[FAIL] 2/2 qwen_decode_split_flash_attention.query1.kv512.masked.head96.value64
       tests/hrx-ops-test.cpp:5440: requirement failed: q8_alternate != nullptr
HRX test summary: 0 passed, 2 failed, 0 known-fail, 0 unexpected-pass, 2 total

# this branch
[PASS] 1/2 qwen_decode_split_flash_attention.query4.kv513.masked.head96.value64
[PASS] 2/2 qwen_decode_split_flash_attention.query1.kv512.masked.head96.value64
HRX test summary: 2 passed, 0 failed, 0 known-fail, 0 unexpected-pass, 2 total

full host tier this branch: HRX test summary: 17 passed, 0 failed, 0 known-fail, 0 unexpected-pass, 17 total
test-hrx-ops this branch:   test-hrx-ops summary: 2 passed, 0 failed, 0 known-fail, 0 unexpected-pass, 2 total

Device evidence (gfx1151, one box-hold both ticket, as root)

Built with the recipe the pinned device builds use (add-on, ggml-hrx, gfx1151, CMAKE_PREFIX_PATH=hrx-install); ran with
the pin's runtime libs from the staged package (pkg/hrx/llama/bin), box env HRX_ALLOW_NO_SVM=1 etc. The 23-Nov build
needed libomp from that same package dir in LD_LIBRARY_PATH.

build query1.kv512.masked.head96.value64 query4.kv513.masked.head96.value64
23-Nov staged add-on (tests-p6a, pre-6164 pin) PASS PASS
pin 6164e5b staged add-on (tests-6164a) FAIL (cpp:5440 q8_alternate) FAIL (cpp:5420 dispatches)
this tree at the pin, unmodified source (control) FAIL (cpp:5440 q8_alternate) FAIL (cpp:5420 dispatches)
this branch PASS PASS

Full add-on device suite on this branch: 409 passed, 1 failed, 1 known-fail, 411 total (the pin is 407 / 3 / 1).
The one remaining failure is mixed_weight_layout_program.q6_k, which is engine#3389's row and unrelated to this
change: it asks for a packed Q6_K decode on a weight imported from a host pointer (a device buffer with no repackable
source), and the real device plan binds it stored. No GPU reset during the ticket (dmesg).

Logs on strixhalo: /data/dev/cl-hrxtest/runs/fa.status, fa-old23-p6a.log, fa-new6164-6164a.log, fa-own-clean.log,
fa-own-fix.log, fa-own-fix-full.log; local host-tier logs are in the lane's scratch.

Refs 1bit-MONSTER/engine#3380
Refs 1bit-MONSTER/engine#3383

…ape - an ordered reshape takes the requested value's rows (engine#3380)

**engine#3380**: the split-FA device rows regressed at 6164e5b; fork #503 (c6c654c) is the cause.

**The defect.** #503 made the alternate-value fallback compare layouts, not just full value ranges. The Q8_1 branch
took same_q8_1_x4_geometry(lhs, rhs), which requires *both* values' ne[0] to be 128-aligned
(ggml/src/ggml-hrx/dispatch/command-plan.h:91). The alias source's ne[0] is its own shape, not the row width the x4
copy was written with. A split-FA output is [value_head_size, heads, tokens] and the o_proj consumer reads
ggml_reshape_2d(output, hidden_size, tokens); with value_head_size 64 the source's ne[0] is 64, so
find_alternate_value() refused the alternate published for the FA output and returned nullptr. The row's
q8_alternate != nullptr failed, and for the 4-query row the plan also lost its q8 next-projection dispatch (fewer than
query_token_count + 1 dispatches). At head size 128 the source's ne[0] is 128 and the same lookup passed, which is why
only the head96/value64 rows broke.

**The fix.** The Q8_1 x4 rows are the *requested* value's rows: that is the row width the reader and the publisher use,
and the alternate's byte_count is the same ordered range either way. q8_1_x4_rows_compatible() keeps the ordered-range
requirement - storage, offset, byte_count, type, element count and contiguity all equal, so a transposed view or a
write's storage is still refused exactly as #503 requires - and checks the 128-element row alignment on the requested
value.

The two rows move to the host tier. Like the attention-output rows #506 moved, they build a graph and read the plan
back and never open a device; as device cases nothing could see this regression on a host, and the pre-fix tree fails
them on a host (both asserts reproduce, see the Evidence section).

Refs 1bit-MONSTER/engine#3380
Refs 1bit-MONSTER/engine#3383
@bong-water-water-bong
bong-water-water-bong force-pushed the fix/3380-alternate-value-ordered-reshape branch from 9c2c2de to f39a6c1 Compare November 24, 2026 12:05
@bong-water-water-bong
bong-water-water-bong merged commit 6a4c13f into 1bit/hrx-vulkan-patched Nov 24, 2026
@bong-water-water-bong
bong-water-water-bong deleted the fix/3380-alternate-value-ordered-reshape branch November 24, 2026 12:05
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