From 83c0b9ee1ecd00faba58eb302be3d9886404d9af Mon Sep 17 00:00:00 2001 From: ebolam Date: Wed, 22 Jun 2022 14:13:44 -0400 Subject: [PATCH] Vars Migration Fix for back/redo Fix for pytest for back/redo and model loading with disk caching --- aiserver.py | 27 ++++++++++++--------------- koboldai_settings.py | 7 ++----- pytest.ini | 2 +- test_aiserver.py | 12 +++++++++--- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/aiserver.py b/aiserver.py index 02e010c1..a732d371 100644 --- a/aiserver.py +++ b/aiserver.py @@ -1401,25 +1401,22 @@ def load_model(use_gpu=True, gpu_layers=None, disk_layers=None, initial_load=Fal args.breakmodel_disklayers = int(disk_layers) #We need to wipe out the existing model and refresh the cuda cache - #Show what's in VRAM - import gc model = None generator = None model_config = None + for tensor in gc.get_objects(): + try: + if torch.is_tensor(tensor): + with torch.no_grad(): + tensor.set_(torch.tensor((), device=tensor.device, dtype=tensor.dtype)) + except: + pass + gc.collect() try: with torch.no_grad(): torch.cuda.empty_cache() except: pass - - for obj in gc.get_objects(): - try: - if torch.is_tensor(obj) or (hasattr(obj, 'data') and torch.is_tensor(obj.data)): - del obj - gc.collect() - torch.cuda.empty_cache() - except: - pass #Reload our badwords model_settings.badwordsids = koboldai_settings.badwordsids_default @@ -3536,7 +3533,7 @@ def actionback(): story_settings.recentback = True remove_story_chunk(last_key + 1) #for the redo to not get out of whack, need to reset the max # in the actions sequence - story_settings.actions.set_next_id(last_key) + #story_settings.actions.set_next_id(last_key) success = True elif(len(story_settings.genseqs) == 0): emit('from_server', {'cmd': 'errmsg', 'data': "Cannot delete the prompt."}) @@ -3563,10 +3560,10 @@ def actionredo(): restore_id+=1 if restore_id not in story_settings.actions_metadata: return - else: - story_settings.actions.set_next_id(restore_id) + #else: + #print("???") + #story_settings.actions.set_next_id(restore_id) - if restore_id in story_settings.actions_metadata: genout = [{"generated_text": item['Text']} for item in story_settings.actions_metadata[restore_id]['Alternative Text'] if (item["Previous Selection"]==True)] if len(genout) > 0: diff --git a/koboldai_settings.py b/koboldai_settings.py index b5c4e1b5..c2553410 100644 --- a/koboldai_settings.py +++ b/koboldai_settings.py @@ -261,7 +261,7 @@ class KoboldStoryRegister(object): def __next__(self): self.itter += 1 - if self.itter < len(self.actions): + if self.itter <= self.action_count: return self.itter else: raise StopIteration @@ -421,10 +421,7 @@ class KoboldStoryRegister(object): return text def get_last_key(self): - if self.action_count >= 0: - return self.action_count - else: - return 0 + return self.action_count def get_last_item(self): if self.action_count >= 0: diff --git a/pytest.ini b/pytest.ini index c930ba37..f7264939 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,2 +1,2 @@ [pytest] -addopts = --ignore=miniconda3 --ignore=runtime --html=unit_test_report.html --self-contained-html -v \ No newline at end of file +addopts = --ignore=miniconda3 --ignore=runtime --html=unit_test_report.html --self-contained-html -vv \ No newline at end of file diff --git a/test_aiserver.py b/test_aiserver.py index 49b91a7c..b9bf4606 100644 --- a/test_aiserver.py +++ b/test_aiserver.py @@ -208,11 +208,17 @@ def test_back_redo(client_data): response = socketio_client.get_received()[0]['args'][0] assert response == {'cmd': 'errmsg', 'data': 'Cannot delete the prompt.'} socketio_client.emit('message',{'cmd': 'redo', 'data': ''}) - socketio_client.emit('message',{'cmd': 'redo', 'data': ''}) + response = socketio_client.get_received() + assert response == [{'name': 'from_server', 'args': [{'cmd': 'updatescreen', 'gamestarted': True, 'data': 'Niko the kobold stalked carefully down the alley, his small scaly figure obscured by a dusky cloak that fluttered lightly in the cold winter breeze. Holding up his tail to keep it from dragging in the dirty snow that covered the cobblestone, he waited patiently for the butcher to turn his attention from his stall so that he could pilfer his next meal: a tender-looking chicken. He crouched just slightly as he neared the stall to ensure that no one was watching, not that anyone would be dumb enough to hassle a small kobold. What else was there for a lowly kobold to'}], 'namespace': '/'}, + {'name': 'from_server', 'args': [{'cmd': 'texteffect', 'data': 1}], 'namespace': '/'}] socketio_client.emit('message',{'cmd': 'redo', 'data': ''}) response = socketio_client.get_received() - assert response == [{'name': 'from_server', 'args': [{'cmd': 'updatescreen', 'gamestarted': True, 'data': 'Niko the kobold stalked carefully down the alley, his small scaly figure obscured by a dusky cloak that fluttered lightly in the cold winter breeze. Holding up his tail to keep it from dragging in the dirty snow that covered the cobblestone, he waited patiently for the butcher to turn his attention from his stall so that he could pilfer his next meal: a tender-looking chicken. He crouched just slightly as he neared the stall to ensure that no one was watching, not that anyone would be dumb enough to hassle a small kobold. What else was there for a lowly kobold to'}], 'namespace': '/'}, {'name': 'from_server', 'args': [{'cmd': 'texteffect', 'data': 1}], 'namespace': '/'}, {'name': 'from_server', 'args': [{'cmd': 'updatechunk', 'data': {'index': 2, 'html': ' do in a city? All that Niko needed to know was'}}], 'namespace': '/'}, {'name': 'from_server', 'args': [{'cmd': 'texteffect', 'data': 2}], 'namespace': '/'}, {'name': 'from_server', 'args': [{'cmd': 'updatechunk', 'data': {'index': 3, 'html': ' where to find the chicken and then how to make off with it.

A soft thud caused Niko to quickly lift his head. Standing behind the stall where the butcher had been cutting his chicken,
'}}], 'namespace': '/'}, {'name': 'from_server', 'args': [{'cmd': 'texteffect', 'data': 3}], 'namespace': '/'}] - + assert response == [{'name': 'from_server', 'args': [{'cmd': 'updatechunk', 'data': {'index': 2, 'html': ' do in a city? All that Niko needed to know was'}}], 'namespace': '/'}, + {'name': 'from_server', 'args': [{'cmd': 'texteffect', 'data': 2}], 'namespace': '/'}] + socketio_client.emit('message',{'cmd': 'redo', 'data': ''}) + response = socketio_client.get_received() + assert response == [{'name': 'from_server', 'args': [{'cmd': 'updatechunk', 'data': {'index': 3, 'html': ' where to find the chicken and then how to make off with it.

A soft thud caused Niko to quickly lift his head. Standing behind the stall where the butcher had been cutting his chicken,
'}}], 'namespace': '/'}, + {'name': 'from_server', 'args': [{'cmd': 'texteffect', 'data': 3}], 'namespace': '/'}]