Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ggml : fix UB in IQ2_S and IQ3_S #6012

Merged
merged 1 commit into from Mar 12, 2024
Merged

ggml : fix UB in IQ2_S and IQ3_S #6012

merged 1 commit into from Mar 12, 2024

Conversation

ggerganov
Copy link
Owner

@ggerganov ggerganov commented Mar 12, 2024

Running on master with thread-sanitizer enabled produces UB warnings:

./bin/test-quantize-fns
Testing iq3_s
/Users/ggerganov/development/github/llama.cpp/ggml-quants.c:9389:79: runtime error: left shift of 36408 by 16 places cannot be represented in type 'int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /Users/ggerganov/development/github/llama.cpp/ggml-quants.c:9389:79 in 
/Users/ggerganov/development/github/llama.cpp/ggml-quants.c:9398:79: runtime error: left shift of 34588 by 16 places cannot be represented in type 'int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /Users/ggerganov/development/github/llama.cpp/ggml-quants.c:9398:79 in 
Testing iq2_s
/Users/ggerganov/development/github/llama.cpp/ggml-quants.c:9028:79: runtime error: left shift of 36408 by 16 places cannot be represented in type 'int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /Users/ggerganov/development/github/llama.cpp/ggml-quants.c:9028:79 in 
/Users/ggerganov/development/github/llama.cpp/ggml-quants.c:9037:79: runtime error: left shift of 34588 by 16 places cannot be represented in type 'int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /Users/ggerganov/development/github/llama.cpp/ggml-quants.c:9037:79 in 

I doubt this causes any real issues, but fixing it to make the thread sanitizer happy

Copy link
Contributor

@ikawrakow ikawrakow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did the UB sanitizer check out the assembly just in case?

It is funny because some compilers cannot be forced to do the shift on 16-bit ints, no matter what you do. Notably, the Metal compiler is one of those.

@ggerganov ggerganov merged commit 184215e into master Mar 12, 2024
125 of 127 checks passed
@ggerganov ggerganov deleted the gg/fix-thread-sanitizer branch March 12, 2024 11:49
NeoZhangJianyu pushed a commit to NeoZhangJianyu/llama.cpp that referenced this pull request Mar 12, 2024
jordankanter pushed a commit to jordankanter/llama.cpp that referenced this pull request Mar 13, 2024
hodlen pushed a commit to hodlen/llama.cpp that referenced this pull request Apr 1, 2024
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.

None yet

2 participants