guidance icon indicating copy to clipboard operation
guidance copied to clipboard

llama.cpp generate calls failing with Segmentation Fault when using tools

Open mcvella opened this issue 2 years ago • 5 comments

The bug Following the examples here https://lightning.ai/lightning-ai/studios/structured-llm-output-and-function-calling-with-guidance#llm-tool-use using tools with llama.cpp and Mistral 8B gguf, I am getting a Segmentation Fault. Examples I tried without tool usage are working. It does not appear to be an out of memory issue, and tried with tiny-llama with the same result.

To Reproduce Give a full working code snippet that can be pasted into a notebook cell or python file. Make sure to include the LLM load step so we know which model you are using.


    path = "./mistral-7b-instruct-v0.2.Q5_K_M.gguf"
    llm = models.LlamaCpp(path, n_ctx=4096, n_gpu_layers=-1)

    @guidance
    def add(lm, input1, input2):
        lm += f' = {int(input1) + int(input2)}'
        return lm

    @guidance
    def subtract(lm, input1, input2):
        lm += f' = {int(input1) - int(input2)}'
        return lm

    @guidance
    def multiply(lm, input1, input2):
        lm += f' = {float(input1) * float(input2)}'
        return lm

    @guidance
    def divide(lm, input1, input2):
        lm += f' = {float(input1) / float(input2)}'
        return lm


    lm = llm + '''\
1 + 1 = add(1, 1) = 2
2 - 3 = subtract(2, 3) = -1
'''
    lm + gen(max_tokens=15, tools=[add, subtract, multiply, divide])

    print(lm)

System info (please complete the following information):

  • OS (e.g. Ubuntu, Windows 11, Mac OS, etc.): Debian 22.04.4
  • Guidance Version (guidance.__version__): 0.1.13

mcvella avatar May 07 '24 16:05 mcvella

Any ideas here? I am trying to evaluate toolsets and this is a blocker for using Guidance for my use case.

mcvella avatar May 08 '24 18:05 mcvella

Likely the segfaults are coming from within LLamaCpp, since that's where most of the C++ code is located. Can you tell us what version of llama-cpp-python you are using? I'd recommend trying older versions to see if any of them resolve the issue.

paulbkoch avatar May 09 '24 01:05 paulbkoch

I think it's llama.cpp + Debian 12+ as I'm not using this repo and getting the same error loading any gguf model. I read recommendations to make llama.cpp again and that didn't help. There's an open issue on https://github.com/ggerganov/llama.cpp/issues/6701

tavyscrolls avatar May 13 '24 13:05 tavyscrolls

llama.cpp (not to mention llama-cpp-python) both get very frequent releases, and we do tend to see a lot of segfaults from them :-(

riedgar-ms avatar May 14 '24 13:05 riedgar-ms

I will say this looks like a neat project, does it work with kobold by chance? That turned out to be my solution. I also assume you can import into a comfyui custom node? That would be my ideal solution but not ready for that yet.

tavyra avatar May 14 '24 14:05 tavyra