Skip to content

Commit 2c48b64

Browse files
TortoiseHamcebtenzzreggerganov
authored andcommitted
Fix MacOS Sonoma model quantization (ggml-org#4052)
Co-authored-by: Jared Van Bortel <[email protected]> Co-authored-by: Georgi Gerganov <[email protected]>
1 parent 21e22e0 commit 2c48b64

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,15 @@ if (LLAMA_LTO)
458458
endif()
459459
endif()
460460

461+
# this version of Apple ld64 is buggy
462+
execute_process(
463+
COMMAND ${CMAKE_C_COMPILER} ${CMAKE_EXE_LINKER_FLAGS} -Wl,-v
464+
ERROR_VARIABLE output
465+
)
466+
if (output MATCHES "dyld-1015\.7")
467+
add_compile_definitions(HAVE_BUGGY_APPLE_LINKER)
468+
endif()
469+
461470
# Architecture specific
462471
# TODO: probably these flags need to be tweaked on some architectures
463472
# feel free to update the Makefile for your architecture and send a pull request or issue

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,11 @@ else
239239
endif
240240
endif
241241

242+
# this version of Apple ld64 is buggy
243+
ifneq '' '$(findstring dyld-1015.7,$(shell $(CC) $(LDFLAGS) -Wl,-v 2>&1))'
244+
MK_CPPFLAGS += -DHAVE_BUGGY_APPLE_LINKER
245+
endif
246+
242247
# OS specific
243248
# TODO: support Windows
244249
ifneq '' '$(filter $(UNAME_S),Linux Darwin FreeBSD NetBSD OpenBSD Haiku)'

ggml-quants.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,7 +1368,12 @@ static float make_qkx2_quants(int n, int nmax, const float * restrict x, const f
13681368
float max = x[0];
13691369
float sum_w = weights[0];
13701370
float sum_x = sum_w * x[0];
1371+
#ifdef HAVE_BUGGY_APPLE_LINKER
1372+
// use 'volatile' to prevent unroll and work around a bug in Apple ld64 1015.7
1373+
for (volatile int i = 1; i < n; ++i) {
1374+
#else
13711375
for (int i = 1; i < n; ++i) {
1376+
#endif
13721377
if (x[i] < min) min = x[i];
13731378
if (x[i] > max) max = x[i];
13741379
float w = weights[i];

0 commit comments

Comments
 (0)