Skip to content

Commit 95d7cc7

Browse files
committed
Merge branch 'concedo_experimental' into croco_nex_0
2 parents 32439d2 + fb1274e commit 95d7cc7

File tree

6 files changed

+83
-26
lines changed

6 files changed

+83
-26
lines changed

gpttype_adapter.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -601,16 +601,23 @@ static void speculative_decoding_setup(std::string spec_model_filename, const ll
601601
{
602602
printf("WARNING: Draft model vocab of (%d) does not match base vocab of (%d).\nIn debug mode, this restriction is bypassed. However, speculative decoding may malfunction!\n",draftvocab,base_n_vocab);
603603
}
604-
else if((draftvocab >= base_n_vocab-512) || (draftvocab <= base_n_vocab+512))
604+
else if((draftvocab >= base_n_vocab-128) || (draftvocab <= base_n_vocab+128))
605605
{
606-
printf("WARNING: Draft model vocab of (%d) does not match base vocab of (%d).\nIn Croco.Cpp, a tolerance of +/- 512 tokens is allowed to account for some variations between the base models and their finetunes/updates and other self-merged frankenmodels + eventual finetunes of those.\nHowever, speculative decoding may malfuction in such cases if the difference between their vocab/tokenizers is too big!\n",draftvocab,base_n_vocab);
606+
printf("WARNING: Draft model vocab of (%d) does not match base vocab of (%d).\nIn Croco.Cpp, a tolerance of +/- 128 tokens is allowed to account for some variations between the base models and their finetunes/updates and other self-merged frankenmodels + eventual finetunes of those.\nHowever, speculative decoding may malfuction in such cases if the difference between their vocab/tokenizers is too big!\n",draftvocab,base_n_vocab);
607607
}
608608
else
609609
{
610-
printf("Error: Draft model vocab of (%d) does not match base vocab of (%d), or is above 512 tokens of difference. Speculative decoding cannot be used!\n",draftvocab,base_n_vocab);
611-
printf("If you REALLY want to override this, run in --debugmode and this restriction will be completely disabled. However, you might encounter unwanted results!\n");
612-
llama_free(draft_ctx);
613-
draft_ctx = nullptr;
610+
int diff = abs(draftvocab-base_n_vocab);
611+
if(diff <= 256)
612+
{
613+
//allow small differences to work
614+
printf("WARNING: Draft model vocab of (%d) does not match base vocab of (%d).\nIn KoboldCpp, a tolerance of +/- 256 tokens is allowed.\nSpeculative decoding may malfunction!\n",draftvocab,base_n_vocab);
615+
} else {
616+
printf("Error: Draft model vocab of (%d) is too different from base vocab of (%d). Speculative decoding cannot be used!\n",draftvocab,base_n_vocab);
617+
printf("If you REALLY want to override this, run in --debugmode and this restriction will be disabled. However, you might encounter unwanted results!\n");
618+
llama_free(draft_ctx);
619+
draft_ctx = nullptr;
620+
}
614621
}
615622
}
616623
}

kcpp_adapters/DeepSeek-V2.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"system_start": "",
3+
"system_end": "",
4+
"user_start": "<|User|>",
5+
"user_end": "",
6+
"assistant_start": "<|Assistant|>",
7+
"assistant_end": "<|end▁of▁sentence|>"
8+
}

koboldcpp.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@
6666
modelbusy = threading.Lock()
6767
requestsinqueue = 0
6868
defaultport = 5001
69-
KcppVersion = "1.83001"
69+
KcppVersion = "1.83002"
7070
LcppVersion = "b4517"
7171
CudaSpecifics = "Cu124_Ar6175_SMC2_DmmvX32Y1"
72-
ReleaseDate = "2025/01/22"
72+
ReleaseDate = "2025/01/23"
7373
showdebug = True
7474
guimode = False
7575
showsamplerwarning = True
@@ -4063,7 +4063,7 @@ def auto_set_backend_gui(manual_select=False):
40634063
def on_picked_model_file(filepath):
40644064
if filepath.lower().endswith('.kcpps') or filepath.lower().endswith('.kcppt'):
40654065
#load it as a config file instead
4066-
with open(filepath, 'r') as f:
4066+
with open(filepath, 'r', encoding='utf-8', errors='ignore') as f:
40674067
dict = json.load(f)
40684068
import_vars(dict)
40694069

@@ -4712,7 +4712,7 @@ def export_vars():
47124712
try:
47134713
if kcpp_exporting_template and isinstance(args.chatcompletionsadapter, str) and args.chatcompletionsadapter!="" and os.path.exists(args.chatcompletionsadapter):
47144714
print("Embedding chat completions adapter...") # parse and save embedded preload story
4715-
with open(args.chatcompletionsadapter, 'r') as f:
4715+
with open(args.chatcompletionsadapter, 'r', encoding='utf-8', errors='ignore') as f:
47164716
args.chatcompletionsadapter = json.load(f)
47174717
except Exception:
47184718
pass
@@ -4723,7 +4723,7 @@ def export_vars():
47234723
try:
47244724
if kcpp_exporting_template and isinstance(args.preloadstory, str) and args.preloadstory!="" and os.path.exists(args.preloadstory):
47254725
print("Embedding preload story...") # parse and save embedded preload story
4726-
with open(args.preloadstory, 'r') as f:
4726+
with open(args.preloadstory, 'r', encoding='utf-8', errors='ignore') as f:
47274727
args.preloadstory = json.load(f)
47284728
except Exception:
47294729
pass
@@ -4993,7 +4993,7 @@ def load_config_gui(): #this is used to populate the GUI with a config file, whe
49934993
if not filename or filename=="":
49944994
return
49954995
runmode_untouched = False
4996-
with open(filename, 'r') as f:
4996+
with open(filename, 'r', encoding='utf-8', errors='ignore') as f:
49974997
dict = json.load(f)
49984998
import_vars(dict)
49994999
pass
@@ -5479,7 +5479,7 @@ def unload_libs():
54795479

54805480
def load_config_cli(filename):
54815481
print("Loading .kcpps configuration file...")
5482-
with open(filename, 'r') as f:
5482+
with open(filename, 'r', encoding='utf-8', errors='ignore') as f:
54835483
config = json.load(f)
54845484
args.istemplate = False
54855485
raw_args = (sys.argv[1:]) #a lousy hack to allow for overriding kcpps
@@ -5718,7 +5718,7 @@ def main(launch_args,start_server=True):
57185718
ccadapter_path = os.path.abspath(premade_adapt_path)
57195719
if ccadapter_path:
57205720
print(f"Loading Chat Completions Adapter: {ccadapter_path}")
5721-
with open(ccadapter_path, 'r') as f:
5721+
with open(ccadapter_path, 'r', encoding='utf-8', errors='replace') as f:
57225722
chatcompl_adapter = json.load(f)
57235723
canload = True
57245724
else:

otherarch/tts_adapter.cpp

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -756,8 +756,9 @@ tts_generation_outputs ttstype_generate(const tts_generation_inputs inputs)
756756

757757
//use creative settings to generate speakers
758758
const int topk = 20;
759+
const float top_p = 1.0f;
759760
const float temp = 1.2f;
760-
llama_token new_token_id = kcpp_quick_sample(logits,ttc_n_vocab,topk,temp,speaker_rng);
761+
llama_token new_token_id = kcpp_quick_sample(logits,ttc_n_vocab,std::vector<int32_t>(),1.0,top_p,topk,temp,speaker_rng);
761762

762763
//guide tokens help prevent hallucinations by forcing the TTS to use the correct word
763764
if(next_token_uses_guide_token && !llama_vocab_is_control(ttcvocab, new_token_id) && !llama_vocab_is_eog(ttcvocab, new_token_id))
@@ -878,7 +879,8 @@ tts_generation_outputs ttstype_generate(const tts_generation_inputs inputs)
878879
//use predictable settings to generate voice
879880
const int topk = 4;
880881
const float temp = 0.75f;
881-
llama_token new_token_id = kcpp_quick_sample(logits,ttc_n_vocab,topk,temp,tts_rng);
882+
const float top_p = 1.0f;
883+
llama_token new_token_id = kcpp_quick_sample(logits,ttc_n_vocab,std::vector<int32_t>(),1.0,top_p,topk,temp,speaker_rng);
882884

883885
//guide tokens help prevent hallucinations by forcing the TTS to use the correct word
884886
if(next_token_uses_guide_token && !llama_vocab_is_control(ttcvocab, new_token_id) && !llama_vocab_is_eog(ttcvocab, new_token_id))
@@ -935,7 +937,7 @@ tts_generation_outputs ttstype_generate(const tts_generation_inputs inputs)
935937
const int n_codes = codes.size();
936938
if(n_codes<=1)
937939
{
938-
printf("\nWarning: TTS vocoder generated nothing!\n");
940+
printf("\nWarning: No Audio Tokens Produced!\n");
939941
last_generated_audio = "";
940942
output.data = last_generated_audio.c_str();
941943
output.status = 1;
@@ -965,12 +967,23 @@ tts_generation_outputs ttstype_generate(const tts_generation_inputs inputs)
965967

966968
//audio = resample_wav(audio,n_sr,t_sr); //resample to 16k
967969

968-
for (int i = 0; i < cutout; ++i) {
969-
audio[i] = 0.0f;
970+
if(audio.size()>cutout+16)
971+
{
972+
for (int i = 0; i < cutout; ++i) {
973+
audio[i] = 0.0f;
974+
}
975+
//add some silence at the end
976+
for (int i = 0; i < cutout; ++i) {
977+
audio.push_back(0.0f);
978+
}
970979
}
971-
//add some silence at the end
972-
for (int i = 0; i < cutout; ++i) {
973-
audio.push_back(0.0f);
980+
else
981+
{
982+
printf("\nWarning: TTS vocoder generated nothing!\n");
983+
last_generated_audio = "";
984+
output.data = last_generated_audio.c_str();
985+
output.status = 1;
986+
return output;
974987
}
975988

976989
last_generated_audio = save_wav16_base64(audio, t_sr);

otherarch/utils.cpp

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,9 +369,9 @@ std::vector<float> resample_wav(const std::vector<float>& input, uint32_t input_
369369
}
370370

371371
//a very rudimentary all in one sampling function which has no dependencies
372-
int32_t kcpp_quick_sample(float * logits, const int n_logits, int top_k, float temp, std::mt19937 & rng)
372+
int32_t kcpp_quick_sample(float * logits, const int n_logits, const std::vector<int32_t> & last_n_tokens, float rep_pen, float top_p, int top_k, float temp, std::mt19937 & rng)
373373
{
374-
if (temp <= 0 || top_k==1) {
374+
if (temp <= 0) {
375375
// select the token with the highest logit directly
376376
float max_logit = logits[0];
377377
int32_t max_id = 0;
@@ -392,8 +392,19 @@ int32_t kcpp_quick_sample(float * logits, const int n_logits, int top_k, float t
392392

393393
//temperature sample
394394
const float scale = 1.0f/temp;
395+
396+
//sample rep pen
395397
for (int i = 0; i < n_logits; ++i) {
396-
logits_id.push_back(std::make_pair(logits[i]*scale, i));
398+
if (rep_pen>1.0f && std::find(last_n_tokens.begin(), last_n_tokens.end(), i) != last_n_tokens.end()) {
399+
// if score < 0 then repetition penalty has to multiplied to reduce the previous token probability
400+
if (logits[i] < 0.0f) {
401+
logits_id.push_back(std::make_pair(logits[i]*scale*rep_pen, i));
402+
} else {
403+
logits_id.push_back(std::make_pair(logits[i]*scale/rep_pen, i));
404+
}
405+
} else {
406+
logits_id.push_back(std::make_pair(logits[i]*scale, i));
407+
}
397408
}
398409

399410
//sample top_k
@@ -421,6 +432,24 @@ int32_t kcpp_quick_sample(float * logits, const int n_logits, int top_k, float t
421432
p /= sum;
422433
}
423434

435+
//apply top p
436+
if (top_p < 1.0) {
437+
double cumsum = 0.0;
438+
for (int i = 0; i < (int) probs.size(); i++) {
439+
cumsum += probs[i];
440+
if (cumsum >= top_p) {
441+
probs.resize(i + 1);
442+
logits_id.resize(i + 1);
443+
break;
444+
}
445+
}
446+
}
447+
448+
// normalize the probs
449+
for (auto & p : probs) {
450+
p /= sum;
451+
}
452+
424453
std::discrete_distribution<> dist(probs.begin(), probs.end());
425454
int idx = dist(rng);
426455

otherarch/utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ std::string kcpp_base64_encode(const std::string &data);
6363
std::string get_timestamp_str();
6464
std::vector<float> resample_wav(const std::vector<float>& input, uint32_t input_rate, uint32_t output_rate);
6565

66-
int32_t kcpp_quick_sample(float * logits, const int n_logits, int top_k, float temp, std::mt19937 & rng);
66+
int32_t kcpp_quick_sample(float * logits, const int n_logits, const std::vector<int32_t> & last_n_tokens, float rep_pen, float top_p, int top_k, float temp, std::mt19937 & rng);
6767

6868
struct kcpp_embd_batch { //duplcated from llava_embd_batch
6969
std::vector<int32_t> pos;

0 commit comments

Comments
 (0)