Repository navigation
Misc. bug: GGML_ASSERT(n <= tokens.size()) failed - Memory in use ('/completion' endpoint and 'cache_prompt=false')Â #13484
Copy link
Copy link
Closed
Labels
Description
Name and Version
llama.cpp version: b5359 (compiled with -DGGML_RPC=ON)
Model: Mistral-Nemo-12B-Instruct-2407-Q8_0.gguf
Command line arguments:
--flash-attn --temp 0 --seed 1 -c 22000 -ngl 99 --mlock --chat-template mistral-v3-tekken
Error: GGML_ASSERT(n <= tokens.size()) failed
- Memory critical error by agent node-0 (Agent handle: 0x59fc5fabc930) on address 0x7cbd6cc00000. Reason: Memory in use.
load_tensors: loading model tensors, this can take a while... (mmap = true)
load_tensors: offloading 40 repeating layers to GPU
load_tensors: offloading output layer to GPU
load_tensors: offloaded 41/41 layers to GPU
load_tensors: ROCm0 model buffer size = 11731.58 MiB
load_tensors: CPU_Mapped model buffer size = 680.00 MiB
...........................................................................................
llama_context: constructing llama_context
llama_context: n_seq_max = 1
llama_context: n_ctx = 22000
llama_context: n_ctx_per_seq = 22000
llama_context: n_batch = 2048
llama_context: n_ubatch = 512
llama_context: causal_attn = 1
llama_context: flash_attn = 1
llama_context: freq_base = 1000000.0
llama_context: freq_scale = 1
llama_context: n_ctx_per_seq (22000) < n_ctx_train (131072) -- the full capacity of the model will not be utilized
llama_context: ROCm_Host output buffer size = 0.50 MiB
llama_kv_cache_unified: kv_size = 22016, type_k = 'f16', type_v = 'f16', n_layer = 40, can_shift = 1, padding = 256
llama_kv_cache_unified: ROCm0 KV buffer size = 3440.00 MiB
llama_kv_cache_unified: KV self size = 3440.00 MiB, K (f16): 1720.00 MiB, V (f16): 1720.00 MiB
llama_context: ROCm0 compute buffer size = 266.00 MiB
llama_context: ROCm_Host compute buffer size = 53.01 MiB
llama_context: graph nodes = 1207
llama_context: graph splits = 2
common_init_from_params: setting dry_penalty_last_n to ctx_size = 22016
common_init_from_params: warming up the model with an empty run - please wait ... (--no-warmup to disable)
Failed to infer a tool call example (possible template bug)
srv init: initializing slots, n_slots = 1
slot init: id 0 | task -1 | new slot n_ctx_slot = 22016
main: model loaded
main: chat template, chat_template: mistral-v3-tekken, example_format: '[INST]You are a helpful assistant
Hello[/INST]Hi there</s>[INST]How are you?[/INST]'
main: server is listening on http://0.0.0.0:18080 - starting the main loop
srv update_slots: all slots are idle
srv log_server_r: request: GET /props 192.168.253.130 200
slot launch_slot_: id 0 | task 0 | processing task
slot update_slots: id 0 | task 0 | new prompt, n_ctx_slot = 22016, n_keep = 0, n_prompt_tokens = 8241
slot update_slots: id 0 | task 0 | kv cache rm [0, end)
slot update_slots: id 0 | task 0 | prompt processing progress, n_past = 2048, n_tokens = 2048, progress = 0.248514
/opt/text/llama.cpp/tools/server/utils.hpp:1157: GGML_ASSERT(n <= tokens.size()) failedslot update_slots: id 0 | task 0 | kv cache rm [2048, end)
Memory critical error by agent node-0 (Agent handle: 0x59fc5fabc930) on address 0x7cbd6cc00000. Reason: Memory in use.
Aborted (core dumped)
Last working version: b5329
load_tensors: loading model tensors, this can take a while... (mmap = true)
load_tensors: offloading 40 repeating layers to GPU
load_tensors: offloading output layer to GPU
load_tensors: offloaded 41/41 layers to GPU
load_tensors: ROCm0 model buffer size = 11731.58 MiB
load_tensors: CPU_Mapped model buffer size = 680.00 MiB
...........................................................................................
llama_context: constructing llama_context
llama_context: n_seq_max = 1
llama_context: n_ctx = 22000
llama_context: n_ctx_per_seq = 22000
llama_context: n_batch = 2048
llama_context: n_ubatch = 512
llama_context: causal_attn = 1
llama_context: flash_attn = 1
llama_context: freq_base = 1000000.0
llama_context: freq_scale = 1
llama_context: n_ctx_per_seq (22000) < n_ctx_train (131072) -- the full capacity of the model will not be utilized
llama_context: ROCm_Host output buffer size = 0.50 MiB
llama_kv_cache_unified: kv_size = 22016, type_k = 'f16', type_v = 'f16', n_layer = 40, can_shift = 1, padding = 256
llama_kv_cache_unified: ROCm0 KV buffer size = 3440.00 MiB
llama_kv_cache_unified: KV self size = 3440.00 MiB, K (f16): 1720.00 MiB, V (f16): 1720.00 MiB
llama_context: ROCm0 compute buffer size = 266.00 MiB
llama_context: ROCm_Host compute buffer size = 53.01 MiB
llama_context: graph nodes = 1207
llama_context: graph splits = 2
common_init_from_params: setting dry_penalty_last_n to ctx_size = 22016
common_init_from_params: warming up the model with an empty run - please wait ... (--no-warmup to disable)
Failed to infer a tool call example (possible template bug)
srv init: initializing slots, n_slots = 1
slot init: id 0 | task -1 | new slot n_ctx_slot = 22016
main: model loaded
main: chat template, chat_template: mistral-v3-tekken, example_format: '[INST]You are a helpful assistant
Hello[/INST]Hi there</s>[INST]How are you?[/INST]'
main: server is listening on http://0.0.0.0:18080 - starting the main loop
srv update_slots: all slots are idle
srv log_server_r: request: GET /props 192.168.253.130 200
slot launch_slot_: id 0 | task 0 | processing task
slot update_slots: id 0 | task 0 | new prompt, n_ctx_slot = 22016, n_keep = 0, n_prompt_tokens = 8241
slot update_slots: id 0 | task 0 | kv cache rm [0, end)
slot update_slots: id 0 | task 0 | prompt processing progress, n_past = 2048, n_tokens = 2048, progress = 0.248514
slot update_slots: id 0 | task 0 | kv cache rm [2048, end)
slot update_slots: id 0 | task 0 | prompt processing progress, n_past = 4096, n_tokens = 2048, progress = 0.497027
slot update_slots: id 0 | task 0 | kv cache rm [4096, end)
slot update_slots: id 0 | task 0 | prompt processing progress, n_past = 6144, n_tokens = 2048, progress = 0.745541
slot update_slots: id 0 | task 0 | kv cache rm [6144, end)
slot update_slots: id 0 | task 0 | prompt processing progress, n_past = 8192, n_tokens = 2048, progress = 0.994054
slot update_slots: id 0 | task 0 | kv cache rm [8192, end)
slot update_slots: id 0 | task 0 | prompt processing progress, n_past = 8241, n_tokens = 49, progress = 1.000000
slot update_slots: id 0 | task 0 | prompt done, n_past = 8241, n_tokens = 49
slot release: id 0 | task 0 | stop processing: n_past = 8638, truncated = 0
slot print_timing: id 0 | task 0 |
prompt eval time = 5977.53 ms / 8241 tokens ( 0.73 ms per token, 1378.66 tokens per second)
eval time = 12231.95 ms / 398 tokens ( 30.73 ms per token, 32.54 tokens per second)
total time = 18209.48 ms / 8639 tokens
srv update_slots: all slots are idle
Operating systems
Linux
Which llama.cpp modules do you know to be affected?
llama-server
Command line
llama-server -m Mistral-Nemo-12B-Instruct-2407-Q8_0.gguf --flash-attn --temp 0 --seed 1 -c 22000 -ngl 99 --mlock --chat-template mistral-v3-tekkenProblem description & steps to reproduce
Error GGML_ASSERT(n <= tokens.size()) failedslot update_slots when the input text is long (8241 tokens with 22000 context size)
First Bad Commit
Relevant log output
load_tensors: loading model tensors, this can take a while... (mmap = true)
load_tensors: offloading 40 repeating layers to GPU
load_tensors: offloading output layer to GPU
load_tensors: offloaded 41/41 layers to GPU
load_tensors: ROCm0 model buffer size = 11731.58 MiB
load_tensors: CPU_Mapped model buffer size = 680.00 MiB
...........................................................................................
llama_context: constructing llama_context
llama_context: n_seq_max = 1
llama_context: n_ctx = 22000
llama_context: n_ctx_per_seq = 22000
llama_context: n_batch = 2048
llama_context: n_ubatch = 512
llama_context: causal_attn = 1
llama_context: flash_attn = 1
llama_context: freq_base = 1000000.0
llama_context: freq_scale = 1
llama_context: n_ctx_per_seq (22000) < n_ctx_train (131072) -- the full capacity of the model will not be utilized
llama_context: ROCm_Host output buffer size = 0.50 MiB
llama_kv_cache_unified: kv_size = 22016, type_k = 'f16', type_v = 'f16', n_layer = 40, can_shift = 1, padding = 256
llama_kv_cache_unified: ROCm0 KV buffer size = 3440.00 MiB
llama_kv_cache_unified: KV self size = 3440.00 MiB, K (f16): 1720.00 MiB, V (f16): 1720.00 MiB
llama_context: ROCm0 compute buffer size = 266.00 MiB
llama_context: ROCm_Host compute buffer size = 53.01 MiB
llama_context: graph nodes = 1207
llama_context: graph splits = 2
common_init_from_params: setting dry_penalty_last_n to ctx_size = 22016
common_init_from_params: warming up the model with an empty run - please wait ... (--no-warmup to disable)
Failed to infer a tool call example (possible template bug)
srv init: initializing slots, n_slots = 1
slot init: id 0 | task -1 | new slot n_ctx_slot = 22016
main: model loaded
main: chat template, chat_template: mistral-v3-tekken, example_format: '[INST]You are a helpful assistant
Hello[/INST]Hi there</s>[INST]How are you?[/INST]'
main: server is listening on http://0.0.0.0:18080 - starting the main loop
srv update_slots: all slots are idle
srv log_server_r: request: GET /props 192.168.253.130 200
slot launch_slot_: id 0 | task 0 | processing task
slot update_slots: id 0 | task 0 | new prompt, n_ctx_slot = 22016, n_keep = 0, n_prompt_tokens = 8241
slot update_slots: id 0 | task 0 | kv cache rm [0, end)
slot update_slots: id 0 | task 0 | prompt processing progress, n_past = 2048, n_tokens = 2048, progress = 0.248514
/opt/text/llama.cpp/tools/server/utils.hpp:1157: GGML_ASSERT(n <= tokens.size()) failedslot update_slots: id 0 | task 0 | kv cache rm [2048, end)
Memory critical error by agent node-0 (Agent handle: 0x59fc5fabc930) on address 0x7cbd6cc00000. Reason: Memory in use.
Aborted (core dumped)Reactions are currently unavailable
Activity
broadbit-hu commentedon May 12, 2025
It works with smaller input token sizes, like this 1386 (maybe less than 2048):
broadbit-hu commentedon May 12, 2025
This bug is reproducible on Nvidia cards as well, with different models, like Qwen Coder:
Build options:
Log:
[-]Misc. bug: GGML_ASSERT(n <= tokens.size()) failed[/-][+]Misc. bug: GGML_ASSERT(n <= tokens.size()) failed - Memory in use[/+][-]Misc. bug: GGML_ASSERT(n <= tokens.size()) failed - Memory in use[/-][+]Misc. bug: GGML_ASSERT(n <= tokens.size()) failed - Memory in use (-DGGML_RPC=ON)[/+][-]Misc. bug: GGML_ASSERT(n <= tokens.size()) failed - Memory in use (-DGGML_RPC=ON)[/-][+]Misc. bug: GGML_ASSERT(n <= tokens.size()) failed - Memory in use[/+]ngxson commentedon May 13, 2025
Can you try
Llama-3.2-1B-Instruct-Q4_K_Mto see if it has the same problem?llama-server -m Llama-3.2-1B-Instruct-Q4_K_M.gguf -c 22000https://huggingface.co/bartowski/Llama-3.2-1B-Instruct-GGUF
With the model above, it works well even when I enter 12000 tokens
broadbit-hu commentedon May 13, 2025
@ngxson: Thanks for your support!
I'm using '/completion' endpoint, not '/v1/chat/completions'.
Same results with this small model (with or without flash-attention and GPU offloading):
Command:
./build/bin/llama-server -hf ggml-org/SmolVLM-500M-Instruct-GGUF -c 22000 --host 0.0.0.0 --port 18080
ngxson commentedon May 13, 2025
I think it's likely that your source code is not clean, try
git cloneand rebuild the project from beginning.Also maybe you are using the build from other source (indicated by the
agent node-0message), try using vanilla llama.cpp insteadbroadbit-hu commentedon May 13, 2025
I'm using llama.cpp repo only, the last working release version is b5329.
prompt.json
Here's a complete test to reproduce:
broadbit-hu commentedon May 13, 2025
prompt-v1-chat-completions.json
The llama.cpp build is tested against the 'v1/chat/completions' endpoint - it's fine:
Results:
[-]Misc. bug: GGML_ASSERT(n <= tokens.size()) failed - Memory in use[/-][+]Misc. bug: GGML_ASSERT(n <= tokens.size()) failed - Memory in use ('/completion' endpoint)[/+]broadbit-hu commentedon May 13, 2025
Thus, the prompt cache will be the cause. If 'cache_prompt' is set to true, the '/completion' endpoint ('prompt.json') will work again â but this is not a solution for this particular case:
[-]Misc. bug: GGML_ASSERT(n <= tokens.size()) failed - Memory in use ('/completion' endpoint)[/-][+]Misc. bug: GGML_ASSERT(n <= tokens.size()) failed - Memory in use ('/completion' endpoint and 'cache_prompt=false')[/+]ngxson commentedon May 13, 2025
Thanks for the info. Yes this seems to be a valid bug in all versions (even the old build)
The reason why old version doesn't crash is because std::vector allow resize to an arbitrary number of elements. If we resize to a number larger to number of current tokens in cache, std::value will fill these "added" values with zero, which is technically incorrect.
For example, if first request does NOT use cache, this logic will fill up the cache_tokens with wrong values. If the second request decide to use cache, now it will get an incorrect list of cache_tokens.
The newer version crashes because I added the check to prevent such case from happening.
I'll push a fix for this, cc @ggerganov
broadbit-hu commentedon May 13, 2025
@ngxson Thanks for your support!
broadbit-hu commentedon May 14, 2025
Tested with release b5379 - work like a charm, thanks for your work guys! :)