From 3f863eed72a0076c13fb758deaca16af9892d552 Mon Sep 17 00:00:00 2001 From: Concedo <39025047+LostRuins@users.noreply.github.com> Date: Tue, 19 Dec 2023 23:18:56 +0800 Subject: [PATCH] add presence penalty --- expose.h | 1 + gpttype_adapter.cpp | 14 +++++++++----- koboldcpp.py | 12 ++++++++---- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/expose.h b/expose.h index c0ff4a520..eb116a5b4 100644 --- a/expose.h +++ b/expose.h @@ -65,6 +65,7 @@ struct generation_inputs const float tfs; const float rep_pen; const int rep_pen_range; + const float presence_penalty = 0.0f; const int mirostat = 0; const float mirostat_eta; const float mirostat_tau; diff --git a/gpttype_adapter.cpp b/gpttype_adapter.cpp index 0e8b4b259..befe360f5 100644 --- a/gpttype_adapter.cpp +++ b/gpttype_adapter.cpp @@ -386,7 +386,7 @@ void sample_top_a(llama_token_data_array * candidates, float a, size_t min_keep) candidates->size = last_idx; } -void sample_rep_pen(int n_ctx, int rep_pen_range, float rep_pen, llama_token_data_array * candidates_p) +void sample_rep_pen(int n_ctx, int rep_pen_range, float rep_pen, float presence_penalty, llama_token_data_array * candidates_p) { auto last_n_repeat = std::min(std::min((int)last_n_tokens.size(), rep_pen_range), n_ctx); @@ -414,6 +414,8 @@ void sample_rep_pen(int n_ctx, int rep_pen_range, float rep_pen, llama_token_dat } else { candidates->data[i].logit /= penalty; } + + candidates->data[i].logit -= presence_penalty; } candidates->sorted = false; @@ -474,7 +476,7 @@ void sample_grammar(FileFormat file_format, int32_t n_vocab, llama_token_data_ar } -int SampleLogits(const float * logits, int n_ctx, int n_vocab, int rep_pen_range, float rep_pen, float top_k, float top_a, float top_p, float min_p, float typical_p, float tfs, float temp, std::mt19937 & rng, +int SampleLogits(const float * logits, int n_ctx, int n_vocab, int rep_pen_range, float rep_pen, float presence_penalty, float top_k, float top_a, float top_p, float min_p, float typical_p, float tfs, float temp, std::mt19937 & rng, int mirostat, float mirostat_tau, float mirostat_eta, const std::vector & sampler_order, llama_grammar * grammar) { int id = 0; @@ -494,7 +496,7 @@ int mirostat, float mirostat_tau, float mirostat_eta, const std::vector 0: + genparams["rep_pen"] = 1.0 # openai allows either a string or a list as a stop sequence if isinstance(genparams.get('stop',[]), list): genparams["stop_sequence"] = genparams.get('stop', []) @@ -500,6 +503,7 @@ class ServerRequestHandler(http.server.SimpleHTTPRequestHandler): tfs=genparams.get('tfs', 1.0), rep_pen=genparams.get('rep_pen', 1.1), rep_pen_range=genparams.get('rep_pen_range', 256), + presence_penalty=genparams.get('presence_penalty', 0.0), mirostat=genparams.get('mirostat', 0), mirostat_tau=genparams.get('mirostat_tau', 5.0), mirostat_eta=genparams.get('mirostat_eta', 0.1),