-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ggml-ci
- Loading branch information
Showing
13 changed files
with
220 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
#include "llama-grammar.h" | ||
|
||
#include "llama-impl.h" | ||
#include "llama-vocab.h" | ||
#include "llama-sampling.h" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#pragma once | ||
|
||
#include "llama-impl.h" | ||
#include "llama.h" | ||
|
||
#include <map> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#include "llama-impl.h" | ||
|
||
#include "llama.h" | ||
|
||
struct llama_logger_state { | ||
ggml_log_callback log_callback = llama_log_callback_default; | ||
void * log_callback_user_data = nullptr; | ||
}; | ||
|
||
static llama_logger_state g_logger_state; | ||
|
||
time_meas::time_meas(int64_t & t_acc, bool disable) : t_start_us(disable ? -1 : ggml_time_us()), t_acc(t_acc) {} | ||
|
||
time_meas::~time_meas() { | ||
if (t_start_us >= 0) { | ||
t_acc += ggml_time_us() - t_start_us; | ||
} | ||
} | ||
|
||
void replace_all(std::string & s, const std::string & search, const std::string & replace) { | ||
if (search.empty()) { | ||
return; | ||
} | ||
std::string builder; | ||
builder.reserve(s.length()); | ||
size_t pos = 0; | ||
size_t last_pos = 0; | ||
while ((pos = s.find(search, last_pos)) != std::string::npos) { | ||
builder.append(s, last_pos, pos - last_pos); | ||
builder.append(replace); | ||
last_pos = pos + search.length(); | ||
} | ||
builder.append(s, last_pos, std::string::npos); | ||
s = std::move(builder); | ||
} | ||
|
||
void llama_log_set(ggml_log_callback log_callback, void * user_data) { | ||
ggml_log_set(log_callback, user_data); | ||
g_logger_state.log_callback = log_callback ? log_callback : llama_log_callback_default; | ||
g_logger_state.log_callback_user_data = user_data; | ||
} | ||
|
||
static void llama_log_internal_v(ggml_log_level level, const char * format, va_list args) { | ||
va_list args_copy; | ||
va_copy(args_copy, args); | ||
char buffer[128]; | ||
int len = vsnprintf(buffer, 128, format, args); | ||
if (len < 128) { | ||
g_logger_state.log_callback(level, buffer, g_logger_state.log_callback_user_data); | ||
} else { | ||
char * buffer2 = new char[len + 1]; | ||
vsnprintf(buffer2, len + 1, format, args_copy); | ||
buffer2[len] = 0; | ||
g_logger_state.log_callback(level, buffer2, g_logger_state.log_callback_user_data); | ||
delete[] buffer2; | ||
} | ||
va_end(args_copy); | ||
} | ||
|
||
void llama_log_internal(ggml_log_level level, const char * format, ...) { | ||
va_list args; | ||
va_start(args, format); | ||
llama_log_internal_v(level, format, args); | ||
va_end(args); | ||
} | ||
|
||
void llama_log_callback_default(ggml_log_level level, const char * text, void * user_data) { | ||
(void) level; | ||
(void) user_data; | ||
fputs(text, stderr); | ||
fflush(stderr); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.