Repository navigation
ggml-hrx: MUL_MAT_ID reads route ids at their row stride (engine #95) - #3
Closed
bong-water-water-bong wants to merge 2 commits into
Closed
bong-water-water-bong wants to merge 2 commits into
bong-water-water-bong wants to merge 2 commits into
Conversation
llama.cpp's route ids are a [n_expert_used, n_tokens] view of the [n_expert, n_tokens] argsort, so each token's ids are n_expert apart. The common MUL_MAT_ID dispatch built its expert and partition tables with route_stride = route_count, reading every token after the first from the wrong place: batched prompts on MoE models that do not go through the Qwen router dispatch (GLM-4.7-Flash, sigmoid router) picked the wrong experts. A standalone MUL_MAT_ID with GLM's ffn_down_exps had l2 error 1.36 against the CPU with strided ids and 8e-3 with packed ids. Take the stride from route_ids->nb[1], bounded like the Qwen router (route_count..expert_count), bind (n_tokens - 1) * stride + route_count ids, and carry the stride through the SwiGLU MoE match. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…witches
GGML_HRX_DISABLE_DISPATCH takes comma-separated substrings of dispatch
registration names to skip ("fused" skips every fused registration);
GGML_HRX_LOG_DISPATCH=1 prints each registration the first time it
matches. Bisecting with them found the MUL_MAT_ID route-stride bug (#95).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
bong-water-water-bong
pushed a commit
that referenced
this pull request
Nov 8, 2026
…se release() nulls slot.task (engine ggml-org#1489) A CLIP encode failure killed llama-server with SIGSEGV three milliseconds after it had already produced the error. Reproduced with a backtrace, and the frame names the site: Thread 1 received signal SIGSEGV #0 server_context_impl::pre_decode()::{lambda(server_slot&)#5}::operator()(server_slot&) #1 server_context_impl::iterate(std::vector<server_slot>&, std::function<void(server_slot&)>) #2 server_context_impl::pre_decode() #3 server_context_impl::update_slots() The failing path is the multimodal chunk loop in pre_decode(): process_mtmd_chunk() returns non-zero, the slot's error is sent, slot.release() runs - which does both "task_prev = std::move(task)" and "task.reset()", leaving slot.task null - and then "continue" re-enters that loop, whose first statement reads slot.task->n_tokens(). Null dereference, every time. Return instead: the slot has been released and must not be batched in this pass. Upstream master's equivalent handler does exactly that, with the comment "the slot is done, skip it entirely". No other site in this file releases a slot and then continues. Not verified by a rebuild in this lane: the tree here has no configured HRX build, and the only configured one on this box is a shared build tree whose rebuild is precisely the ggml-org#1403 incident (it swaps libraries under running services). The pre-fix crash is recorded with the full backtrace in engine ggml-org#1489; the post-fix acceptance is the issue's own - an HTTP error and a live process - which CI's build can run.
bong-water-water-bong
added a commit
that referenced
this pull request
Nov 8, 2026
…se release() nulls slot.task (engine ggml-org#1489) (#246) Same one-line fix as #245, cherry-picked onto 1bit/hrx-vulkan-patched -- the branch the engine actually pins. The bug site is identical on this branch (tools/server/server-context.cpp:3667-3670), so until this lands the pinned tree still dies on a failed CLIP encode. A CLIP encode failure kills llama-server with SIGSEGV three milliseconds after it has already produced the error. Reproduced with a backtrace, and the frame names the site: Thread 1 received signal SIGSEGV #0 server_context_impl::pre_decode()::{lambda(server_slot&)#5}::operator()(server_slot&) #1 server_context_impl::iterate(std::vector<server_slot>&, std::function<void(server_slot&)>) #2 server_context_impl::pre_decode() #3 server_context_impl::update_slots() The failing path is the multimodal chunk loop in pre_decode(): process_mtmd_chunk() returns non-zero, the slot's error is sent, slot.release() runs - which does both "task_prev = std::move(task)" and "task.reset()", leaving slot.task null - and then "continue" re-enters that loop, whose first statement reads slot.task->n_tokens(). Null dereference, every time. Return instead: the slot has been released, nothing is left to advance (the failed chunk was never added to the prompt or the cache), and it must not be batched in this pass. Upstream check, since the reviewer of #245 could not reach it from the fork tree: at upstream origin/master the equivalent handler does slot.release(); return; // the slot is done, skip it entirely (verified by fetching origin/master into a fork checkout and reading tools/server/server-context.cpp there; the honest caveat is that upstream has since refactored the chunk helper into free functions, so the surrounding code differs while the failure handling does not). No other site in this file releases a slot and then continues (checked on this branch). Not verified by a rebuild in this lane: this tree has no configured HRX build, and the box's only configured one is a shared build tree whose rebuild is precisely the ggml-org#1403 incident. The pre-fix crash is recorded with the full backtrace in engine ggml-org#1489; the post-fix acceptance is the issue's own - an HTTP error and a live process. Co-authored-by: bong-water-water-bong <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the GLM-4.7-Flash batched wrong answer in 1bit-MONSTER/engine#95.
Bug. llama.cpp's route ids are a
[n_expert_used, n_tokens]view of the[n_expert, n_tokens]argsort, so each token's ids aren_expertapart (nb[1] = n_expert * 4). The common MUL_MAT_ID dispatch built its expert and partition tables withroute_stride = route_count, so every token after the first was read from the wrong place.Qwen MoE models never hit this, because their router dispatch supplies the routing bundle with the real stride. MoE models without it, such as GLM-4.7-Flash (sigmoid router), picked wrong experts for batched prompts:
-ub 1/2/4answered correctly,-ub 16and the default 512 did not.Fix. Take the stride from
route_ids->nb[1], bounded like the Qwen router (route_count..expert_count). Bind(n_tokens - 1) * stride + route_countids, and carry the stride through the SwiGLU MoE match.Evidence (Strix Halo). A standalone MUL_MAT_ID with GLM's real
blk.1.ffn_down_exps(Q6_K, 64 experts, top-4, 16 tokens), measured as l2 error against the CPU:Qwen3-Coder-30B's experts and GLM's Q4_K gate experts give the same result.
test-backend-ops -b HRX0: 790/790.tests/serve_e2e.sh ... hrx: 7 of 7 answer "Paris" on c075cc1 plus this fix plus the narrowed router claim (engine ggml-hrx: run prompt batches above 512 tokens (engine #389) #101's third fix): Qwen3-0.6B, Qwen2.5-7B, Qwen3-Coder-30B-A3B, Qwen3.6-35B-A3B Q8_0, GLM-4.7-Flash, MiniCPM4-8B, MiniCPM5-1B.GLM also needs #101's router-claim change. Without it, GLM stops at
unsupported HRX node: SUM_ROWS.The second commit adds the
GGML_HRX_DISABLE_DISPATCH/GGML_HRX_LOG_DISPATCHdebug switches, which found this bug.🤖 Generated with Claude Code