commit 55cd2b3271de4ee25a1fe5d984c83c6b2a1d41cc
parent f57548cefd990956690d6bac3fb8cf6a7be33c6d
Author: Stefan Koch <programming@stefan-koch.name>
Date: Sat, 11 Nov 2023 16:19:20 +0100
clean up memory after loading a new model
Diffstat:
1 file changed, 5 insertions(+), 0 deletions(-)
diff --git a/src/nlparrot/server.py b/src/nlparrot/server.py
@@ -1,3 +1,4 @@
+import gc
import os
from multiprocessing.connection import Listener
@@ -41,6 +42,10 @@ if __name__ == "__main__":
tokenizers = get_tokenizers(language)
current_language = language
+ # Clean up memory after the new model was loaded.
+ # Python does not clean up the old data immediately, but models are quite big in RAM.
+ gc.collect()
+
# TODO: Generic way
if language == "hr":
reading_ease = flesch_reading_ease.croatian(task["text"])