Skip to content

Commit

Permalink
fix: app hangs if we unload model during stream completion (#513)
Browse files Browse the repository at this point in the history
  • Loading branch information
vansangpfiev committed Apr 17, 2024
1 parent 6654c7e commit 1c69519
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions controllers/llamaCPP.cc
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,7 @@ void llamaCPP::InferenceImpl(
if (llama.model_type == ModelType::EMBEDDING) {
LOG_WARN << "Not support completion for embedding model";
Json::Value jsonResp;
jsonResp["message"] =
"Not support completion for embedding model";
jsonResp["message"] = "Not support completion for embedding model";
auto resp = nitro_utils::nitroHttpJsonResponse(jsonResp);
resp->setStatusCode(drogon::k400BadRequest);
callback(resp);
Expand Down Expand Up @@ -429,7 +428,8 @@ void llamaCPP::InferenceImpl(

// Since this is an async task, we will wait for the task to be
// completed
while (state->inference_status != FINISHED && retries < 10) {
while (state->inference_status != FINISHED && retries < 10 &&
state->instance->llama.model_loaded_external) {
// Should wait chunked_content_provider lambda to be called within
// 3s
if (state->inference_status == PENDING) {
Expand Down Expand Up @@ -748,9 +748,10 @@ void llamaCPP::StopBackgroundTask() {
if (llama.model_loaded_external) {
llama.model_loaded_external = false;
llama.condition_tasks.notify_one();
LOG_INFO << "Background task stopped! ";
LOG_INFO << "Stopping background task! ";
if (backgroundThread.joinable()) {
backgroundThread.join();
}
LOG_INFO << "Background task stopped! ";
}
}

0 comments on commit 1c69519

Please sign in to comment.