Skip to content

xpu: serve logprobs and top_logprobs on Qwen3.8-27B - #3051

Closed
Mirrdhyn wants to merge 4 commits into
ashhart:mainfrom
hygurlabs:xpu-logprobs
Closed

Mirrdhyn wants to merge 4 commits into
ashhart:mainfrom
hygurlabs:xpu-logprobs

Conversation

@Mirrdhyn

@Mirrdhyn Mirrdhyn commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Closes #3050. Follows the suggestion on #2000: logprobs on the XPU host as their own PR.

What changes

The Intel GPU engine for Qwen3.8-27B now declares logprobs and answers logprobs: true, top_logprobs: N (0 to 20) on every path it has for that model: a lone drafted stream (DFlash2 trees), plain streams and shared rounds, greedy and sampled. prompt_logprobs is still refused, as are logprobs on the Nemotron-H, LFM3 and Gemma 4 engines, which this change does not touch.

The core already had the mechanism, so there is no XPU-only rule: the lane core takes the first token's row from Backend.first_row and every later row from Verified.rows. The XPU backend now gives both, from the logits it already reads back (Runner.rowLogits). The first token's row keeps the token first drew, as CUDA does; the verified rows are built on the host the way step5 and llama build theirs (native/xpu_logrow.zig: f32 blocks of 64 summed in f64, the 20 best, ties to the lower id, the raw distribution). A lone drafted stream takes its rows from the tree walk: treeRound gets an optional Note, called before commitPath; tokens and their order are unchanged.

The one core change is opt-in, in core/lanes/drafted.zig: a Drafted wrapper had no first_row, so a drafted stream could not give its first token's row. A new field rows: bool = false makes backend() offer the target's first_row (its verify already passes Verified.rows through). The default is unchanged, so MiniMax and the CUDA hosts behave as before. Only the XPU wrapper sets it.

Checks

Receipt: docs/receipts/xpu-qwen27-logprobs/.

  • zig build test and zig build test-draft-xpu-host pass, base 223da7659 against this head, each with an empty build cache: zig build test 9202 passed, 0 failed, 69 skipped of 9271, and 9209, 0, 69 of 9278; zig build test-draft-xpu-host 8 passed and 13 passed, 0 failed, 0 skipped. tools/zig/lean_check.py reads 341 problems on base and 341 on head, so none new. New host tests: the row (normalizer, order, ties, a pick outside the best, the vector exponential); laneInfo, loneDriver and wrapDrafter declare logprobs (removing any one makes the test fail); windowRows, the loop that hands each verified window row its own place in the block, is tested with a fake source across windows with and without logprobs; a NaN or +inf logit gives a NaN logprob, which the server refuses, as the sampled draw already refuses such logits; the wrapper offers first_row only when asked; on the fake target a drafted stream's rows equal a plain stream's, greedy and sampled.
  • Tokens unchanged: six prompts, greedy and sampled (seed 7), drafted and "draft": false, max_tokens 160 (prompts 3 and 5 stop earlier, at the end of the reply, which covers the alignment of the last rows): the same token_sha256 and text with and without logprobs (24 of 24).
  • Drafted rows equal plain rows, exactly (12 of 12 cells, largest difference 0.0, same top lists in the same order).
  • Shared rounds (--parallel 2, two requests at once, 12 runs): tokens and rows equal what each returns alone.
  • Default path unchanged: main against this head without logprobs in the request, alternating fresh servers, median of 5, one Arc Pro B70 in a PCIe 5.0 x16 slot (the cost bullet below is the other card, Gen4 x4): lone drafted greedy, main 125.28 and head 125.30 tok/s, sampled 125.79 and 125.85, "draft": false greedy 33.50 and 33.51, two streams greedy 195.06 and 196.02 (passes from 192.39 to 202.65). Every token_sha256 equals main's.
  • Resumed equals fresh: prompt cache on, logprobs: true, top_logprobs: 5, the same request twice. In the 8 cells that resumed, the second reply matches the first in text, token_sha256 and logprob rows, exactly (greedy and sampled, drafted and "draft": false; 320 to 1,472 of 355 to 1,519 prompt tokens). The other 4 prompts are under one cache block and were not a resume; they matched too.
  • Cost, same binary and server, alternating, median of 5, on one Arc Pro B70 in a Gen4 x4 chipset slot (an order of magnitude only; only the with/without pairs are comparable): lone drafted greedy 123.8 to 116.1 tok/s (6.3 %), sampled 123.4 to 115.7 (6.2 %), plain 33.1 to 32.4 (2.0 %), 7,457-token prompt 67.8 to 65.5 (3.3 %); two streams at once, 193.7 to 167.5 tok/s in total, prefill included (13.6 %). The binary measured is the commit plus a local VRAM-guard patch that selects the card and is not in the diff.

Notes for review

  • A shared round computes every row of every window, not only the rows that land: the lane core allocates one row per verified row and learns the accepted path afterwards, and a forced window keeps all its rows, so skipping rows would need the window to say which kind it is. A lone drafted stream computes the accepted path only. The receipt does not isolate how much of the two-stream cost this is; I left it for a later change rather than widening the core's contract here.
  • The first row costs a host copy of the last prompt row for every logprobs request; sampled and grammar streams already paid it.
  • Logged.take (the lone driver's per-path row) reads the runner directly, so it has no host test; the device receipt is what locks it.

@ashhart

ashhart commented Nov 12, 2026

Copy link
Copy Markdown
Owner

Thanks @Mirrdhyn. This is a clean way in: the XPU backend fills the rows the lane core already asks for, and the server's OpenAI format doesn't change. We checked the parts that decide correctness, and they hold:

  • windowRows (zig/src/native/xpu_lanes.zig:18-28) walks the block in the order verifyFn lays it out, one row per verified row. It skips windows that didn't ask, since the core allocates rows only for logprobs streams (zig/src/core/lanes/engine.zig:271).
  • The first row keeps the token first drew (xpu_lanes.zig:330, :378), and the core re-points it with forToken, as on the other backends.
  • The walk's Note (zig/src/xpu/drafter_tree.zig:154, :160) runs before commitPath, and its place at lines up with the tokens committed at xpu_lanes.zig:568.
  • Drafted.rows (zig/src/core/lanes/drafted.zig:35) is off by default, so MiniMax and the CUDA hosts get the same vtable as on main.
  • Rows reach the client through the shared formatter (zig/src/server/logprobs.zig:133), which refuses a NaN logprob, as your test expects.

The lean checker reads 345 on main and 345 on this head, so 0 new. CI is green.

Before it can land

  1. Main against this branch, without logprobs. The receipt compares the branch with and without logprobs. But the default path changed too: verifyFn now calls windowRows every round (xpu_lanes.zig:467), and first and first_masked store the pick. Please post main against this head on the same card, with no logprobs in the request. Cover a lone drafted stream (greedy and sampled), "draft": false, and two streams. Show tok/s, with every token_sha256 equal to main's.
  2. Resumed equals fresh. Every run used --prompt-cache-gib 0. Please add one check with the prompt cache on: the same prompt twice with logprobs: true, top_logprobs: 5, greedy and sampled. The second request's tokens and rows should equal the first's.
  3. Room in xpu_lanes.zig. This head takes the file to 598 lines. xpu: a sampled Qwen3.8-27B row draws from a top-k kept on the card #2895 is approved and ahead of this one in the queue, and it adds 26 lines to the same file, so after a rebase this would be about 624, over the 600-line bound. XPU Qwen3.8-27B: a lone DFlash2 stream draws its tree's width from the lane rule's lone pricing #3052 adds about 24 more. Please move windowRows (xpu_lanes.zig:18-28) and Logged (xpu_lanes.zig:576-584) into xpu_logrow.zig, which is 135 lines. That leaves room for all three.
  4. Order with XPU Qwen3.8-27B: a lone DFlash2 stream draws its tree's width from the lane rule's lone pricing #3052. The two conflict in xpu_lanes.zig, drafter_tree.zig and draft_sources_xpu_test.zig. XPU Qwen3.8-27B: a lone DFlash2 stream draws its tree's width from the lane rule's lone pricing #3052 splits treeRound into grow, settle, follow and walk, so the Note hook will move into walk. We'd land this one first, and XPU Qwen3.8-27B: a lone DFlash2 stream draws its tree's width from the lane rule's lone pricing #3052 rebases on it.
  5. Description. Please add the template's counts: pass, fail and skip for zig build test and zig build test-draft-xpu-host, and the lean checker on base and head.
  6. Changelog. Please end the line with (#3051, for #3050).

Not for this PR, but worth noting: a shared round builds a row for every verified row, landed or not. That is most of the 13.6% cost at two streams. Building only the landed rows, or picking the top 20 on the card, would make a good follow-up.

  • Synthena (Ash's Agent)

@Mirrdhyn

Copy link
Copy Markdown
Contributor Author

Thanks for the review. All six are done. The branch is rebased on 223da7659 (head c1cb4caa7) and the description has the counts. The device runs below are on one Arc Pro B70 in a PCIe 5.0 x16 slot, the same server flags as the receipt (--context 32768 --parallel 2 --prompt-cache-gib 0 unless stated), base 223da7659 against head c1cb4caa7. That is the other card from the receipt's cost table (Gen4 x4), so compare these with each other, not with it. These runs are not in docs/receipts/xpu-qwen27-logprobs/, which is unchanged; I can add them there if you want them in the tree.

  1. Main against this head, no logprobs in the request. Each pass is a fresh server, base and head alternating, 5 passes each, one warmup and one timed request per cell, 256 tokens. Median tok/s:

    cell main head change
    lone drafted, greedy 125.28 125.30 +0.0 %
    lone drafted, sampled (seed 7) 125.79 125.85 +0.0 %
    "draft": false, greedy 33.50 33.51 +0.0 %
    two streams at once, greedy (total, prefill included) 195.06 196.02 +0.5 %

    The two-stream passes run from 192.39 to 199.75 on main and from 192.42 to 202.65 on this head, so +0.5 % sits inside that noise. The token_sha256 is the same in every pass of both sides, cell by cell.

  2. Resumed equals fresh. Head, prompt cache on (--prompt-cache-gib 2), logprobs: true, top_logprobs: 5, 160 tokens, the same request twice. Each cell's prompt has its own prefix, so the first request is cold. Greedy and sampled (seed 7), drafted and "draft": false, three prompt sizes: 12 cells. In the 8 cells where the second request resumed (320 to 1,472 of 355 to 1,519 prompt tokens, the server log and usage.prompt_tokens_details.cached_tokens agree), its reply has the same text, token_sha256 and logprob rows (token, logprob, top list and its order, compared as exact floats) as the first. The other 4 prompts are 40 and 41 tokens, under one 64-token cache block, so they never resume and test nothing about it; they match too. Two of the resumed replies stop at 40 and 21 tokens, on both requests.

  3. Room in xpu_lanes.zig. windowRows and Logged now live in xpu_logrow.zig (1e019eb91). Logged holds the runner instead of the Lanes, the only thing it read through it. xpu_lanes.zig is 574 lines and xpu_logrow.zig 161. A local merge with xpu: a sampled Qwen3.8-27B row draws from a top-k kept on the card #2895 rebased on the same main takes xpu_lanes.zig to exactly 600, so XPU Qwen3.8-27B: a lone DFlash2 stream draws its tree's width from the lane rule's lone pricing #3052's lines will have to come out of it when it rebases; its item 6 (the pricing moved into lone_costs) is the obvious place.

  4. Order. Fine by me: this one first, then XPU Qwen3.8-27B: a lone DFlash2 stream draws its tree's width from the lane rule's lone pricing #3052 rebases on it and moves the Note hook into walk.

  5. Description. Updated. On base and head, each with an empty build cache: zig build test 9202 passed, 0 failed, 69 skipped of 9271, and 9209, 0, 69 of 9278; zig build test-draft-xpu-host 8 passed and 13 passed, 0 failed, 0 skipped. tools/zig/lean_check.py reads 341 on base and 341 on head. The 345 you read was on the old base 6c5cef894, where it still reads 345.

  6. Changelog. The line ends with (#3051, for #3050).

Main has moved since my rebase (0591c4e85), and the only conflict is again CHANGELOG.md. I can rebase once more if you'd rather not resolve it at merge.

@ashhart

ashhart commented Nov 14, 2026

Copy link
Copy Markdown
Owner

Thanks @Mirrdhyn. The alternating main/head runs without logprobs, eight genuine resumed cells with matching rows, helper move, test counts and corrected CHANGELOG suffix answer all six asks. The XPU draft host checks and shared-wrapper row tests pass too.

This goes to the landing queue, ahead of #3052. We'll handle CHANGELOG placement and check the combined line budget with #2895. Your Arc Pro B70 runs supply the device evidence; nothing further is needed from you on this review.

  • Synthena (Ash's Agent)

@ashhart

ashhart commented Nov 14, 2026

Copy link
Copy Markdown
Owner

Thanks @Mirrdhyn. The rebase retains first-token rows, accepted-path row alignment and the wrapper's opt-in row forwarding; the focused XPU and shared-wrapper checks pass. Combined with #2895, the code merges and xpu_lanes.zig stays at exactly 600 lines; the changelog is the remaining merge context. Your B70 token, row and genuine-resume receipts answer the device gate. No new author changes requested; ready ahead of #3052 once current-head CI is green.

  • Synthena (Ash's Agent)

@ashhart

ashhart commented Nov 16, 2026

Copy link
Copy Markdown
Owner

@Mirrdhyn, this now conflicts with main in zig/src/core/lanes/drafted.zig, and it's an overlap rather than a text clash: #3511 (Flint's DFlash2 drafts on Metal) landed this morning with the same pass-through your rows field adds. Main's Drafted has first_rows: bool = false; when it's set, backend() returns one of eight static row_tables, each the matching vtable with first_row = firstRow, and firstRow forwards to the target's firstRow, as yours does. zig/src/native/flint.zig:96 and drafted_test.zig:586 show it in use.

Could you rebase onto main and set first_rows = true where you set rows = true, dropping your rows and table fields and the runtime vtable copy in backend()? That keeps one path for both callers. The rest of the PR applies cleanly, and we'll take another look once it's pushed.

  • Synthena (Ash's Agent)

@Mirrdhyn

Copy link
Copy Markdown
Contributor Author

@ashhart, rebased onto main 9489c3817 as you asked. drafted.zig is now main's file unchanged: our rows and table fields, the runtime vtable copy in backend() and our own firstRow are gone, and zig/src/native/xpu.zig and drafted_rows_test.zig set first_rows = true where they set rows = true. The switch is in the first commit, not in a fixup on top, and the CHANGELOG line is now under Unreleased.

Checks on the new head: tools/pr_check.py 0 errors, 0 warnings (lean 221 against main's 221); zig fmt --check clean on the touched files; test-qwen27-shared-allocation-host 408 passed, 1 skipped; test-lane-api-host 667; test-draft-xpu-host 12 + 1. zig build test fails one test, serve --config: expand reads the file…, which fails the same on main on this machine (umask 0002, so its file is group-writable); the receipt says so.

On one Arc Pro B70, a short check, not the receipt: 3 short prompts, greedy and sampled (seed 7), drafted and plain, 48 tokens, top_logprobs: 5, so 12 cells, each also run without logprobs. On the new head all 12 give the same text with and without logprobs, and in all 6 drafted-against-plain pairs the drafted stream's rows equal the plain stream's.

Against the head before the rebase, the logprob rows differ in all 12 cells, and 4 cells change tokens (prompt 0 greedy and prompt 2 sampled, drafted and plain). Without logprobs, the old merge base and main differ in tokens in exactly those 4 cells, and in all 12 the text before the rebase equals the old base's text and the text after it equals main's. So the tokens move with main, not with this branch; main refuses logprobs, so I could not compare its rows directly, and I have not isolated which change in main moves the logits. Two XPU changes landed between the old base and this one: c0b584863 (#2000, the RoPE tables from core's helper, a declared value change) and f454f343d (gdn_out); I have not run them apart.

I re-ran the receipt in docs/receipts/xpu-qwen27-logprobs/ (measured first on the pre-rebase source) on this head's code with the same scripts and cells, this time on the card in the Gen5 x16 slot (the first run used the Gen4 x4 one). With and without logprobs, 24 of 24 pairs keep their tokens; drafted rows equal plain rows in 12 of 12; shared rounds 12 of 12. A lone drafted stream now costs 4.9% and two streams at once 12.9%, and the CHANGELOG line says so. One cell moved more than the others: drafted greedy on the 32-token prompt runs at 111.2 tok/s without logprobs, against 123.8 before, with five runs within 0.03% of each other. I have not traced why that reply drafts slower on main.

@ashhart

ashhart commented Nov 17, 2026

Copy link
Copy Markdown
Owner

Thanks @Mirrdhyn. This passed every check today, together with the PRs that landed just before it: the gate, CI and the device cells. Its branch sits on an organisation fork that doesn't allow maintainer pushes, though, so we couldn't update it for landing. It lands instead as #3722, with your four commits unchanged and authored by you, plus our changelog commit with the corrected cost figure and the thanks. Once #3722 is in, we'll close this one in its favour. Nothing is needed from you.

  • Synthena

ashhart pushed a commit that referenced this pull request Nov 17, 2026
ashhart pushed a commit that referenced this pull request Nov 17, 2026
@ashhart

ashhart commented Nov 17, 2026

Copy link
Copy Markdown
Owner

Thanks again @Mirrdhyn. Your four commits have landed on main through #3722, unchanged and credited to you, so we're closing this one in its favour. Logprobs and top_logprobs on Intel GPUs will be in the next release.

  • Synthena

@ashhart ashhart closed this Nov 17, 2026
@ashhart

ashhart commented Nov 18, 2026

Copy link
Copy Markdown
Owner

Thanks @Mirrdhyn! This is in TensorFold 1.2.10, out now: https://github.com/ashhart/TensorFold/releases/tag/v1.2.10

  • Synthena

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.

XPU (B70) Qwen3.8-27B: serve logprobs and top_logprobs

2 participants