guidance
guidance copied to clipboard
llama-cpp-python is already installed but guidance still ask to please install llama-cpp-python when run
The bug llama-cpp-python is already installed but guidance still ask to please install llama-cpp-python when run
To Reproduce
$ ls ./venv/lib/python3.10/site-packages/ | grep llama
llama_cpp
llama_cpp_python-0.2.56.dist-info
$ ls ./venv/lib/python3.10/site-packages/ | grep guidance
guidance
guidance-0.1.10.dist-info
$ python --version
Python 3.10.8
$ python -c 'import torch; print(torch.cuda.get_device_name(0))'
NVIDIA RTX A2000 8GB Laptop GPU
from guidance import models
path_to_model = "dolphin-2.6-mistral-7b-dpo-laser.Q4_K_M.gguf"
lm = models.LlamaCpp(path_to_model, n_gpu_layers=-1)
System info (please complete the following information):
- OS (e.g. Ubuntu, Windows 11, Mac OS, etc.): win 10 wsl Ubuntu 20.04
- Guidance Version (
guidance.__version__
):
Hi @Kahdeg-15520487 -- your code looks fine to me and it certainly looks like the site-packages directory is has llama_cpp, so that's pretty odd. I'm curious if there's some kind of other corruption in your environment. Can you run the following and tell us what error you get, if any:
import llama_cpp
@paulbkoch
Running into the same issue.
import llama_cpp
print(llama_cpp.__version__)
Output:
0.2.57
But...
from guidance import models, gen, system, assistant
mistral = models.MistralInstruct()
Output:
---------------------------------------------------------------------------
Exception Traceback (most recent call last)
[<ipython-input-18-6f8bfd51793a>](https://localhost:8080/#) in <cell line: 4>()
1 from guidance import models, gen, system, assistant
2
----> 3 gpt2 = models.MistralInstruct()
1 frames
[/usr/local/lib/python3.10/dist-packages/guidance/models/llama_cpp/_llama_cpp.py](https://localhost:8080/#) in __init__(self, model, compute_log_probs, **kwargs)
64 def __init__(self, model, compute_log_probs, **kwargs):
65 if not is_llama_cpp:
---> 66 raise Exception("Please install llama-cpp-python with `pip install llama-cpp-python` in order to use guidance.models.LlamaCpp!")
67
68 if isinstance(model, Path):
Exception: Please install llama-cpp-python with `pip install llama-cpp-python` in order to use guidance.models.LlamaCpp!
These lines:
https://github.com/guidance-ai/guidance/blob/94744ea84fec2145091d94ab6821e47b06863037/guidance/models/llama_cpp/_llama_cpp.py#L13-L17
Are supposed to detect the common scenario that a module isn't installed and later throw the "Please install llama-cpp-python" exception. ImportError is a broader exception than is required here though, and it should instead be ModuleNotFoundError, which is a subclass of ImportError.
Unfortunately, since the exception only seems to trigger when the import is called from the package, there isn't a lot of specific information about the underlying issue. I've submitted this PR https://github.com/guidance-ai/guidance/pull/733 which should allow the exception through.