fix(mtmd): guard clip d_head/kq_scale against n_head==0 (Gemma 4 12B SIGFPE)#166
Closed
TheTom wants to merge 1 commit into
Closed
fix(mtmd): guard clip d_head/kq_scale against n_head==0 (Gemma 4 12B SIGFPE)#166TheTom wants to merge 1 commit into
TheTom wants to merge 1 commit into
Conversation
…SIGFPE) Gemma 4 12B's vision tower has no attention encoder, so hparams.n_head is 0. The clip_graph constructor computed d_head(n_embd / n_head) and kq_scale(1/sqrt(d_head)), causing a SIGFPE (integer divide-by-zero) at load of the mmproj. Guard both: d_head = n_head > 0 ? n_embd/n_head : 0, and kq_scale falls back to 0.0f when d_head is 0. Mirrors the upstream fix for ggml-org#24085. Fixes #163.
Owner
Author
|
Superseded by #168. Testing on the actual gemma-4-12B revealed the fork was missing the whole |
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
Fixes #163. Loading the Gemma 4 12B mmproj crashes with
SIGFPE, Arithmetic exceptionatclip.cpp:250.Root cause: Gemma 4 12B's vision tower has no attention encoder, so
hparams.n_head == 0. Theclip_graphconstructor's init list does:Fix
Guard both, identical to the upstream fix for ggml-org#24085 (closed):
When the tower has no encoder,
d_head/kq_scaleare unused, so 0 is safe.Testing
mtmdtarget builds clean (Metal, clip.cpp.o compiles).Thanks to @guarismo for the clear report and backtrace.