mirror of
https://github.com/ollama/ollama.git
synced 2026-10-20 18:41:17 +00:00
mlx update (#17850)
Temporarily carry https://github.com/ml-explore/mlx-c/pull/127
This commit is contained in:
parent
a5165c53ac
commit
0bb0925920
8 changed files with 108 additions and 4 deletions
|
|
@ -1 +1 @@
|
|||
adf21deabd32c4fe3726ab2d373ff2165c3f27d6
|
||||
7f062ddcb81bedb537f3f95d11a7343ba6b5f909
|
||||
|
|
@ -169,6 +169,14 @@ if(OLLAMA_MLX_BACKENDS)
|
|||
list(APPEND _mlx_source_targets ollama-mlx-source)
|
||||
endif()
|
||||
|
||||
# Temporary MLX-C carry patch: regenerated bindings for force_fused and the
|
||||
# thread-local compile cache, carried until they merge upstream into
|
||||
# ml-explore/mlx-c. Then bump MLX_C_VERSION and delete mlx/compat/.
|
||||
find_package(Git REQUIRED)
|
||||
set(OLLAMA_MLX_C_COMPAT_PATCH_COMMAND
|
||||
${GIT_EXECUTABLE} apply ${CMAKE_SOURCE_DIR}/mlx/compat/0001-mlx-c-regen-0.32.1.patch
|
||||
CACHE INTERNAL "MLX-C carry patch")
|
||||
|
||||
if(DEFINED "FETCHCONTENT_SOURCE_DIR_MLX-C" AND NOT "${FETCHCONTENT_SOURCE_DIR_MLX-C}" STREQUAL "")
|
||||
get_filename_component(OLLAMA_MLX_C_SOURCE_DIR
|
||||
"${FETCHCONTENT_SOURCE_DIR_MLX-C}" ABSOLUTE BASE_DIR "${CMAKE_SOURCE_DIR}")
|
||||
|
|
@ -188,7 +196,9 @@ if(OLLAMA_MLX_BACKENDS)
|
|||
CONFIGURE_COMMAND ""
|
||||
BUILD_COMMAND ""
|
||||
INSTALL_COMMAND ""
|
||||
USES_TERMINAL_DOWNLOAD TRUE)
|
||||
PATCH_COMMAND ${OLLAMA_MLX_C_COMPAT_PATCH_COMMAND}
|
||||
USES_TERMINAL_DOWNLOAD TRUE
|
||||
USES_TERMINAL_PATCH TRUE)
|
||||
list(APPEND _mlx_source_targets ollama-mlx-c-source)
|
||||
endif()
|
||||
# Refresh the vendored MLX-C headers once the sources are present. Every MLX
|
||||
|
|
|
|||
88
mlx/compat/0001-mlx-c-regen-0.32.1.patch
Normal file
88
mlx/compat/0001-mlx-c-regen-0.32.1.patch
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
diff --git a/mlx/c/compile.cpp b/mlx/c/compile.cpp
|
||||
index bc7b864..260ee86 100644
|
||||
--- a/mlx/c/compile.cpp
|
||||
+++ b/mlx/c/compile.cpp
|
||||
@@ -42,22 +42,25 @@ extern "C" int mlx_detail_compile(
|
||||
}
|
||||
extern "C" int mlx_detail_compile_clear_cache(void) {
|
||||
try {
|
||||
- mlx::core::detail::compile_clear_cache();
|
||||
+ mlx::core::detail::compile_clear_cache(mlx::core::detail::compile_cache());
|
||||
} catch (std::exception& e) {
|
||||
mlx_error(e.what());
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
+
|
||||
extern "C" int mlx_detail_compile_erase(uintptr_t fun_id) {
|
||||
try {
|
||||
- mlx::core::detail::compile_erase(fun_id);
|
||||
+ mlx::core::detail::compile_erase(
|
||||
+ mlx::core::detail::compile_cache(), fun_id);
|
||||
} catch (std::exception& e) {
|
||||
mlx_error(e.what());
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
+
|
||||
extern "C" int mlx_disable_compile(void) {
|
||||
try {
|
||||
mlx::core::disable_compile();
|
||||
diff --git a/mlx/c/compile.h b/mlx/c/compile.h
|
||||
index 2892a1f..ff3abc4 100644
|
||||
--- a/mlx/c/compile.h
|
||||
+++ b/mlx/c/compile.h
|
||||
@@ -44,7 +44,9 @@ int mlx_detail_compile(
|
||||
const uint64_t* constants,
|
||||
size_t constants_num);
|
||||
int mlx_detail_compile_clear_cache(void);
|
||||
+
|
||||
int mlx_detail_compile_erase(uintptr_t fun_id);
|
||||
+
|
||||
int mlx_disable_compile(void);
|
||||
int mlx_enable_compile(void);
|
||||
int mlx_set_compile_mode(mlx_compile_mode mode);
|
||||
diff --git a/mlx/c/fast.cpp b/mlx/c/fast.cpp
|
||||
index ac17d54..eb35d16 100644
|
||||
--- a/mlx/c/fast.cpp
|
||||
+++ b/mlx/c/fast.cpp
|
||||
@@ -3,8 +3,8 @@
|
||||
/* This file is auto-generated. Do not edit manually. */
|
||||
/* */
|
||||
|
||||
-#include "mlx/c/fast.h"
|
||||
#include "mlx/c/error.h"
|
||||
+#include "mlx/c/fast.h"
|
||||
#include "mlx/c/private/mlx.h"
|
||||
#include "mlx/fast.h"
|
||||
|
||||
@@ -610,6 +610,7 @@ extern "C" int mlx_fast_scaled_dot_product_attention(
|
||||
const char* mask_mode,
|
||||
const mlx_array mask_arr /* may be null */,
|
||||
const mlx_array sinks /* may be null */,
|
||||
+ bool force_fused,
|
||||
const mlx_stream s) {
|
||||
try {
|
||||
mlx_array_set_(
|
||||
@@ -624,6 +625,7 @@ extern "C" int mlx_fast_scaled_dot_product_attention(
|
||||
: std::nullopt),
|
||||
(sinks.ctx ? std::make_optional(mlx_array_get_(sinks))
|
||||
: std::nullopt),
|
||||
+ force_fused,
|
||||
mlx_stream_get_(s)));
|
||||
} catch (std::exception& e) {
|
||||
mlx_error(e.what());
|
||||
diff --git a/mlx/c/fast.h b/mlx/c/fast.h
|
||||
index c825d00..e6c5bdf 100644
|
||||
--- a/mlx/c/fast.h
|
||||
+++ b/mlx/c/fast.h
|
||||
@@ -195,6 +195,7 @@ int mlx_fast_scaled_dot_product_attention(
|
||||
const char* mask_mode,
|
||||
const mlx_array mask_arr /* may be null */,
|
||||
const mlx_array sinks /* may be null */,
|
||||
+ bool force_fused,
|
||||
const mlx_stream s);
|
||||
|
||||
/**@}*/
|
||||
|
|
@ -21,7 +21,7 @@ func FastScaledDotProductAttention(q, k, v *Array, scale float32, mode string, m
|
|||
}
|
||||
|
||||
out := New("FAST_SDPA")
|
||||
C.mlx_fast_scaled_dot_product_attention(&out.ctx, q.ctx, k.ctx, v.ctx, C.float(scale), cMode, maskCtx, sinks.ctx, DefaultStream().ctx)
|
||||
C.mlx_fast_scaled_dot_product_attention(&out.ctx, q.ctx, k.ctx, v.ctx, C.float(scale), cMode, maskCtx, sinks.ctx, C.bool(false), DefaultStream().ctx)
|
||||
return out
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -518,6 +518,7 @@ int (*mlx_fast_scaled_dot_product_attention_)(
|
|||
const char* mask_mode,
|
||||
const mlx_array mask_arr /* may be null */,
|
||||
const mlx_array sinks /* may be null */,
|
||||
bool force_fused,
|
||||
const mlx_stream s) = NULL;
|
||||
int (*mlx_fft_fft_)(
|
||||
mlx_array* res,
|
||||
|
|
|
|||
|
|
@ -1761,6 +1761,7 @@ extern int (*mlx_fast_scaled_dot_product_attention_)(
|
|||
const char* mask_mode,
|
||||
const mlx_array mask_arr /* may be null */,
|
||||
const mlx_array sinks /* may be null */,
|
||||
bool force_fused,
|
||||
const mlx_stream s);
|
||||
extern int (*mlx_fft_fft_)(
|
||||
mlx_array* res,
|
||||
|
|
@ -4518,8 +4519,9 @@ static inline int mlx_fast_scaled_dot_product_attention(
|
|||
const char* mask_mode,
|
||||
const mlx_array mask_arr /* may be null */,
|
||||
const mlx_array sinks /* may be null */,
|
||||
bool force_fused,
|
||||
const mlx_stream s) {
|
||||
return mlx_fast_scaled_dot_product_attention_(res, queries, keys, values, scale, mask_mode, mask_arr, sinks, s);
|
||||
return mlx_fast_scaled_dot_product_attention_(res, queries, keys, values, scale, mask_mode, mask_arr, sinks, force_fused, s);
|
||||
}
|
||||
static inline int mlx_fft_fft(
|
||||
mlx_array* res,
|
||||
|
|
|
|||
|
|
@ -44,7 +44,9 @@ int mlx_detail_compile(
|
|||
const uint64_t* constants,
|
||||
size_t constants_num);
|
||||
int mlx_detail_compile_clear_cache(void);
|
||||
|
||||
int mlx_detail_compile_erase(uintptr_t fun_id);
|
||||
|
||||
int mlx_disable_compile(void);
|
||||
int mlx_enable_compile(void);
|
||||
int mlx_set_compile_mode(mlx_compile_mode mode);
|
||||
|
|
|
|||
|
|
@ -195,6 +195,7 @@ int mlx_fast_scaled_dot_product_attention(
|
|||
const char* mask_mode,
|
||||
const mlx_array mask_arr /* may be null */,
|
||||
const mlx_array sinks /* may be null */,
|
||||
bool force_fused,
|
||||
const mlx_stream s);
|
||||
|
||||
/**@}*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue