Skip to content

Commit

Permalink
fix: fix clean_checkpoints (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
34j authored Mar 22, 2023
1 parent 44da8d2 commit e5169bf
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/so_vits_svc_fork/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,14 +452,18 @@ def clean_checkpoints(
False -> lexicographically delete ckpts
"""
path_to_models = Path(path_to_models)
name_key = lambda p: int(re.match(r"._(\d+)\.pth", p.name).group(1))
name_key = lambda p: int(re.match(r"._(\d+)", p.stem).group(1))
time_key = lambda p: p.stat().st_mtime
models_sorted = sorted(
path_to_models.glob(r"._(\d+).pth"), key=time_key if sort_by_time else name_key
filter(
lambda p: (p.is_file() and re.match(r"._\d+", p.stem)),
path_to_models.glob("*.pth"),
),
key=time_key if sort_by_time else name_key,
)
models_sorted_grouped = groupby(models_sorted, lambda p: p.name[0])
models_sorted_grouped = groupby(models_sorted, lambda p: p.stem[0])
for k, g in models_sorted_grouped:
to_dels = list(g)[n_ckpts_to_keep:]
to_dels = list(g)[:-n_ckpts_to_keep]
for to_del in to_dels:
if to_del.stem.endswith("_0"):
continue
Expand Down

0 comments on commit e5169bf

Please sign in to comment.