]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
Fix MacOS Sonoma model quantization (#4052)
authorMichael Potter <redacted>
Tue, 14 Nov 2023 17:34:41 +0000 (09:34 -0800)
committerGitHub <redacted>
Tue, 14 Nov 2023 17:34:41 +0000 (12:34 -0500)
Co-authored-by: Jared Van Bortel <redacted>
Co-authored-by: Georgi Gerganov <redacted>
CMakeLists.txt
Makefile
ggml-quants.c

index 7b4eb18403c0bfa1e64718cb7361429d73491270..db1f42f1eda6a71660e146020a2c704404b37520 100644 (file)
@@ -458,6 +458,15 @@ if (LLAMA_LTO)
     endif()
 endif()
 
+# this version of Apple ld64 is buggy
+execute_process(
+    COMMAND ${CMAKE_C_COMPILER} ${CMAKE_EXE_LINKER_FLAGS} -Wl,-v
+    ERROR_VARIABLE output
+)
+if (output MATCHES "dyld-1015\.7")
+    add_compile_definitions(HAVE_BUGGY_APPLE_LINKER)
+endif()
+
 # Architecture specific
 # TODO: probably these flags need to be tweaked on some architectures
 #       feel free to update the Makefile for your architecture and send a pull request or issue
index d6be254a0f3626c74d337ae0b353555e6528d339..36d08811e32b6dca54372c8c759959e8296b66bd 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -239,6 +239,11 @@ else
        endif
 endif
 
+# this version of Apple ld64 is buggy
+ifneq '' '$(findstring dyld-1015.7,$(shell $(CC) $(LDFLAGS) -Wl,-v 2>&1))'
+       MK_CPPFLAGS += -DHAVE_BUGGY_APPLE_LINKER
+endif
+
 # OS specific
 # TODO: support Windows
 ifneq '' '$(filter $(UNAME_S),Linux Darwin FreeBSD NetBSD OpenBSD Haiku)'
index a48eda7320c46d2b39f0d9ed76e14aeee3a2461d..cf2860b8cbd5924c3da459a5feb78541dd120323 100644 (file)
@@ -1368,7 +1368,12 @@ static float make_qkx2_quants(int n, int nmax, const float * restrict x, const f
     float max = x[0];
     float sum_w = weights[0];
     float sum_x = sum_w * x[0];
+#ifdef HAVE_BUGGY_APPLE_LINKER
+    // use 'volatile' to prevent unroll and work around a bug in Apple ld64 1015.7
+    for (volatile int i = 1; i < n; ++i) {
+#else
     for (int i = 1; i < n; ++i) {
+#endif
         if (x[i] < min) min = x[i];
         if (x[i] > max) max = x[i];
         float w = weights[i];