From 6b650343b5bc9bcea8f74c39374612bf53fbfbed Mon Sep 17 00:00:00 2001 From: saloui Date: Fri, 4 Aug 2023 10:29:38 +0200 Subject: [PATCH] upgraded version --- lollms/main_config.py | 5 +++-- lollms/utilities.py | 39 +++++++++++++++++++++++++++++++++++++++ setup.py | 2 +- 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/lollms/main_config.py b/lollms/main_config.py index daddbd6..cfba606 100644 --- a/lollms/main_config.py +++ b/lollms/main_config.py @@ -175,10 +175,11 @@ class LOLLMSConfig(BaseConfig): # Check if file already exists in folder if model_full_path.exists(): print("File already exists in folder") + return False else: # Create folder if it doesn't exist folder_path.mkdir(parents=True, exist_ok=True) with open(model_full_path,"w") as f: f.write(path) - print("Reference created, please make sure you don't delete the file or you will have broken link") - + ASCIIColors.warning("Reference created, please make sure you don't delete or move the referenced file. This can cause the link to be broken") + return True diff --git a/lollms/utilities.py b/lollms/utilities.py index 9561c17..b781252 100644 --- a/lollms/utilities.py +++ b/lollms/utilities.py @@ -7,6 +7,45 @@ from pathlib import Path import json import re import subprocess +import gc + +class AdvancedGarbageCollector: + @staticmethod + def hardCollect(obj): + all_referrers = gc.get_referrers(obj) + for referrer in all_referrers: + if not isinstance(referrer, (list, tuple, dict, set)): + referrer = None + del obj + + @staticmethod + def safeHardCollect(variable_name, instance=None): + if instance is not None: + if hasattr(instance, variable_name): + obj = getattr(instance, variable_name) + AdvancedGarbageCollector.hardCollect(obj) + else: + print(f"The variable '{variable_name}' does not exist in the instance.") + else: + if variable_name in locals(): + obj = locals()[variable_name] + AdvancedGarbageCollector.hardCollect(obj) + elif variable_name in globals(): + obj = globals()[variable_name] + AdvancedGarbageCollector.hardCollect(obj) + else: + print(f"The variable '{variable_name}' does not exist in the local or global namespace.") + + @staticmethod + def safeHardCollectMultiple(variable_names, instance=None): + for variable_name in variable_names: + AdvancedGarbageCollector.safeHardCollect(variable_name, instance) + + @staticmethod + def collect(): + gc.collect() + + class PackageManager: @staticmethod def install_package(package_name): diff --git a/setup.py b/setup.py index 4e74e6b..a084f66 100644 --- a/setup.py +++ b/setup.py @@ -26,7 +26,7 @@ def get_all_files(path): setuptools.setup( name="lollms", - version="2.3.0", + version="2.3.1", author="Saifeddine ALOUI", author_email="aloui.saifeddine@gmail.com", description="A python library for AI personality definition",