Fully automatic censorship removal for language models
Follow up after recent PRs
Philipp Emanuel Weidmann694edf18d3ca
diff --git a/src/heretic/main.py b/src/heretic/main.pyindex 7b14d34..334f1a1 100644--- a/src/heretic/main.py+++ b/src/heretic/main.py@@ -201,7 +201,7 @@ def run():p=2,dim=1,)- # we don't need the residuals after computing refusal directions+ # We don't need the residuals after computing refusal directions.del good_residuals, bad_residualsempty_cache()@@ -420,8 +420,11 @@ def run():continueuser = huggingface_hub.whoami(token)- fullname = user.get("fullname", user.get("name", "Unknown"))- email = user.get("email", "Not provided")+ fullname = user.get(+ "fullname",+ user.get("name", "unknown user"),+ )+ email = user.get("email", "no email found")print(f"Logged in as [bold]{fullname} ({email})[/]")repo_id = questionary.text(diff --git a/src/heretic/utils.py b/src/heretic/utils.pyindex bae2a11..c0cff59 100644--- a/src/heretic/utils.py+++ b/src/heretic/utils.py@@ -48,6 +48,9 @@ def batchify(items: list[T], batch_size: int) -> list[list[T]]:def empty_cache():+ # Collecting garbage is not an idempotent operation, and to avoid OOM errors,+ # gc.collect() has to be called both before and after emptying the backend cache.+ # See https://github.com/p-e-w/heretic/pull/17 for details.gc.collect()if torch.cuda.is_available():