Skip to content

tools: compare drafted and plain IDs on recorded BF16 near-ties - #3841

Merged
ashhart merged 2 commits into
mainfrom
lead/draft-divergence-tool
Nov 19, 2026
Merged

ashhart merged 2 commits into
mainfrom
lead/draft-divergence-tool

Conversation

@ashhart

@ashhart ashhart commented Nov 18, 2026

Copy link
Copy Markdown
Owner

Adds tools/draft_divergence.py, a harness that checks drafted decoding returns exactly the token IDs plain decoding does, on the prompts most likely to break that: near-ties in recorded BF16 raw logits.

Speculative decoding verifies several draft tokens at once, so its arithmetic can run in a different order than a one-token step. A near-tie between the top two logits is where a different order could flip a token. TensorFold's rule is that drafted output equals plain output; this tool tests it where it is most fragile.

How it works:

  • From a recorded window of raw BF16 scores, it picks up to eight distinct token prefixes around the closest near-ties, ranked by margin over the BF16 spacing (reusing tools/zig/qwen27_margins.py's spacing and verdict).
  • Each prefix runs plain first, then with draft caps 1, 4 and 8, through separately configured endpoint profiles (the server takes a per-request draft flag, not a depth).
  • Requests are greedy and non-streaming, send raw token-array prompts, ask for exact IDs and ignore EOS. Token IDs compare exactly, including length.
  • Output is one summary line and a JSON report (both ID streams, draft-work counters, the first mismatch per cap, input hashes). Exit 0 is exact equality with full coverage, 1 is a divergence, 2 is incomplete or an error. No draft work done, an early stop, or plain output that fails to reproduce the recorded window counts as incomplete, never a pass.
  • It talks only to the endpoint URLs you configure, refuses credentials in URLs and does not follow redirects.

The live API does not expose raw logits, so the report carries the recorded source's score pair at the first mismatch. Given raw scores recorded for each run, the tool also says whether a mismatch was a near-tie (label near-tie) or a real fault (label bug).

Twenty fixture tests (tools/tests/test_draft_divergence.py) build requests through an injected client, with no device, model or socket. tools/draft_divergence.md has usage.

Checked on this head: the new tests (20 pass), zig build check-release-paths, and the lean check (no new problems).

  • Synthena

@ashhart
ashhart force-pushed the lead/draft-divergence-tool branch from 35dacd0 to 5659431 Compare November 19, 2026 09:57
@ashhart
ashhart merged commit d1a958e into main Nov 19, 2026
2 of 11 checks passed
@ashhart
ashhart deleted the lead/draft-divergence-tool branch November 19, 2026 09:57
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.

1 participant