mirror of
https://github.com/KoboldAI/KoboldAI-Client.git
synced 2025-06-05 21:59:24 +02:00
Additional speed increase
This commit is contained in:
@@ -154,6 +154,7 @@ class koboldai_vars(object):
|
|||||||
self._model_settings.reset_for_model_load()
|
self._model_settings.reset_for_model_load()
|
||||||
|
|
||||||
def calc_ai_text(self, submitted_text="", return_text=False):
|
def calc_ai_text(self, submitted_text="", return_text=False):
|
||||||
|
start_time = time.time()
|
||||||
if self.alt_gen:
|
if self.alt_gen:
|
||||||
method = 2
|
method = 2
|
||||||
else:
|
else:
|
||||||
@@ -380,6 +381,8 @@ class koboldai_vars(object):
|
|||||||
|
|
||||||
self.context = context
|
self.context = context
|
||||||
|
|
||||||
|
logger.debug("Calc_AI_text: {}s".format(time.time()-start_time))
|
||||||
|
|
||||||
if return_text:
|
if return_text:
|
||||||
return text
|
return text
|
||||||
return tokens, used_tokens, used_tokens+self.genamt, used_world_info
|
return tokens, used_tokens, used_tokens+self.genamt, used_world_info
|
||||||
@@ -452,6 +455,7 @@ class settings(object):
|
|||||||
if 'no_save' in self.__dict__:
|
if 'no_save' in self.__dict__:
|
||||||
setattr(self, 'no_save', True)
|
setattr(self, 'no_save', True)
|
||||||
for key, value in json_data.items():
|
for key, value in json_data.items():
|
||||||
|
start_time = time.time()
|
||||||
if key in self.__dict__ and key not in self.no_save_variables:
|
if key in self.__dict__ and key not in self.no_save_variables:
|
||||||
if key == 'sampler_order':
|
if key == 'sampler_order':
|
||||||
if(len(value) < 7):
|
if(len(value) < 7):
|
||||||
@@ -476,7 +480,7 @@ class settings(object):
|
|||||||
getattr(self, key).load_json(value)
|
getattr(self, key).load_json(value)
|
||||||
else:
|
else:
|
||||||
setattr(self, key, value)
|
setattr(self, key, value)
|
||||||
|
logger.debug("Processing {}: {}s".format(key, time.time()-start_time))
|
||||||
if 'no_save' in self.__dict__:
|
if 'no_save' in self.__dict__:
|
||||||
setattr(self, 'no_save', False)
|
setattr(self, 'no_save', False)
|
||||||
|
|
||||||
@@ -1085,20 +1089,32 @@ class KoboldStoryRegister(object):
|
|||||||
return {"action_count": self.action_count, "actions": self.actions}
|
return {"action_count": self.action_count, "actions": self.actions}
|
||||||
|
|
||||||
def load_json(self, json_data):
|
def load_json(self, json_data):
|
||||||
|
start_time = time.time()
|
||||||
if type(json_data) == str:
|
if type(json_data) == str:
|
||||||
import json
|
import json
|
||||||
json_data = json.loads(json_data)
|
json_data = json.loads(json_data)
|
||||||
|
logger.debug("json to dict: {}s".format(time.time()-start_time))
|
||||||
#JSON forces keys to be strings, so let's fix that
|
#JSON forces keys to be strings, so let's fix that
|
||||||
|
start_time = time.time()
|
||||||
temp = {}
|
temp = {}
|
||||||
for item in json_data['actions']:
|
for item in json_data['actions']:
|
||||||
temp[int(item)] = json_data['actions'][item]
|
temp[int(item)] = json_data['actions'][item]
|
||||||
process_variable_changes(self.socketio, "story", 'actions', {"id": item, 'action': temp[int(item)]}, None)
|
process_variable_changes(self.socketio, "story", 'actions', {"id": item, 'action': temp[int(item)]}, None)
|
||||||
|
|
||||||
|
logger.debug("fixing key to int and sending to client: {}s".format(time.time()-start_time))
|
||||||
|
start_time = time.time()
|
||||||
self.action_count = json_data['action_count']
|
self.action_count = json_data['action_count']
|
||||||
self.actions = temp
|
self.actions = temp
|
||||||
|
logger.debug("Saving action var: {}s".format(time.time()-start_time))
|
||||||
|
start_time = time.time()
|
||||||
self.set_game_saved()
|
self.set_game_saved()
|
||||||
|
logger.debug("set_game_saved: {}s".format(time.time()-start_time))
|
||||||
|
start_time = time.time()
|
||||||
self.recalc_token_length()
|
self.recalc_token_length()
|
||||||
|
logger.debug("recalc_token_length: {}s".format(time.time()-start_time))
|
||||||
|
start_time = time.time()
|
||||||
self.story_settings.save_story()
|
self.story_settings.save_story()
|
||||||
|
logger.debug("save_story: {}s".format(time.time()-start_time))
|
||||||
|
|
||||||
|
|
||||||
def append(self, text):
|
def append(self, text):
|
||||||
@@ -1311,6 +1327,7 @@ class KoboldStoryRegister(object):
|
|||||||
def recalc_token_length(self):
|
def recalc_token_length(self):
|
||||||
if self.tokenizer is not None:
|
if self.tokenizer is not None:
|
||||||
for key in self.actions:
|
for key in self.actions:
|
||||||
|
if self.actions[key]['In AI Input']:
|
||||||
self.actions[key]['Selected Text Length'] = len(self.tokenizer.encode(self.actions[key]['Selected Text']))
|
self.actions[key]['Selected Text Length'] = len(self.tokenizer.encode(self.actions[key]['Selected Text']))
|
||||||
process_variable_changes(self.socketio, "story", 'actions', {"id": key, 'action': self.actions[key]}, None)
|
process_variable_changes(self.socketio, "story", 'actions', {"id": key, 'action': self.actions[key]}, None)
|
||||||
else:
|
else:
|
||||||
@@ -1385,6 +1402,7 @@ class KoboldStoryRegister(object):
|
|||||||
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 to_sentences(self):
|
def to_sentences(self):
|
||||||
|
start_time = time.time()
|
||||||
#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
|
#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]['Selected Text'] 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
|
actions[-1] = self.story_settings.prompt
|
||||||
@@ -1425,6 +1443,7 @@ class KoboldStoryRegister(object):
|
|||||||
break
|
break
|
||||||
Sentence_Position[1] = len(action_text_split[Sentence_Position[0]][0])
|
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]]
|
#OK, action_text_split now contains a list of [sentence including trailing space if needed, [action IDs that sentence includes]]
|
||||||
|
logger.debug("to_sentences: {}s".format(time.time()-start_time))
|
||||||
return action_text_split
|
return action_text_split
|
||||||
|
|
||||||
def __setattr__(self, name, value):
|
def __setattr__(self, name, value):
|
||||||
|
Reference in New Issue
Block a user