Repository navigation
Studio: sample Vulkan drafts on the CPU when the vocab misaligns the logits rows - #15258
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Chef's kiss. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Nice work! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Nice work! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Fixes #14987
Problem
On the Vulkan build, loading
openbmb/MiniCPM-V-4.7-1B-ggufwith speculative decoding on Auto (the default, which picks the DSpark sidecar) prints one token and then llama-server dies: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, atop_k(10)chain per draft sequence).llm_graph_context::build_samplinghands each output row to the sampler asggml_view_1d(logits, n_vocab, row * logits->nb[1]), so rowrstartsr * n_vocab * 4bytes into the logits buffer. The VulkanTOP_Kpath binds that view withggml_vk_tensor_subbuffer(ctx, src0)withoutallow_misalign, so any row offset that is not a multiple of the device'sminStorageBufferOffsetAlignmentaborts.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):
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-samplingto its spec flags. Drafts are then sampled on the CPU with the sametop_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-samplingin 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-defaultdrops it too.The root fix is in llama.cpp: unslothai/llama.cpp#328 makes the Vulkan
TOP_Kcopy 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:
ggml-vulkan.cpp:5759 GGML_ASSERT(allow_misalign || misalign_bytes == 0)GGML_VK_DISABLE_FUSION=1orGGML_VK_DISABLE_GRAPH_OPTIMIZE=1--no-spec-draft-backend-samplingTests:
studio/backend/tests/test_vulkan_draft_backend_sampling.py(19 cases) covers the predicate and drives the realload_modelfor 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):
ggml-vulkan.cpp:5759: GGML_ASSERT(allow_misalign || misalign_bytes == 0) failed--no-spec-draft-backend-sampling--no-spec-draft-backend-samplingVerdict: CONFIRMED (the defect reproduces at base and is absent at head).