Skip to content

fix: load_checkpoint uses assert instead of raising FileNotFoundError - #27

Open
andrewwhitecdw wants to merge 1 commit into
NVIDIA:mainfrom
andrewwhitecdw:codequality/utils-load-checkpoint-uses-assert-instead-of
Open

fix: load_checkpoint uses assert instead of raising FileNotFoundError#27
andrewwhitecdw wants to merge 1 commit into
NVIDIA:mainfrom
andrewwhitecdw:codequality/utils-load-checkpoint-uses-assert-instead-of

Conversation

@andrewwhitecdw

Copy link
Copy Markdown

This PR addresses the following issue in utils.py: load_checkpoint uses assert instead of raising FileNotFoundError.

Changes

  • utils.py: load_checkpoint uses assert instead of raising FileNotFoundError.

Details

--- a/utils.py
+++ b/utils.py
@@ -1,3 +1,4 @@
-    assert os.path.isfile(filepath)
-    print(f"Loading '{filepath}'")
-    checkpoint_dict = torch.load(filepath, map_location=device)
+    if not os.path.isfile(filepath):
+        raise FileNotFoundError(f"Checkpoint not found: '{filepath}'")
+    print(f"Loading '{filepath}'")
+    checkpoint_dict = torch.load(filepath, map_location=device)

Tests

  • tests/test_checkpoint_validation.py
--- /dev/null
+++ b/tests/test_checkpoint_validation.py
@@ -0,0 +1,9 @@
+import pytest
+import torch
+from utils import load_checkpoint
+
+
+def test_load_checkpoint_raises_for_missing_file():
+    missing_path = "/nonexistent/path/checkpoint.pt"
+    with pytest.raises(FileNotFoundError, match="Checkpoint not found"):
+        load_checkpoint(missing_path, device="cpu")

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