fix(ds4): preserve exact speculative verification#548
Open
cheese-cakee wants to merge 2 commits into
Open
Conversation
cheese-cakee
marked this pull request as ready for review
July 20, 2026 14:12
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 6 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
all_logits_out, instead of applying the multi-token last-row output optimizationDFLASH_DS4_FUSED_VERIFY=1fail closed to the normal verifier because the persistent fused graph is not token-exact at near-tied logitsDFLASH_DS4_ALLOW_APPROX_FUSED_VERIFY=1research opt-inRoot cause
Current
maincombines the multi-token output-projection optimization with a verifier hook that still consumes one logits row per verified token. The projection could allocate only the final row while the verifier read allqrows, triggeringGGML_ASSERT(offset + size <= ggml_nbytes(tensor))in normal DSpark verification.After restoring the requested row count, the fused verifier still diverged deterministically. Its persistent whole-model HIP graph uses a different HC/reduction topology from the normal causal verifier. Identical inputs, positions, and cache state therefore produce small numerical differences that can flip a near-tied greedy token; this is a numerical-parity boundary, not a binding or cache-state bug.
Runtime behavior
DFLASH_DS4_FUSED_VERIFY=1now emits a warning and uses the normal verifier. The previous graph remains available only when both the public flag andDFLASH_DS4_ALLOW_APPROX_FUSED_VERIFY=1are set, making approximate inference an explicit research choice.DFLASH_DS4_PARITY_TRACE=1records full generated token IDs plus per-row top-two logits and margins.DFLASH_DS4_ADAPTIVE_WIDTH=0fixes the verification width for deterministic comparisons and takes precedence over the legacy/tmp/ds4_awidthcontrol. Both diagnostics are off by default.Reproduction
Hardware and software:
gfx1151, ROCm 7.2.4main:405ab02482592f248f8f574087cf6964e06698b7DeepSeek-V4-Flash-IQ2XXS-w2Q2K-AProjQ8-SExpQ8-OutQ8-chat-v2-imatrix.gguf, SHA-256efc7ed607ff27076e3e501fc3fefefa33c0ed8cf1eff483a2b7fdc0c2e616668ds4-dspark-draft.gguf, SHA-25648883d35b8a67ecfd2858a90e12a47d04cb5ac581acef868ca0f58544816f746Explain why a bicycle stays upright while moving.q=4, adaptive width disabled, model-default six expertsThe first divergence occurs on the eighth generated token:
Tracing confirmed identical verifier inputs, positions, and cache state before the first fused batch. The approximate graph already shows numerical differences at the initial verification step.
Validation
gfx1151: passedtest_deepseek4_unit: passeddflash_servermodel-backed regression:PASS: 32 generated token IDs are identicalpython -m py_compile server/scripts/test_ds4_fused_verify_parity.py: passedgit diff --check: passedThe model-backed test launches the production server once in normal mode and once with the public fused flag, then compares the complete generated token trace. It is intentionally a hardware/model regression rather than a normal CI test because the target and draft artifacts total roughly 98 GB.