From 694edf18d3ca0c03785b1dc470f75623ac197a43 Mon Sep 17 00:00:00 2001 From: Philipp Emanuel Weidmann Date: Wed, 19 Nov 2025 11:19:47 +0530 Subject: [PATCH] Follow up after recent PRs --- src/heretic/main.py | 9 ++++++--- src/heretic/utils.py | 3 +++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/heretic/main.py b/src/heretic/main.py index 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_residuals empty_cache() @@ -420,8 +420,11 @@ def run(): continue user = 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.py index 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():