Last active
December 11, 2019 05:47
-
-
Save MightyAlex200/f640fbca963788d096c2505d30cb4665 to your computer and use it in GitHub Desktop.
AIDungeon2 hang detection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%%bash | |
# Add hang detector | |
pip install func_timeout | |
echo """From fadf0c784811d890456e0c882caef593af0bc2f2 Mon Sep 17 00:00:00 2001 | |
From: MightyAlex200 <quantumtraveling@gmail.com> | |
Date: Wed, 11 Dec 2019 00:31:42 -0500 | |
Subject: [PATCH] Hang detection | |
--- | |
play.py | 27 +++++++++++++++++++++++++-- | |
1 file changed, 25 insertions(+), 2 deletions(-) | |
diff --git a/play.py b/play.py | |
index 31cd2bd..c5b6cc5 100644 | |
--- a/play.py | |
+++ b/play.py | |
@@ -5,6 +5,7 @@ import time | |
from generator.gpt2.gpt2_generator import * | |
from story.story_manager import * | |
from story.utils import * | |
+from func_timeout import func_timeout, FunctionTimedOut | |
os.environ[\"TF_CPP_MIN_LOG_LEVEL\"] = \"3\" | |
@@ -105,6 +106,11 @@ def play_aidungeon_2(): | |
print(\"\\nInitializing AI Dungeon! (This might take a few minutes)\\n\") | |
generator = GPT2Generator() | |
story_manager = UnconstrainedStoryManager(generator) | |
+ inference_timeout = 30 | |
+ def act(action): | |
+ return func_timeout(inference_timeout, story_manager.act, (action,)) | |
+ def notify_hanged(): | |
+ console_print(f\"That input caused the model to hang (timeout is {inference_timeout}, use infto ## command to change)\") | |
print(\"\\n\") | |
with open(\"opening.txt\", \"r\", encoding=\"utf-8\") as file: | |
@@ -208,10 +214,23 @@ def play_aidungeon_2(): | |
console_print(story_manager.story.story_start) | |
continue | |
+ elif len(action.split(\" \")) == 2 and action.split(\" \")[0] == 'infto': | |
+ | |
+ try: | |
+ inference_timeout = int(action.split(\" \")[1]) | |
+ console_print(f\"Set timeout to {inference_timeout}\") | |
+ except: | |
+ console_print(\"Failed to set timeout. Example usage: infto 30\") | |
+ continue | |
+ | |
else: | |
if action == \"\": | |
action = \"\" | |
- result = story_manager.act(action) | |
+ try: | |
+ result = act(action) | |
+ except FunctionTimedOut: | |
+ notify_hanged() | |
+ continue | |
console_print(result) | |
elif action[0] == '\"': | |
@@ -231,7 +250,11 @@ def play_aidungeon_2(): | |
action = \"\\n> \" + action + \"\\n\" | |
- result = \"\\n\" + story_manager.act(action) | |
+ try: | |
+ result = \"\\n\" + act(action) | |
+ except FunctionTimedOut: | |
+ notify_hanged() | |
+ continue | |
if len(story_manager.story.results) >= 2: | |
similarity = get_similarity( | |
story_manager.story.results[-1], story_manager.story.results[-2] | |
-- | |
2.24.0""" > fix.patch | |
# email and username required | |
git config user.email "anonymous@example.com" | |
git config user.name "Anonymous" | |
git am --3way fix.patch && echo Patch Applied! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment