Skip to content

Bug: Tool calling in Kimi K2 causes core dump #865

@whoisjeremylam

Description

@whoisjeremylam

What happened?

When tool calling is used with Kimi K2, the request causes ik_llama.cpp to segfault.

I've tried a couple of different apps (opencode.ai and the K2 Vendor Verifier) that use tool calling with the same result. It is probably the easiest to reproduce using the K2 Vendor Verifier since it is a simple Python script.

Command to start Kimi K2:

~/ik_llama.cpp/build/bin/llama-server \
  -t 23 \
  -m /home/ai/models/ubergarm/Kimi-K2-Instruct-0905-GGUF/Kimi-K2-Instruct-0905-IQ2_KS.gguf \
  --alias Kimi-K2 \
  --jinja \
  --host 0.0.0.0 \
  --port 5000 \
  -c 131072 -ctk q8_0 --no-mmap -ngl 999 \
  -ot "blk.(0|1|2|3|4|5).ffn.=CUDA0" \
  -ot "blk.(11|12|13|14|15|16).ffn.=CUDA1" \
  -ot "blk.(21|22).ffn.=CUDA2" \
  -ot "blk.(31|32).ffn.=CUDA3" \
  -ot exps=CPU \
  -mg 0 -ub 4096 -b 4096 -mla 3 -amb 512 \
  --temp 0.6 --min_p 0.01

Command for the official K2 Vendor Verifier app:

python tool_calls_eval.py samples.jsonl \
    --model kimi-k2-0905 \
    --base-url http://192.168.100.200:5000/v1 \
    --api-key not_used \
    --concurrency 1 \
    --output results.jsonl \
    --summary summary.json

Name and Version

$ ~/ik_llama.cpp/build/bin/llama-server --version
version: 3928 (16f30fcf)
built with cc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0 for x86_64-linux-gnu

What operating system are you seeing the problem on?

Linux

Relevant log output

Grammar lazy: false
Chat format: Generic
INFO [   launch_slot_with_task] slot is processing task | tid="137164878520320" timestamp=1761389674 id_slot=0 id_task=0
INFO [            update_slots] kv cache rm [p0, end) | tid="137164878520320" timestamp=1761389674 id_slot=0 id_task=0 p0=0
INFO [   launch_slot_with_task] slot is processing task | tid="137164878520320" timestamp=1761389674 id_slot=0 id_task=00=0minate called after throwing an instance of 'std::runtime_error'
  what():  Invalid diff: '{                                                                                             d in the background, so the shell expects another complete command after it. When you type:\n\n\ncurl -XPOST -H \"host: wechat-verify-apisix.yunzhanghu.net\" http://[IP_ADDRESS]:80/weixin-xiaochengxu-apisix-add-route?addPathTxt=test1.txt&addPathUuid=test1111223444411&addDomain=thirdparty3.yunzhanghu.com\n\n\nthe part after the first `&` is interpreted as a new command, which causes the parse error.\n\nFix: wrap the entire URL in quotes so the shell treats it as a single argument:\n\n\ncurl -XPOST -H \"host: wechat-verify-apisix.yunzhanghu.net\" \"http://[IP_ADDRESS]:80/weixin-xiaochengxu-apisix-add-route?addPathTxt=test1.txt&addPathUuid=test1111223444411&addDomain=thirdparty3.yunzhanghu.com\"\n\n\n(Replace `[IP_ADDRESS]` with the actual IP address or hostname.)"
' not found at start of 'The error you're seeing—`zsh: parse error near '&'`—comes from the shell, not from the remote server.

In zsh (and most other POSIX shells) the ampersand `&` is treated as a command separator that puts the preceding command in the background, so the shell expects another complete command after it. When you type:


curl -XPOST -H "host: wechat-verify-apisix.yunzhanghu.net" http://[IP_ADDRESS]:80/weixin-xiaochengxu-apisix-add-route?a
ddPathTxt=                                                                                                             =
test1.txt&addPathUuid=test1111223444411&addDomain=thirdparty3.yunzhanghu.com"


(Replace `[IP_ADDRESS]` with the actual IP address or hostname.)'
Aborted (core dumped)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions