@novastera-oss/llamarn 0.1.3-beta.2 → 0.1.3-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/CMakeLists.txt +28 -6
- package/cpp/PureCppImpl.cpp +32 -5
- package/package.json +1 -1
package/android/CMakeLists.txt
CHANGED
|
@@ -90,6 +90,24 @@ target_compile_definitions(RNLlamaCpp PRIVATE
|
|
|
90
90
|
-DGGML_OPENCL=1 # Enable OpenCL backend support for dynamic loading
|
|
91
91
|
)
|
|
92
92
|
|
|
93
|
+
# Conditionally enable GPU backends only if they're actually available
|
|
94
|
+
if(VULKAN_BACKEND_AVAILABLE)
|
|
95
|
+
# Don't enable Vulkan on Android - causes crashes during auto-initialization
|
|
96
|
+
# target_compile_definitions(common PRIVATE -DGGML_VULKAN=1)
|
|
97
|
+
# target_compile_definitions(RNLlamaCpp PRIVATE -DGGML_VULKAN=1)
|
|
98
|
+
message(STATUS "Vulkan backend support disabled on Android to prevent crashes")
|
|
99
|
+
else()
|
|
100
|
+
message(STATUS "Vulkan backend support disabled - library not available")
|
|
101
|
+
endif()
|
|
102
|
+
|
|
103
|
+
if(OPENCL_BACKEND_AVAILABLE)
|
|
104
|
+
target_compile_definitions(common PRIVATE -DGGML_OPENCL=1)
|
|
105
|
+
target_compile_definitions(RNLlamaCpp PRIVATE -DGGML_OPENCL=1)
|
|
106
|
+
message(STATUS "OpenCL backend support enabled for dynamic loading")
|
|
107
|
+
else()
|
|
108
|
+
message(STATUS "OpenCL backend support disabled - library not available")
|
|
109
|
+
endif()
|
|
110
|
+
|
|
93
111
|
# Include directories
|
|
94
112
|
target_include_directories(common PRIVATE
|
|
95
113
|
${CPP_DIR}
|
|
@@ -161,12 +179,16 @@ add_custom_command(TARGET RNLlamaCpp POST_BUILD
|
|
|
161
179
|
|
|
162
180
|
# Also copy any optional GPU libraries if they exist
|
|
163
181
|
if(EXISTS ${JNI_LIBS_DIR}/${ANDROID_ABI}/libggml-vulkan.so)
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
182
|
+
# Don't copy Vulkan backend on Android - it crashes on emulators during auto-initialization
|
|
183
|
+
# Even with n_gpu_layers=0, llama.cpp tries to initialize all available backends
|
|
184
|
+
# and the Android emulator Vulkan driver is broken
|
|
185
|
+
message(STATUS "Skipping Vulkan backend copy to prevent emulator crashes")
|
|
186
|
+
# add_custom_command(TARGET RNLlamaCpp POST_BUILD
|
|
187
|
+
# COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
|
188
|
+
# ${JNI_LIBS_DIR}/${ANDROID_ABI}/libggml-vulkan.so
|
|
189
|
+
# $<TARGET_FILE_DIR:RNLlamaCpp>/libggml-vulkan.so
|
|
190
|
+
# COMMENT "Copying Vulkan library to build output directory"
|
|
191
|
+
# )
|
|
170
192
|
endif()
|
|
171
193
|
|
|
172
194
|
if(EXISTS ${JNI_LIBS_DIR}/${ANDROID_ABI}/libggml-opencl.so)
|
package/cpp/PureCppImpl.cpp
CHANGED
|
@@ -235,11 +235,38 @@ jsi::Value PureCppImpl::initLlama(jsi::Runtime &runtime, jsi::Object options) {
|
|
|
235
235
|
}
|
|
236
236
|
|
|
237
237
|
// Initialize using common_init_from_params
|
|
238
|
-
common_init_result result
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
238
|
+
common_init_result result;
|
|
239
|
+
|
|
240
|
+
try {
|
|
241
|
+
result = common_init_from_params(params);
|
|
242
|
+
|
|
243
|
+
// Check if initialization was successful
|
|
244
|
+
if (!result.model || !result.context) {
|
|
245
|
+
throw std::runtime_error("Failed to initialize model and context");
|
|
246
|
+
}
|
|
247
|
+
} catch (const std::exception& e) {
|
|
248
|
+
// If we were trying to use GPU and got a Vulkan/shader error, retry with CPU-only
|
|
249
|
+
if (params.n_gpu_layers > 0) {
|
|
250
|
+
// Other GPU error, still try CPU fallback
|
|
251
|
+
fprintf(stderr, "GPU initialization failed (%s), retrying with CPU-only\n", e.what());
|
|
252
|
+
|
|
253
|
+
params.n_gpu_layers = 0;
|
|
254
|
+
|
|
255
|
+
try {
|
|
256
|
+
result = common_init_from_params(params);
|
|
257
|
+
|
|
258
|
+
if (!result.model || !result.context) {
|
|
259
|
+
throw std::runtime_error("Failed to initialize model and context even with CPU-only mode");
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
fprintf(stderr, "Successfully recovered with CPU-only mode after GPU failure\n");
|
|
263
|
+
} catch (const std::exception& cpu_e) {
|
|
264
|
+
throw std::runtime_error(std::string("Model initialization failed: ") + cpu_e.what());
|
|
265
|
+
}
|
|
266
|
+
} else {
|
|
267
|
+
// Was already CPU-only, re-throw the original error
|
|
268
|
+
throw std::runtime_error(std::string("Model initialization failed: ") + e.what());
|
|
269
|
+
}
|
|
243
270
|
}
|
|
244
271
|
|
|
245
272
|
// Create and initialize rn_llama_context
|