[Misc] improve gguf check (#15974)

Signed-off-by: reidliu41 <reid201711@gmail.com>
Co-authored-by: reidliu41 <reid201711@gmail.com>
This commit is contained in:
Reid 2025-04-04 09:33:36 +08:00 committed by GitHub
parent 092475f738
commit 86cbd2eee9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -23,9 +23,14 @@ def check_gguf_file(model: Union[str, PathLike]) -> bool:
elif model.suffix == ".gguf":
return True
with open(model, "rb") as f:
header = f.read(4)
return header == b"GGUF"
try:
with model.open("rb") as f:
header = f.read(4)
return header == b"GGUF"
except Exception as e:
logger.debug("Error reading file %s: %s", model, e)
return False
def modelscope_list_repo_files(