Skip to content

Commit

Permalink
Check that unlearning data exists before running unlearning eval
Browse files Browse the repository at this point in the history
  • Loading branch information
adamkarvonen committed Jan 18, 2025
1 parent e2b0b3c commit 294b25c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
4 changes: 4 additions & 0 deletions sae_bench/custom_saes/run_all_evals_custom_saes.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ def run_evals(
else:
api_key = None

if "unlearning" in eval_types:
if not os.path.exists("./sae_bench/evals/unlearning/data/bio-forget-corpus.jsonl"):
raise Exception("Please download bio-forget-corpus.jsonl for unlearning evaluation")

# If evaluating multiple SAEs on the same layer, set save_activations to True
# This will require at least 100GB of disk space
save_activations = False
Expand Down
25 changes: 16 additions & 9 deletions sae_bench/custom_saes/run_all_evals_dictionary_learning_saes.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,9 @@ def run_evals(
device = general_utils.setup_environment()

# Select your eval types here.
# Note: Unlearning is not recommended for models with < 2B parameters and we recommend an instruct tuned model
# Unlearning will also require requesting permission for the WMDP dataset (see unlearning/README.md)
# Absorption not recommended for models < 2B parameters
eval_types = [
"absorption",
"core",
Expand All @@ -343,6 +346,19 @@ def run_evals(
# "unlearning",
]

if "autointerp" in eval_types:
try:
with open("openai_api_key.txt") as f:
api_key = f.read().strip()
except FileNotFoundError:
raise Exception("Please create openai_api_key.txt with your API key")
else:
api_key = None

if "unlearning" in eval_types:
if not os.path.exists("./sae_bench/evals/unlearning/data/bio-forget-corpus.jsonl"):
raise Exception("Please download bio-forget-corpus.jsonl for unlearning evaluation")

repos = [
(
"adamkarvonen/saebench_pythia-160m-deduped_width-2pow14_date-0104",
Expand All @@ -369,15 +385,6 @@ def run_evals(
# Unlearning will also require requesting permission for the WMDP dataset (see unlearning/README.md)
# Absorption not recommended for models < 2B parameters

if "autointerp" in eval_types:
try:
with open("openai_api_key.txt") as f:
api_key = f.read().strip()
except FileNotFoundError:
raise Exception("Please create openai_api_key.txt with your API key")
else:
api_key = None

run_evals(
repo_id=repo_id,
model_name=model_name,
Expand Down
17 changes: 14 additions & 3 deletions sae_bench/sae_bench_utils/misc_notebooks/export_results.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,20 @@
" print(f\"Folder {folder} does not exist. Skipping.\")\n",
" continue\n",
"\n",
" # Get all json files in the current directory\n",
" files = [f for f in os.listdir(\".\") if f.endswith(\".json\")]\n",
" if len(files) == 0:\n",
" print(f\"No json files found in {folder}. Skipping.\")\n",
" continue\n",
"\n",
" num_files_with_prefix = 0\n",
"\n",
" for prefix in prefixes:\n",
" num_files_with_prefix += len([f for f in files if f.startswith(prefix)])\n",
"\n",
" if num_files_with_prefix == 0:\n",
" raise ValueError(f\"No files with prefix {prefixes} found in {folder}.\")\n",
"\n",
" os.chdir(folder) # Change to the target directory\n",
" print(f\"Processing folder: {folder}\")\n",
"\n",
Expand All @@ -104,9 +118,6 @@
" if not os.path.exists(prefix):\n",
" os.makedirs(prefix)\n",
"\n",
" # Get all json files in the current directory\n",
" files = [f for f in os.listdir(\".\") if f.endswith(\".json\")]\n",
"\n",
" # Move files to appropriate folders\n",
" for file in files:\n",
" for prefix in prefixes:\n",
Expand Down

0 comments on commit 294b25c

Please sign in to comment.