File size: 1,023 Bytes
b59223f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# ztrain/io.py
# Copyright (c) 2024 Praxis Maldevide - cc-by-nc-4.0 granted
import os
from glob import glob
def flatten_index(model_paths : list[str], allow_list : list[str]):
flat = []
subtype = []
index = {}
ix = 0
for g in sorted(model_paths):
name = os.path.basename(g)
if name in allow_list:
index[name] = ix
flat.append(name)
if 'base' in g:
subtype.append('base')
elif 'instruct' in g:
subtype.append('instruct')
else:
subtype.append('other')
ix += 1
return index, flat, subtype
def list_for_path(path: str, include_folders: list[str], search: str = "/**/*") -> tuple[list[str], list[str], list[str], dict[str, int]]:
model_list = sorted([*[ f for f in glob(path + search)]])
group_idx, model_names, subtypes = flatten_index(model_list, include_folders)
groups = [[m] for m in model_names]
return model_names, subtypes, model_list, group_idx |