Skip to content

Commit 0483a58

Browse files
authored
Merge pull request containers#1838 from engelmi/improve-no-model-file-error-message
Added error message for GGUF not found and safetensor unsupported
2 parents d802f2d + 27f69bf commit 0483a58

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

ramalama/cli.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from ramalama.common import accel_image, get_accel, perror
2929
from ramalama.config import CONFIG, coerce_to_bool, load_file_config
3030
from ramalama.logger import configure_logger, logger
31-
from ramalama.model import MODEL_TYPES, trim_model_name
31+
from ramalama.model import MODEL_TYPES, NoGGUFModelFileFound, SafetensorModelNotSupported, trim_model_name
3232
from ramalama.model_factory import ModelFactory, New
3333
from ramalama.model_inspect.error import ParseError
3434
from ramalama.model_store.global_store import GlobalModelStore
@@ -1256,6 +1256,8 @@ def eprint(e, exit_code):
12561256
perror("Error: " + str(e).strip("'\""))
12571257
sys.exit(exit_code)
12581258

1259+
parser: ArgumentParserWithDefaults
1260+
args: argparse.Namespace
12591261
try:
12601262
parser, args = init_cli()
12611263
try:
@@ -1293,3 +1295,13 @@ def eprint(e, exit_code):
12931295
eprint(e, errno.EIO)
12941296
except ParseError as e:
12951297
eprint(f"Failed to parse model: {e}", errno.EINVAL)
1298+
except SafetensorModelNotSupported:
1299+
eprint(
1300+
f"""Safetensor models are not supported. Please convert it to GGUF via:
1301+
$ ramalama convert --gguf=<quantization> {args.model} <oci-name>
1302+
$ ramalama run <oci-name>
1303+
""",
1304+
errno.EMEDIUMTYPE,
1305+
)
1306+
except NoGGUFModelFileFound:
1307+
eprint(f"No GGUF model file found for downloaded model '{args.model}'", errno.ENOMEDIUM)

ramalama/model.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,22 @@
5555
$(error)s"""
5656

5757

58+
class NoGGUFModelFileFound(Exception):
59+
pass
60+
61+
62+
class SafetensorModelNotSupported(Exception):
63+
pass
64+
65+
5866
class NoRefFileFound(Exception):
5967
def __init__(self, model: str, *args):
6068
super().__init__(*args)
6169

6270
self.model = model
6371

6472
def __str__(self):
65-
return f"No ref file or models found for '{self.model}'. Please pull model."
73+
return f"No ref file found for '{self.model}'. Please pull model."
6674

6775

6876
def trim_model_name(model):
@@ -201,8 +209,12 @@ def _get_entry_model_path(self, use_container: bool, should_generate: bool, dry_
201209
return f"oci://{self.model}"
202210

203211
ref_file = self.model_store.get_ref_file(self.model_tag)
204-
if ref_file is None or not ref_file.model_files:
212+
if ref_file is None:
205213
raise NoRefFileFound(self.model)
214+
if not ref_file.model_files:
215+
if any(file.name.endswith(".safetensors") for file in ref_file.files):
216+
raise SafetensorModelNotSupported()
217+
raise NoGGUFModelFileFound()
206218

207219
# Use the first model file
208220
if is_split_file_model(self.model_name):

0 commit comments

Comments
 (0)