Skip to content

Improve error message when model file is missing #2041

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions llama_cpp/llama.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,15 +369,25 @@ def __init__(
if not os.path.exists(model_path):
raise ValueError(f"Model path does not exist: {model_path}")

self._model = self._stack.enter_context(
contextlib.closing(
internals.LlamaModel(
path_model=self.model_path,
params=self.model_params,
verbose=self.verbose,
try:
self._model = self._stack.enter_context(
contextlib.closing(
internals.LlamaModel(
path_model=self.model_path,
params=self.model_params,
verbose=self.verbose,
)
)
)
)
)
except RuntimeError as e:
if "No such file or directory" in str(e):
raise FileNotFoundError(
f"Model file not found at '{self.model_path}'. "
"Make sure the .gguf model file exists at the given path."
) from e
else:
raise


# Override tokenizer
self.tokenizer_ = tokenizer or LlamaTokenizer(self)
Expand Down