Skip to content

Commit

Permalink
fix(cpp): skip register metal backend on os simulator
Browse files Browse the repository at this point in the history
  • Loading branch information
jhen0409 committed Nov 2, 2024
1 parent 05b13a4 commit 192c9ae
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 37 deletions.
2 changes: 1 addition & 1 deletion cpp/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,7 @@ struct llama_model_params common_model_params_to_llama(const common_params & par
if (params.n_gpu_layers != -1) {
mparams.n_gpu_layers = params.n_gpu_layers;
}

mparams.vocab_only = params.vocab_only;
mparams.rpc_servers = params.rpc_servers.c_str();
mparams.main_gpu = params.main_gpu;
Expand Down
3 changes: 3 additions & 0 deletions cpp/ggml-backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,11 @@ struct lm_ggml_backend_registry {
register_backend(lm_ggml_backend_cuda_reg());
#endif
#ifdef LM_GGML_USE_METAL
#include <TargetConditionals.h>
#if !TARGET_OS_SIMULATOR
register_backend(lm_ggml_backend_metal_reg());
#endif
#endif
#ifdef LM_GGML_USE_SYCL
register_backend(lm_ggml_backend_sycl_reg());
#endif
Expand Down
10 changes: 1 addition & 9 deletions cpp/llama.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19097,9 +19097,7 @@ struct llama_model_params llama_model_default_params() {

#ifdef LM_GGML_USE_METAL
// note: we usually have plenty of VRAM, so by default offload all layers to the GPU
if (result.n_gpu_layers > 0) {
result.n_gpu_layers = 999;
}
result.n_gpu_layers = 999;
#endif

return result;
Expand Down Expand Up @@ -19302,13 +19300,7 @@ struct llama_model * llama_load_model_from_file(
break;

case LM_GGML_BACKEND_DEVICE_TYPE_GPU:
#ifdef LM_GGML_USE_METAL
if (params.n_gpu_layers > 0) {
model->devices.push_back(dev);
}
#else
model->devices.push_back(dev);
#endif
break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ PODS:
- hermes-engine/Pre-built (= 0.72.3)
- hermes-engine/Pre-built (0.72.3)
- libevent (2.1.12)
- llama-rn (0.3.10):
- llama-rn (0.3.11):
- RCT-Folly
- RCTRequired
- RCTTypeSafety
Expand Down Expand Up @@ -1261,7 +1261,7 @@ SPEC CHECKSUMS:
glog: 04b94705f318337d7ead9e6d17c019bd9b1f6b1b
hermes-engine: 10fbd3f62405c41ea07e71973ea61e1878d07322
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
llama-rn: bb4447eb237c895e526b1adbb2b88700093005ac
llama-rn: 07a172eaad49cc56323f326e4c3ce3ec734b6a9e
RCT-Folly: 424b8c9a7a0b9ab2886ffe9c3b041ef628fd4fb1
RCTRequired: a2faf4bad4e438ca37b2040cb8f7799baa065c18
RCTTypeSafety: cb09f3e4747b6d18331a15eb05271de7441ca0b3
Expand Down
1 change: 1 addition & 0 deletions scripts/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ patch -p0 -d ./cpp < ./scripts/common.cpp.patch
patch -p0 -d ./cpp < ./scripts/log.cpp.patch
patch -p0 -d ./cpp < ./scripts/llama.cpp.patch
patch -p0 -d ./cpp < ./scripts/ggml-metal.m.patch
patch -p0 -d ./cpp < ./scripts/ggml-backend.cpp.patch
patch -p0 -d ./cpp < ./scripts/ggml.c.patch


Expand Down
14 changes: 14 additions & 0 deletions scripts/ggml-backend.cpp.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--- ggml-backend.cpp.orig 2024-11-02 18:37:57
+++ ggml-backend.cpp 2024-11-02 18:39:36
@@ -575,8 +575,11 @@
register_backend(lm_ggml_backend_cuda_reg());
#endif
#ifdef LM_GGML_USE_METAL
+#include <TargetConditionals.h>
+#if !TARGET_OS_SIMULATOR
register_backend(lm_ggml_backend_metal_reg());
#endif
+#endif
#ifdef LM_GGML_USE_SYCL
register_backend(lm_ggml_backend_sycl_reg());
#endif
25 changes: 0 additions & 25 deletions scripts/llama.cpp.patch
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,3 @@
strerror(errno));
}
}
@@ -19086,7 +19097,9 @@

#ifdef LM_GGML_USE_METAL
// note: we usually have plenty of VRAM, so by default offload all layers to the GPU
- result.n_gpu_layers = 999;
+ if (result.n_gpu_layers > 0) {
+ result.n_gpu_layers = 999;
+ }
#endif

return result;
@@ -19289,7 +19302,13 @@
break;

case LM_GGML_BACKEND_DEVICE_TYPE_GPU:
+#ifdef LM_GGML_USE_METAL
+ if (params.n_gpu_layers > 0) {
+ model->devices.push_back(dev);
+ }
+#else
model->devices.push_back(dev);
+#endif
break;
}
}

0 comments on commit 192c9ae

Please sign in to comment.