Skip to content

Eval bug: GLM-4.7-Flash flash attention error on (long?) prompts with KV quantization #19036

Description

@SharkWipf

Name and Version

(0) sebastiaan@almavm:~/src/llama.cpp $ ./build/bin/llama-server --version
ggml_cuda_init: found 1 CUDA devices:
  Device 0: NVIDIA GeForce RTX 3090, compute capability 8.6, VMM: yes
version: 7813 (51fa458a9)
built with GNU 14.3.1 for Linux x86_64

Operating systems

Linux

GGML backends

CUDA

Hardware

Ryzen 5950X (not used, fully offloaded) + RTX 3090

Models

Unsloth GLM-4.7-Flash-UD-Q4_K_XL.gguf (Post Jan 21 update)

Problem description & steps to reproduce

Build command:
cmake -B build -DGGML_CUDA=ON -DGGML_CUDA_FA_ALL_QUANTS=ON -DGGML_CUDA_ENABLE_UNIFIED_MEMORY=1 && cmake --build build --config Release -j

Launch command (minimal reproduction):
./build/bin/llama-server -m models/GLM-4.7-Flash-UD-Q4_K_XL.gguf --n-gpu-layers 1100 -c $((202752/2)) --flash-attn on --cache-type-k q4_1 --cache-type-v q4_1
Also tried with q4_0.
(Edit: No problems without kv quant btw)
(Edit 2: Issue also happens with q8_0)

Seems to work fine for short/simple prompts, but once I throw in a ~79k token prompt (or possibly something specific in that prompt), it goes through the whole KV cache processing fine for the most part, but then hits a crash by the end.
The prompt contents is mostly a map of a large codebase and some instructions.

First Bad Commit

No response

Relevant log output

Logs
main: model loaded                                                                                                                     
main: server is listening on http://127.0.0.1:8080                                                                                     
main: starting the main loop...                                                                                                        
srv  update_slots: all slots are idle                                                                                                  
srv  log_server_r: done request: GET / 127.0.0.1 200                                                                                   
srv  params_from_: Chat format: GLM 4.5                                                                                                
slot get_availabl: id  3 | task -1 | selected slot by LRU, t_last = -1                                                      
slot launch_slot_: id  3 | task -1 | sampler chain: logits -> ?penalties -> ?dry -> ?top-n-sigma -> top-k -> ?typical -> top-p -> min-p -> ?xtc -> temp-ext -> dist 
slot launch_slot_: id  3 | task 0 | processing task, is_child = 0                                                                      
slot update_slots: id  3 | task 0 | new prompt, n_ctx_slot = 101376, n_keep = 0, task.n_tokens = 78995
slot update_slots: id  3 | task 0 | n_tokens = 0, memory_seq_rm [0, end)                                                    
slot update_slots: id  3 | task 0 | prompt processing progress, n_tokens = 2048, batch.n_tokens = 2048, progress = 0.025926
slot update_slots: id  3 | task 0 | n_tokens = 2048, memory_seq_rm [2048, end)                                              
slot update_slots: id  3 | task 0 | prompt processing progress, n_tokens = 4096, batch.n_tokens = 2048, progress = 0.051851

[...]

slot update_slots: id  3 | task 0 | prompt processing progress, n_tokens = 57344, batch.n_tokens = 2048, progress = 0.725919                                                                                                                                01:47:57 [14/1840]
slot update_slots: id  3 | task 0 | n_tokens = 57344, memory_seq_rm [57344, end)
slot update_slots: id  3 | task 0 | prompt processing progress, n_tokens = 59392, batch.n_tokens = 2048, progress = 0.751845
slot update_slots: id  3 | task 0 | n_tokens = 59392, memory_seq_rm [59392, end)
slot update_slots: id  3 | task 0 | prompt processing progress, n_tokens = 61440, batch.n_tokens = 2048, progress = 0.777771
slot update_slots: id  3 | task 0 | n_tokens = 61440, memory_seq_rm [61440, end)
slot update_slots: id  3 | task 0 | prompt processing progress, n_tokens = 63488, batch.n_tokens = 2048, progress = 0.803696
slot update_slots: id  3 | task 0 | n_tokens = 63488, memory_seq_rm [63488, end)
slot update_slots: id  3 | task 0 | prompt processing progress, n_tokens = 65536, batch.n_tokens = 2048, progress = 0.829622
/home/sebastiaan/src/llama.cpp/ggml/src/ggml-cuda/ggml-cuda.cu:96: CUDA error
CUDA error: invalid argument
  current device: 0, in function launch_fattn at /home/sebastiaan/src/llama.cpp/ggml/src/ggml-cuda/template-instances/../fattn-common.cuh:1004
  cudaGetLastError()
[New LWP 14401]
[New LWP 14400]
[New LWP 14399]
[New LWP 14398]
[New LWP 14397]
[New LWP 14396]
[New LWP 14395]
[New LWP 14394]
[New LWP 14393]
[New LWP 14392]
[New LWP 14391]
[New LWP 14390]
[New LWP 14389]
[New LWP 14388]
[New LWP 14387]
[New LWP 14386]
[New LWP 14385]
[New LWP 14384]
[New LWP 14383]
[New LWP 14382]
[New LWP 14381]
[New LWP 14380]
[New LWP 14379]
[New LWP 14378]
[New LWP 14377]
[New LWP 14376]
[New LWP 14375]
[New LWP 14374]
[New LWP 14373]
[New LWP 14372]
[New LWP 14371]
[New LWP 14370]
[New LWP 14369]
[New LWP 14368]
[New LWP 14363]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
0x00007f4afbf1ac73 in wait4 () from /lib64/libc.so.6
#0  0x00007f4afbf1ac73 in wait4 () from /lib64/libc.so.6
#1  0x00007f4b0557804b in ggml_print_backtrace () from /home/sebastiaan/src/llama.cpp/build/bin/libggml-base.so.0
#2  0x00007f4b055781a6 in ggml_abort () from /home/sebastiaan/src/llama.cpp/build/bin/libggml-base.so.0
#3  0x00007f4b0259f653 in ggml_cuda_error(char const*, char const*, char const*, int, char const*) () from /home/sebastiaan/src/llama.cpp/build/bin/libggml-cuda.so.0
#4  0x00007f4b028590a3 in void launch_fattn<512, 16, 4>(ggml_backend_cuda_context&, ggml_tensor*, void (*)(char const*, char const*, char const*, char const*, char const*, int const*, float*, float2*, float, float, float, float, unsigned int, float, int, uint3, int, int
, int, int, int, int, int, int, int, int, int, long, int, int, long, int, int, int, int, int, long), int, unsigned long, int, bool, bool, bool, int) () from /home/sebastiaan/src/llama.cpp/build/bin/libggml-cuda.so.0
#5  0x00007f4b02859433 in void ggml_cuda_flash_attn_ext_mma_f16_case<576, 512, 16, 4>(ggml_backend_cuda_context&, ggml_tensor*) () from /home/sebastiaan/src/llama.cpp/build/bin/libggml-cuda.so.0
#6  0x00007f4b025b19c4 in ggml_cuda_graph_evaluate_and_capture(ggml_backend_cuda_context*, ggml_cgraph*, bool, bool) () from /home/sebastiaan/src/llama.cpp/build/bin/libggml-cuda.so.0
#7  0x00007f4b025b2d7e in ggml_backend_cuda_graph_compute(ggml_backend*, ggml_cgraph*) () from /home/sebastiaan/src/llama.cpp/build/bin/libggml-cuda.so.0
#8  0x00007f4b05593dd6 in ggml_backend_sched_graph_compute_async () from /home/sebastiaan/src/llama.cpp/build/bin/libggml-base.so.0
#9  0x00007f4b04cac751 in llama_context::graph_compute(ggml_cgraph*, bool) () from /home/sebastiaan/src/llama.cpp/build/bin/libllama.so.0
#10 0x00007f4b04cae404 in llama_context::process_ubatch(llama_ubatch const&, llm_graph_type, llama_memory_context_i*, ggml_status&) () from /home/sebastiaan/src/llama.cpp/build/bin/libllama.so.0
#11 0x00007f4b04cb5661 in llama_context::decode(llama_batch const&) () from /home/sebastiaan/src/llama.cpp/build/bin/libllama.so.0
#12 0x00007f4b04cb701b in llama_decode () from /home/sebastiaan/src/llama.cpp/build/bin/libllama.so.0
#13 0x0000000000542303 in server_context_impl::update_slots() ()
#14 0x0000000000588fdf in server_queue::start_loop(long) ()
#15 0x00000000004a781d in main ()
[Inferior 1 (process 14362) detached]
Aborted (core dumped)

Metadata

Metadata

Assignees

No one assigned

    Labels

    CUDARelated to the CUDA backendbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions