Skip to content

fix(viscy-utils): fail fast when ckpt_path does not exist - #505

Open
ieivanov wants to merge 1 commit into
mainfrom
fix/cli-ckpt-path-exists
Open

ieivanov wants to merge 1 commit into
mainfrom
fix/cli-ckpt-path-exists

Conversation

@ieivanov

Copy link
Copy Markdown
Contributor

Summary

Lightning's LightningCLI._parse_ckpt_path silently skips a ckpt_path that doesn't exist (if ckpt_path and Path(ckpt_path).is_file()). As a result, viscy predict --ckpt_path=<missing> builds the trainer, model and datamodule first, and only then fails with Checkpoint file not found.

VisCyCLI._parse_ckpt_path now calls a new _check_ckpt_paths_exist helper right after parsing. It raises FileNotFoundError when either of these is set but isn't an existing file:

  • the subcommand-level ckpt_path (e.g. viscy predict --ckpt_path)
  • model.init_args.ckpt_path (e.g. VSUNet(ckpt_path=...))

Lightning's keyword values (best, last, hpc, registry...) skip the check. The check runs for every subcommand, so fit, validate and test also fail early on a missing checkpoint.

Before / after

# before (after trainer + model + data setup)
Restoring states from the checkpoint path at /tmp/nope.ckpt
FileNotFoundError: Checkpoint file not found: /tmp/nope.ckpt

# after (immediately after parsing)
FileNotFoundError: ckpt_path does not exist or is not a file: /tmp/nope.ckpt

Tests

  • Unit tests for _check_ckpt_paths_exist: existing files, unset paths, Lightning keywords, missing trainer-level ckpt, missing model ckpt.
  • End-to-end viscy predict subprocess test with BoringModel/BoringDataModule, which asserts the new error message.
  • packages/viscy-utils/tests/test_cli.py: 21 passed. prek is clean.

🤖 Generated with Claude Code

Lightning's LightningCLI._parse_ckpt_path silently skips a missing
ckpt_path, so `viscy predict --ckpt_path=<missing>` only failed after the
trainer, model and datamodule were built. VisCyCLI now checks the
subcommand-level ckpt_path and model.init_args.ckpt_path right after
parsing and raises FileNotFoundError. Lightning keywords ("best", "last",
"hpc", "registry...") are passed through unchanged.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@ieivanov

Copy link
Copy Markdown
Contributor Author

@edyoshikun @alxndrkalinin let me know what you think about this, I think it's nice to have but optional

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant