Skip to content

Commit 30331ba

Browse files
dariocazzaniclaude
andcommitted
Change experiment exists from fail to skip-with-warning
- Rename check_safe_to_run to should_skip_experiment - Return bool and print warning instead of raising FileExistsError - Allows chained experiment commands to continue when some already exist - --force flag still available for intentional overwrites Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent ce134c6 commit 30331ba

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

experiments/paths.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,18 +85,18 @@ def experiment_exists(experiment_dir: Path) -> bool:
8585
return (experiment_dir / "results.json").exists()
8686

8787

88-
def check_safe_to_run(experiment_dir: Path, *, force: bool = False) -> None:
89-
"""Check if it's safe to run an experiment.
88+
def should_skip_experiment(experiment_dir: Path, *, force: bool = False) -> bool:
89+
"""Check if an experiment should be skipped.
9090
9191
Args:
9292
experiment_dir: Path to experiment directory.
9393
force: If True, allow overwriting existing results.
9494
95-
Raises:
96-
FileExistsError: If experiment exists and force is False.
95+
Returns:
96+
True if the experiment should be skipped (already exists and not forcing).
9797
"""
9898
if experiment_exists(experiment_dir) and not force:
99-
raise FileExistsError(
100-
f"Experiment already exists: {experiment_dir}\n"
101-
f"Use --force to overwrite, or check if this is a duplicate run."
102-
)
99+
print(f"\n[SKIP] Experiment already exists: {experiment_dir}")
100+
print(" Use --force to overwrite.\n")
101+
return True
102+
return False

experiments/train.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
)
2727
from experiments.datasets.factory import AUGMENT_CHOICES, get_dataset
2828
from experiments.models.factory import get_model
29-
from experiments.paths import check_safe_to_run
29+
from experiments.paths import should_skip_experiment
3030
from experiments.training import checkpoint, logging_config
3131
from experiments.training.loops import evaluate, get_scheduler, train_epoch
3232

@@ -199,8 +199,9 @@ def main() -> None:
199199
quiet=args.quiet,
200200
)
201201

202-
# Safety check: prevent accidental overwrites
203-
check_safe_to_run(Path(config.output_dir), force=args.force)
202+
# Skip if experiment already exists (unless --force)
203+
if should_skip_experiment(Path(config.output_dir), force=args.force):
204+
return
204205

205206
train(config)
206207

experiments/train_kd.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
)
2626
from experiments.datasets.factory import AUGMENT_CHOICES, get_dataset
2727
from experiments.models.factory import get_model
28-
from experiments.paths import ExperimentType, check_safe_to_run, get_experiment_dir
28+
from experiments.paths import ExperimentType, get_experiment_dir, should_skip_experiment
2929
from experiments.training import checkpoint, logging_config
3030
from experiments.training.kd_loss import KDLoss
3131
from experiments.training.loops import evaluate, get_scheduler
@@ -253,8 +253,9 @@ def main() -> None:
253253
)
254254
args.output_dir = str(experiment_dir)
255255

256-
# Safety check: prevent accidental overwrites
257-
check_safe_to_run(Path(args.output_dir), force=args.force)
256+
# Skip if experiment already exists (unless --force)
257+
if should_skip_experiment(Path(args.output_dir), force=args.force):
258+
return
258259

259260
config = TrainConfig(
260261
model=args.model,

0 commit comments

Comments
 (0)