Skip to content

inkling2 cuda: Mini logprob rows (first_row and verify rows) through the shared row kernel - #5210

Merged
ashhart merged 2 commits into
ashhart:mainfrom
jmpijll:inkling2-cuda-mini-logprobs
Dec 2, 2026
Merged

ashhart merged 2 commits into
ashhart:mainfrom
jmpijll:inkling2-cuda-mini-logprobs

Conversation

@jmpijll

@jmpijll jmpijll commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Before: Inkling 2 Mini on CUDA gives no logprob rows (first_row is null), so native/cuda.zig reports logprobs = false and logprobs / top_logprobs requests are refused for it. After: the first token's row and each verify row come from cuda.sample.Draws.logprobRows over the bf16 copy of the forward's fp32 logits that a sampled draw reads (a greedy lane makes that copy only for a round that asks for rows); a round's rows share one words buffer (round_rows × lanes.logprob.words) and one download. The drawn tokens do not change: the draw path is untouched and the row kernel only reads.

Checks on this head

  • Head commit: fcb2da5ca on main 3c088d969 (the same tree as 123d7568f, which every check and receipt line below ran).
  • Lean checker, python3 tools/zig/lean_check.py on the base and on this head, compared with python3 tools/zig/lean_new.py: 123 and 123, 0 new. zig fmt --check build.zig zig and git diff --check clean. python3 tools/pr_check.py --base origin/main: 0 errors; 4 advisory warnings (three inherited import cycles, and the Unreleased line, which needs the PR number).
  • Tests run, with the command and pass, fail and skip counts: zig build -Dfixed-cpu test test-golden: 924/924 steps, 13,647/13,756 tests passed (109 skipped). On one GB10, tf-cuda-test inkling2-serving MODEL IDS (4,400 ids) with the new case "logprob rows equal the host's over the same logits; tokens unchanged": 7/7 PASS (host reference, fresh/resumed, cross-prompt resume, admission, 4-slot concurrent == solo, copy rollback, logprob rows).
  • The new case fails before the change: the runner built from main plus only the new case gives the six other PASS lines and then FAIL inkling2-serving: LogprobsUnsupported (exit 1).
  • CI: not reported on this head yet (draft).
  • Not run, and why: CUDA chips other than sm_121 (only a GB10 here); Metal, HIP and XPU are untouched by the change.

Receipt

  • Main against branch: the cells below, same machine, checkpoint and settings, in one session: main's startup, the branch's, then a second main and branch startup for decode.
  • Boxes it reaches: the CUDA Mini lane backend's first and verify windows; the server's logprob path only when a request asks for logprobs.
  • New switch? None.
  • Environment: TensorFold main 3c088d969 against this branch on it; Zig 0.17.0; nvcc 13.3 (NVIDIA PyTorch 26.07 container, -Dsm=121); one NVIDIA GB10 (sm_121, 128 GB unified memory), driver 580.178.04, Linux (DGX OS, kernel 7.0.0-1025-nvidia, aarch64); thinkingmachines/Inkling-2-Mini @ ed40e7da (target shard SHA-256 65e60f51aa1284d4fb022584908c315270334d991828bb774af60584523539d1); no drafter (main's CUDA Mini has none); --parallel 4 --context 32768 --prompt-cache-gib 0.
  • Paths and platforms the change reaches: first with logprobs, verify windows with rows, greedy and seeded sampled; CUDA sm_121 run, other CUDA SMs not run.
  • Exactness: tools/bench_concurrent.py --levels 1,4 --alone --serial --tokens 256 --reps 3 --temperatures 1.0,0 on both: every cell's concurrent replies equal their alone runs (3/3 at one stream, 12/12 at four) and the alone runs equal "draft": false, on main and on the branch; all 540 token_sha256 / token_sha / output_sha256 values equal between main and the branch. A logprobs request's token ids (return_token_ids) equal the same request without it, greedy and seeded T 1.0: 24-token completions with logprobs: 5 (24 rows of 5) and chat with top_logprobs: 3 (110 and 138 ids; 7 and 27 answer rows of 3); the ids without logprobs equal main's. Main answers 400 "logprobs are not supported by this model or backend". The serving case checks the rows' ids against the host's top-k over the same bf16-rounded logits and their values within 1e-3.
  • Main against this branch, same machine and checkpoint: below.
  • Decode speed before and after, tools/bench_openai.py --tokens 256 --reps 3 --temperatures 0 (median of 3), runs alternated main, branch, main, branch: fibonacci-raw 25.63, 25.33 against 25.40, 25.44 tok/s; gpu-chat-no-think 25.98, 25.75 against 25.86, 25.88. Main's two runs differ by 1.2%, more than main and the branch do. bench_concurrent (3 reps; one-stream cells: per-stream decode tok/s; four-stream cells: aggregate tok/s), main -> branch, one pass over every cell: code T 1.0 25.6 -> 25.4 and 57.3 -> 56.1; chat T 1.0 25.8 -> 25.7 and 61.2 -> 61.2; code greedy 25.4 -> 25.3 and 77.2 -> 77.2; chat greedy 25.8 -> 25.8 and 79.8 -> 79.8. The T 1.0 cells were then rerun with a fresh server each in the order main, branch, main, branch (--levels 4, then --levels 1, --tokens 256 --reps 3 --temperatures 1.0; medians of three reps): code four streams 57.49, 57.27, 57.20, 57.16; chat four streams 61.51, 61.19, 61.27, 61.17; code one stream 25.49, 25.35, 25.43, 25.32; chat one stream 25.80, 25.70, 25.75, 25.69. At four streams the branch is 0.2% below main (median of six reps each), less than main's own difference between its two runs (0.5% code, 0.4% chat), so the first pass's 2.1% did not repeat; at one stream it is 0.1 tok/s (0.4%) lower in both pairs, more than main's 0.2% between its runs. Every token hash is equal across the four runs. Requests without logprobs run the same kernels as on main: the branch adds a rows.len test a window and allocates the words buffer once.
  • Prompt speed: n/a, the prompt path is unchanged (cold TTFT in the decode runs 0.100, 0.101 against 0.101, 0.101 s for fibonacci-raw and 0.330, 0.334 against 0.340, 0.344 s for gpu-chat-no-think).
  • Licence of any new weights or drafter: n/a.

Raw results (decode.json for the four decode runs, concurrent.json for both arms, the logprob requests, the serving and control logs) can be attached.

Checklist

  • The title and description match the head commit, including the receipt and the stack.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency.
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.
  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off.
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo.
  • No precision traded for speed. If the bits change, the description says which sums change and why.
  • Decode and prompt processing are no slower than main at one stream and the widest admitted; with --drafter, no slower than without it, greedy and sampled. (Not ticked: in the alternated rerun the four-stream cells are within main's own spread, but the one-stream T 1.0 cells are 0.1 tok/s (0.4%) lower in both pairs, with no added kernel on that path; see Receipt.)

@ashhart

ashhart commented Dec 2, 2026

Copy link
Copy Markdown
Owner

Thanks for the slice and the clean exactness story.

What it is: Inkling 2 Mini on CUDA currently refuses logprobs / top_logprobs because the lane backend's first_row is null; this PR fills the first token's row and each verify row from cuda.sample.Draws.logprobRows over the bf16 copy of the forward's fp32 logits that a sampled draw reads, with one shared words buffer and one download per round. The draw path is untouched and the row kernel only reads, so no served token can move - and your receipts back that up: all 540 hash values equal between main and the branch, a logprobs request's token ids equal the same request without it, and the speed deltas sit inside main's own run-to-run spread.

This is not on main: zig/src/families/inkling2/cuda_native.zig and loop_backend.zig have no logprob row path, and the Metal side (metal/backend.zig's firstRowFn / logprobRow) shows the shape the CUDA side should match. It is a real user-facing gap (Mini on CUDA is the only Mini backend without logprobs), and the host test that fails before the change (LogprobsUnsupported) is the failing-before test we ask for.

Two notes for review, both ours to handle:

  • The trial merge against current main conflicts in zig/tests/cuda/inkling2_serving_tests.zig (your Inkling 2 Mini: one shared per-head kept-state walk (CUDA uses it) and a shared DSpark lane host with one tokenBytes #4724 note: whichever lands second keeps both pairs). Do not rebase; we do that at pickup.
  • The logprob words come from bf16 logits, while the host reference is over the fp32 forward output. The 7/7 serving case says rows equal the host's over the same logits; the review should confirm the bf16 rounding path is the same one the sampled draw uses, so a row is never computed from a different copy than the token was drawn from.

Status: ready for our review and device run. The run needs one GB10 (sm_121) with Inkling-2-Mini, a logprobs: 5 and a top_logprobs: 3 request against main's refusal, plus the 4,400-id serving case; Metal is untouched.

  • Synthena

@jmpijll

jmpijll commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

Thanks. I won't rebase; the inkling2_serving_tests.zig conflict is yours at pickup as you say.

On the bf16 copy: every row is computed from the bf16 buffer the token's draw reads, on the same stream, before the next lane's draw can overwrite it.

  • Sampled lane: drawRows converts the lane's fp32 rows with ops.tobf into logits16 and draws from it; wordRows then runs logprobRows on that same logits16 without converting again. Both first and the verify round call wordRows directly after drawRows for the same lane.
  • Greedy lane: the token comes from ops.top1 over the fp32 rows, as on main. wordRows makes the bf16 copy with the same ops.tobf call the sampled path uses, and each row reports the logprob of the token that was actually drawn (LogRow.fromWords(..., got[at + i], ...)). One visible consequence: if two ids are equal after bf16 rounding, top_logprobs orders them by the row kernel's tie rule (lower id first), which can differ from the id fp32 top1 picked; the drawn token's own logprob is the same value either way.

The serving case's host reference rounds with the same round-to-nearest-even as the draws' copy (the bf16 helper in inkling2_serving_tests.zig), so its 7/7 compares rows over identical bf16 inputs.

Marking ready for review.

@jmpijll
jmpijll marked this pull request as ready for review December 2, 2026 14:01
@jmpijll

jmpijll commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

One gap to know about before the device run: with --drafter (main's batched DSpark), Mini still answers a logprobs request with 400, on main and on this head. The CUDA drafted wrapper (native/cuda_drafted.zig) never turns on first-row logprobs for Mini's opened drafter, so the path this PR adds is not reached when a drafter is loaded. A run without --drafter shows the PR's rows; a run with it would look like nothing changed.

I have the fix ready but have not pushed it, since you rebase at pickup: one field on Mini's opened drafter, one line in the wrapper (the same line open #2475 adds, so the two merge in either order), and a host test that fails without it. On a GB10 against main bc8c0c993 it keeps token ids equal with and without logprobs, with and without DSpark, and the drafted rounds' rows equal the "draft": false rows in all six cells. Say if you want it as a second commit on this PR or left for #2475.

@ashhart
ashhart force-pushed the inkling2-cuda-mini-logprobs branch from fcb2da5 to 3f6c580 Compare December 2, 2026 14:29
@ashhart

ashhart commented Dec 2, 2026

Copy link
Copy Markdown
Owner

READY to land on this head. Tokens unchanged: the logprob rows read the same bf16 copy of the logits the sampled draw reads, the draw path is untouched, and the device test compares rows with the host over the same logits. Our rebase kept both test pairs in the CUDA serving tests.

  • Synthena

jmpijll and others added 2 commits December 2, 2026 16:32
…the shared row kernel

Mini on CUDA gave no logprob rows, so the server refused logprobs for it. The first token's row and each verify row
now come from cuda.sample's logprobRows over the bf16 copy of the forward's fp32 logits that a sampled draw reads (a
greedy lane makes that copy only when a row is asked for); a round's rows go through one words buffer and one download.
Draws are unchanged. The serving test checks both rows against the host's rows over the same logits, greedy and sampled.
@ashhart
ashhart force-pushed the inkling2-cuda-mini-logprobs branch from 3f6c580 to bd198d3 Compare December 2, 2026 16:32
@ashhart
ashhart merged commit 0ba35fe into ashhart:main Dec 2, 2026
@ashhart

ashhart commented Dec 2, 2026

Copy link
Copy Markdown
Owner

Thank you @jmpijll. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes.

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.

2 participants