llama.cpp icon indicating copy to clipboard operation
llama.cpp copied to clipboard

Eval bug: crash when evaluating images with MTP with Qwen3.6

Open fakezeta opened this issue 6 months ago • 6 comments

Name and Version

llama-cli --version
version: 9198 (a6d6183db)
built with Clang 19.1.5 for Windows x86_64

Operating systems

Windows

GGML backends

CUDA

Hardware

i5 12600 RTX 5060ti

Models

Qwen3.6 35B A3B Q5K_M with MTP

Problem description & steps to reproduce

llama-server crashes when evaluating image in input with GGML_ASSERT(i01 >= 0 && i01 < ne01) failed with spec-type draft-mtp

MTP Image in input Crash
Yes Yes Yes
Yes No No
No Yes No

First Bad Commit

b9190

Relevant log output

Logs
0.34.836.765 I srv  process_chun: processing image...
0.37.784.068 W init: embeddings required but some input tokens were not marked as outputs -> overriding
0.37.792.110 W find_slot: non-consecutive token position 3818 after 3817 for sequence 0 with 2048 new tokens
0.37.792.118 W find_slot: non-consecutive token position 3818 after 3818 for sequence 0 with 912 new tokens
0.37.793.771 W find_slot: non-consecutive token position 3818 after 3817 for sequence 0 with 2048 new tokens
0.40.113.093 W find_slot: non-consecutive token position 3818 after 3818 for sequence 0 with 912 new tokens
0.42.132.317 I srv  process_chun: image processed in 7295 ms
0.42.132.324 I srv  process_chun: processing image...
D:/a/llama.cpp/llama.cpp/ggml/src/ggml-cpu/ops.cpp:4745: GGML_ASSERT(i01 >= 0 && i01 < ne01) failed

fakezeta avatar May 17 '26 21:05 fakezeta

I am not able to reproduce:

Image

What is your startup command for the llama-server?

ggerganov avatar May 18 '26 05:05 ggerganov

I also have this problem with Qwen3.5 122B from unsloth quants. Was not able to reproduce with Qwen3.6 though. Also on Windows.

llama-server --version
version: 9205 (dd7cad719)
built with MSVC 19.44.35226.0 for x64

My startup command is -

llama-server  --model Qwen3.5-122B-A10B-UD-Q6_K_XL-00001-of-00003.gguf --fit on --parallel 1 --jinja --ctx-size 32768 -ctk q8_0 -ctv q8_0 --no-mmap --temp 1.0 --top-p 0.95 --top-k 20 --min-p 0.00 --presence-penalty 1.5 --chat-template-kwargs "{\"preserve_thinking\":true}"  --mmproj mmproj-BF16.gguf  --mmproj-offload --image-min-tokens 1024 --spec-type draft-mtp --spec-draft-n-max 3

Edit:I was able to reproduce it once with Qwen3.6-35B-A3B-UD-Q8_K_XL seems to only occur for me during the second processing image step.

ConnoisseurProtege avatar May 18 '26 08:05 ConnoisseurProtege

llama-server.exe 
        -c 131072
        -fa on
        --jinja
        -kvu
        -m C:/Models/Qwen3.6-35B-A3B-UD-Q5_K_S.gguf
        --mmproj C:/Models/mmproj-Qwen3.6-35B-A3B-F16.gguf
        -cmoe
        --spec-type draft-mtp 
        --spec-draft-n-max 3

tested both CUDA 12.4 and 13.1 and also the Vulkan one (b9198) Tried also -ctk and -ctv bf16 and q8_0 Tested with and without flash attention Tested with mmproj in F16 and BF16 I made a quick test also with unsloth Q4_K_XL quant of Qwen3.6 35B

fakezeta avatar May 18 '26 09:05 fakezeta

I can reproduce this on Windows with current official b9204 builds, and I have a backend/model comparison that may help narrow it down.

Environment:

  • Windows x64
  • GPU: AMD Radeon(TM) 8060S Graphics
  • llama.cpp official b9204 Vulkan build: llama-b9204-bin-win-vulkan-x64
  • llama.cpp official b9204 HIP/ROCm build: llama-b9204-bin-win-hip-radeon-x64

Startup shape, Vulkan failing case:

llama-server.exe ^
  -m C:\models\unsloth\Qwen3.6-35B-A3B-UD-Q8_K_XL\Qwen3.6-35B-A3B-UD-Q8_K_XL.gguf ^
  --mmproj C:\models\unsloth\Qwen3.6-35B-A3B-UD-Q8_K_XL\mmproj-BF16.gguf ^
  --ctx-size 262144 ^
  --flash-attn on ^
  --parallel 1 ^
  --kv-unified ^
  --spec-type draft-mtp ^
  --spec-draft-n-max 2

What I observed:

  1. Qwen3.6-27B-UD-Q4_K_XL + Vulkan + mmproj + --spec-type draft-mtp works.

    • It still prints recurrent-position warnings during image eval:
      • non-consecutive token position ... with 512 new tokens
      • later ... with 6 new tokens
    • But it continues to prompt processing and generation.
  2. Qwen3.6-35B-A3B-UD-Q8_K_XL + Vulkan + mmproj + --spec-type draft-mtp fails.

    • Text-only generation works.
    • Image request reaches processing image, prints the same kind of recurrent-position warnings, then the HTTP client gets Connection reset before generation starts.
    • This usually happens around the second image/eval chunk.
  3. The same Qwen3.6-35B-A3B-UD-Q8_K_XL model and same mmproj work with the HIP/ROCm b9204 build.

    • It prints the same non-consecutive token position warnings, but completes the image request and streams output normally.

So the model/mmproj pair does not seem fundamentally broken. The difference appears to be specific to the Vulkan path with qwen35moe / A3B when multimodal embeddings and draft MTP are both enabled.

Model metadata difference:

Qwen3.6-27B-UD-Q4_K_XL:
  general.architecture = qwen35
  qwen35.block_count = 65
  qwen35.embedding_length = 5120

Qwen3.6-35B-A3B-UD-Q8_K_XL:
  general.architecture = qwen35moe
  qwen35moe.block_count = 41
  qwen35moe.expert_count = 256
  qwen35moe.expert_used_count = 8
  qwen35moe.embedding_length = 2048

Representative log pattern from the failing Vulkan A3B run:

processing image
non-consecutive token position ... with 512 new tokens
processing image
non-consecutive token position ... with 6 new tokens
java.net.SocketException: Connection reset

The same warning pattern appears in the successful ROCm run, but only Vulkan terminates/reset the connection for the A3B MoE model.

jamesweiym-ops avatar May 18 '26 12:05 jamesweiym-ops

Commit 3e12fbdea5c1 ("llama: avoid copying logits during prompt decode in MTP (#23198)") is the culprit. It is the only change in b9189..b9204 touching the decode path and Qwen3 model code (src/llama-context.cpp +37/-14, src/models/qwen35.cpp, and src/llama-graph.cpp).

The crash affects all Qwen3-arch models on cold load, regardless of MTP settings, indicating the new decode logic lacks proper guards.

Repro with MiniCPM-V-4.6 (Qwen3 arch): b9189 is clean, but b9190+ crashes during warmup:

llama-cli --model MiniCPM-V-4_6-Q4_K_M.gguf -p "Hello" -n 16 --gpu-layers 0 --no-warmup -no-cnv

DoradusResearch avatar May 18 '26 23:05 DoradusResearch

Commit 3e12fbdea5c1 is confirmed as the bad commit.

Reverting it eliminates both crashes. The text-only repro now exits cleanly:

$ ./bin/llama-cli --model MiniCPM-V-4_6-Q4_K_M.gguf -p "Hello" -n 16 \
    --gpu-layers 0 --no-warmup -no-cnv
> [exit 0, REPL rendered, no assertion]

The mtmd image repro also succeeds without crashing:

$ ./bin/llama-mtmd-cli --model MiniCPM-V-4_6-Q4_K_M.gguf \
    --mmproj mmproj-model-f16.gguf --image red.png \
    -p "What color is this image?" -n 32 --gpu-layers 0
The image is a solid, vibrant red.

The regression likely stems from set_output for t_h_pre_norm in llama-graph.cpp or unconditional decode-path changes in llama-context.cpp when MTPMode==0.

DoradusResearch avatar May 18 '26 23:05 DoradusResearch

Confirmed 3e12fbdea5c1 is the bad commit.

Built llama-cli + llama-mtmd-cli from b9204 with that single commit reverted (git revert 3e12fbdea5c1, clean apply, 10 files changed, 27/91). Both crashes are gone:

Text-only repro (was crashing in ggml_compute_forward_get_rows warmup):

$ ./bin/llama-cli --model MiniCPM-V-4_6-Q4_K_M.gguf -p "Hello" -n 16 \
    --gpu-layers 0 --no-warmup -no-cnv
> [exit 0, REPL rendered, no assertion]

mtmd image repro (was crashing same place during eval_chunks):

$ ./bin/llama-mtmd-cli --model MiniCPM-V-4_6-Q4_K_M.gguf \
    --mmproj mmproj-model-f16.gguf --image red.png \
    -p "What color is this image?" -n 32 --gpu-layers 0
The image is a solid, vibrant red.

So the regression sits entirely inside that one commit — most likely either the set_output for t_h_pre_norm change in llama-graph.cpp or the decode-path changes in llama-context.cpp running unconditionally even when MTP isn't active (which is our case — MTPMode==0).

Happy to test a guarded version that only runs the new code path when MTP is enabled if @amangupta1006 wants to keep the perf optimization.

I think you mentioned the wrong person?

ConnoisseurProtege avatar May 19 '26 02:05 ConnoisseurProtege

The PR #23198 author is @am17an, not @amangupta1006. Apologies to @amangupta1006 for the unrelated ping.

@am17an — happy to test a guarded version that only runs the new MTP decode path when MTP is actually enabled (our case is MTPMode==0). Repro takes about 2 minutes per build with the text-only command in the previous comment.

DoradusResearch avatar May 19 '26 20:05 DoradusResearch

Same issue with 397b mtp unsloth quant:

[59197] 266.04.779.154 I srv  process_chun: processing image...
[59197] 267.14.905.722 W find_slot: non-consecutive token position 1882 after 1881 for sequence 1 with 2048 new tokens
[59197] 267.14.906.604 W find_slot: non-consecutive token position 1882 after 1881 for sequence 1 with 2048 new tokens
[59197] 267.20.671.194 W find_slot: non-consecutive token position 1882 after 1882 for sequence 1 with 24 new tokens
[59197] 267.20.671.236 W find_slot: non-consecutive token position 1882 after 1882 for sequence 1 with 24 new tokens
[59197] 267.20.997.982 I srv  process_chun: image processed in 76219 ms
[59197] 267.20.997.991 I srv  process_chun: processing image...
[59197] /home/drros/llama.cpp/ggml/src/ggml-cpu/ops.cpp:4745: GGML_ASSERT(i01 >= 0 && i01 < ne01) failed
[59197] /home/drros/llama.cpp/build/bin/libggml-base.so.0(+0x1addb)[0x76fe53f57ddb]
[59197] /home/drros/llama.cpp/build/bin/libggml-base.so.0(ggml_print_backtrace+0x21c)[0x76fe53f5825c]
[59197] /home/drros/llama.cpp/build/bin/libggml-base.so.0(ggml_abort+0x15b)[0x76fe53f5843b]
[59197] /home/drros/llama.cpp/build/bin/libggml-cpu.so.0(ggml_compute_forward_get_rows+0xb54)[0x76fe52ce94d4]
[59197] /home/drros/llama.cpp/build/bin/libggml-cpu.so.0(+0x198b0)[0x76fe52c608b0]
[59197] /home/drros/llama.cpp/build/bin/libggml-cpu.so.0(ggml_graph_compute+0x1f3)[0x76fe52c63033]
[59197] /home/drros/llama.cpp/build/bin/libggml-cpu.so.0(+0x1c3b1)[0x76fe52c633b1]
[59197] /home/drros/llama.cpp/build/bin/libggml-base.so.0(ggml_backend_sched_graph_compute_async+0x817)[0x76fe53f758e7]
[59197] /home/drros/llama.cpp/build/bin/libllama.so.0(_ZN13llama_context13graph_computeEP11ggml_cgraphb+0xa1)[0x76fe53cd72f1]
[59197] /home/drros/llama.cpp/build/bin/libllama.so.0(_ZN13llama_context14process_ubatchERK12llama_ubatch14llm_graph_typeP22llama_memory_context_iR11ggml_status+0x114)[0x76fe53cd9a84]
[59197] /home/drros/llama.cpp/build/bin/libllama.so.0(_ZN13llama_context6decodeERK11llama_batch+0x3a1)[0x76fe53ce1331]
[59197] /home/drros/llama.cpp/build/bin/libllama.so.0(llama_decode+0xf)[0x76fe53ce2f8f]
[59197] /home/drros/llama.cpp/build/bin/libmtmd.so.0(mtmd_helper_decode_image_chunk+0x77c)[0x76fe5458aadc]
[59197] /home/drros/llama.cpp/build/bin/libmtmd.so.0(mtmd_helper_eval_chunk_single+0x164)[0x76fe5458c344]
[59197] /home/drros/llama.cpp/build/bin/llama-server(+0xc0b04)[0x5fe10beb7b04]
[59197] /home/drros/llama.cpp/build/bin/llama-server(+0x11009e)[0x5fe10bf0709e]
[59197] /home/drros/llama.cpp/build/bin/llama-server(+0x1a2ad1)[0x5fe10bf99ad1]
[59197] /home/drros/llama.cpp/build/bin/llama-server(+0x70397)[0x5fe10be67397]
[59197] /lib/x86_64-linux-gnu/libc.so.6(+0x2a1ca)[0x76fe5342a1ca]
[59197] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x8b)[0x76fe5342a28b]
[59197] /home/drros/llama.cpp/build/bin/llama-server(+0x6a205)[0x5fe10be61205]
Details

0.23.299.330 I srv          load: spawning server instance with name=qwen3.5-397b-ud-q4-k-xl:thinking-coding-vision on port 59197
0.23.299.369 I srv          load: spawning server instance with args:
0.23.299.369 I srv          load:   /home/drros/llama.cpp/build/bin/llama-server
0.23.299.405 I srv          load:   --host
0.23.299.409 I srv          load:   127.0.0.1
0.23.299.409 I srv          load:   --image-min-tokens
0.23.299.409 I srv          load:   2048
0.23.299.410 I srv          load:   --min-p
0.23.299.410 I srv          load:   0.0
0.23.299.410 I srv          load:   --mlock
0.23.299.410 I srv          load:   --no-mmap
0.23.299.411 I srv          load:   --no-mmproj-offload
0.23.299.411 I srv          load:   --port
0.23.299.411 I srv          load:   59197
0.23.299.411 I srv          load:   --presence-penalty
0.23.299.412 I srv          load:   0.0
0.23.299.412 I srv          load:   --repeat-penalty
0.23.299.412 I srv          load:   1.0
0.23.299.412 I srv          load:   --spec-default
0.23.299.412 I srv          load:   --spec-draft-n-max
0.23.299.413 I srv          load:   3
0.23.299.413 I srv          load:   --cache-type-k-draft
0.23.299.413 I srv          load:   q8_0
0.23.299.413 I srv          load:   --cache-type-v-draft
0.23.299.414 I srv          load:   q8_0
0.23.299.414 I srv          load:   --spec-type
0.23.299.414 I srv          load:   draft-mtp
0.23.299.414 I srv          load:   --temperature
0.23.299.415 I srv          load:   0.6
0.23.299.415 I srv          load:   --top-k
0.23.299.415 I srv          load:   20
0.23.299.415 I srv          load:   --top-p
0.23.299.416 I srv          load:   0.95
0.23.299.416 I srv          load:   --webui-mcp-proxy
0.23.299.416 I srv          load:   --alias
0.23.299.416 I srv          load:   qwen3.5-397b-ud-q4-k-xl:thinking-coding-vision
0.23.299.417 I srv          load:   --ctx-size
0.23.299.417 I srv          load:   262144
0.23.299.417 I srv          load:   --cache-ram
0.23.299.417 I srv          load:   65536
0.23.299.418 I srv          load:   --cache-type-k
0.23.299.418 I srv          load:   q8_0
0.23.299.418 I srv          load:   --cache-type-v
0.23.299.418 I srv          load:   q8_0
0.23.299.419 I srv          load:   --swa-checkpoints
0.23.299.419 I srv          load:   128
0.23.299.419 I srv          load:   --fit
0.23.299.419 I srv          load:   on
0.23.299.420 I srv          load:   --fit-target
0.23.299.420 I srv          load:   4096,512,5120
0.23.299.420 I srv          load:   --kv-unified
0.23.299.420 I srv          load:   --model
0.23.299.421 I srv          load:   /mnt/ds1nfs/codellamaweights/qwen3.5-397b-ud-q4-k-xl-mtp/Qwen3.5-397B-A17B-UD-Q4_K_XL-00001-of-00007.gguf
0.23.299.421 I srv          load:   --mmproj
0.23.299.426 I srv          load:   /mnt/ds1nfs/codellamaweights/qwen3.5-397b-ud-q4-k-xl-mtp/mmproj-BF16.gguf
0.23.299.428 I srv          load:   --parallel
0.23.299.428 I srv          load:   4
0.23.299.429 I srv          load:   --reasoning
0.23.299.429 I srv          load:   on
0.23.299.429 I srv          load:   --ubatch-size
0.23.299.429 I srv          load:   2048
[59197] 0.00.351.397 I device_info:
[59197] 0.00.351.579 I   - CUDA0   : NVIDIA RTX PRO 4000 Blackwell (23987 MiB, 23525 MiB free)
[59197] 0.00.351.599 I   - CUDA1   : NVIDIA RTX PRO 4000 Blackwell (23987 MiB, 23525 MiB free)
[59197] 0.00.351.610 I   - CUDA2   : NVIDIA RTX PRO 4000 Blackwell (23987 MiB, 23525 MiB free)
[59197] 0.00.351.623 I   - CPU     : AMD EPYC 9274F 24-Core Processor (386471 MiB, 386471 MiB free)

drrros avatar May 21 '26 13:05 drrros

I got the same ASSERT as above in ops.cpp: 4745. And this seems to have solved the problem for me when processing image with MTP (someone wants to try it out and commit to git if that's the right fix?)

Image

woiang avatar May 24 '26 03:05 woiang

here is the patch from the screenshot llama-23233.patch trying it I found my issues resolved. tested 4 images all worked, without the patch crashes on same number of images

brettowe avatar May 24 '26 15:05 brettowe

here is the patch from the screenshot llama-23233.patch trying it I found my issues resolved. tested 4 images all worked, without the patch crashes on same number of images

It removes the error for me, but is anyone else getting slower tokens/second with this patch than without the MTP?

I'm running the patched version with --spec-type draft-mtp --spec-draft-n-max 2.

I would expect the MTP to be faster but instead it's roughly 0.80 the speed of the regular model, comparing between original Qwen3.6-35B-A3B-Q8_0 and Qwen3.6-35B-A3B-MTP-Q8_0.

Jay4242 avatar May 24 '26 18:05 Jay4242

Tested various images with the patch, 9305 and Qwen3.6-35B-A3B-Uncensored-Genesis-V2-APEX-MTP. For me, it works.

luee29 avatar May 24 '26 21:05 luee29

Sorry I wasn't certain as that minor change I did was to address my crash when processing image with MTP. That's why I didn't want to commit anything. Just thought I just shared it and ask someone else who knows it better to go over.

At least this was the cause of my crash: The MTP draft graph (graph_mtp in both qwen35.cpp and qwen35moe.cpp) always includes ggml_get_rows(ctx0, tok_embd_w, inp->tokens) unconditionally in the forward pass — unlike the standard graph which uses ggml_build_forward_select to skip it when there are no token IDs. When process_chunk is called on the MTP draft context (ctx_dft) for an image chunk, the batch has tokens = nullptr and only embd = float*. llm_graph_input_embd::set_input only writes to tokens when ubatch->token != nullptr, leaving inp->tokens with uninitialized memory. The garbage token IDs then fail GGML_ASSERT(i01 >= 0 && i01 < ne01) in ggml_compute_forward_get_rows.

With the zero-fill tokens when no token IDs are provided in set_input. Token ID 0 is always a valid in-range index, so the ggml_get_rows lookup produces the embedding for token 0 for image positions (semantically wrong but harmless). The MTP draft's KV cache entries for image positions will use token-0's embedding rather than a meaningful image token embedding, which may slightly degrade draft acceptance rate for multimodal prompts but is far better than crashing.

woiang avatar May 25 '26 01:05 woiang

Hi, PR https://github.com/ggml-org/llama.cpp/pull/23643 fixed also this bug for me.

Thank you!

fakezeta avatar May 29 '26 18:05 fakezeta