Skip to content

Studio: sample Vulkan drafts on the CPU when the vocab misaligns the logits rows - #15258

Merged
danielhanchen merged 5 commits into
mainfrom
studio-vulkan-draft-sampling-misaligned-vocab
Oct 26, 2026
Merged

danielhanchen merged 5 commits into
mainfrom
studio-vulkan-draft-sampling-misaligned-vocab

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Oct 25, 2026 •

Copy link
Copy Markdown
Member

Fixes #14987

Problem

On the Vulkan build, loading openbmb/MiniCPM-V-4.7-1B-gguf with speculative decoding on Auto (the default, which picks the DSpark sidecar) prints one token and then llama-server dies:

ggml-vulkan.cpp:5759: GGML_ASSERT(allow_misalign || misalign_bytes == 0) failed

It happens with or without an image, and turning speculative decoding off avoids it.

Root cause

llama.cpp samples drafts on the backend by default (--spec-draft-backend-sampling, a top_k(10) chain per draft sequence). llm_graph_context::build_sampling hands each output row to the sampler as ggml_view_1d(logits, n_vocab, row * logits->nb[1]), so row r starts r * n_vocab * 4 bytes into the logits buffer. The Vulkan TOP_K path binds that view with ggml_vk_tensor_subbuffer(ctx, src0) without allow_misalign, so any row offset that is not a multiple of the device's minStorageBufferOffsetAlignment aborts.

MiniCPM-V-4.7 has 248094 tokens, so row 1 starts at byte 992376, which is 8 bytes past a 16-byte boundary and 56 past a 64-byte one. Vocabs that are a multiple of 64 (151936, 248320, 262144, 128256, 201088, ...) keep every row aligned for any alignment up to the Vulkan maximum of 256, which is why other models are fine. CUDA has no such restriction.

Backtrace from a reproduction on the same prebuilt line (b11734, and still on the latest b11798):

ggml_vk_tensor_subbuffer(...) [clone .constprop.1]
ggml_vk_topk(...)
ggml_vk_build_graph(...)
ggml_backend_vk_graph_compute(...)
llama_context::decode(...)
common_speculative_impl_draft_dflash::draft(...)

Fix

When the llama.cpp build is Vulkan, a draft speculative mode is emitted (DSpark, DFlash, MTP, EAGLE-3), the target vocab is not a multiple of 64, and the build advertises the flag in --help, Studio appends --no-spec-draft-backend-sampling to its spec flags. Drafts are then sampled on the CPU with the same top_k(10); acceptance logic and every UI setting are unchanged.

Everything else launches byte-identically: non-Vulkan builds, aligned vocabs, Off / n-gram modes, and builds without the flag. A user-supplied --spec-draft-backend-sampling in the extra args still wins (llama.cpp is last-wins and the extras follow the spec block). The flag sits inside the spec block, so the drafter-failure retry that swaps that block for --spec-default drops it too.

The root fix is in llama.cpp: unslothai/llama.cpp#328 makes the Vulkan TOP_K copy a misaligned input to an aligned scratch instead of aborting, and unslothai/llama.cpp#329 pins it into the prebuilt. This PR keeps Studio users on existing prebuilts working until a release carrying that pin is installed; on a fixed prebuilt it only costs the CPU-side sampling of the drafts for those models.

Evidence

Tiny random-weight copies of the target and the DSpark drafter (real GGUF metadata and tokenizer, vocab 248094 kept, hidden size shrunk), Studio's exact launch flags, a CPU Vulkan device reporting the reporter's 64-byte storage-buffer alignment:

Arm Result
b11734, backend draft sampling on crash, ggml-vulkan.cpp:5759 GGML_ASSERT(allow_misalign || misalign_bytes == 0)
b11798 (latest prebuilt), backend draft sampling on same crash
alignment 16 or 32 instead of 64 same crash
GGML_VK_DISABLE_FUSION=1 or GGML_VK_DISABLE_GRAPH_OPTIMIZE=1 same crash
speculative decoding off 48 tokens, no crash
b11734 and b11798 with --no-spec-draft-backend-sampling 48 tokens, drafting active (135 drafted), no crash
same model with the vocab padded to 248128 (multiple of 64), backend sampling on 48 tokens, no crash

Tests: studio/backend/tests/test_vulkan_draft_backend_sampling.py (19 cases) covers the predicate and drives the real load_model for a DSpark launch. With the one line that appends the flag reverted, the two launch tests fail.

On real hardware (AMD Radeon 8060S, RADV GFX1151)

The same differential on a gfx1151 box: the released b11798 Vulkan llama-server with Studio's DSpark launch, base (main) Studio code vs this PR, RADV wrapped to report the reporter's 64-byte storage-buffer alignment (RADV's own is 4, where every f32 row is aligned):

state Studio extra flags server drafted
base (none) aborts: ggml-vulkan.cpp:5759: GGML_ASSERT(allow_misalign || misalign_bytes == 0) failed -
head --no-spec-draft-backend-sampling answers 135
head merged into main --no-spec-draft-backend-sampling answers 135

Verdict: CONFIRMED (the defect reproduces at base and is absent at head).

@danielhanchen danielhanchen self-assigned this Oct 25, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-26T06:34:14.041805Z 2af6ed7 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: 77cf3b1527

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: cf075ad430

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 2af6ed7270

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit f1fbcf8 into main Oct 26, 2026
@danielhanchen
danielhanchen deleted the studio-vulkan-draft-sampling-misaligned-vocab branch October 26, 2026 07:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Text generation failure with MiniCPM-V-4.7-1B Vulkan backend

1 participant