Skip to content

Commit

Permalink
fix for chat templates and drafting
Browse files Browse the repository at this point in the history
  • Loading branch information
LostRuins committed Jan 23, 2025
1 parent 03def28 commit cca4a93
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
16 changes: 12 additions & 4 deletions gpttype_adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -601,10 +601,18 @@ static void speculative_decoding_setup(std::string spec_model_filename, const ll
}
else
{
printf("Error: Draft model vocab of (%d) does not match base vocab of (%d). Speculative decoding cannot be used!\n",draftvocab,base_n_vocab);
printf("If you REALLY want to override this, run in --debugmode and this restriction will be disabled. However, you might encounter unwanted results!\n");
llama_free(draft_ctx);
draft_ctx = nullptr;
int diff = abs(draftvocab-base_n_vocab);
if(diff <= 256)
{
//allow small differences to work
printf("WARNING: Draft model vocab of (%d) does not match base vocab of (%d).\nSpeculative decoding may malfunction!\n",draftvocab,base_n_vocab);
} else {
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);
printf("If you REALLY want to override this, run in --debugmode and this restriction will be disabled. However, you might encounter unwanted results!\n");
llama_free(draft_ctx);
draft_ctx = nullptr;
}

}
}
}
Expand Down
8 changes: 8 additions & 0 deletions kcpp_adapters/DeepSeek-V2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"system_start": "",
"system_end": "",
"user_start": "<|User|>",
"user_end": "",
"assistant_start": "<|Assistant|>",
"assistant_end": "<|end▁of▁sentence|>"
}
14 changes: 7 additions & 7 deletions koboldcpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
modelbusy = threading.Lock()
requestsinqueue = 0
defaultport = 5001
KcppVersion = "1.82.3"
KcppVersion = "1.82.4"
showdebug = True
guimode = False
showsamplerwarning = True
Expand Down Expand Up @@ -3421,7 +3421,7 @@ def auto_set_backend_gui(manual_select=False):
def on_picked_model_file(filepath):
if filepath.lower().endswith('.kcpps') or filepath.lower().endswith('.kcppt'):
#load it as a config file instead
with open(filepath, 'r') as f:
with open(filepath, 'r', encoding='utf-8', errors='ignore') as f:
dict = json.load(f)
import_vars(dict)

Expand Down Expand Up @@ -4014,7 +4014,7 @@ def export_vars():
try:
if kcpp_exporting_template and isinstance(args.chatcompletionsadapter, str) and args.chatcompletionsadapter!="" and os.path.exists(args.chatcompletionsadapter):
print("Embedding chat completions adapter...") # parse and save embedded preload story
with open(args.chatcompletionsadapter, 'r') as f:
with open(args.chatcompletionsadapter, 'r', encoding='utf-8', errors='ignore') as f:
args.chatcompletionsadapter = json.load(f)
except Exception:
pass
Expand All @@ -4025,7 +4025,7 @@ def export_vars():
try:
if kcpp_exporting_template and isinstance(args.preloadstory, str) and args.preloadstory!="" and os.path.exists(args.preloadstory):
print("Embedding preload story...") # parse and save embedded preload story
with open(args.preloadstory, 'r') as f:
with open(args.preloadstory, 'r', encoding='utf-8', errors='ignore') as f:
args.preloadstory = json.load(f)
except Exception:
pass
Expand Down Expand Up @@ -4283,7 +4283,7 @@ def load_config_gui(): #this is used to populate the GUI with a config file, whe
if not filename or filename=="":
return
runmode_untouched = False
with open(filename, 'r') as f:
with open(filename, 'r', encoding='utf-8', errors='ignore') as f:
dict = json.load(f)
import_vars(dict)
pass
Expand Down Expand Up @@ -4761,7 +4761,7 @@ def unload_libs():

def load_config_cli(filename):
print("Loading .kcpps configuration file...")
with open(filename, 'r') as f:
with open(filename, 'r', encoding='utf-8', errors='ignore') as f:
config = json.load(f)
args.istemplate = False
raw_args = (sys.argv[1:]) #a lousy hack to allow for overriding kcpps
Expand Down Expand Up @@ -4990,7 +4990,7 @@ def main(launch_args,start_server=True):
ccadapter_path = os.path.abspath(premade_adapt_path)
if ccadapter_path:
print(f"Loading Chat Completions Adapter: {ccadapter_path}")
with open(ccadapter_path, 'r') as f:
with open(ccadapter_path, 'r', encoding='utf-8', errors='replace') as f:
chatcompl_adapter = json.load(f)
canload = True
else:
Expand Down

0 comments on commit cca4a93

Please sign in to comment.