summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Potter <NanoTekGuy@Gmail.com>2023-11-14 09:34:41 -0800
committerGitHub <noreply@github.com>2023-11-14 12:34:41 -0500
commit6bb4908a17150b49373b5f977685b2e180a04f6f (patch)
treed56e5ce7934cc91cb01d2f4fb7777b761d46a01e
parent36eed0c42c5b0bf74af81fb9243d262014f9382f (diff)
Fix MacOS Sonoma model quantization (#4052)
Co-authored-by: Jared Van Bortel <jared@nomic.ai> Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
-rw-r--r--CMakeLists.txt9
-rw-r--r--Makefile5
-rw-r--r--ggml-quants.c5
3 files changed, 19 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7b4eb184..db1f42f1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -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
diff --git a/Makefile b/Makefile
index d6be254a..36d08811 100644
--- 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)'
diff --git a/ggml-quants.c b/ggml-quants.c
index a48eda73..cf2860b8 100644
--- a/ggml-quants.c
+++ b/ggml-quants.c
@@ -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];