@novastera-oss/llamarn 0.1.3-beta.3 → 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 +1 -33
- 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
|
@@ -245,40 +245,8 @@ jsi::Value PureCppImpl::initLlama(jsi::Runtime &runtime, jsi::Object options) {
|
|
|
245
245
|
throw std::runtime_error("Failed to initialize model and context");
|
|
246
246
|
}
|
|
247
247
|
} catch (const std::exception& e) {
|
|
248
|
-
std::string error_msg = e.what();
|
|
249
|
-
|
|
250
|
-
// Check for specific Vulkan errors that indicate Adreno GPU shader incompatibility
|
|
251
|
-
bool isVulkanShaderError = (
|
|
252
|
-
error_msg.find("createComputePipeline") != std::string::npos ||
|
|
253
|
-
error_msg.find("ErrorUnknown") != std::string::npos ||
|
|
254
|
-
error_msg.find("matmul_q4_k") != std::string::npos ||
|
|
255
|
-
error_msg.find("matmul_q5_k") != std::string::npos ||
|
|
256
|
-
error_msg.find("dequant_q4_K") != std::string::npos ||
|
|
257
|
-
error_msg.find("dequant_q5_K") != std::string::npos ||
|
|
258
|
-
error_msg.find("vulkan") != std::string::npos
|
|
259
|
-
);
|
|
260
|
-
|
|
261
248
|
// If we were trying to use GPU and got a Vulkan/shader error, retry with CPU-only
|
|
262
|
-
if (params.n_gpu_layers > 0
|
|
263
|
-
fprintf(stderr, "Vulkan shader compilation failed (likely Adreno GPU incompatibility): %s\n", e.what());
|
|
264
|
-
fprintf(stderr, "This is a known issue with Q4_K/Q5_K shaders on Qualcomm Adreno GPUs\n");
|
|
265
|
-
fprintf(stderr, "Retrying with CPU-only mode...\n");
|
|
266
|
-
|
|
267
|
-
// Retry with CPU-only
|
|
268
|
-
params.n_gpu_layers = 0;
|
|
269
|
-
|
|
270
|
-
try {
|
|
271
|
-
result = common_init_from_params(params);
|
|
272
|
-
|
|
273
|
-
if (!result.model || !result.context) {
|
|
274
|
-
throw std::runtime_error("Failed to initialize model and context even with CPU-only mode");
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
fprintf(stderr, "Successfully recovered with CPU-only mode after Vulkan shader failure\n");
|
|
278
|
-
} catch (const std::exception& cpu_e) {
|
|
279
|
-
throw std::runtime_error(std::string("Model initialization failed: ") + cpu_e.what());
|
|
280
|
-
}
|
|
281
|
-
} else if (params.n_gpu_layers > 0) {
|
|
249
|
+
if (params.n_gpu_layers > 0) {
|
|
282
250
|
// Other GPU error, still try CPU fallback
|
|
283
251
|
fprintf(stderr, "GPU initialization failed (%s), retrying with CPU-only\n", e.what());
|
|
284
252
|
|