Repository navigation
Remove blocking reads from FlashInfer planning in the speculative cycle (hostgap) - #120
Conversation
cycle_profile.py holds C streaming requests in decode and measures unprofiled cycle time from the decode-pass counter, py-spy shares and nsys windows; gap_analysis.py attributes GPU idle per cycle to the host function open on the scheduler thread and lists blocking host calls; equality.py compares greedy outputs under a deterministic batching protocol; plan_equivalence.py checks the sync-free plans against FlashInfer's stock plan on the GPU; ab_sweep.sh and ab_summary.py run and summarize interleaved bench sweeps.
…e a hung py-spy The first profile run lost client token counts when http.client's chunked line iterator failed mid-stream, sampled far past the model's end of text under ignore_eos, and aborted a step when py-spy hung. Windows now start C new requests (at most 4,096 tokens), mark any window where a stream ended early, and py-spy runs under timeout.
… hold At a shared slot's static memory fraction of 0.25, SGLang sizes the pool from the memory free at start-up, so with other shared servers resident the MTP server could not load (all four variants failed on 2026-10-01).
Every server starts on an empty GPU (at least 90 GiB free) with the running limit, KV tokens and mamba slots set explicitly; launch_summary records the resolved limits, pool sizes and the running high-water mark, and compare refuses equality between servers whose pools differ.
…windows from summaries
…GLE seam in gap_analysis
…lity, before/after cycle times Patch 0004 joins the exported series; its GPU check, equality and timing are queued.
# Conflicts: # engine/sglang/README.md
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Verdict: REQUEST CHANGES Review of the exact head 5b62d27 ("Relate the hostgap arms to bench's tuned arms"). The engine work is sound, and the exactness evidence supports bitwise equality for 0001-0003. What needs changing is how the timing evidence is reported. The headline idle figures come from host-traced runs. One quantity in the mechanism argument is mislabelled. And 0004 is described as equivalent without a check. What I verified
Blocking
Suggestions (non-blocking)
|
- Engine series: 0004's commit message no longer quotes host timings that have no committed artifact (its tree is unchanged); new 0005 mirrors FlashInfer plan()'s NVFP4 disable_split_kv rule and fixes the module docstring. The engine README's default apply command is the validated 0001-0003; 0004-0005 are an optional, not yet validated step. - summarize.py writes per-label provenance (commits, launch command, flag environment, start time), every counted window, the stock idle estimate from the patched trace's GPU busy time when stock has no trace of its own, the before/after pairs with their start times, and the GPU work queued at the EAGLE seam. - hold_mtp.sh runs tests/test_hostgap_plan.py first; both hold scripts profile patched before stock, so with the earlier hold they form an A-B / B-A pair.
…claims Review of PR #120: the headline idle is now the derived untraced estimate (stock MTP 1.44-1.79 ms, 21% to 9% of the cycle; assumption stated), with traced values kept for attribution only. The share of idle the patches remove is given per batch size (13-16% at B <= 8, 55% at B = 128), the queued GPU work at the seam is 0.54-0.90 ms (the 0.93-1.15 ms figure was the idle gap), the c = 128 serving-loop attribution is a labelled hypothesis, the before/after pairs are described as sequential, the DFlash gain as unconfirmed, and the py-spy, eager-time, DFlash B = 1 and validation-count figures match the committed files. cycle_profiles.json is regenerated with the new summary fields; every earlier value is unchanged.
# Conflicts: # engine/sglang/README.md
|
@codex review |
|
Verdict: APPROVE (provisional, on e1dc80f: Codex is still running on this head. I will confirm or withdraw once it finishes.) Re-review of the commits since 5b62d27: 7e42b57 (code), 2e61ad9 (evidence and README), and e1dc80f (merge of main; the backbone patch files in the stat come from #91 through main). All eight blocking items from 5933518035 are resolved.
Also verified
Suggestion (non-blocking). The one |
|
Codex Review: Didn't find any major issues. Delightful! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Verdict: APPROVE (confirmed on e1dc80f) Codex finished its review of e1dc80f with no findings: the summary reads "Completed", it reacted with a thumbs-up, and it left no inline comments on this head. The head is unchanged, so my approval stands. The remaining |
Fold in evidence/hostgap/ as its README scopes it. The untraced stock idle is derived (1.44-1.79 ms per tuned MTP cycle, 21% at B = 1 to 9% at 128; 1.36-1.46 ms for DFlash block 8). Patches 0001-0003 keep plans, attention output bits and greedy outputs equal to stock in the same configuration (192/192 requests per arm at c = 1, 8, 32, top-k 1 chains, radix off). The MTP cycle shrinks 2.7-4.8% in held batches, 13-16% of the idle at B = 1-8, 27-35% at 32-64 and 55% at 128, from sequential (not interleaved) pairs; the DFlash gain is unconfirmed. Patches 0004-0005, the serving A/B and retaken stock traces are pending (hostgap-served). Adds the hostgap register entry and pins-table series, the System overheads row of the levers table and the H6 status row.
Fold in evidence/hostgap/ as its README scopes it. The untraced stock idle is derived (1.44-1.79 ms per tuned MTP cycle, 21% at B = 1 to 9% at 128; 1.36-1.46 ms for DFlash block 8). Patches 0001-0003 keep plans, attention output bits and greedy outputs equal to stock in the same configuration (192/192 requests per arm at c = 1, 8, 32, top-k 1 chains, radix off). The MTP cycle shrinks 2.7-4.8% in held batches, 13-16% of the idle at B = 1-8, 27-35% at 32-64 and 55% at 128, from sequential (not interleaved) pairs; the DFlash gain is unconfirmed. Patches 0004-0005, the serving A/B and retaken stock traces are pending (hostgap-served). Adds the hostgap register entry and pins-table series, the System overheads row of the levers table and the H6 status row.
Appendix E: blocking reads removed from attention planning (#120)
Without a profiler, stock SGLang leaves the GH200 idle an estimated 1.44-1.79 ms of each tuned-MTP cycle for Qwen3.5-4B at held batches of 1-128 requests: 21% of the cycle at B = 1, 9% at B = 128 (derived; the assumption is below). This PR names where that idle comes from, removes the blocking device-to-host reads on the draft and verify planning paths with bitwise-identical plans and outputs (patches 0001-0003), and measures what that buys: MTP cycles 2.7-4.8% shorter, which is 13-16% of the idle at B = 1-8, 27-35% at B = 32-64 and 55% at B = 128. The DFlash change (0.7-1.7%) is not confirmed yet. Evidence and commands:
evidence/hostgap/README.md.How much of the cycle is idle
Stock SGLang
bd66ce343e, tuned MTP arm (s3, replayssm-spec, radix off; the same flags as bench'smtp-tuned), windows with exactly B requests decoding. Derived (cycle_profiles.json,derived_idleandbefore_after): untraced stock cycle time minus the GPU busy time per cycle of the patched engine's host trace from the same session.The estimate assumes the stock cycle does the patched cycle's GPU work (both launch the same graphs and kernels on the same data; stock adds only the small copies the patches remove) and that graph-level tracing does not lengthen kernels. For DFlash (block 8) the estimate is 1.36-1.46 ms (21% at B = 1, 9% at B = 32). The queued hold retakes the stock traces with the same driver, which will replace the borrowed busy time.
So the claim that most idle is host work, not waiting on a read, holds at low batch only; at B = 128 removing the reads took away over half of it. A blocking read costs more than the time spent inside it, because the host work behind it waits until the GPU drains and then runs while the GPU idles: at B = 128 the patches saved 0.98 ms per cycle, while the stock trace shows only 0.29 ms of memcpy and synchronize calls during idle.
Where the idle sits (host-traced, attribution only)
Host tracing slows the host (traced cycle 8.35 ms against 6.93 untraced at B = 1, 22.92 against 20.30 at B = 128), so traced idle (2.6-2.9 ms per MTP cycle) is used only to place the idle:
eagle_prepare_for_verify > DecodeCudaGraphRunner.load_batch > init_forward_metadata_out_graph > FlashInferIndicesUpdaterPrefill.call_begin_forward > BatchPrefillWithPagedKVCacheWrapper.plan, 1.1-1.8 ms exposed per traced cycle. FlashInfer'splan()blocks four times per verify:segment_packbits'.item()and three.to("cpu"). SGLang gives DFlash's verify a sync-free plan already; EAGLE keeps a custom mask and cannot use it.FlashInferMultiStepDraftBackend.common_template'skv_indptr.cpu(), about 0.5 ms exposed withfast_decode_plan.fast_prefill_plan, so the draft forward's plan blocks six times per cycle (1.1-1.2 ms exposed). Bench'sdflash-tunedarm uses FA4 draft attention and does not take this path.run_batch, traced cycle shorter than untraced); the README lists it with that caveat and leaves it out of every range.points.csvrecords only the maximum.Change
Engine patches
engine/sglang/patches/hostgap/(apply to the pin; README section inengine/sglang/README.md), each flagged path off by default. 0001-0003 are the validated state and the default apply command:SGLANG_HOSTGAP_VERIFY_PLAN=1:fast_verify_planmirrors FlashInfer 0.6.18'splan()(fa2, CUDA-graph mode) step by step with the four reads replaced by values fromseq_lens_cpu, installed at the first replay so capture is stock. A per-wrapper event orders reuse of FlashInfer's pinned plan buffer, which the removed reads used to guarantee.SGLANG_HOSTGAP_DRAFT_INDPTR=1: the draftkv_indptrrows on the host.SGLANG_HOSTGAP_DFLASH_DRAFT_PLAN=1: the DFlash draft's two wrappers plan from the worker's exact host copy of the lengths.fast_verify_planpassesdisable_split_kvasplan()does, forced on for NVFP4 KV; no change with this BF16 KV cache. Also corrects the module docstring.SGLANG_HOSTGAP_VALIDATE=1runs the stock read-back path next to every sync-free plan and raises on any difference.Tooling in
experiments/hostgap/: held-batch cycle profiler (cycle_profile.py), idle attribution by host call site and blocking-call listing from nsys (gap_analysis.py), GPU plan check (plan_equivalence.py, small version intests/test_hostgap_plan.py), deterministic greedy equality (equality.py), the summary (summarize.py, which now also writes per-label provenance, every counted window, the stock idle estimate, the before/after pairs with their run order and the work queued at the EAGLE seam), A/B sweep runner and the hold scripts.Validation (engine
02b0e36ec8, patches 0001-0003)plan()againstfast_verify_planon 280 random batches each for the EAGLE verify and the DFlash block (B = 1-128, padding rows): identicalplan_info, pinned plan bytes, device buffers and replayed attention output bits; draftkv_indptrequal to the Triton kernel on 160 batches.all_equal: falseat the top level for the pools alone; a rerun with a binding cap is queued.tests/test_hostgap_plan.pyhas not run on a GPU yet;hold_mtp.shnow runs it first, on the engine head of that hold (0001-0005).What remains
The idle that is left is a host critical path. After the previous verify finishes, the traced host needs 1.70-1.83 ms to plan and launch the next draft, while the GPU still has 0.54-0.90 ms of work queued (host resolve-to-draft-launch time minus the GPU's idle gap before the draft, 0.93-1.15 ms; a difference of medians from the patched traces, assuming the draft starts when launched). The verify planning then runs past the draft's end. The waits on the previous verify's lengths stay: every plan needs them. Triton attention avoids host planning altogether and is +17% at c = 1 on this arm in bench's tuning data (+11% at c = 8, +2% at c = 32, -14% at c = 128), with different numerics; those are single runs, and other processes' CPU load peaked at 2.2-3.1 cores at c = 8 and 9.6-10.1 at c ≥ 32. Matching that exactly would need cheaper host planning (0004 is a first step) or a scheduler that stops planning the next draft after the previous verify. One
cudaStreamSynchronizeper cycle remains under the verify'scall_begin_forward(0.007-0.009 ms at B ≤ 64, 0.21 ms at B = 128); stock has it too, and its source is not identified yet.Pending, queued
hold_mtp.sh(in the FIFO queue) andhold_dflash.sh(submitted when the first starts): the GPU test and plan check on 0001-0005, equality for the full series, same-driver stock host traces (patched before stock, so hold 2 and this hold form an A-B / B-A pair), the DFlash pinned-KV equality, and the interleaved serving A/B sweeps at c = 1, 2, 4, 8, 16, 32 (stock / hostgap / hostgap / stock, Triton as a reference). I will add the results to this PR.Review 5933518035: how each item was handled
summarize.pynow writes it intocycle_profiles.json(derived_idle.mtp,gpu_busy_sourcenames the borrowed trace). Traced values appear only in the attribution table, labelled as such.summarize.pywrites it per batch (gpu_work_queued_at_resolve_ms).000[1-3]-*.patch, with 0004-0005 as a separate optional step. The 46 → 12 / 55 → 19 us numbers are dropped from the README and from 0004's commit message (reworded; its tree is unchanged,ee426e8df4). 0004's check is inhold_mtp.sh.points.csvrecords only the maximum.plan()14.8% againstfast_verify_plan5.4%,common_template6.2% stock against 9.1% patched, each attributed to its arm. GDN split dropped. DFlash B = 32 traced row caveated and excluded from ranges (DFlash draft planning is now 1.1-1.2 ms). Eager time at B = 128: 1.83 ms in all, GDN state 1.46 and sampling 0.24. DFlash B = 1: -1.0%. Validation counts: "at least 8,192", with the power-of-two logging stated.foreign_cpu_maxvalues.Suggestions: the remaining synchronize is described (present in stock as the fifth sync for four copies; source not identified). NVFP4: patch 0005 mirrors
plan()'s rule rather than asserting. Run order:hold_mtp.shandhold_dflash.shnow profile patched before stock. DFlash compare files: one sentence in the README explains the top-levelall_equal: false. Provenance:summarize.pywritesgenerated_by, per-labelprovenance(commits, launch command, flag environment, start time) and every counted window, andcycle_profiles.jsonis regenerated with it (all values unchanged);stock_traces_hold1.jsonkeeps its README provenance and will be superseded by the same-driver stock traces. Docstring: fixed in 0005.Codex reviewed 5b62d27 with no findings (no inline comments).
No new dependencies were installed. The shared-slot equality attempt failed (SGLang applies
--mem-fraction-static 0.25to the free memory at start-up, so with ~50 GB held by other shared servers the weights did not fit); the equality runs moved to an exclusive hold.The branch now includes origin/main (merge
e1dc80f); the only conflict was the end ofengine/sglang/README.md, where main's backbone section and this hostgap section both stay. Head:e1dc80f.