llama.cpp
llama.cpp copied to clipboard
Fix for quantize fail on init due to undefined static initialization of complex objects
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 this MR still can not fix the issue.
Hmm, how is this UB - on which compiler / platform?
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
@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
@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)
@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
Updated code as requested
@ggerganov , let me know if something is missing to merge this