llama.cpp icon indicating copy to clipboard operation
llama.cpp copied to clipboard

Fix for quantize fail on init due to undefined static initialization of complex objects

Open arikpoz opened this issue 1 year ago • 7 comments

Addresses issue #920

Replaced static initialization of complex objects with a initialization on first use. This prevents an undefined behavior on program run, for example, crash in Release build, works in Debug build

arikpoz avatar Apr 12 '23 23:04 arikpoz

@arikpoz this MR still can not fix the issue.

image

jayliang701 avatar Apr 13 '23 13:04 jayliang701

Hmm, how is this UB - on which compiler / platform?

ggerganov avatar Apr 13 '23 13:04 ggerganov

I was able to reproduce it and fix it on Windows 10 with MSVC compiler, where the exception came from the static initialization of the maps. It could be the original reported issue was a different exception

arikpoz avatar Apr 13 '23 14:04 arikpoz

@jayliang701 , do you get the same behavior if you compile in Debug vs. Release? If it works in Debug and fails on Release, try to compile in Release with Debug symbols, and get a more accurate location of the exception

arikpoz avatar Apr 13 '23 14:04 arikpoz

@jayliang701 , do you get the same behavior if you compile in Debug vs. Release? If it works in Debug and fails on Release, try to compile in Release with Debug symbols, and get a more accurate location of the exception

still using Macbook Air M1 (2020), Memory 16G

yes. I have tried Debug (cmake --build . --config Debug, is it correct?) & Release using this MR, both have same issue like before. And main command also returns zsh: killed error (I download a ggml q4 model from HuggingFace)

jayliang701 avatar Apr 13 '23 15:04 jayliang701

@ggerganov , after fixed AVX flag mentioned in PR #809 , the original crash on static initialization I had with quantize disappeared. That said, I believe this is random behavior of the compiler and we should keep the changes suggested in this PR, since when you have static initialization of complex objects that uses other modules (std::) there is no guaranteed order for running the static initializers across the different modules, so the behavior is undefined. See https://en.cppreference.com/w/cpp/language/siof for reference

arikpoz avatar Apr 14 '23 21:04 arikpoz

Updated code as requested

arikpoz avatar Apr 15 '23 17:04 arikpoz

@ggerganov , let me know if something is missing to merge this

arikpoz avatar Apr 17 '23 14:04 arikpoz