Skip to content

cuda: opt-in complete-round attribution for speculative decoding - #5263

Open
ashhart wants to merge 25 commits into
mainfrom
lead/cuda-round-attribution
Open

ashhart wants to merge 25 commits into
mainfrom
lead/cuda-round-attribution

Conversation

@ashhart

@ashhart ashhart commented Nov 26, 2026

Copy link
Copy Markdown
Owner

Adds an opt-in attribution of complete speculative rounds on CUDA, so we can see where a round's time goes before choosing what to optimise next. With TF_CUDA_ROUND_TRACE set, each round writes a versioned record: source and binary identity, checkpoint and quantization, prompt and sampling identity, live rows, shape bucket, MT2 selection, QMMF N/K/SK/cluster/reduce, proposal nodes, connected accepted depth, keep/rollback and the committed ids. Device events are correlated with each launch and joined to forward/land, token readback, proposal hold/sync and candidate-frame readback. The record keeps separate budgets for target verify, proposal, attention, QMMF, logits/sampling, host wait and state publication, and never reports a sum of kernels as the complete round.

With the variable unset, the attribution is compiled out of the legacy timing path: no new events, syncs, allocations or branches beyond the flag test. With it set, the extra events and host reads cannot change output.

A review asked for 11 fixes (strict MT2 comparisons, schema-version enforcement, ordered frame windows, MTP absorption counted as proposal work, event-pair recovery and ownership on failure, YaRN geometry bound into the round identity). Each has its own commit and a host test that fails before and passes after.

Not yet run: a GB10 collection pass. The decision gates it feeds: reopen kernel ranking if QMMF is under 60% of the GPU-active round, and skip MT2 fusion if MT2 improves the median round by less than 5%.

  • Synthena

Recognize aliases of typed environment-map fields so the health nonce is inventoried. Regenerate and tag all five round-attribution names. Move the unchanged draft timing helper behind its existing alias to keep cuda_draft.zig at the 600-line cap.
@ashhart
ashhart force-pushed the lead/cuda-round-attribution branch from cc3b89d to abeb260 Compare November 28, 2026 17:15
@ashhart ashhart added kind:feature Classified by Synthena as feature addition synthena:needs-changes Reviewed by Synthena; changes requested labels Dec 3, 2026
@ashhart

ashhart commented Dec 3, 2026

Copy link
Copy Markdown
Owner Author

Synthena Initial Review — Needs changes (kind:feature)

Adds an opt-in CUDA complete-round attribution for speculative decoding behind TF_CUDA_ROUND_TRACE, with identity, policy-clock tapes, health nonce echo, and host tests. The diff is large and touches the serving path, and CI (pytest, zig, zig-windows) is failing while the branch is mergeable-conflicting.

  • Branch currently has merge conflicts against base.
  • Failing CI check(s): pytest, zig, zig-windows.

Findings:

  • [BLOCKER] zig/src/families/qwen3_5/cuda_pick.zig: The bounds check compares against c.vocab, but the function receives an opaque context pointer that is never used, so the vocabulary size is not actually sourced from the model; if the caller's vocab differs from the compile-time constant, valid tokens are rejected or out-of-range handles pass. Suggested fix: Take the vocabulary size from the passed context (or the engine's actual vocab) instead of the compile-time config constant, and use the context parameter.
  • [BLOCKER] zig/src/families/qwen3_5/cuda_shapes.zig: This check runs after appending frame metadata but t.fail is invoked unconditionally when learning/pockets are active, aborting serving runs that previously worked whenever the attribution build flag is on, not only when TF_CUDA_ROUND_TRACE is set. Suggested fix: Gate the failure on the runtime trace flag (owner active) rather than the compile-time profile, or defer/skip attribution for learning/pocket shapes.
  • [BLOCKER] zig/src/families/qwen3_5/cuda_draft_graphs.zig: Skipping timing nodes during graph capture changes which kernel nodes are captured when attribution is compiled in, altering the replayed graph relative to the untraced path even when TF_CUDA_ROUND_TRACE is unset at runtime (the guard is comptime, not runtime). Suggested fix: Make the skip conditional on the runtime trace flag (owner != null and active) so the captured graph is byte-identical when tracing is off.
  • [WARNING] zig/src/server/status_routes.zig: Echoing an arbitrary environment value into the open /health response leaks a caller-controlled string to any unauthenticated client that can reach the endpoint, and the env var name is not documented as spawned-child-only. Suggested fix: Restrict the nonce to an internal/spawned-child source (not general env) or validate/limit its format and length before echoing; document the threat model in docs/environment-names.md.
  • [WARNING] zig/src/native/cuda_policy_clock.zig: Policy.open unconditionally prints the full serialized config on every open (even when neither record nor replay is active is avoided, but any record/replay use dumps config to stderr), which is noisy and may leak configuration details in shared logs. Suggested fix: Gate the print behind the diagnostic flag or a TF_ debug env var, and route it through the project's logging facility.
  • [WARNING] zig/build/qwen35_round_identity_host.zig: The host test extracts a slice of cuda_native.zig by string matching source text; any unrelated edit to that file's formatting breaks the build of this test step with an opaque panic. Suggested fix: Move the post-init statements into a real function in cuda_native.zig that the host test imports directly, instead of slicing source text at build time.
  • Synthena

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind:feature Classified by Synthena as feature addition synthena:needs-changes Reviewed by Synthena; changes requested

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant