Off by default. With the switch the verify graph ends with verify_clear_status, verify_scan_logits and a one-word store of the status into a host-mapped verdict word (vanilla's logits_nonfinite_rows order); the post-drain check reads that word instead of launching the scan, synchronising the stream, copying the status back and synchronising the context. Same error at the same place, before complete_window and any commit. Sealed PTX unchanged. Unit tests for the switch, the graph tail commands, the verdict decode and the post-drain dispatch. Note updated with the corrected O7 ledger wording. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
23 KiB
Verify end to the first draft kernel (ledger row O7): where the 0.32 ms go, and what "accept on the device" is
Status: sections 1-7 are a reading of the code and of existing measurements; section 8 is option A, implemented behind
LELEKA_SM120_ACCEPT_ON_DEVICE (default off) on the coordinator's decision. No GPU run: nothing here is measured. Base: 5b8c0eba0 (branch
claude/speed-vs-strata-08143a), Strata pin 41cf05a06a25 (docs/upstream.md). Ledger row: step-ledger.md section C3,
O7: LEL 0.32 ms, VANL 0.08 ms ("accept decided on the device"), +0.24 ms, source ORCH (a figure given by the
orchestrator session; this note does not re-derive it).
1. Result in five lines
- The premise of the row is not what the vanilla code does. In vanilla's greedy serve loop the accept count
ais computed on the host (engine/strata/src/program/generate.cpp:15255:while (a < T-1 && window[a+1] == outv[a]) ++a), the commit getsa + 1from the host (:15271), andMtpDrafter::draftreceivesaas anint, writes it to a host-mapped word (src/core/mtp.cpp:1605,h_row_[0] = a) and picks the round graph byT(:1580-1582). The device-side accept in the vanilla tree is the probabilistic rejection sampler (STRATA_SPEC_PROB,src/kernels/cuda/sampler.cu:883-1045), which is another mode and not the default greedy path. - What vanilla does keep on the device is the finite (NaN) verdict of the head logits.
Verifier::recordcaptureslogits_nonfinite_rowsinto the window's own stream after the greedy pick (src/core/verify.cpp:2380); after the window's onecudaStreamSynchronize(:3178) the host only reads the mapped ids (:3260) and the mapped flags (note_nonfinite,:4180). No extra launch, no second sync. - Ours does that check after the drain, with two more synchronisations (section 2, hops 4-5), in files that are ours
(
verify_gdn_journal_ladder_logits_scan.rs,original_verify_schedule/window_phases.rs,original_gpu_verify_bridge.rs). - An exact device-side accept that removes a host round trip cannot be built inside our files. Every consumer of
a(the controller, the draft round, the chain steps, token emission, the NaN guard) is host code outside them (section 4). I stopped at the decision point and gave the options (section 5); the coordinator chose option A, which is section 8. - Recommendation: option A (the finite verdict into the verify graph, mapped result, no new PTX; it is vanilla's structure and lives in our files) as the step for this row, with the honest size: the only measured span of the scan is 0.05 ms per round (older tree), i.e. about a fifth of the +0.24 ms. The rest of the gap is the host chain between the sync and the draft launch (hex-finish).
2. Our path, verify graph end to the first draft kernel
Per round, in call order. File:line refer to this tree (crates/cuda-driver/src and
crates/engine-qwen35-cuda/src/qwen_forward).
| hop | what happens | where | host or GPU | figure (source) |
|---|---|---|---|---|
| 1 | last kernel of the window graph (greedy argmax into the head rows' mapped words) ends | native_head/original_native_head_rows/original_native_head_rows_greedy_submit.rs:84-104 (greedy), captured by capture_head_greedy from original_verify_window_ops/window_ops_kernels_and_pcie_plan.rs:244 |
GPU | n/a |
| 2 | compute.synchronize_with_receipt() returns, then copy.synchronize() (already idle), release_pcie_sources, record_window_profile (off) |
original_verify_schedule/window_phases.rs:277-285 (drv.sync_compute, drv.sync_copy) |
host wake from a blocking sync | not isolated; drv.sync_compute + drv.head together 0.88 ms incl. the last layer and head on the GPU (docs/serve-step-costs.md, job 901) |
| 3 | verifier_head_after_drain: stream and receipt checks, resources_after_stream_drain |
original_gpu_verify_bridge.rs:7-20 |
host | below the noise of the spans |
| 4 | post-drain logits scan, launch and stream sync: verify_clear_status + verify_scan_logits over all T x vocab words are launched on the compute stream, then stream.synchronize() |
original_verify/original_verify_gdn_journal/verify_gdn_journal_ladder_logits_scan.rs:116-136 (head.validate_stream) |
host launch (2 kernels) + a second blocking sync + the scan itself on the GPU | head.validate_logits (the whole of hops 4 and 5): 0.05 ms per round, job 901 on claude/ms-trim (docs/serve-step-costs.md: "head validation scan 0.05") |
| 5 | status read back: cuMemcpyDtoH of the 4-byte status from the arena's hit_count scratch, then a context-wide synchronize |
same file :138-157 (head.validate_ctx_copy) |
host, third sync of the window | in the 0.05 ms above |
| 6 | sample_on_stream is skipped for greedy; read_selection reads the mapped ids and range-checks them; complete_window copies them, sets window_ready |
original_native_head_rows_greedy_submit.rs:156-168, 235-242, window_phases.rs:303-321 (head.read_ids) |
host | not isolated |
| 7 | back in the engine: admit_receipt, quality_force::apply, optional traces, NativeWindow built |
original_serve_native/native_serve_port_original_serve_port.rs:60-89 |
host | in the "verify_commit outside any span" row below |
| 8 | controller: accepted_prefix (the while loop over inputs/outputs), note_round_profile, begin_adaptation (choose + queue swaps), commit_verified(keep = a + 1) |
original_spec_controller/original_spec_controller_methods/commit_parts.rs:12-24, 78-121; native_serve_port_original_serve_port.rs:92-109 |
host | verify_commit outside any span 0.094 ms at 247k context (0.038 at 45k) (draft-tail-5090.md table); round.adapt (choose + queue) 0.079-0.084 ms (decode-tail-5090.md, section 5) |
| 9 | commit enqueue: host.commit_enqueued, Verifier::commit = stage_commit(keep), graph launch, event record (async, no wait) |
original_verify_schedule/original_verifier.rs:34-67, original_verify/share_window_modules/original_verify_bank.rs:158 |
host | drv.commit_enqueue 0.004 ms, round.commit 0.005-0.006 ms (draft-round-5090.md section 2; draft-tail-5090.md) |
| 10 | draft_overlapped -> launch_overlapped: take_window_parts, host.launch_draft (staging of the round's mapped words including a, snapshot publication, round graph launch). The draft stream does not wait for the commit event unless LELEKA_SERVE_DRAFT_AFTER_COMMIT=on |
original_serve_native/native_window.rs:155-201, draft_waits_for_commit :272; draft side in mtp_original_* (hex-finish) |
host | draft.launch 0.027-0.041 ms untraced (draft-round-5090.md section 2; decode-tail-5090.md section 5); window graph launch 0.008 ms |
| 11 | first kernel of the MTP round graph starts | GPU | tracer timeline: verify end -> first kernel of the round graph 315 us (before), 230 us (fused commit + attention switch) in a CUPTI window; the tracer inflates the launch calls (draft-round-5090.md section 2) |
Sum of the independently measured host spans of hops 4-5, 8, 9, 10: 0.05 + (0.09 + 0.08) + 0.005 + 0.035 = about 0.26
ms, plus the wake-up latencies of three blocking syncs that nobody has isolated. That is the same size as the ORCH 0.32
ms. It is an addition of figures from different trees and runs (older ms-trim for the scan, 247k context for
verify_commit), so it is an estimate and not a trace. The CUPTI window CL.1 has the real gap; the script that prints
round and verify-graph spans is scripts/e2e/codex/speed/decode_rounds.py (the "verify end to first draft kernel"
column is the orchestrator's).
Where the draft sits relative to the commit: the commit graph is not on the draft's critical path (the draft stream no
longer waits for it, draft-round-5090.md section 2: draft end - commit end 1,066 us), so hop 9 costs the critical path
only its host time (about 0.01 ms), not the commit graph's GPU time.
3. Vanilla's path (the 0.08 ms)
| hop | what happens | where |
|---|---|---|
| 1 | window graph ends; its tail contains the greedy pick and logits_nonfinite_rows writing to mapped flags |
src/core/verify.cpp:2372-2380 |
| 2 | one cudaStreamSynchronize(cs_); copy_ is synchronised only if it was used |
:3178, :3213-3216 |
| 3 | the host reads the mapped ids (out[t]), then note_nonfinite reads the mapped flags: no launch, no sync |
:3260, :4180-4200 |
| 4 | a by the while loop; adaptive tier on a separate std::thread (not on the path) |
generate.cpp:15255-15270 |
| 5 | ver.commit(a + 1): enqueue, async |
:15271, core/verify.cpp set_commit_async |
| 6 | nonfinite_hit reads the flags already read; tokens are printed and flushed; mtp.draft(T, outv, p, a, ...) stages the mapped words (h_row_[0] = a, cells p + a + j) and launches the round graph on its own stream cs_ with no dependency on the commit |
:15276-15316, src/core/mtp.cpp:1597-1629 |
So the difference is not "device against host accept". It is: one blocking sync against three (hops 2, 4, 5 of ours),
no scan launch against two kernels, and a short host chain (no begin_adaptation, no controller bookkeeping, no
snapshot publication) before the draft launch.
4. Can an exact device-side accept be built inside our files?
The computation itself is trivial and exact: one single-thread kernel after the greedy pick that compares
inputs[i + 1] with ids[i] (the staged window tokens are on the device) and stores a or keep = a + 1. It would be
bitwise-equal to the host loop (integer compare). The question is who can consume it without a host read, and there the
answer is no, inside our files:
- The draft round and chain need
ain host-staged mapped words before the launch:launch_innerreadswindow.accepted_row(mtp_original_full_drafter/original_mtp_drafter/original_mtp_drafter_launch_rounds.rs:16, 131), the chain steps' cells arep + a + jstaged by the host (vanilla:mtp.cpp:1601-1603). Making the round graph readafrom the device means editingmtp_original_*and the draft kernels' operand addresses: another team's files, and the chain stepsj >= 1would still have to be launched from the host after reading draftj - 1(the stop rulep_j >= min_pis host-side, both in vanillamtp.cpp:1694and ours). - The controller (emission of tokens, EOS, the budget
max_new, the adaptive window policyobserve, the cancel check) needsaon the host in the same round; it cannot be deferred. - The commit is the only consumer that could take a device value: its
keepis a mapped word staged bystage_commit(original_verify_bank.rs:158, ours). Enqueuing the commit graph right behind the window in the same stream, withkeepcomputed on the device, would remove hop 9 from the host path (about 0.01 ms) and nothing else, because the commit is not on the draft's critical path. It is also unsafe: the NaN guard may refuse the window (discard_windowinverifier_commit_window_lifecycle.rsrequires that no commit was enqueued, andnative_serve_port_original_serve_port.rsdiscard_windowfails the port if one is pending: "an enqueued commit cannot be undone"), and the finite verdict is exactly what is decided after the drain. A pre-launched commit would have to run behind the finite verdict on the device (a conditional graph node), which is a larger design for a 0.01 ms host saving. - CUDA conditional nodes (graph
switchona) could select the right draft round graph on the device and drop the host launch altogether, but the draft graphs are keyed per row count and rebuilt per request (OriginalGraphKey::MtpRound { rows, coupled }), the chain steps are host-driven, and it is a new draft design (hex-finish,mtp_original_*). Not a step of the device part.
Verdict: not implementable as an exact, same-policy device accept inside original_verify_window_*,
original_verify_gpu_plan* and the cuda-driver verify files without edits to the draft chain and the controller.
Per the brief I stop here.
5. Options and recommendation
| option | what | files | saves (documented / estimated) | risk |
|---|---|---|---|---|
| A. Finite verdict in the verify graph (vanilla's structure; the "verdict decided on the device") | capture verify_clear_status + verify_scan_logits (already in the sealed original_verify.ptx) after capture_head_greedy in OriginalVerifyWindowOps::head, the result in a host-mapped word; post-drain code only reads it (no launch, no stream sync, no cuMemcpyDtoH, no context sync) |
ours: original_verify_window_ops/window_ops_kernels_and_pcie_plan.rs, verify_gdn_journal_ladder_logits_scan.rs, original_gpu_verify_bridge.rs, the mapped-slot list in original_verify.rs; one new mapped word; no new PTX |
hops 4-5: 0.05 ms per round measured on ms-trim (job 901); the GPU part (the scan over T x 248k words, 2 extra kernels) moves into the graph's own tail |
the scan kernel atomicOrs into the status: on a device-arena word that is fine, on host-mapped memory atomics are platform dependent. The safe form is: scan into a device word (as now), then a plain 4-byte store to the mapped word at the end of the graph (the greedy kernel already stores its ids to mapped memory this way). The NaN guard behaviour must stay (Error::NonFiniteMmqOutput("Original Verifier full logits") before any token is used); a test with an injected non-finite logit (the vanilla analogue is STRATA_NAN_INJECT) is needed on the GPU. No number of the model changes |
| B. Shorten the host chain between the sync and the draft launch | begin_adaptation (0.08), verify_commit bookkeeping (0.09 at 247k, O(context)), draft staging (0.03-0.04): move off the path or make O(1) |
original_spec_controller*, original_serve_native*, mtp_original_*: hex-finish |
up to 0.15-0.20 ms of the 0.24 (sum of documented spans) | owned by hex-finish; the two earlier trims (decode-tail, draft-round) already took 0.16 ms and 0.03 ms of it |
C. Commit pre-launched with a device keep |
section 4, item 3 | ours | 0.01 ms host, 0 on the critical path | breaks discard_window unless conditioned on the finite verdict; not recommended |
| D. Device-selected draft (conditional graph nodes) | section 4, item 4 | draft chain | host launch of the round graph, potentially most of hop 10 | new design in their files; not a device-part step |
Recommendation: A for this row (smallest, exact, in our files, it is what vanilla has), with the expectation set
from the data: about 0.05 ms, not 0.24. Close the remaining part of O7 by B with hex-finish. If A is approved I would
implement it under LELEKA_SM120_ACCEPT_ON_DEVICE (default off, resolved in original_verify_window_sm120.rs in its own
block), keep the post-drain scan as the off path, and add unit tests for the switch resolution, for the graph recording
(two more nodes in the verify graph, DBG graph window t=.. nodes=), and for the refusal on a non-zero status. Suggested
ledger text for O7 meanwhile: "vanilla's greedy accept is host-side (generate.cpp:15255); the difference is the
finite-verdict scan after the drain (3 syncs against 1) and the host chain before the draft launch".
6. How the orchestrator would see option A in a CUPTI window (if built)
- Before: after the verify graph, standalone launches of
verify_clear_statusandverify_scan_logits(1 block, then up to 65535 blocks of 256 threads) on the compute stream, followed by a gap while the host doescuMemcpyDtoHand a context synchronize, then the commit and draft launches. - After: the same two kernels as the last nodes of the verify graph (kernels per verify graph +2, outside-the-graph
kernels per round -2), and no
cuMemcpyDtoH/cuCtxSynchronizein the API-call list between the window and the commit (the ledger's API calls per round, row O4, and syncs per round, row O6, fall by one and one respectively). - Host-side check without CUPTI:
LELEKA_SERVE_PROFILE=1, spanshead.validate_logits,head.validate_streamandhead.validate_ctx_copy(all three should vanish or become sub-microsecond),drv.head.
7. Sources
engine/strata/src/program/generate.cpp:15236-15316,src/core/mtp.cpp:1559-1744,src/core/verify.cpp:2372-2380, 3170-3270, 4180-4200(vanilla, read-only).docs/experiments/draft-round-5090.mdsection 2 (CUPTI window of the commit, round and step graphs; untraced host spans),docs/experiments/decode-tail-5090.mdsections 5-6 (host spans per round),docs/experiments/draft-tail-5090.md(per-round table at 247k),docs/serve-step-costs.md(job 901, "head validation scan 0.05"),docs/experiments/codex-compare-speed-gap.md"Kernel level: one CUPTI window of request 29" (round 17.86 against 15.89 ms; after the verify graph to the next start 4.30 against 4.14),docs/experiments/step-ledger.mdC3/C5.
8. Option A as built: LELEKA_SM120_ACCEPT_ON_DEVICE (default off)
What it does. With the switch on, the verify graph of every T ends with the finite scan of the head logits, after
the greedy pick: verify_clear_status, verify_scan_logits (both already in the sealed original_verify.ptx, the
same launch shapes and arguments as the literal post-drain scan) and one more node, verify_copy_i32_from_mapped_kernel
with n = 1, that stores the status word into a host-mapped verdict word (a plain store, as the greedy kernel stores its
ids; no atomics on mapped memory). So the graph has three more kernel nodes, not two: the store is the third. The
post-drain check then reads that word and launches, copies and synchronises nothing. With the switch off nothing is
recorded and the post-drain path is the literal one, unchanged.
Semantics when on (same as off). The verdict is read at the same place, in verifier_head_after_drain before the
head selection is read and before complete_window, so a non-finite window raises the same
Error::NonFiniteMmqOutput("Original Verifier full logits") before window_ready is set and before any commit can be
enqueued (the commit needs window_ready). discard_window and the controller's NaN-guard path are untouched. The word
is 0 finite, 1 non-finite; it is armed with a pending sentinel (0x5a5a5a5a) at allocation and after each read, so a
graph that did not store it reads as an InvalidDriverValue error, never as "finite".
Switch. Sm120Switches.accept_on_device, DEFAULT_ON_ACCEPT_ON_DEVICE = false, resolved in
original_verify_window_sm120.rs in its own lines (variable LELEKA_SM120_ACCEPT_ON_DEVICE, =1/on on, =0/off
off; a card below compute capability 12.x never takes it, like the others). resolve_sm120_switches marks the head rows
of the graph being recorded (each T has its own) through a Cell<bool> on OriginalNativeHeadRows; WindowPolicy
(398 lines) is not touched. The startup line leleka-serve sm120 switches: ... prints accept_on_device in the
requested set.
Files. original_verify/finite_verdict.rs (new: the commands, the verdict decode, the post-drain dispatch),
original_verify_window_sm120.rs (switch), original_verify_window_ops/original_verifier.rs (marks the head rows),
original_verify_window_ops/window_ops_kernels_and_pcie_plan.rs (head() records the tail),
original_verify/original_verify_gdn_journal/verify_gdn_journal_ladder_logits_scan.rs (shared operands, the capture),
native_head/... (the mapped verdict word next to the ids), original_gpu_verify_bridge.rs (the post-drain dispatch),
original_verify.rs (one mod). No PTX was added or changed, so no nvcc was needed.
Identity. The model's numbers are not touched: nothing is recorded before the greedy pick changes, the added nodes
read the logits and write only the status scratch (hit_count word 0, which the literal post-drain scan already
overwrote) and the verdict word. The ids, logits and top-16 rows must be bit-equal; the orchestrator's teacher-forced job
(draftround-id.sh) with the switch set is the gate. The scan ordering relative to the commit graph is the stream
order, as before.
Tests (unit, no GPU): switch default off, on by variable, master switch, below 12.x, not a side branch
(original_verify_window_sm120.rs); the graph tail is exactly verify_clear_status, verify_scan_logits, the store, in
that order, with the literal scan's launch shapes; the verdict decode (finite, non-finite with the literal error, pending
or stale words refused); with the verdict in the graph the post-drain scan closure (launch, stream sync, copy back,
context sync) is never called and only the mapped read runs, and with the switch off the scan runs and the word is not
read; the same error on both paths. Not covered without a GPU: that the recorded graph really has the three nodes
last (the recorder needs a device); the orchestrator checks it with DBG graph window t=.. nodes= (+3 nodes per window
graph with the switch on) and with a CUPTI window (below).
How to see it. CUPTI window: with the switch on, verify_clear_status, verify_scan_logits and
verify_copy_i32_from_mapped_kernel (1 block) are the last three kernels of each verify graph and no longer launch
after it; no cuMemcpyDtoH and no cuCtxSynchronize between the window's cuStreamSynchronize and the commit launch
(API calls per round -1 to -2, syncs per round -2, rows O4 and O6). LELEKA_SERVE_PROFILE=1: the spans
head.validate_logits, head.validate_stream and head.validate_ctx_copy disappear. Expected size: the 0.05 ms per round
measured for the scan on the older tree (section 2), not the whole +0.24 ms.
Risks. (1) The extra three nodes sit at the end of the graph and add their GPU time (the scan over T x 248k words,
a few microseconds) to the graph itself while the host no longer waits for a separate launch; the net is for the
measurement to say. (2) The store to mapped memory is visible to the host after the stream synchronisation, as the ids
are; no separate fence was added. (3) A non-finite logit must still be injected on a GPU once to see the error path
(vanilla has STRATA_NAN_INJECT; ours has no injector for the logits).
Corrected wording for ledger row O7 (section C3), to copy
| O7 | verify end to first draft kernel, ms | 0.32 | 0.08 | +0.24 | ORCH | hex-finish + device | fixing: the accept count is host-side in both engines (vanilla
generate.cpp:15255, the draft takesaas anintand stages it,mtp.cpp:1605); the vanilla window decides only the finite verdict of the logits on the device (verify.cpp:2380) and reads it with the window's one sync, ours scans after the drain (stream sync, copy back, context sync: three syncs against one, 0.05 ms in the older profile). Device part:LELEKA_SM120_ACCEPT_ON_DEVICErecords the scan in the verify graph (code onclaude/verify-accept-on-device, off, not measured). The rest of the gap is the host chain between the sync and the draft launch (controller bookkeeping 0.09 at 247k,begin_adaptation0.08, draft staging 0.03-0.04),hex-finish. Note:docs/experiments/verify-accept-on-device.md|