Skip to content

Commit

Permalink
skip batch file if it already exists
Browse files Browse the repository at this point in the history
  • Loading branch information
hijohnnylin committed Apr 22, 2024
1 parent 5c967e7 commit 7d0e396
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
11 changes: 10 additions & 1 deletion sae_lens/analysis/neuronpedia_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,13 @@ def run(self):
# print(f"Skipping batch - it's after end_batch: {feature_batch_count}")
continue

output_file = f"{self.outputs_dir}/batch-{feature_batch_count}.json"
# if output_file exists, skip
if os.path.isfile(output_file):
logline = f"\n++++++++++ Skipping Batch #{feature_batch_count} output. File exists: {output_file} ++++++++++\n"
print(logline)
continue

print(f"========== Running Batch #{feature_batch_count} ==========")

layout = SaeVisLayoutConfig(
Expand Down Expand Up @@ -422,9 +429,11 @@ def run(self):
json_object = json.dumps(to_write, cls=NpEncoder)

with open(
f"{self.outputs_dir}/batch-{feature_batch_count}.json",
output_file,
"w",
) as f:
f.write(json_object)

logline = f"\n========== Completed Batch #{feature_batch_count} output: {output_file} ==========\n"

return
7 changes: 0 additions & 7 deletions tutorials/neuronpedia/neuronpedia.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,6 @@ def generate(
print(f"Error: Output directory {outputs_dir.as_posix()} exists and is a file.")
raise typer.Abort()
outputs_dir.mkdir(parents=True, exist_ok=True)
# Check if output_dir has any files starting with "batch_"
batch_files = list(outputs_dir.glob("batch-*.json"))
if len(batch_files) > 0 and resume_from_batch == 1:
print(
f"Error: Output directory {outputs_dir.as_posix()} has existing batch files. This is only allowed if you are resuming from a batch. Please delete or move the existing batch-*.json files."
)
raise typer.Abort()

sparsity = load_sparsity(sae_path_string)
# convert sparsity to logged sparsity if it's not
Expand Down

0 comments on commit 7d0e396

Please sign in to comment.