perf(dflash): gate top-5 logits diagnostic behind LLAMA_DFLASH_DEBUG#78
Merged
Conversation
Epoch #73 task 5 (DFlash perf scout, in lieu of titan-gated bench). The top-5 logits selection at common/speculative.cpp:935 was unconditional — `if (i == 1)` gated when (once per draft call) but not whether. The LOG_INF below it is verbosity-gated, so on production the log is suppressed, but the O(n_vocab * log 5) selection still runs. On gemma-class vocabs (~256k tokens) the selection burns ~1ms per draft call. At Round-10's measured ~8% accept rate, every output token costs several draft calls — so this debug computation is in the steady-state hot path. Fix: extend the gate to `if (i == 1 && dflash_debug)`. `dflash_debug` is the cached env-var probe already declared at line 883 (used by the features-debug block immediately above). When LLAMA_DFLASH_DEBUG is set the diagnostic still fires; production is unaffected. Found during epoch #73 task 5 — DFlash hot-path scout. Local CPU build verifies; behavior change only when LLAMA_DFLASH_DEBUG is set (was unconditional → now gated; same code runs when enabled).
This was referenced Jun 5, 2026
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.
Epoch #73 task 5 (DFlash perf scout, in lieu of titan-gated bench).
Finding
common/speculative.cpp:935has an unconditional top-5 logits selection inside the DFlash drafter's hot path:The
if (i == 1)gates when (once per draft call) but not whether. TheLOG_INFbelow is verbosity-gated, so on production the log is suppressed — but the O(n_vocab × log 5) selection still runs.On gemma-class vocabs (~256k tokens), that's ~1ms per draft call. At Round-10's measured ~8% accept rate, every output token costs several draft calls — so this debug computation is in the steady-state hot path.
Fix
Extend the gate to
if (i == 1 && dflash_debug).dflash_debugis the cached env-var probe already declared at line 883 (used by the features-debug block immediately above).Verified
cmake --build build --target llama-serversucceedsLLAMA_DFLASH_DEBUGis set (was unconditional → now gated; identical code runs when enabled)Out of scope
Other DFlash hot-path observations from the scout that did NOT make this PR (no clear-win fix):
accumulated_ctxgrows unboundedly across draft calls. With defaultLLAMA_DFLASH_CTX_WINDOW=512only the tail is used, but the buffer keeps growing. Memory leak shape, not perf. Worth a follow-up trim.std::sortinside the j-loop is asymptotically fine but has a 5-element sort per insertion. Could be replaced by a hand-rolled 5-slot insertion-sort (O(5) vs O(5 log 5 × n_vocab) constant factor). Speed-up is small and only matters when DFLASH_DEBUG=1.