From 51b8b1d223aea95b4459a0497dc3ea115577f646 Mon Sep 17 00:00:00 2001 From: ebolam Date: Thu, 29 Sep 2022 12:12:46 -0400 Subject: [PATCH] Partial fix for text context --- aiserver.py | 2 +- koboldai_settings.py | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/aiserver.py b/aiserver.py index 824b2fcb..6edd7dbe 100644 --- a/aiserver.py +++ b/aiserver.py @@ -2673,7 +2673,7 @@ def load_model(use_gpu=True, gpu_layers=None, disk_layers=None, initial_load=Fal raise RuntimeError("One of your GPUs ran out of memory when KoboldAI tried to load your model.") raise e tokenizer.save_pretrained("models/{}".format(koboldai_vars.model.replace('/', '_'))) - model.save_pretrained("models/{}".format(koboldaivars.model.replace('/', '_')), max_shard_size="500MiB") + model.save_pretrained("models/{}".format(koboldai_vars.model.replace('/', '_')), max_shard_size="500MiB") koboldai_vars.modeldim = get_hidden_size_from_model(model) # Is CUDA available? If so, use GPU, otherwise fall back to CPU if(koboldai_vars.hascuda and koboldai_vars.usegpu): diff --git a/koboldai_settings.py b/koboldai_settings.py index a8a219ba..a298416a 100644 --- a/koboldai_settings.py +++ b/koboldai_settings.py @@ -260,6 +260,8 @@ class koboldai_vars(object): game_context = [] authors_note_final = self.authornotetemplate.replace("<|>", self.authornote) used_all_tokens = False + with open("test.txt", "w") as f: + f.write(str(action_text_split)) for action in range(len(self.actions)): self.actions.set_action_in_ai(action, used=False) for i in range(len(action_text_split)-1, -1, -1): @@ -270,12 +272,14 @@ class koboldai_vars(object): game_text = "{}{}".format(authors_note_final, game_text) game_context.insert(0, {"type": "authors_note", "text": authors_note_final}) length = 0 if self.tokenizer is None else len(self.tokenizer.encode(action_text_split[i][0])) + print("Length for sentence {}: {}".format(i, length)) if length+used_tokens <= token_budget and not used_all_tokens: used_tokens += length selected_text = action_text_split[i][0] action_text_split[i][3] = True game_text = "{}{}".format(selected_text, game_text) game_context.insert(0, {"type": "action", "text": selected_text}) + print("Adding in game for the following actions: {}".format(action_text_split[i][1])) for action in action_text_split[i][1]: if action >= 0: self.actions.set_action_in_ai(action) @@ -311,6 +315,7 @@ class koboldai_vars(object): self.worldinfo_v2.set_world_info_used(wi['uid']) else: used_all_tokens = True + break #if we don't have enough actions to get to author's note depth then we just add it right before the game text if len(action_text_split) < self.andepth and self.authornote != "": @@ -1380,7 +1385,7 @@ class KoboldStoryRegister(object): def to_sentences(self): #we're going to split our actions by sentence for better context. We'll add in which actions the sentence covers. Prompt will be added at a -1 ID - actions = {i: self.actions[i] for i in range(len(self.actions))} + actions = {i: self.actions[i]['Selected Text'] for i in range(len(self.actions))} actions[-1] = self.story_settings.prompt action_text = self.__str__() action_text = "{}{}".format(self.story_settings.prompt, action_text) @@ -1410,12 +1415,12 @@ class KoboldStoryRegister(object): if advance_action: Action_Position[0] += 1 - if Action_Position[0] >= max(actions): + if Action_Position[0] > max(actions): break Action_Position[1] = len(actions[Action_Position[0]]) if advance_sentence: Sentence_Position[0] += 1 - if Sentence_Position[0] >= len(action_text_split): + if Sentence_Position[0] > len(action_text_split): break Sentence_Position[1] = len(action_text_split[Sentence_Position[0]][0]) #OK, action_text_split now contains a list of [sentence including trailing space if needed, [action IDs that sentence includes]]