Skip to content

Commit 6b6d5b5

Browse files
authored
Fixed tokenizer.model not found error when model dir is symlink (#325)
1 parent a791a68 commit 6b6d5b5

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

convert-pth-to-ggml.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# and vocabulary.
1818
#
1919
import argparse
20+
import os
2021
import sys
2122
import json
2223
import struct
@@ -44,8 +45,14 @@ def get_n_parts(dim):
4445

4546
def load_hparams_and_tokenizer(dir_model):
4647

48+
# `dir_model` is something like `models/7B` or `models/7B/`.
49+
# "tokenizer.model" is expected under model's parent dir.
50+
# When `dir_model` is a symlink, f"{dir_model}/../tokenizer.model" would not be found.
51+
# Let's use the model's parent dir directly.
52+
model_parent_dir = os.path.dirname(os.path.normpath(dir_model))
53+
4754
fname_hparams = f"{dir_model}/params.json"
48-
fname_tokenizer = f"{dir_model}/../tokenizer.model"
55+
fname_tokenizer = f"{model_parent_dir}/tokenizer.model"
4956

5057
with open(fname_hparams, "r") as f:
5158
hparams = json.load(f)

0 commit comments

Comments
 (0)