fix(i2_s): resolve to_float UB + guard BLAS I2_S routing#533
Open
JasonOA888 wants to merge 1 commit intomicrosoft:mainfrom
Open
fix(i2_s): resolve to_float UB + guard BLAS I2_S routing#533JasonOA888 wants to merge 1 commit intomicrosoft:mainfrom
JasonOA888 wants to merge 1 commit intomicrosoft:mainfrom
Conversation
819bb55 to
226b2ab
Compare
226b2ab to
a6fdd51
Compare
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 #468, Fixes #512
Bug 1: to_float callback UB (missing scale param)
The type_traits entry for
GGML_TYPE_I2_Sregistersdequantize_row_i2_sas aggml_to_float_tcallback, but the signatures dont match: the function takes 4 params(x, y, n, i2_scale)but the typedef only has 3. The cast silences the compiler but causes UB — the 4th argument register contains garbage, producing wrong dequantized weights on ARM and potentially x86.Fix: Added
dequantize_row_i2_s_wrapper()that matches theggml_to_float_tsignature and calls the real dequantizer.Bug 2: BLAS routes I2_S through generic MUL_MAT (segfault on Apple Silicon)
When
ubatch >= 32, the BLAS backend claims the generic MUL_MAT path for I2_S becauseto_floatis non-NULL. But I2_S stores an external scale outside the per-row payload, which the generic BLAS dequantize path does not handle. This causes segfaults on Apple Silicon Metal+BLAS.Fix: Explicitly reject
GGML_TYPE_I2_Sfrom the BLAS MUL_MAT support check so I2_S uses its specialized kernel path.Changes
llama.cpp submodule updated with fixes (commit
aa603a3):ggml-quants.c: Addeddequantize_row_i2_s_wrapper()with correct 3-param signatureggml-quants.h: Declared the wrapper functionggml.c: Use wrapper instead of cast in type_traitsggml-blas.cpp: RejectGGML_TYPE_I2_Sfrom both MUL_MAT and OUT_PROD support checksSubmodule URL changed to
JasonOA888/llama.cppso the fix commit is publicly reachable (previous PR pointed to a local-only commit).Testing