Skip to content

Commit ca988db

Browse files
committed
update debug statements
1 parent 775089a commit ca988db

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

src/main/cpp/jllama.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,10 +477,14 @@ JNIEXPORT jint JNICALL Java_de_kherud_llama_LlamaModel_requestCompletion(JNIEnv
477477
jlong server_handle = env->GetLongField(obj, f_model_pointer);
478478
auto *ctx_server = reinterpret_cast<server_context *>(server_handle); // NOLINT(*-no-int-to-ptr)
479479

480+
std::cout << "DEBUG " << 1 << std::endl;
481+
480482
std::string c_params = parse_jstring(env, jparams);
481483
json json_params = json::parse(c_params);
482484
const bool infill = json_params.contains("input_prefix") || json_params.contains("input_suffix");
483485

486+
std::cout << "DEBUG " << 2 << std::endl;
487+
484488
if (json_params.value("use_chat_template", false))
485489
{
486490
json chat;
@@ -489,8 +493,12 @@ JNIEXPORT jint JNICALL Java_de_kherud_llama_LlamaModel_requestCompletion(JNIEnv
489493
json_params["prompt"] = format_chat(ctx_server->model, ctx_server->params.chat_template, chat);
490494
}
491495

496+
std::cout << "DEBUG " << 3 << std::endl;
497+
492498
const int id_task = ctx_server->queue_tasks.get_new_id();
499+
std::cout << "DEBUG " << 4 << std::endl;
493500
ctx_server->queue_results.add_waiting_task_id(id_task);
501+
std::cout << "DEBUG " << 5 << std::endl;
494502
ctx_server->request_completion(id_task, -1, json_params, infill, false);
495503

496504
return id_task;
@@ -501,6 +509,7 @@ JNIEXPORT jobject JNICALL Java_de_kherud_llama_LlamaModel_receiveCompletion(JNIE
501509
jlong server_handle = env->GetLongField(obj, f_model_pointer);
502510
auto *ctx_server = reinterpret_cast<server_context *>(server_handle); // NOLINT(*-no-int-to-ptr)
503511

512+
std::cout << "DEBUG " << 8 << std::endl;
504513
server_task_result result = ctx_server->queue_results.recv(id_task);
505514

506515
if (result.error)
@@ -510,12 +519,14 @@ JNIEXPORT jobject JNICALL Java_de_kherud_llama_LlamaModel_receiveCompletion(JNIE
510519
env->ThrowNew(c_llama_error, response.c_str());
511520
return nullptr;
512521
}
522+
std::cout << "DEBUG " << 9 << std::endl;
513523

514524
std::string response = result.data["content"].get<std::string>();
515525
if (result.stop)
516526
{
517527
ctx_server->queue_results.remove_waiting_task_id(id_task);
518528
}
529+
std::cout << "DEBUG " << 10 << std::endl;
519530

520531
jobject o_probabilities = env->NewObject(c_hash_map, cc_hash_map);
521532
if (result.data.contains("completion_probabilities"))
@@ -536,6 +547,7 @@ JNIEXPORT jobject JNICALL Java_de_kherud_llama_LlamaModel_receiveCompletion(JNIE
536547
}
537548
}
538549
}
550+
std::cout << "DEBUG " << 11 << std::endl;
539551

540552
jbyteArray jbytes = parse_jbytes(env, response);
541553
return env->NewObject(c_output, cc_output, jbytes, o_probabilities, result.stop);

src/main/cpp/server.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,6 +1661,8 @@ struct server_context
16611661
task.embedding = embedding;
16621662
task.type = SERVER_TASK_TYPE_COMPLETION;
16631663

1664+
std::cout << "DEBUG " << 6 << std::endl;
1665+
16641666
// when a completion task's prompt array is not a singleton, we split it into multiple requests
16651667
// otherwise, it's a single-prompt task, we actually queue it
16661668
// if there's numbers in the prompt array it will be treated as an array of tokens
@@ -1694,6 +1696,8 @@ struct server_context
16941696
{
16951697
queue_tasks.post(task);
16961698
}
1699+
1700+
std::cout << "DEBUG " << 7 << std::endl;
16971701
}
16981702

16991703
void request_cancel(int id_task)

src/main/cpp/utils.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ static const char *log_level_to_string(ggml_log_level level)
8989
static inline void server_log(ggml_log_level level, const char *function, int line, const char *message,
9090
const json &extra)
9191
{
92+
std::cout << "DEBUG LOG " << 1 << std::endl;
9293
std::stringstream ss_tid;
9394
ss_tid << std::this_thread::get_id();
9495

@@ -119,32 +120,43 @@ static inline void server_log(ggml_log_level level, const char *function, int li
119120
}
120121
else
121122
{
123+
std::cout << "DEBUG LOG " << 2 << std::endl;
122124
std::stringstream ss;
123125
ss << message;
124126

127+
std::cout << "DEBUG LOG " << 3 << std::endl;
125128
if (!extra.empty())
126129
{
130+
std::cout << "DEBUG LOG " << 4 << std::endl;
127131
for (const auto &el : extra.items())
128132
{
129133
const std::string value = el.value().dump(-1, ' ', false, json::error_handler_t::replace);
130134
ss << " " << el.key() << "=" << value;
131135
}
136+
std::cout << "DEBUG LOG " << 5 << std::endl;
132137
}
133138

139+
std::cout << "DEBUG LOG " << 6 << std::endl;
134140
#if SERVER_VERBOSE
135141
ss << " | ts " << time(nullptr) << " | tid " << ss_tid.str() << " | " << function << " line " << line;
136142
#endif
137143

144+
std::cout << "DEBUG LOG " << 7 << std::endl;
138145
const std::string str = ss.str();
139146
if (log_callback == nullptr)
140147
{
148+
std::cout << "DEBUG LOG " << 8 << std::endl;
141149
printf("[%4s] %.*s\n", log_level_to_string(level), (int)str.size(), str.data());
150+
std::cout << "DEBUG LOG " << 9 << std::endl;
142151
}
143152
else
144153
{
154+
std::cout << "DEBUG LOG " << 10 << std::endl;
145155
log_callback(level, str.c_str(), nullptr);
156+
std::cout << "DEBUG LOG " << 11 << std::endl;
146157
}
147158
}
159+
std::cout << "DEBUG LOG " << 12 << std::endl;
148160
fflush(stdout);
149161
}
150162

src/test/java/de/kherud/llama/LlamaModelTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@ public void testLogStdout() {
213213

214214
System.out.println("########## Log Text ##########");
215215
LlamaModel.setLogger(LogFormat.TEXT, null);
216-
System.out.println("DEBUG: Logger set");
217216
model.complete(params);
218217

219218
System.out.println("########## Log JSON ##########");

0 commit comments

Comments
 (0)