Skip to content

Commit

Permalink
[WASI-NN] llama.cpp: Fix segfault of the wrong usage of the user_data…
Browse files Browse the repository at this point in the history
… field.

Signed-off-by: hydai <hydai@secondstate.io>
  • Loading branch information
hydai committed Nov 3, 2023
1 parent 9377320 commit f7931f2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion plugins/wasi_nn/ggml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ Expect<ErrNo> setInput(WasiNNEnvironment &Env, uint32_t ContextId,
"[WASI-NN] GGML backend: Unable to retrieve the enable-log option."sv);
return ErrNo::InvalidArgument;
}
llama_log_set(nullptr, &CxtRef.EnableLog);
}
if (Doc.at_key("stream-stdout").error() == simdjson::SUCCESS) {
auto Err = Doc["stream-stdout"].get<bool>().get(CxtRef.StreamStdout);
Expand Down Expand Up @@ -187,7 +188,7 @@ Expect<ErrNo> setInput(WasiNNEnvironment &Env, uint32_t ContextId,
// If the `n_gpu_layers` in `setInput` is different from the
// `n_gpu_layers` in `llama_model_params`, we will reload
// the model with the new configuration.
if (ModelParams.n_gpu_layers != CxtRef.NGPULayers) {
if (ModelParams.n_gpu_layers != static_cast<int32_t>(CxtRef.NGPULayers)) {
ModelParams.n_gpu_layers = CxtRef.NGPULayers;
GraphRef.LlamaModel = llama_load_model_from_file(
GraphRef.ModelFilePath.c_str(), ModelParams);
Expand Down
4 changes: 2 additions & 2 deletions plugins/wasi_nn/thirdparty/ggml/llama.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9625,8 +9625,8 @@ static void llama_log_internal(ggml_log_level level, const char * format, ...) {

static void llama_log_callback_default(ggml_log_level level, const char * text, void * user_data) {
(void) level;
bool enable_log = static_cast<bool>(user_data);
if (enable_log) {
bool * enable_log = static_cast<bool *>(user_data);
if (enable_log && *enable_log) {
fputs(text, stderr);
fflush(stderr);
}
Expand Down

0 comments on commit f7931f2

Please sign in to comment.