From d1fae8c1d569738a71b2cbcbdd1adb1fb9e7556d Mon Sep 17 00:00:00 2001 From: Asatov Oybek Date: Mon, 9 Mar 2026 22:41:10 +0300 Subject: [PATCH] Fix: add directory existence check in find_largest_model to prevent FileNotFoundError on Windows --- nanochat/checkpoint_manager.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/nanochat/checkpoint_manager.py b/nanochat/checkpoint_manager.py index f71524e..1af830f 100644 --- a/nanochat/checkpoint_manager.py +++ b/nanochat/checkpoint_manager.py @@ -116,6 +116,10 @@ def build_model(checkpoint_dir, step, device, phase): def find_largest_model(checkpoints_dir): + # Check if the directory exists to prevent FileNotFoundError on Windows/Linux + if not os.path.exists(checkpoints_dir): + raise FileNotFoundError(f"Directory not found: {checkpoints_dir}. You may need to train a model first.") + # attempt to guess the model tag: take the biggest model available model_tags = [f for f in os.listdir(checkpoints_dir) if os.path.isdir(os.path.join(checkpoints_dir, f))] if not model_tags: