mirror of
https://github.com/karpathy/nanochat.git
synced 2025-12-06 04:12:13 +00:00
Merge 958543fcd5 into 4a87a0d19f
This commit is contained in:
commit
602a9e02c1
|
|
@ -3,7 +3,6 @@ Utilities for saving and loading model/optim/state checkpoints.
|
||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import glob
|
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import torch
|
import torch
|
||||||
|
|
@ -115,10 +114,10 @@ def find_largest_model(checkpoint_dir):
|
||||||
|
|
||||||
def find_last_step(checkpoint_dir):
|
def find_last_step(checkpoint_dir):
|
||||||
# Look into checkpoint_dir and find model_<step>.pt with the highest step
|
# Look into checkpoint_dir and find model_<step>.pt with the highest step
|
||||||
checkpoint_files = glob.glob(os.path.join(checkpoint_dir, "model_*.pt"))
|
checkpoint_files = [f for f in os.listdir(checkpoint_dir) if re.search(r'model_(\d+)\.pt$', f)]
|
||||||
if not checkpoint_files:
|
if not checkpoint_files:
|
||||||
raise FileNotFoundError(f"No checkpoints found in {checkpoint_dir}")
|
raise FileNotFoundError(f"No checkpoints found in {checkpoint_dir}")
|
||||||
last_step = int(max(os.path.basename(f).split("_")[-1].split(".")[0] for f in checkpoint_files))
|
last_step = int(max(f.split("_")[-1].split(".")[0] for f in checkpoint_files))
|
||||||
return last_step
|
return last_step
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user