Skip to content

Commit 8db003a

Browse files
py : support converting local models (#7547)
* Support of converting local models added to convert-hf-to-gguf-update.py * Description fixed * shutil added to imports
1 parent 0996c55 commit 8db003a

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

convert_hf_to_gguf_update.py

+22-6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import requests
3232
import sys
3333
import json
34+
import shutil
3435

3536
from hashlib import sha256
3637
from enum import IntEnum, auto
@@ -125,12 +126,27 @@ def download_model(model):
125126
if tokt == TOKENIZER_TYPE.UGM:
126127
files.append("spiece.model")
127128

128-
for file in files:
129-
save_path = f"models/tokenizers/{name}/{file}"
130-
if os.path.isfile(save_path):
131-
logger.info(f"{name}: File {save_path} already exists - skipping")
132-
continue
133-
download_file_with_auth(f"{repo}/resolve/main/{file}", token, save_path)
129+
if os.path.isdir(repo):
130+
# If repo is a path on the file system, copy the directory
131+
for file in files:
132+
src_path = os.path.join(repo, file)
133+
dst_path = f"models/tokenizers/{name}/{file}"
134+
if os.path.isfile(dst_path):
135+
logger.info(f"{name}: File {dst_path} already exists - skipping")
136+
continue
137+
if os.path.isfile(src_path):
138+
shutil.copy2(src_path, dst_path)
139+
logger.info(f"{name}: Copied {src_path} to {dst_path}")
140+
else:
141+
logger.warning(f"{name}: Source file {src_path} does not exist")
142+
else:
143+
# If repo is a URL, download the files
144+
for file in files:
145+
save_path = f"models/tokenizers/{name}/{file}"
146+
if os.path.isfile(save_path):
147+
logger.info(f"{name}: File {save_path} already exists - skipping")
148+
continue
149+
download_file_with_auth(f"{repo}/resolve/main/{file}", token, save_path)
134150

135151

136152
for model in models:

0 commit comments

Comments
 (0)