From 487739911ab11049214feb40ef50c672eefc6c85 Mon Sep 17 00:00:00 2001 From: henk717 Date: Wed, 8 Mar 2023 18:44:03 +0100 Subject: [PATCH 01/18] Restore Pygmalion 6B Dev --- colab/TPU.ipynb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/colab/TPU.ipynb b/colab/TPU.ipynb index 3976f6dd..96207af4 100644 --- a/colab/TPU.ipynb +++ b/colab/TPU.ipynb @@ -66,7 +66,7 @@ "#@title <-- Select your model below and then click this to start KoboldAI\n", "#@markdown You can find a description of the models below along with instructions on how to start KoboldAI.\n", "\n", - "Model = \"Nerys 13B V2\" #@param [\"Nerys 13B V2\", \"Nerybus 13B\", \"Erebus 13B\", \"Janeway 13B\", \"Shinen 13B\", \"Skein 20B\", \"Erebus 20B\", \"Skein 6B\", \"Janeway 6B\", \"Adventure 6B\", \"Shinen 6B\", \"Pygmalion 6B\", \"Lit V2 6B\", \"Lit 6B\", \"NeoX 20B\", \"OPT 13B\", \"Fairseq Dense 13B\", \"GPT-J-6B\"] {allow-input: true}\n", + "Model = \"Nerys 13B V2\" #@param [\"Nerys 13B V2\", \"Nerybus 13B\", \"Erebus 13B\", \"Janeway 13B\", \"Shinen 13B\", \"Skein 20B\", \"Erebus 20B\", \"Skein 6B\", \"Janeway 6B\", \"Adventure 6B\", \"Shinen 6B\", \"Pygmalion 6B\", \"Pygmalion 6B Dev\", \"Lit V2 6B\", \"Lit 6B\", \"NeoX 20B\", \"OPT 13B\", \"Fairseq Dense 13B\", \"GPT-J-6B\"] {allow-input: true}\n", "Version = \"Official\" #@param [\"Official\", \"United\"] {allow-input: true}\n", "Provider = \"Cloudflare\" #@param [\"Localtunnel\", \"Cloudflare\"]\n", "use_google_drive = True #@param {type:\"boolean\"}\n", @@ -177,7 +177,7 @@ "else:\n", " tunnel = \"\"\n", "\n", - "!wget https://koboldai.org/ckds -O - | bash /dev/stdin $path$download -m $Model -g $Version $tunnel" + "!wget https://koboldai.org/ckds -O - | bash /dev/stdin $path$download -m $Model -g $Version $tunnel $Revision" ] }, { From ffa5c0bc13ae98f10d521da3cdec665337a87bf1 Mon Sep 17 00:00:00 2001 From: henk717 Date: Wed, 8 Mar 2023 20:52:03 +0100 Subject: [PATCH 02/18] Empty Revision Fix --- colab/TPU.ipynb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/colab/TPU.ipynb b/colab/TPU.ipynb index 96207af4..131b134a 100644 --- a/colab/TPU.ipynb +++ b/colab/TPU.ipynb @@ -89,6 +89,8 @@ " if not os.path.exists(\"/content/drive/MyDrive/\"):\n", " os.mkdir(\"/content/drive/MyDrive/\")\n", "\n", + "Revision = \"\"\n", + "\n", "if Model == \"Janeway 13B\":\n", " Model = \"KoboldAI/fairseq-dense-13B-Janeway\"\n", " path = \"\"\n", From 4371de2c117d99c7be63aeee240d9c5868469fe3 Mon Sep 17 00:00:00 2001 From: YellowRoseCx <80486540+YellowRoseCx@users.noreply.github.com> Date: Wed, 8 Mar 2023 15:35:55 -0600 Subject: [PATCH 03/18] added rng_states variable added rng_states variable to fix an error caused by passing a seed through the API without having a seed already in use --- koboldai_settings.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/koboldai_settings.py b/koboldai_settings.py index e921b307..300cd658 100644 --- a/koboldai_settings.py +++ b/koboldai_settings.py @@ -1202,12 +1202,12 @@ class system_settings(settings): local_only_variables = ['lua_state', 'lua_logname', 'lua_koboldbridge', 'lua_kobold', 'lua_koboldcore', 'regex_sl', 'acregex_ai', 'acregex_ui', 'comregex_ai', 'comregex_ui', 'sp', '_horde_pid', 'inference_config', 'image_pipeline', - 'summarizer', 'summary_tokenizer', 'tts_model'] + 'summarizer', 'summary_tokenizer', 'tts_model', 'rng_states'] no_save_variables = ['lua_state', 'lua_logname', 'lua_koboldbridge', 'lua_kobold', 'lua_koboldcore', 'sp', 'sp_length', '_horde_pid', 'horde_share', 'aibusy', 'serverstarted', 'inference_config', 'image_pipeline', 'summarizer', 'summary_tokenizer', 'use_colab_tpu', 'noai', 'disable_set_aibusy', 'cloudflare_link', 'tts_model', - 'generating_image', 'bit_8_available', 'host', 'hascuda', 'usegpu'] + 'generating_image', 'bit_8_available', 'host', 'hascuda', 'usegpu', 'rng_states'] settings_name = "system" def __init__(self, socketio, koboldai_var): self._socketio = socketio @@ -1263,6 +1263,7 @@ class system_settings(settings): self.disable_output_formatting = False self.full_determinism = False # Whether or not full determinism is enabled self.seed_specified = False # Whether or not the current RNG seed was specified by the user (in their settings file) + self.rng_states = {} # creates an empty dictionary to store the random number generator (RNG) states for a given seed, which is used to restore the RNG state later on self.seed = None # The current RNG seed (as an int), or None if unknown self.alt_gen = False # Use the calc_ai_text method for generating text to go to the AI self.theme_list = [".".join(f.split(".")[:-1]) for f in os.listdir("./themes") if os.path.isfile(os.path.join("./themes", f))] From c5607110ee47ae3b68c340a6056c8843b035d767 Mon Sep 17 00:00:00 2001 From: YellowRoseCx <80486540+YellowRoseCx@users.noreply.github.com> Date: Wed, 8 Mar 2023 15:36:30 -0600 Subject: [PATCH 04/18] typo fix fixed typo of "specfic" to "specific" --- gensettings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gensettings.py b/gensettings.py index 5b1dea42..863a2ba5 100644 --- a/gensettings.py +++ b/gensettings.py @@ -825,7 +825,7 @@ gensettingstf = [ "max": 1, "step": 1, "default": 0, - "tooltip": "If enabled a specfic seed will be used for the random generator on text generation", + "tooltip": "If enabled, a specific seed will be used for the random generator on text generation", "menu_path": "Settings", "sub_path": "Other", "classname": "system", From 0d1771501fff3b8f315bb65aa610b7ec7fedaa69 Mon Sep 17 00:00:00 2001 From: SillyLossy Date: Thu, 9 Mar 2023 13:15:50 +0200 Subject: [PATCH 05/18] Fix setting softprompt via V1 API --- aiserver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aiserver.py b/aiserver.py index 80ccd1d7..7c60b04e 100644 --- a/aiserver.py +++ b/aiserver.py @@ -10510,7 +10510,7 @@ def soft_prompt_validator(soft_prompt: str): raise ValidationError("Cannot use soft prompts with current backend.") if any(q in soft_prompt for q in ("/", "\\")): return - z, _, _, _, _ = fileops.checksp(soft_prompt.strip(), koboldai_vars.modeldim) + z, _, _, _, _ = fileops.checksp("./softprompts/"+soft_prompt.strip(), koboldai_vars.modeldim) if isinstance(z, int): raise ValidationError("Must be a valid soft prompt name.") z.close() From 423c0226488fd6dc8870ee362247aedf3a8a5767 Mon Sep 17 00:00:00 2001 From: jojorne Date: Sat, 11 Mar 2023 13:14:46 -0300 Subject: [PATCH 06/18] Fix save loading between v1 and v2 to v3 with wi features --- aiserver.py | 83 +++++++++++++++++++++++--------------------- koboldai_settings.py | 59 +++++++++++++++---------------- 2 files changed, 74 insertions(+), 68 deletions(-) diff --git a/aiserver.py b/aiserver.py index 7c60b04e..08bdafc0 100644 --- a/aiserver.py +++ b/aiserver.py @@ -4394,11 +4394,11 @@ def get_message(msg): emit('from_server', {'cmd': 'wiexpandfolder', 'data': msg['data']}, broadcast=True, room="UI_1") elif(msg['cmd'] == 'wifoldercollapsecontent'): setgamesaved(False) - koboldai_vars.wifolders_d[msg['data']]['collapsed'] = True + koboldai_vars.wifolders_d[str(msg['data'])]['collapsed'] = True emit('from_server', {'cmd': 'wifoldercollapsecontent', 'data': msg['data']}, broadcast=True, room="UI_1") elif(msg['cmd'] == 'wifolderexpandcontent'): setgamesaved(False) - koboldai_vars.wifolders_d[msg['data']]['collapsed'] = False + koboldai_vars.wifolders_d[str(msg['data'])]['collapsed'] = False emit('from_server', {'cmd': 'wifolderexpandcontent', 'data': msg['data']}, broadcast=True, room="UI_1") elif(msg['cmd'] == 'wiupdate'): setgamesaved(False) @@ -4410,12 +4410,12 @@ def get_message(msg): emit('from_server', {'cmd': 'wiupdate', 'num': msg['num'], 'data': {field: koboldai_vars.worldinfo[num][field] for field in fields}}, broadcast=True, room="UI_1") elif(msg['cmd'] == 'wifolderupdate'): setgamesaved(False) - uid = str(msg['uid']) + str_uid = str(msg['uid']) fields = ("name", "collapsed") for field in fields: if(field in msg['data'] and type(msg['data'][field]) is (str if field != "collapsed" else bool)): - koboldai_vars.wifolders_d[uid][field] = msg['data'][field] - emit('from_server', {'cmd': 'wifolderupdate', 'uid': msg['uid'], 'data': {field: koboldai_vars.wifolders_d[uid][field] for field in fields}}, broadcast=True, room="UI_1") + koboldai_vars.wifolders_d[str_uid][field] = msg['data'][field] + emit('from_server', {'cmd': 'wifolderupdate', 'uid': msg['uid'], 'data': {field: koboldai_vars.wifolders_d[str_uid][field] for field in fields}}, broadcast=True, room="UI_1") elif(msg['cmd'] == 'wiselon'): setgamesaved(False) koboldai_vars.worldinfo[msg['data']]["selective"] = True @@ -6756,7 +6756,8 @@ def togglewimode(): # #==================================================================# def addwiitem(folder_uid=None): - assert folder_uid is None or folder_uid in koboldai_vars.wifolders_d + str_folder_uid = str(folder_uid) if folder_uid is not None else None + assert str_folder_uid is None or str_folder_uid in koboldai_vars.wifolders_d ob = {"key": "", "keysecondary": "", "content": "", "comment": "", "folder": folder_uid, "num": len(koboldai_vars.worldinfo), "init": False, "selective": False, "constant": False} koboldai_vars.worldinfo.append(ob) while(True): @@ -6764,9 +6765,9 @@ def addwiitem(folder_uid=None): if(uid not in koboldai_vars.worldinfo_u): break koboldai_vars.worldinfo_u[uid] = koboldai_vars.worldinfo[-1] - koboldai_vars.worldinfo[-1]["uid"] = uid - if(folder_uid is not None): - koboldai_vars.wifolders_u[folder_uid].append(koboldai_vars.worldinfo[-1]) + koboldai_vars.worldinfo[-1]["uid"] = int(uid) + if(str_folder_uid is not None): + koboldai_vars.wifolders_u[str_folder_uid].append(koboldai_vars.worldinfo[-1]) emit('from_server', {'cmd': 'addwiitem', 'data': ob}, broadcast=True, room="UI_1") #==================================================================# @@ -6779,10 +6780,10 @@ def addwifolder(): break ob = {"name": "", "collapsed": False} koboldai_vars.wifolders_d[uid] = ob - koboldai_vars.wifolders_l.append(uid) + koboldai_vars.wifolders_l.append(int(uid)) koboldai_vars.wifolders_u[uid] = [] - emit('from_server', {'cmd': 'addwifolder', 'uid': uid, 'data': ob}, broadcast=True, room="UI_1") - addwiitem(folder_uid=uid) + emit('from_server', {'cmd': 'addwifolder', 'uid': int(uid), 'data': ob}, broadcast=True, room="UI_1") + addwiitem(folder_uid=int(uid)) #==================================================================# # Move the WI entry with UID src so that it immediately precedes @@ -6886,14 +6887,14 @@ def stablesortwi(): #==================================================================# def commitwi(ar): for ob in ar: - ob["uid"] = str(ob["uid"]) - koboldai_vars.worldinfo_u[ob["uid"]]["key"] = ob["key"] - koboldai_vars.worldinfo_u[ob["uid"]]["keysecondary"] = ob["keysecondary"] - koboldai_vars.worldinfo_u[ob["uid"]]["content"] = ob["content"] - koboldai_vars.worldinfo_u[ob["uid"]]["comment"] = ob.get("comment", "") - koboldai_vars.worldinfo_u[ob["uid"]]["folder"] = ob.get("folder", None) - koboldai_vars.worldinfo_u[ob["uid"]]["selective"] = ob["selective"] - koboldai_vars.worldinfo_u[ob["uid"]]["constant"] = ob.get("constant", False) + str_uid = str(ob["uid"]) + koboldai_vars.worldinfo_u[str_uid]["key"] = ob["key"] + koboldai_vars.worldinfo_u[str_uid]["keysecondary"] = ob["keysecondary"] + koboldai_vars.worldinfo_u[str_uid]["content"] = ob["content"] + koboldai_vars.worldinfo_u[str_uid]["comment"] = ob.get("comment", "") + koboldai_vars.worldinfo_u[str_uid]["folder"] = ob.get("folder", None) + koboldai_vars.worldinfo_u[str_uid]["selective"] = ob["selective"] + koboldai_vars.worldinfo_u[str_uid]["constant"] = ob.get("constant", False) stablesortwi() koboldai_vars.worldinfo_i = [wi for wi in koboldai_vars.worldinfo if wi["init"]] koboldai_vars.sync_worldinfo_v1_to_v2() @@ -6903,20 +6904,22 @@ def commitwi(ar): # #==================================================================# def deletewi(uid): - if(uid in koboldai_vars.worldinfo_u): + if(str(uid) in koboldai_vars.worldinfo_u): setgamesaved(False) # Store UID of deletion request koboldai_vars.deletewi = uid if(koboldai_vars.deletewi is not None): - if(koboldai_vars.worldinfo_u[koboldai_vars.deletewi]["folder"] is not None): - for i, e in enumerate(koboldai_vars.wifolders_u[koboldai_vars.worldinfo_u[koboldai_vars.deletewi]["folder"]]): - if(e is koboldai_vars.worldinfo_u[koboldai_vars.deletewi]): - koboldai_vars.wifolders_u[koboldai_vars.worldinfo_u[koboldai_vars.deletewi]["folder"]].pop(i) + str_uid = str(uid) + if(koboldai_vars.worldinfo_u[str_uid]["folder"] is not None): + str_folder_uid = str(koboldai_vars.worldinfo_u[str_uid]["folder"]) + for i, e in enumerate(koboldai_vars.wifolders_u[str_folder_uid]): + if(e is koboldai_vars.worldinfo_u[str_uid]): + koboldai_vars.wifolders_u[str_folder_uid].pop(i) for i, e in enumerate(koboldai_vars.worldinfo): - if(e is koboldai_vars.worldinfo_u[koboldai_vars.deletewi]): + if(e is koboldai_vars.worldinfo_u[str_uid]): del koboldai_vars.worldinfo[i] break - del koboldai_vars.worldinfo_u[koboldai_vars.deletewi] + del koboldai_vars.worldinfo_u[str_uid] # Send the new WI array structure sendwi() # And reset deletewi @@ -6926,9 +6929,9 @@ def deletewi(uid): # #==================================================================# def deletewifolder(uid): - uid = str(uid) - del koboldai_vars.wifolders_u[uid] - del koboldai_vars.wifolders_d[uid] + str_uid = str(uid) + del koboldai_vars.wifolders_u[str_uid] + del koboldai_vars.wifolders_d[str_uid] del koboldai_vars.wifolders_l[koboldai_vars.wifolders_l.index(uid)] setgamesaved(False) # Delete uninitialized entries in the folder we're going to delete @@ -7438,7 +7441,7 @@ def loadJSON(json_text_or_dict, from_file=None): ignore = koboldai_vars.calc_ai_text() def load_story_v1(js, from_file=None): - logger.debug("Loading V1 Story") + logger.info("Loading V1 Story") logger.debug("Called from {}".format(inspect.stack()[1].function)) loadpath = js['v1_loadpath'] if 'v1_loadpath' in js else koboldai_vars.savedir filename = js['v1_filename'] if 'v1_filename' in js else 'untitled.json' @@ -7467,7 +7470,7 @@ def load_story_v1(js, from_file=None): koboldai_vars.worldinfo = [] koboldai_vars.worldinfo_i = [] koboldai_vars.worldinfo_u = {} - koboldai_vars.wifolders_d = {int(k): v for k, v in js.get("wifolders_d", {}).items()} + koboldai_vars.wifolders_d = {k: v for k, v in js.get("wifolders_d", {}).items()} koboldai_vars.wifolders_l = js.get("wifolders_l", []) koboldai_vars.wifolders_u = {uid: [] for uid in koboldai_vars.wifolders_d} koboldai_vars.lastact = "" @@ -7527,8 +7530,9 @@ def load_story_v1(js, from_file=None): folder = "root" else: if 'wifolders_d' in js: - if wi['folder'] in js['wifolders_d']: - folder = js['wifolders_d'][wi['folder']]['name'] + str_folder_uid = str(wi['folder']) + if str_folder_uid in js['wifolders_d']: + folder = js['wifolders_d'][str_folder_uid]['name'] else: folder = "root" else: @@ -7567,7 +7571,7 @@ def load_story_v1(js, from_file=None): def load_story_v2(js, from_file=None): - logger.debug("Loading V2 Story") + logger.info("Loading V2 Story") logger.debug("Called from {}".format(inspect.stack()[1].function)) leave_room(session['story']) session['story'] = js['story_name'] @@ -7578,7 +7582,8 @@ def load_story_v2(js, from_file=None): if from_file is not None and os.path.basename(from_file) != "story.json": #Save the file so we get a new V2 format, then move the save file into the proper directory koboldai_vars.save_story() - shutil.move(from_file, koboldai_vars.save_paths.story.replace("story.json", "v2_file.json")) + #We're no longer moving the original file. It'll stay in place. + #shutil.move(from_file, koboldai_vars.save_paths.story.replace("story.json", "v2_file.json")) @@ -11206,7 +11211,7 @@ def get_story(): chunks = [] if koboldai_vars.gamestarted: chunks.append({"num": 0, "text": koboldai_vars.prompt}) - for num, action in koboldai_vars.actions.items(): + for num, action in koboldai_vars.actions.actions.items(): chunks.append({"num": num + 1, "text": action}) return {"results": chunks} @@ -11592,7 +11597,7 @@ def get_world_info(): if wi["folder"] != last_folder: folder = [] if wi["folder"] is not None: - folders.append({"uid": wi["folder"], "name": koboldai_vars.wifolders_d[wi["folder"]]["name"], "entries": folder}) + folders.append({"uid": wi["folder"], "name": koboldai_vars.wifolders_d[str(wi["folder"])]["name"], "entries": folder}) last_folder = wi["folder"] (folder if wi["folder"] is not None else entries).append({k: v for k, v in wi.items() if k not in ("init", "folder", "num") and (wi["selective"] or k != "keysecondary")}) return {"folders": folders, "entries": entries} @@ -11680,7 +11685,7 @@ def get_world_info_folders(): """ stablesortwi() koboldai_vars.worldinfo_i = [wi for wi in koboldai_vars.worldinfo if wi["init"]] - return {"folders": [{"uid": folder, **{k: v for k, v in koboldai_vars.wifolders_d[folder].items() if k != "collapsed"}} for folder in koboldai_vars.wifolders_l]} + return {"folders": [{"uid": folder, **{k: v for k, v in koboldai_vars.wifolders_d[str(folder)].items() if k != "collapsed"}} for folder in koboldai_vars.wifolders_l]} @api_v1.get("/world_info/folders/uids") diff --git a/koboldai_settings.py b/koboldai_settings.py index e921b307..c438d265 100644 --- a/koboldai_settings.py +++ b/koboldai_settings.py @@ -968,9 +968,9 @@ class story_settings(settings): else: logger.warning(f"Story mismatch in v2 migration. Existing file had story id {v2j['story_id']} but we have {self.story_id}") + self.gamesaved = True with open(self.save_paths.story, "w", encoding="utf-8") as file: file.write(self.to_json()) - self.gamesaved = True def update_story_path_structure(self, path: str) -> None: # Upon loading a file, makes directories that are required for certain @@ -2357,7 +2357,8 @@ class KoboldWorldInfo(object): raise if folder not in self.world_info_folder: self.world_info_folder[folder] = [] - self.world_info_folder[folder].append(uid) + if uid not in self.world_info_folder[folder]: + self.world_info_folder[folder].append(uid) self.story_settings.gamesaved = False if sync: self.sync_world_info_to_old_format() @@ -2536,14 +2537,10 @@ class KoboldWorldInfo(object): file.write(base64.b64decode(image_b64)) data["entries"] = {k: self.upgrade_entry(v) for k,v in data["entries"].items()} - - if folder is None: - self.world_info_folder = data['folders'] #Add the item start_time = time.time() for uid, item in data['entries'].items(): - self.add_item(item['title'] if 'title' in item else item['key'][0], item['key'] if 'key' in item else [], item['keysecondary'] if 'keysecondary' in item else [], @@ -2555,10 +2552,9 @@ class KoboldWorldInfo(object): use_wpp=item['use_wpp'] if 'use_wpp' in item else False, wpp=item['wpp'] if 'wpp' in item else {'name': "", 'type': "", 'format': "W++", 'attributes': {}}, object_type=item.get("object_type"), + v1_uid=item.get("v1_uid"), recalc=False, sync=False) - if folder is None: - #self.world_info = {int(x): data['entries'][x] for x in data['entries']} - self.world_info_folder = data['folders'] + logger.debug("Load World Info took {}s".format(time.time()-start_time)) try: start_time = time.time() @@ -2577,50 +2573,52 @@ class KoboldWorldInfo(object): for folder in self.world_info_folder: folder_entries[folder] = i i-=1 - - + + #self.wifolders_l = [] # List of World Info folder UIDs + self.story_settings.wifolders_l = [folder_entries[x] for x in folder_entries if x != "root"] + #self.worldinfo_i = [] # List of World Info key/value objects sans uninitialized entries self.story_settings.worldinfo_i = [{ - "comment": self.world_info[x]['comment'], - "constant": self.world_info[x]['constant'], - "content": self.world_info[x]['content'], - "folder": folder_entries[self.world_info[x]['folder']], - "init": True, "key": ",".join(self.world_info[x]['key']), "keysecondary": ",".join(self.world_info[x]['keysecondary']), + "content": self.world_info[x]['content'], + "comment": self.world_info[x]['comment'], + "folder": folder_entries[self.world_info[x]['folder']] if self.world_info[x]['folder'] != "root" else None, "num": x, + "init": True, "selective": len(self.world_info[x]['keysecondary'])>0, + "constant": self.world_info[x]['constant'], "uid": self.world_info[x]['uid'] if 'v1_uid' not in self.world_info[x] or self.world_info[x]['v1_uid'] is None else self.world_info[x]['v1_uid'] } for x in self.world_info] - + #self.worldinfo = [] # List of World Info key/value objects self.story_settings.worldinfo = [x for x in self.story_settings.worldinfo_i] #We have to have an uninitialized blank entry for every folder or the old method craps out for folder in folder_entries: self.story_settings.worldinfo.append({ - "comment": "", - "constant": False, - "content": "", - "folder": folder_entries[folder], - "init": False, "key": "", "keysecondary": "", + "content": "", + "comment": "", + "folder": folder_entries[folder] if folder != "root" else None, "num": (0 if len(self.world_info) == 0 else max(self.world_info))+(folder_entries[folder]*-1), + "init": False, "selective": False, + "constant": False, "uid": folder_entries[folder] }) + mapping = {uid: index for index, uid in enumerate(self.story_settings.wifolders_l)} + self.story_settings.worldinfo.sort(key=lambda x: mapping[x["folder"]] if x["folder"] is not None else float("inf")) + #self.wifolders_d = {} # Dictionary of World Info folder UID-info pairs - self.story_settings.wifolders_d = {folder_entries[x]: {'collapsed': False, 'name': x} for x in folder_entries} + self.story_settings.wifolders_d = {str(folder_entries[x]): {'name': x, 'collapsed': False} for x in folder_entries if x != "root"} #self.worldinfo_u = {} # Dictionary of World Info UID - key/value pairs - self.story_settings.worldinfo_u = {x['uid']: x for x in self.story_settings.worldinfo} - - #self.wifolders_l = [] # List of World Info folder UIDs - self.story_settings.wifolders_l = [folder_entries[x] for x in folder_entries] + self.story_settings.worldinfo_u = {str(y["uid"]): y for x in folder_entries for y in self.story_settings.worldinfo if y["folder"] == (folder_entries[x] if x != "root" else None)} #self.wifolders_u = {} # Dictionary of pairs of folder UID - list of WI UID - self.story_settings.wifolders_u = {folder_entries[x]: [y for y in self.story_settings.worldinfo if y['folder'] == x] for x in folder_entries} + self.story_settings.wifolders_u = {str(folder_entries[x]): [y for y in self.story_settings.worldinfo if y['folder'] == folder_entries[x]] for x in folder_entries if x != "root"} def reset_used_in_game(self): for key in self.world_info: @@ -2638,7 +2636,10 @@ class KoboldWorldInfo(object): self._socketio.emit("world_info_entry_used_in_game", {"uid": uid, "used_in_game": True}, broadcast=True, room="UI_2") def get_used_wi(self): - return [x['content'] for x in self.world_info if x['used_in_game']] + # return [self.world_info[x]['content'] for x in self.world_info if self.world_info[x]['used_in_game']] + result = [x['content'] for x in self.world_info if x['used_in_game']] + logger.warning("get_used_wi: " + str(result)) + return result def to_wi_fewshot_format(self, excluding_uid: int) -> List[str]: """ From 47242e9abeb31fdd0f275565183fc88d2a30ef06 Mon Sep 17 00:00:00 2001 From: jojorne Date: Sat, 11 Mar 2023 13:21:22 -0300 Subject: [PATCH 07/18] remove debug code --- koboldai_settings.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/koboldai_settings.py b/koboldai_settings.py index c438d265..58eba561 100644 --- a/koboldai_settings.py +++ b/koboldai_settings.py @@ -2636,10 +2636,7 @@ class KoboldWorldInfo(object): self._socketio.emit("world_info_entry_used_in_game", {"uid": uid, "used_in_game": True}, broadcast=True, room="UI_2") def get_used_wi(self): - # return [self.world_info[x]['content'] for x in self.world_info if self.world_info[x]['used_in_game']] - result = [x['content'] for x in self.world_info if x['used_in_game']] - logger.warning("get_used_wi: " + str(result)) - return result + return [self.world_info[x]['content'] for x in self.world_info if self.world_info[x]['used_in_game']] def to_wi_fewshot_format(self, excluding_uid: int) -> List[str]: """ From e4ad8547a7f4b31a89997bb0adaf5ec205f2130b Mon Sep 17 00:00:00 2001 From: jojorne Date: Sat, 11 Mar 2023 13:39:19 -0300 Subject: [PATCH 08/18] revert unrelated code --- koboldai_settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/koboldai_settings.py b/koboldai_settings.py index 58eba561..143fe203 100644 --- a/koboldai_settings.py +++ b/koboldai_settings.py @@ -2636,7 +2636,7 @@ class KoboldWorldInfo(object): self._socketio.emit("world_info_entry_used_in_game", {"uid": uid, "used_in_game": True}, broadcast=True, room="UI_2") def get_used_wi(self): - return [self.world_info[x]['content'] for x in self.world_info if self.world_info[x]['used_in_game']] + return [x['content'] for x in self.world_info if x['used_in_game']] def to_wi_fewshot_format(self, excluding_uid: int) -> List[str]: """ From c87ef60db1418a0ec48fb84880889421c47e90a2 Mon Sep 17 00:00:00 2001 From: jojorne Date: Sat, 11 Mar 2023 13:48:41 -0300 Subject: [PATCH 09/18] revert more unrelated code --- aiserver.py | 6 +++--- koboldai_settings.py | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/aiserver.py b/aiserver.py index 08bdafc0..412fce91 100644 --- a/aiserver.py +++ b/aiserver.py @@ -11211,7 +11211,7 @@ def get_story(): chunks = [] if koboldai_vars.gamestarted: chunks.append({"num": 0, "text": koboldai_vars.prompt}) - for num, action in koboldai_vars.actions.actions.items(): + for num, action in koboldai_vars.actions.items(): chunks.append({"num": num + 1, "text": action}) return {"results": chunks} @@ -11597,7 +11597,7 @@ def get_world_info(): if wi["folder"] != last_folder: folder = [] if wi["folder"] is not None: - folders.append({"uid": wi["folder"], "name": koboldai_vars.wifolders_d[str(wi["folder"])]["name"], "entries": folder}) + folders.append({"uid": wi["folder"], "name": koboldai_vars.wifolders_d[wi["folder"]]["name"], "entries": folder}) last_folder = wi["folder"] (folder if wi["folder"] is not None else entries).append({k: v for k, v in wi.items() if k not in ("init", "folder", "num") and (wi["selective"] or k != "keysecondary")}) return {"folders": folders, "entries": entries} @@ -11685,7 +11685,7 @@ def get_world_info_folders(): """ stablesortwi() koboldai_vars.worldinfo_i = [wi for wi in koboldai_vars.worldinfo if wi["init"]] - return {"folders": [{"uid": folder, **{k: v for k, v in koboldai_vars.wifolders_d[str(folder)].items() if k != "collapsed"}} for folder in koboldai_vars.wifolders_l]} + return {"folders": [{"uid": folder, **{k: v for k, v in koboldai_vars.wifolders_d[folder].items() if k != "collapsed"}} for folder in koboldai_vars.wifolders_l]} @api_v1.get("/world_info/folders/uids") diff --git a/koboldai_settings.py b/koboldai_settings.py index 143fe203..8e24e581 100644 --- a/koboldai_settings.py +++ b/koboldai_settings.py @@ -1801,7 +1801,6 @@ class KoboldStoryRegister(object): if "wi_highlighted_text" in self.actions[action_id]: del self.actions[action_id]["wi_highlighted_text"] self.actions[action_id]['Selected Text Length'] = 0 - self.action_count -= 1 process_variable_changes(self._socketio, "story", 'actions', {"id": action_id, 'action': self.actions[action_id]}, None) self.set_game_saved() logger.debug("Calcing AI Text from Action Delete") From 53f06903c222f729599afda4ffd30a3b78750e6c Mon Sep 17 00:00:00 2001 From: jojorne Date: Sat, 11 Mar 2023 13:54:01 -0300 Subject: [PATCH 10/18] revert more unrelated code --- koboldai_settings.py | 1 + 1 file changed, 1 insertion(+) diff --git a/koboldai_settings.py b/koboldai_settings.py index 8e24e581..143fe203 100644 --- a/koboldai_settings.py +++ b/koboldai_settings.py @@ -1801,6 +1801,7 @@ class KoboldStoryRegister(object): if "wi_highlighted_text" in self.actions[action_id]: del self.actions[action_id]["wi_highlighted_text"] self.actions[action_id]['Selected Text Length'] = 0 + self.action_count -= 1 process_variable_changes(self._socketio, "story", 'actions', {"id": action_id, 'action': self.actions[action_id]}, None) self.set_game_saved() logger.debug("Calcing AI Text from Action Delete") From e5c1b0506a39b46d7e836475caf426903e217e43 Mon Sep 17 00:00:00 2001 From: jojorne Date: Sun, 12 Mar 2023 20:05:40 -0300 Subject: [PATCH 11/18] Renaming the root folder is not supported --- koboldai_settings.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/koboldai_settings.py b/koboldai_settings.py index 143fe203..e5d01b37 100644 --- a/koboldai_settings.py +++ b/koboldai_settings.py @@ -2272,7 +2272,7 @@ class KoboldWorldInfo(object): def add_item_to_folder(self, uid, folder, before=None): if uid in self.world_info: - #fiirst we need to remove the item from whatever folder it's in + #first we need to remove the item from whatever folder it's in for temp in self.world_info_folder: if uid in self.world_info_folder[temp]: self.world_info_folder[temp].remove(uid) @@ -2464,6 +2464,8 @@ class KoboldWorldInfo(object): ignore = self._koboldai_vars.calc_ai_text() def rename_folder(self, old_folder, folder): + if old_folder == "root": + raise Exception("renaming the root folder is not supported") self.story_settings.gamesaved = False if folder in self.world_info_folder: i=0 From 4219e3e8d37c32d9b5e020425057d5d1098d3958 Mon Sep 17 00:00:00 2001 From: jojorne Date: Sun, 12 Mar 2023 20:38:58 -0300 Subject: [PATCH 12/18] Removing the root folder is not supported --- koboldai_settings.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/koboldai_settings.py b/koboldai_settings.py index e5d01b37..484c95fc 100644 --- a/koboldai_settings.py +++ b/koboldai_settings.py @@ -2259,6 +2259,8 @@ class KoboldWorldInfo(object): self._socketio.emit("world_info_folder", {x: self.world_info_folder[x] for x in self.world_info_folder}, broadcast=True, room="UI_2") def delete_folder(self, folder): + if folder == "root": + raise Exception("removing the root folder is not supported") keys = [key for key in self.world_info] for key in keys: if self.world_info[key]['folder'] == folder: @@ -2443,6 +2445,9 @@ class KoboldWorldInfo(object): self._socketio.emit("world_info_entry", self.world_info[uid], broadcast=True, room="UI_2") def delete(self, uid): + if self.world_info[uid]['folder'] == "root": + raise Exception("removing the root folder is not supported") + del self.world_info[uid] try: From 4b8d4cde7de1512fbf2c78ff6318ca0897425ebe Mon Sep 17 00:00:00 2001 From: jojorne Date: Sun, 12 Mar 2023 20:41:34 -0300 Subject: [PATCH 13/18] fix spacing --- koboldai_settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/koboldai_settings.py b/koboldai_settings.py index 484c95fc..2057197f 100644 --- a/koboldai_settings.py +++ b/koboldai_settings.py @@ -2449,7 +2449,7 @@ class KoboldWorldInfo(object): raise Exception("removing the root folder is not supported") del self.world_info[uid] - + try: os.remove(os.path.join(self._koboldai_vars.save_paths.wi_images, str(uid))) except FileNotFoundError: From b4b24f13895909035d135998928c9fc332ee3a62 Mon Sep 17 00:00:00 2001 From: Nick Perez Date: Mon, 13 Mar 2023 06:21:25 -0400 Subject: [PATCH 14/18] Fix out of range after deletion in for loop --- koboldai_settings.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/koboldai_settings.py b/koboldai_settings.py index e921b307..4e324eca 100644 --- a/koboldai_settings.py +++ b/koboldai_settings.py @@ -1504,9 +1504,9 @@ class KoboldStoryRegister(object): else: self.actions[i]["Probabilities"][token_num][token_option]["Used"] = False if "Options" in self.actions[i]: - for j in range(len(self.actions[i]["Options"])): - if self.actions[i]["Options"][j]["text"] == text: - del self.actions[i]["Options"][j] + for option in self.actions[i]["Options"][:]: + if option["text"] == text: + self.actions[i]["Options"].remove(option) if old_text != "": self.actions[i]["Options"].append({"text": old_text, "Pinned": False, "Previous Selection": False, "Edited": True}) else: From 0dce4c700f7b1ab971d8b9e93a4cb701709c5c5c Mon Sep 17 00:00:00 2001 From: Nick Perez Date: Mon, 13 Mar 2023 07:00:51 -0400 Subject: [PATCH 15/18] Just reverse the range --- koboldai_settings.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/koboldai_settings.py b/koboldai_settings.py index 4e324eca..4d9737a7 100644 --- a/koboldai_settings.py +++ b/koboldai_settings.py @@ -1504,9 +1504,9 @@ class KoboldStoryRegister(object): else: self.actions[i]["Probabilities"][token_num][token_option]["Used"] = False if "Options" in self.actions[i]: - for option in self.actions[i]["Options"][:]: - if option["text"] == text: - self.actions[i]["Options"].remove(option) + for j in reversed(range(len(self.actions[i]["Options"]))): + if self.actions[i]["Options"][j]["text"] == text: + del self.actions[i]["Options"][j] if old_text != "": self.actions[i]["Options"].append({"text": old_text, "Pinned": False, "Previous Selection": False, "Edited": True}) else: From 8da04a98a4491902cca4db657cfe0cef4474bb99 Mon Sep 17 00:00:00 2001 From: Henk Date: Mon, 13 Mar 2023 18:41:25 +0100 Subject: [PATCH 16/18] Better Runtime Isolation --- commandline.bat | 4 ++++ play.bat | 4 ++++ update-koboldai.bat | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/commandline.bat b/commandline.bat index d25da157..5372a9a3 100644 --- a/commandline.bat +++ b/commandline.bat @@ -1,6 +1,10 @@ @echo off cd /D %~dp0 + +:Isolation SET CONDA_SHLVL= +SET PYTHONNOUSERSITE=1 +SET PYTHONPATH= TITLE CMD for KoboldAI Runtime SET /P M= Date: Fri, 17 Mar 2023 01:28:59 +0100 Subject: [PATCH 17/18] SocketIO Requirements Pin --- environments/huggingface.yml | 7 ++++--- environments/rocm.yml | 7 ++++--- requirements.txt | 9 +++++---- requirements_mtj.txt | 9 +++++---- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/environments/huggingface.yml b/environments/huggingface.yml index 5942d79a..1bef463d 100644 --- a/environments/huggingface.yml +++ b/environments/huggingface.yml @@ -5,12 +5,13 @@ channels: - defaults dependencies: - colorama - - flask-socketio - - flask-session + - flask-socketio=5.3.2 + - flask-session=0.4.0 + - python-socketio=5.7.2 - pytorch=1.11.* - python=3.8.* - cudatoolkit=11.1 - - eventlet + - eventlet=0.33.3 - dnspython=2.2.1 - markdown - bleach=4.1.0 diff --git a/environments/rocm.yml b/environments/rocm.yml index c9c6b487..47d29e07 100644 --- a/environments/rocm.yml +++ b/environments/rocm.yml @@ -4,10 +4,11 @@ channels: - defaults dependencies: - colorama - - flask-socketio - - flask-session + - flask-socketio=5.3.2 + - flask-session=0.4.0 + - python-socketio=5.7.2 - python=3.8.* - - eventlet + - eventlet=0.33.3 - dnspython=2.2.1 - markdown - bleach=4.1.0 diff --git a/requirements.txt b/requirements.txt index b79ca5cb..b13230ed 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,12 +1,13 @@ transformers==4.24.0 huggingface_hub==0.12.1 -Flask -Flask-SocketIO +Flask==2.2.3 +Flask-SocketIO==5.3.2 +python-socketio==5.7.2 requests torch >= 1.9, < 1.13 flask-cloudflared==0.0.10 flask-ngrok -eventlet +eventlet==0.33.3 dnspython==2.2.1 lupa==1.10 markdown @@ -14,7 +15,7 @@ bleach==4.1.0 sentencepiece protobuf accelerate -flask-session +flask-session==0.4.0 marshmallow>=3.13 apispec-webframeworks loguru diff --git a/requirements_mtj.txt b/requirements_mtj.txt index c99852e7..e66e1ba7 100644 --- a/requirements_mtj.txt +++ b/requirements_mtj.txt @@ -9,16 +9,17 @@ transformers == 4.24.0 huggingface_hub==0.12.1 progressbar2 git+https://github.com/VE-FORBRYDERNE/mesh-transformer-jax@ck -flask -Flask-SocketIO +Flask==2.2.3 +Flask-SocketIO==5.3.2 +python-socketio==5.7.2 flask-cloudflared==0.0.10 flask-ngrok -eventlet +eventlet==0.33.3 dnspython==2.2.1 lupa==1.10 markdown bleach==4.1.0 -flask-session +flask-session==0.4.0 marshmallow>=3.13 apispec-webframeworks loguru From 90a7eb615351afd7901939c616b5165576198889 Mon Sep 17 00:00:00 2001 From: Henk Date: Fri, 17 Mar 2023 12:40:08 +0100 Subject: [PATCH 18/18] LLama tokenizer settings --- aiserver.py | 7 +++++- install_git_transformers.bat | 41 ++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 install_git_transformers.bat diff --git a/aiserver.py b/aiserver.py index 412fce91..3368447b 100644 --- a/aiserver.py +++ b/aiserver.py @@ -3217,7 +3217,12 @@ def load_model(use_gpu=True, gpu_layers=None, disk_layers=None, initial_load=Fal #koboldai_vars.badwords = gettokenids("[") #for key in koboldai_vars.badwords: # koboldai_vars.badwordsids.append([vocab[key]]) - + + # These are model specific overrides if a model has bad defaults + if koboldai_vars.model_type == "llama": + tokenizer.decode_with_prefix_space = True + tokenizer.add_bos_token = False + logger.info(f"Pipeline created: {koboldai_vars.model}") else: diff --git a/install_git_transformers.bat b/install_git_transformers.bat new file mode 100644 index 00000000..3e154b80 --- /dev/null +++ b/install_git_transformers.bat @@ -0,0 +1,41 @@ +@echo off +cd /D %~dp0 +SET CONDA_SHLVL= + +TITLE KoboldAI - Git Transformers Installer +ECHO This script will replace the Transformers version with the latest Git Transformers which may contain breaking changes. +ECHO If you wish to return to the approved version of transformers you can run the install_requirements.bat script or KoboldAI Updater. +pause + +SET /P M=nul +subst K: miniconda3 >nul +SET TEMP=K:\ +SET TMP=K:\ +call K:\python\condabin\activate +pip install git+https://github.com/huggingface/transformers +cmd /k + +:drivemap_B +ECHO Runtime launching in B: drive mode +subst /D B: >nul +subst B: miniconda3 >nul +SET TEMP=B:\ +SET TMP=B:\ +call B:\python\condabin\activate +pip install git+https://github.com/huggingface/transformers +cmd /k \ No newline at end of file