mirror of
https://github.com/KoboldAI/KoboldAI-Client.git
synced 2025-06-05 21:59:24 +02:00
Better probability support (multi-option without token streaming not working)
This commit is contained in:
@@ -765,13 +765,13 @@ class model_settings(settings):
|
|||||||
#Setup TQDP for token generation
|
#Setup TQDP for token generation
|
||||||
elif name == "generated_tkns" and 'tqdm' in self.__dict__:
|
elif name == "generated_tkns" and 'tqdm' in self.__dict__:
|
||||||
if value == 0:
|
if value == 0:
|
||||||
self.tqdm.reset(total=self.genamt * self.numseqs if self.alt_multi_gen else 1 )
|
self.tqdm.reset(total=self.genamt * (self.numseqs if self.alt_multi_gen else 1) )
|
||||||
self.tqdm_progress = 0
|
self.tqdm_progress = 0
|
||||||
else:
|
else:
|
||||||
self.tqdm.update(value-self.tqdm.n)
|
self.tqdm.update(value-self.tqdm.n)
|
||||||
self.tqdm_progress = int(float(self.generated_tkns)/float(self.genamt * self.numseqs if self.alt_multi_gen else 1)*100)
|
self.tqdm_progress = int(float(self.generated_tkns)/float(self.genamt * (self.numseqs if self.alt_multi_gen else 1))*100)
|
||||||
if self.tqdm.format_dict['rate'] is not None:
|
if self.tqdm.format_dict['rate'] is not None:
|
||||||
self.tqdm_rem_time = str(datetime.timedelta(seconds=int(float((self.genamt * self.numseqs if self.alt_multi_gen else 1)-self.generated_tkns)/self.tqdm.format_dict['rate'])))
|
self.tqdm_rem_time = str(datetime.timedelta(seconds=int(float((self.genamt * (self.numseqs if self.alt_multi_gen else 1))-self.generated_tkns)/self.tqdm.format_dict['rate'])))
|
||||||
#Setup TQDP for model loading
|
#Setup TQDP for model loading
|
||||||
elif name == "loaded_layers" and 'tqdm' in self.__dict__:
|
elif name == "loaded_layers" and 'tqdm' in self.__dict__:
|
||||||
if value == 0:
|
if value == 0:
|
||||||
@@ -1409,7 +1409,13 @@ class KoboldStoryRegister(object):
|
|||||||
old_text = self.actions[i]["Selected Text"]
|
old_text = self.actions[i]["Selected Text"]
|
||||||
if self.actions[i]["Selected Text"] != text:
|
if self.actions[i]["Selected Text"] != text:
|
||||||
self.actions[i]["Selected Text"] = text
|
self.actions[i]["Selected Text"] = text
|
||||||
self.actions[i]["Probabilities"] = []
|
tokens = self.koboldai_vars.tokenizer.encode(text)
|
||||||
|
for token_num in range(len(self.actions[action_id]["Probabilities"])):
|
||||||
|
for token_option in range(len(self.actions[action_id]["Probabilities"][token_num])):
|
||||||
|
if token_num < len(tokens):
|
||||||
|
self.actions[action_id]["Probabilities"][token_num][token_option]["Used"] = tokens[token_num] == self.actions[action_id]["Probabilities"][token_num][token_option]["tokenId"]
|
||||||
|
else:
|
||||||
|
self.actions[action_id]["Probabilities"][token_num][token_option]["Used"] = False
|
||||||
if "Options" in self.actions[i]:
|
if "Options" in self.actions[i]:
|
||||||
for j in range(len(self.actions[i]["Options"])):
|
for j in range(len(self.actions[i]["Options"])):
|
||||||
if self.actions[i]["Options"][j]["text"] == text:
|
if self.actions[i]["Options"][j]["text"] == text:
|
||||||
@@ -1490,14 +1496,20 @@ class KoboldStoryRegister(object):
|
|||||||
if action_id_offset > 0:
|
if action_id_offset > 0:
|
||||||
if self.actions[action_id_offset-1]['Selected Text'][-1] == " " and text[0] == " ":
|
if self.actions[action_id_offset-1]['Selected Text'][-1] == " " and text[0] == " ":
|
||||||
text = text[1:]
|
text = text[1:]
|
||||||
self.clear_unused_options()
|
self.clear_unused_options(clear_probabilities=False)
|
||||||
self.action_count+=1
|
self.action_count+=1
|
||||||
action_id = self.action_count + action_id_offset
|
action_id = self.action_count + action_id_offset
|
||||||
if action_id in self.actions:
|
if action_id in self.actions:
|
||||||
if self.actions[action_id]["Selected Text"] != text:
|
if self.actions[action_id]["Selected Text"] != text:
|
||||||
self.actions[action_id]["Selected Text"] = text
|
self.actions[action_id]["Selected Text"] = text
|
||||||
self.actions[action_id]["Probabilities"] = []
|
|
||||||
self.actions[action_id]["Time"] = self.actions[action_id].get("Time", int(time.time()))
|
self.actions[action_id]["Time"] = self.actions[action_id].get("Time", int(time.time()))
|
||||||
|
tokens = self.koboldai_vars.tokenizer.encode(text)
|
||||||
|
for token_num in range(len(self.actions[action_id]["Probabilities"])):
|
||||||
|
for token_option in range(len(self.actions[action_id]["Probabilities"][token_num])):
|
||||||
|
if token_num < len(tokens):
|
||||||
|
self.actions[action_id]["Probabilities"][token_num][token_option]["Used"] = tokens[token_num] == self.actions[action_id]["Probabilities"][token_num][token_option]["tokenId"]
|
||||||
|
else:
|
||||||
|
self.actions[action_id]["Probabilities"][token_num][token_option]["Used"] = False
|
||||||
selected_text_length = 0
|
selected_text_length = 0
|
||||||
self.actions[action_id]["Selected Text Length"] = selected_text_length
|
self.actions[action_id]["Selected Text Length"] = selected_text_length
|
||||||
for item in self.actions[action_id]["Options"]:
|
for item in self.actions[action_id]["Options"]:
|
||||||
@@ -1535,6 +1547,15 @@ class KoboldStoryRegister(object):
|
|||||||
#First let's check if we did streaming, as we can just replace those items with these
|
#First let's check if we did streaming, as we can just replace those items with these
|
||||||
old_options = copy.deepcopy(self.actions[self.action_count+1]["Options"])
|
old_options = copy.deepcopy(self.actions[self.action_count+1]["Options"])
|
||||||
i=-1
|
i=-1
|
||||||
|
|
||||||
|
#First since the probabilities are run first we could have a dummy option in our options list. Lets look for that and kill it (after grabing the probabilities
|
||||||
|
probabilities = []
|
||||||
|
for option in self.actions[self.action_count+1]["Options"]:
|
||||||
|
if 'temp_prob' in option:
|
||||||
|
probabilities = option['Probabilities']
|
||||||
|
self.actions[self.action_count+1]["Options"] = []
|
||||||
|
break
|
||||||
|
|
||||||
for option in option_list:
|
for option in option_list:
|
||||||
i+=1
|
i+=1
|
||||||
found = False
|
found = False
|
||||||
@@ -1543,6 +1564,13 @@ class KoboldStoryRegister(object):
|
|||||||
item['text'] = option
|
item['text'] = option
|
||||||
del item['stream_id']
|
del item['stream_id']
|
||||||
found = True
|
found = True
|
||||||
|
tokens = self.koboldai_vars.tokenizer.encode(option)
|
||||||
|
for token_num in range(len(item["Probabilities"])):
|
||||||
|
for token_option in range(len(item["Probabilities"][token_num])):
|
||||||
|
if token_num < len(tokens):
|
||||||
|
item["Probabilities"][token_num][token_option]["Used"] = tokens[token_num] == item["Probabilities"][token_num][token_option]["tokenId"]
|
||||||
|
else:
|
||||||
|
item["Probabilities"][token_num][token_option]["Used"] = False
|
||||||
break
|
break
|
||||||
elif item['text'] == option:
|
elif item['text'] == option:
|
||||||
found = True
|
found = True
|
||||||
@@ -1552,7 +1580,7 @@ class KoboldStoryRegister(object):
|
|||||||
break
|
break
|
||||||
|
|
||||||
if not found:
|
if not found:
|
||||||
self.actions[self.action_count+1]['Options'].append({"text": option, "Pinned": False, "Previous Selection": False, "Edited": False, "Probabilities": []})
|
self.actions[self.action_count+1]['Options'].append({"text": option, "Pinned": False, "Previous Selection": False, "Edited": False, "Probabilities": probabilities})
|
||||||
else:
|
else:
|
||||||
old_options = None
|
old_options = None
|
||||||
self.actions[self.action_count+1] = {
|
self.actions[self.action_count+1] = {
|
||||||
@@ -1583,7 +1611,7 @@ class KoboldStoryRegister(object):
|
|||||||
self.actions[action_id]["Options"].append(item)
|
self.actions[action_id]["Options"].append(item)
|
||||||
process_variable_changes(self.socketio, "story", 'actions', {"id": action_id, 'action': self.actions[action_id]}, None)
|
process_variable_changes(self.socketio, "story", 'actions', {"id": action_id, 'action': self.actions[action_id]}, None)
|
||||||
|
|
||||||
def clear_unused_options(self, pointer=None):
|
def clear_unused_options(self, pointer=None, clear_probabilities=True):
|
||||||
new_options = []
|
new_options = []
|
||||||
old_options = None
|
old_options = None
|
||||||
if pointer is None:
|
if pointer is None:
|
||||||
@@ -1592,6 +1620,8 @@ class KoboldStoryRegister(object):
|
|||||||
old_options = copy.deepcopy(self.actions[pointer]["Options"])
|
old_options = copy.deepcopy(self.actions[pointer]["Options"])
|
||||||
self.actions[pointer]["Options"] = [x for x in self.actions[pointer]["Options"] if x["Pinned"] or x["Previous Selection"] or x["Edited"]]
|
self.actions[pointer]["Options"] = [x for x in self.actions[pointer]["Options"] if x["Pinned"] or x["Previous Selection"] or x["Edited"]]
|
||||||
new_options = self.actions[pointer]["Options"]
|
new_options = self.actions[pointer]["Options"]
|
||||||
|
if clear_probabilities:
|
||||||
|
self.actions[pointer]['Probabilities'] = []
|
||||||
process_variable_changes(self.socketio, "story", 'actions', {"id": pointer, 'action': self.actions[pointer]}, None)
|
process_variable_changes(self.socketio, "story", 'actions', {"id": pointer, 'action': self.actions[pointer]}, None)
|
||||||
self.set_game_saved()
|
self.set_game_saved()
|
||||||
|
|
||||||
@@ -1720,7 +1750,17 @@ class KoboldStoryRegister(object):
|
|||||||
#other way to figure out wich spot in our options list we're on. We'll figure it out by seeing how many
|
#other way to figure out wich spot in our options list we're on. We'll figure it out by seeing how many
|
||||||
#tokens we generated vs how many each option should take
|
#tokens we generated vs how many each option should take
|
||||||
stream_offset = int((self.koboldai_vars.generated_tkns-1) / self.koboldai_vars.genamt)
|
stream_offset = int((self.koboldai_vars.generated_tkns-1) / self.koboldai_vars.genamt)
|
||||||
|
else:
|
||||||
|
stream_offset = 0
|
||||||
if self.action_count+1 in self.actions:
|
if self.action_count+1 in self.actions:
|
||||||
|
#First since the probabilities are run first we could have a dummy option in our options list. Lets look for that and kill it (after grabing the probabilities
|
||||||
|
probabilities = []
|
||||||
|
for option in self.actions[self.action_count+1]["Options"]:
|
||||||
|
if 'temp_prob' in option:
|
||||||
|
probabilities = option['Probabilities']
|
||||||
|
logger.info("Found temp probability")
|
||||||
|
self.actions[self.action_count+1]["Options"] = []
|
||||||
|
break
|
||||||
for i in range(len(text_list)):
|
for i in range(len(text_list)):
|
||||||
found = False
|
found = False
|
||||||
for j in range(len(self.actions[self.action_count+1]['Options'])):
|
for j in range(len(self.actions[self.action_count+1]['Options'])):
|
||||||
@@ -1729,7 +1769,8 @@ class KoboldStoryRegister(object):
|
|||||||
found = True
|
found = True
|
||||||
self.actions[self.action_count+1]['Options'][j]['text'] = "{}{}".format(self.actions[self.action_count+1]['Options'][j]['text'], text_list[i])
|
self.actions[self.action_count+1]['Options'][j]['text'] = "{}{}".format(self.actions[self.action_count+1]['Options'][j]['text'], text_list[i])
|
||||||
if not found:
|
if not found:
|
||||||
self.actions[self.action_count+1]['Options'].append({"text": text_list[i], "Pinned": False, "Previous Selection": False, "Edited": False, "Probabilities": [], "stream_id": i+stream_offset})
|
self.actions[self.action_count+1]['Options'].append({"text": text_list[i], "Pinned": False, "Previous Selection": False, "Edited": False, "Probabilities": probabilities, "stream_id": i+stream_offset})
|
||||||
|
probabilities = []
|
||||||
else:
|
else:
|
||||||
self.actions[self.action_count+1] = {"Selected Text": "", "Selected Text Length": 0, "Options": [], "Time": int(time.time())}
|
self.actions[self.action_count+1] = {"Selected Text": "", "Selected Text Length": 0, "Options": [], "Time": int(time.time())}
|
||||||
for i in range(len(text_list)):
|
for i in range(len(text_list)):
|
||||||
@@ -1772,8 +1813,19 @@ class KoboldStoryRegister(object):
|
|||||||
if action_id is None:
|
if action_id is None:
|
||||||
action_id = self.action_count+1
|
action_id = self.action_count+1
|
||||||
if action_id in self.actions:
|
if action_id in self.actions:
|
||||||
|
if 'Probabilities' not in self.actions[action_id]:
|
||||||
|
self.actions[action_id]['Probabilities'] = []
|
||||||
self.actions[action_id]['Probabilities'].append(probabilities)
|
self.actions[action_id]['Probabilities'].append(probabilities)
|
||||||
process_variable_changes(self.socketio, "story", 'actions', {"id": action_id, 'action': self.actions[action_id]}, None)
|
else:
|
||||||
|
self.actions[action_id] = {
|
||||||
|
"Selected Text": "",
|
||||||
|
"Selected Text Length": 0,
|
||||||
|
"Options": [],
|
||||||
|
"Probabilities": [probabilities],
|
||||||
|
"Time": int(time.time()),
|
||||||
|
}
|
||||||
|
|
||||||
|
process_variable_changes(self.socketio, "story", 'actions', {"id": action_id, 'action': self.actions[action_id]}, None)
|
||||||
|
|
||||||
def set_option_probabilities(self, probabilities, option_number, action_id=None):
|
def set_option_probabilities(self, probabilities, option_number, action_id=None):
|
||||||
if action_id is None:
|
if action_id is None:
|
||||||
@@ -1785,6 +1837,13 @@ class KoboldStoryRegister(object):
|
|||||||
self.actions[action_id]["Options"][option_number]["Probabilities"] = []
|
self.actions[action_id]["Options"][option_number]["Probabilities"] = []
|
||||||
self.actions[action_id]["Options"][option_number]['Probabilities'].append(probabilities)
|
self.actions[action_id]["Options"][option_number]['Probabilities'].append(probabilities)
|
||||||
process_variable_changes(self.socketio, "story", 'actions', {"id": action_id, 'action': self.actions[action_id]}, None)
|
process_variable_changes(self.socketio, "story", 'actions', {"id": action_id, 'action': self.actions[action_id]}, None)
|
||||||
|
else:
|
||||||
|
self.actions[action_id] = {
|
||||||
|
"Selected Text": "",
|
||||||
|
"Selected Text Length": 0,
|
||||||
|
"Options": [{"temp_prob": True, "text": "", "Pinned": False, "Previous Selection": False, "Edited": False, "Probabilities": [probabilities]}],
|
||||||
|
"Time": int(time.time()),
|
||||||
|
}
|
||||||
|
|
||||||
def to_sentences(self, submitted_text=None):
|
def to_sentences(self, submitted_text=None):
|
||||||
"""Return a list of the actions split into sentences.
|
"""Return a list of the actions split into sentences.
|
||||||
|
@@ -447,9 +447,6 @@ function process_actions_data(data) {
|
|||||||
actions_data[parseInt(action.id)] = action.action;
|
actions_data[parseInt(action.id)] = action.action;
|
||||||
do_story_text_updates(action);
|
do_story_text_updates(action);
|
||||||
create_options(action);
|
create_options(action);
|
||||||
if ('Probabilities' in action.action) {
|
|
||||||
do_probabilities(action);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
clearTimeout(game_text_scroll_timeout);
|
clearTimeout(game_text_scroll_timeout);
|
||||||
@@ -623,48 +620,6 @@ function do_story_text_length_updates(action) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function do_probabilities(action) {
|
|
||||||
//console.log(data);
|
|
||||||
if (document.getElementById('probabilities_'+action.id)) {
|
|
||||||
prob_area = document.getElementById('probabilities_'+action.id)
|
|
||||||
} else {
|
|
||||||
probabilities = document.getElementById('probabilities');
|
|
||||||
prob_area = document.createElement('span');
|
|
||||||
prob_area.id = 'probabilities_'+action.id;
|
|
||||||
probabilities.append(prob_area);
|
|
||||||
}
|
|
||||||
//Clear
|
|
||||||
while (prob_area.firstChild) {
|
|
||||||
prob_area.removeChild(prob_area.lastChild);
|
|
||||||
}
|
|
||||||
//create table
|
|
||||||
table = document.createElement("table");
|
|
||||||
table.border=1;
|
|
||||||
if ("Probabilities" in action.action) {
|
|
||||||
for (token of action.action.Probabilities) {
|
|
||||||
actual_text = document.createElement("td");
|
|
||||||
actual_text.setAttribute("rowspan", token.length);
|
|
||||||
actual_text.textContent = "Word Goes Here";
|
|
||||||
for (const [index, word] of token.entries()) {
|
|
||||||
tr = document.createElement("tr");
|
|
||||||
if (index == 0) {
|
|
||||||
tr.append(actual_text);
|
|
||||||
}
|
|
||||||
decoded = document.createElement("td");
|
|
||||||
decoded.textContent = word.decoded;
|
|
||||||
tr.append(decoded);
|
|
||||||
score = document.createElement("td");
|
|
||||||
score.textContent = (word.score*100).toFixed(2)+"%";
|
|
||||||
tr.append(score);
|
|
||||||
table.append(tr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
prob_area.append(table);
|
|
||||||
|
|
||||||
//prob_area.textContent = data.value.action["Probabilities"];
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function save_story() { socket.emit("save_story", null, response => save_as_story(response)); }
|
function save_story() { socket.emit("save_story", null, response => save_as_story(response)); }
|
||||||
function load_story_list() { socket.emit("load_story_list", ""); }
|
function load_story_list() { socket.emit("load_story_list", ""); }
|
||||||
|
@@ -106,9 +106,6 @@
|
|||||||
<span class="setting_minlabel"><span style="top: -4px; position: relative;"></span></span>
|
<span class="setting_minlabel"><span style="top: -4px; position: relative;"></span></span>
|
||||||
<span class="setting_maxlabel"><span style="top: -4px; position: relative;"></span></span>
|
<span class="setting_maxlabel"><span style="top: -4px; position: relative;"></span></span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
<div id="probabilities">
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<span id="debug-dump" class="cursor" onclick="openPopup('debug-file-prompt');">Download debug dump</span>
|
<span id="debug-dump" class="cursor" onclick="openPopup('debug-file-prompt');">Download debug dump</span>
|
||||||
<div id="Images">
|
<div id="Images">
|
||||||
|
Reference in New Issue
Block a user