Repository navigation
pr-set: pin the Vulkan misaligned top_k fix (#328) - #329
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. 👍 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. Keep them coming! 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". |
…logits rows (unslothai#15258) Fixes unslothai#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).
Pins #328 (Vulkan: copy a misaligned top_k input to an aligned scratch instead of aborting) at
02428e283, so the Vulkan prebuilt stops aborting on the first speculative draft for models whose vocab is not a multiple of 64 (MiniCPM-V-4.7 with its DSpark drafter, unslothai/unsloth#14987).Changes
scripts/unsloth/pr-set.json: appendunslothai/llama.cpp#328 @ 02428e283cb078eb320deeda71ff599278bd4927after model: add MiniMax-M3.1 #320.scripts/unsloth/feature-checks.json:unslothai#328underunchecked. TOP_K already exists upstream, so a backend-op presence check cannot tell the pin apart; the behaviour is covered by the new test-backend-ops TOP_K row cases, which need a Vulkan device.Evidence (pin set = master + this pin, 24 pins)
Vulkan build of the merged b11887 tree, on lavapipe through a wrapper ICD that reports the 64-byte
minStorageBufferOffsetAlignmentof the reporter's Intel Arc 140V:test-backend-ops -o TOP_K -b Vulkan0 -p row=--spec-type draft-dspark --spec-draft-n-max 3, backend draft sampling onGGML_ASSERT(allow_misalign || misalign_bytes == 0))Not run here: the CUDA build and GPU feature checks (no local GPU in this session), and real Intel or NVIDIA Vulkan hardware.