Skip to content

Commit 56382aa

Browse files
authored
Merge pull request #290 from ZhangShuaiyi/dev/check_gguf_path
ensure that gguf_path argument is a directory.
2 parents c8bf250 + 22280bf commit 56382aa

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

ktransformers/util/custom_gguf.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ def __init__(self, gguf_path: str):
166166
# Check dir exist
167167
if not os.path.exists(gguf_path):
168168
raise FileNotFoundError(f"GGUF dir not found: {gguf_path}")
169+
if os.path.isfile(gguf_path):
170+
gguf_path = os.path.dirname(gguf_path)
169171

170172
self.tensor_info = {}
171173
self.gguf_path = gguf_path
@@ -175,14 +177,18 @@ def __init__(self, gguf_path: str):
175177
self.tensor_device_map = {}
176178

177179
# Walk through all the .gguf files in the directory
180+
found_gguf = False
178181
for root, dirs, files in os.walk(gguf_path):
179182
for file in files:
180183
if file.endswith(".gguf"):
184+
found_gguf = True
181185
file_name = os.path.join(root, file)
182186
with open(file_name, "rb") as f:
183187
self.load_gguf(f)
184188
if file_name not in self.file_data_map:
185189
self.file_data_map[file_name] = np.memmap(file_name, mode = 'r')
190+
if not found_gguf:
191+
raise FileNotFoundError(f"Cannot find any .gguf files in: {gguf_path}")
186192

187193
def load_gguf(self, f):
188194
f.seek(0)

0 commit comments

Comments
 (0)