fix: prevent gallocr hash overflow in tiny graph-cut segments - #1880
Open
fszontagh wants to merge 1 commit into
Open
fix: prevent gallocr hash overflow in tiny graph-cut segments#1880fszontagh wants to merge 1 commit into
fszontagh wants to merge 1 commit into
Conversation
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.
Summary
build_segment_graph()sized each segment graph frominternal_node_indices + input_refs, butggml_gallocrhashes more tensors than that: a view-typed input leaf'sview_srcis a distinct tensor it must hash, even though it is marked external and never allocated.gallocr sizes its hash set to
(n_nodes + n_leafs) + (n_nodes + n_leafs)/4. The 25% margin normally absorbs the extra tensor, but on a one-node segment the integer division yields zero margin, so 4 distinct tensors overflow a 3-slot hash andggml_hash_findaborts.The segment graph now registers every tensor gallocr will hash - leaf
view_srcs, plus any nodesrc/view_srcnot already present - so the count covers them. External tensors are hashed but never allocated, so measurement is unchanged.Related Issue / Discussion
Fixes the crash reported in #1788.
#1788 also reports mosaic/blank output on the CPU path. That is a separate bug and is not addressed here, so the issue should stay open after this lands.
Additional Information
Reproduced on CUDA (RTX 3060) with an edit model that uses the Qwen2.5-VL vision encoder (Qwen-Image-Edit-2509, LongCat-Image-Edit) and
--offload-to-cpu --max-vram -1 --stream-layers. It aborts atggml/src/ggml-impl.h:318immediately afterresize conditioner ref image, and the process then hangs.Instrumented segment at the point of failure:
A patched vs unpatched A/B on regular (non-edit) Qwen streaming produced byte-identical output, so the change is numerically inert. With the patch the abort and hang are gone and the edit pipeline runs to completion.
Checklist