Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -1293,19 +1293,20 @@ def load_some_model(path: Path) -> ModelPlus:


class VocabFactory:
_FILES = {"spm": "tokenizer.model", "bpe": "vocab.json", "hfft": "tokenizer.json"}
_FILES = {"spm": ["tokenizer.model"], "bpe": ["vocab.json", "tokenizer.json"], "hfft": ["tokenizer.json"]}

def __init__(self, path: Path):
self.path = path
self.file_paths = self._detect_files()
print(f"Found vocab files: {self.file_paths}")

def _detect_files(self) -> dict[str, Path | None]:
def locate(file: str) -> Path | None:
if (path := self.path / file).exists():
return path
if (path := self.path.parent / file).exists():
return path
def locate(files: list[str]) -> Path | None:
for file in files:
if (path := self.path / file).exists():
return path
if (path := self.path.parent / file).exists():
return path
return None

return {vt: locate(f) for vt, f in self._FILES.items()}
Expand Down