Skip to content

Distribute and run LLMs with a single file.

Remap <|eot_id|> → <|end_of_text|>

Justine Tunney4a6bada6f5fc
diff --git a/llama.cpp/llama.cpp b/llama.cpp/llama.cpp
index 7c66acd0..a477de26 100644
--- a/llama.cpp/llama.cpp
+++ b/llama.cpp/llama.cpp
@@ -17204,3 +17204,12 @@ static void llama_log_callback_default(ggml_log_level level, const char * text,
fputs(text, stderr);
fflush(stderr);
}
+
+llama_token llama_string_to_token(const struct llama_model *model, const char *str) {
+ auto i = model->vocab.token_to_id.find(str);
+ if (i != model->vocab.token_to_id.end()) {
+ return i->second;
+ } else {
+ return -1;
+ }
+}
diff --git a/llama.cpp/llama.h b/llama.cpp/llama.h
index 8cca0e12..d65b37fe 100644
--- a/llama.cpp/llama.h
+++ b/llama.cpp/llama.h
@@ -1065,6 +1065,8 @@ extern "C" {
LLAMA_API void llama_dump_timing_info_yaml(FILE * stream, const struct llama_context * ctx);
+ LLAMA_API llama_token llama_string_to_token(const struct llama_model *, const char *);
+
#ifdef __cplusplus
}
#endif
diff --git a/llama.cpp/sampling.cpp b/llama.cpp/sampling.cpp
index 211221f7..26440981 100644
--- a/llama.cpp/sampling.cpp
+++ b/llama.cpp/sampling.cpp
@@ -329,7 +329,15 @@ llama_token llama_sampling_sample(
struct llama_context * ctx_cfg,
const int idx) {
// Call the implementation function with is_resampling set to false by default
- return llama_sampling_sample_impl(ctx_sampling, ctx_main, ctx_cfg, idx, false);
+ llama_token tok = llama_sampling_sample_impl(ctx_sampling, ctx_main, ctx_cfg, idx, false);
+
+ // [jart] llama3 <|eot_id|> → <|end_of_text|>
+ // https://github.com/ggerganov/llama.cpp/pull/6745#issuecomment-2064950897
+ if (tok == llama_string_to_token(llama_get_model(ctx_main), "<|eot_id|>")) {
+ tok = llama_token_eos(llama_get_model(ctx_main));
+ }
+
+ return tok;
}
llama_token_data_array llama_sampling_prepare(