Repository navigation
Certified LM head in SGLang: greedy decode, verify, drafting and fixed-noise sampled verify - #52
Conversation
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 Reviewed head cb3885d against its base
What blocks is that this evidence is not yet documented in the repository at the scope it supports, and the engine README section is missing. BlockingB1.
B2. The engine README's kernel section is missing (
Checked
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cb3885d98b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
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".
| stop_server | ||
| grep -E "Certified LM head|Traceback|Error" "$dir/server.log" | head -20 >"$dir/server_notes.txt" || true | ||
| return "$rc" |
There was a problem hiding this comment.
Fail check-mode arms on recorded token mismatches
When a *_check arm records nonzero mismatch_rows, the client request can still complete successfully, and this function stops the server and returns only the client exit code without examining certified_stats.json. Consequently, the primary same-batch equality check described by this script reports success even when the certified head emits incorrect tokens; parse the counters and fail any check arm with mismatches.
Useful? React with 👍 / 👎.
| print(json.dumps(report, indent=1)) | ||
| if args.out: | ||
| args.out.write_text(json.dumps(report, indent=1) + '\n') |
There was a problem hiding this comment.
Return a failure status when comparison finds divergence
When certified and stock output files contain different token sequences, compare() records the differences but always exits successfully. The caller in engine_validate.sh explicitly relies on compare ... || status=1, so an end-to-end regression cannot make validation fail; return a nonzero status when diverged is nonempty.
Useful? React with 👍 / 👎.
For the SGLang integration: - CertifiedHead.argmax and gumbel_sample take an optional 0-d device bool gate. The certified stages run in one conditional node and each fallback in its own top-level node, with flags cleared before the gated stages, so an engine can choose per CUDA-graph replay between this head and its own stock head without nesting conditional nodes. - CertifiedHead.sibling gives each graph family its own buffers over the same int8 codes and metadata. - quantize.quantized_for caches the quantized copy of any head tensor under its SHA-256, reusing the pinned checkpoint's cache when it matches. - certified_head.engine reads the SGLANG_CERTIFIED_HEAD_* flags, builds one head per enabled path from the engine's own head weight, and keeps device counters per path (calls, rows, fallbacks, status bits, and in check mode rows whose token differs from the stock token). - tests/test_certified_engine.py checks the gated graph shape the engine captures, in both fallback modes; it has not run on the GPU yet.
engine/sglang/patches/kernel/0001 wires the certified head into SGLang's greedy plain decode behind SGLANG_CERTIFIED_HEAD_DECODE (off by default): each decode CUDA graph captures the certified head under a device flag and the stock head under its negation, and the host sets the flag per replay for batches that are all greedy and need no logits. The patch applies to bd66ce34 with git am and reproduces the engine branch's tree. - engine.PathHead.warm compiles every kernel variant a captured call uses and runs the column self-test per batch size on first sight; enable_column_fallback(extend=True) adds sizes one at a time. - Counters cover the rows that are not CUDA-graph padding. - experiments/certified_head/engine_validate.sh launches servers under the shared lock for each arm (check mode in batch and column modes, the Hopper model, and one-request-at-a-time certified and stock runs) and engine_equality.py drives them and compares outputs.
engine/sglang/patches/kernel/0002 routes greedy target verify for EAGLE/MTP and DFlash through the certified head behind SGLANG_CERTIFIED_HEAD_VERIFY. The certified ids travel on the replay's LogitsProcessorOutput and replace the greedy argmax in eagle_sample and in DFlash's accept step. The series applies to bd66ce34 and reproduces the engine branch's tree. engine_validate.sh gains MTP (NEXTN, 3 steps, top-1) and DFlash (block 16) arms in check mode and one request at a time, with the stock comparisons.
engine/sglang/patches/kernel/0003 routes MTP draft top-1 (draft steps in the draft CUDA graph and the draft-extend token) and DFlash's greedy draft projection through the certified head behind SGLANG_CERTIFIED_HEAD_DRAFT. engine.PATH_FLAG maps the three draft paths to that flag. The series applies to bd66ce34 and reproduces the engine branch's tree.
engine/sglang/patches/kernel/0003-0004: MTP draft top-1 and DFlash's greedy draft projection (SGLANG_CERTIFIED_HEAD_DRAFT), and fixed-noise sampled verify for EAGLE/MTP (SGLANG_CERTIFIED_HEAD_SAMPLED_VERIFY). The four patches apply to bd66ce34 and reproduce the engine branch's tree. - engine.PathHead.warm_sampling compiles the sampler and SGLang's multinomial_with_seed for each shape; add_mismatches counts differences found outside the graph. - reference.stock_seeded_sample_from_logits runs SGLang's seeded chain on given logits, for the sampled-verify check. - engine_validate.sh gains the sampled-verify arm (seeded T = 0.7 under --enable-deterministic-inference). - INTEGRATION.md describes the patch series, its flags and when a batch is certified.
P8 follow-up (3): for every real row and temperature, compare SGLang's temperature-only seeded token (FP32 softmax and log, SGLang's own noise) with the FP64 log of the same probabilities and with exact FP64 log-softmax, count the rows where they differ, and keep the first few witnesses with their inputs for GPU regressions.
tests/test_certified_head.py replays every witness that p8_witness_search.py wrote (evidence/certified_head/p8_witnesses.json, or VP_P8_WITNESSES) and requires the certified sampler to return SGLang's seeded token; it skips until the file exists.
Patch 0004 needs --enable-deterministic-inference; its reference is stock SGLang in that mode, so it is not compared with default-mode outputs.
engine_validate.sh falls back to the main checkout's scripts/gpu_startup_lock.sh, which this stacked branch does not have yet.
On 60,000 real decode rows SGLang's temperature-only seeded token never differs from an FP64-log variant and differs from exact arithmetic on 0.31% (T = 0.7) and 0.35% (T = 1.0) of rows. The first eight such rows are kept for the GPU regression.
At a 0.25 memory fraction SGLang caps running requests by its state cache (3 for plain decode in the first run), so the batch shapes a check covers depended on the free memory at start-up. MAMBA_SLOTS sets the cache explicitly; mtp_all_check certifies MTP verify and draft together.
evidence/certified_head/engine_v1.json summarizes engine_validate.sh at 8f4f3d7 (engine 71c521db) with engine_summary.py. In check mode every certified row equals the stock head's row at the same batch shape: plain decode, MTP and DFlash greedy verify, MTP draft steps and draft extend, the DFlash draft projection and MTP fixed-noise sampled verify (against SGLang's seeded sampler on the same verify logits), 0 differing rows in each. One request at a time, certified and stock servers give identical outputs on 64 of 64 prompts for plain decode and for MTP. The engine-glue tests (7) and the new W8A8 and witness tests (3) pass. At the 0.25 memory fraction SGLang's state cache capped some arms at 2-4 running requests; a second session sizes it explicitly.
engine/sglang/patches/kernel/0005 keeps, per path, a histogram of the real row counts of certified steps, so a validation run states the batch sizes at which equality was observed. engine_validate.sh gains arms with the bench workstream's tuned flags: buffered GDN verify for MTP (--enable-linear-replayssm-spec), replay SSM for plain decode, no radix cache, stream interval 4, and Triton attention. The five patches apply to bd66ce34 and reproduce the engine branch's tree.
Brings in engine/sglang/README.md, which the stacked SGLang integration (PR #52) documents its patches in.
One row per patch with its variable and default, the worktree commands, the configurations that keep the stock head, and the validation script.
Per arm: the largest batch reached, certified steps, rows, rows differing from the stock head (0 everywhere), and fallback rates stated as rates; the sampled-verify row is labelled with its own contract; the column-mode crossover is marked pending; the commands and commits.
cb3885d to
f9ca667
Compare
|
Verdict: REQUEST CHANGES Re-reviewed head f9ca667 against its base Earlier items
Blocking
Suggestions (not blocking)
Codex. The two comments on f9ca667 are items 1 and 2. No earlier Codex comments are open. |
Review of PR #52 (re-review items 1-4): - engine_validate.sh: a check arm now fails if any certified row differed from the stock row or if the server wrote no counters. - engine_equality.py compare exits 1 when outputs diverge or a prompt is missing from either run, and lists such prompts. - The evidence README cites the rebased twins of the run commits, and the original commits are tagged (kernel-engine-v1, kernel-p8-witness-search). - Under --enable-deterministic-inference SGLang replaces aten::mm with its batch-invariant Triton matmul, so the sampled arm's stock head, and the certified fallback, run that kernel rather than cuBLAS. The README and INTEGRATION.md say so; the arm used the conservative model; patch 0006 refuses hopper-wgmma under deterministic inference.
|
Verdict: REQUEST CHANGES Re-reviewed head af0fa0c (one commit on f9ca667). Items 1-3 are fixed. Item 4 is fixed in substance (patch 0006 and the model statement), but the README and Earlier items
Pre-commit passes on the changed scripts. BlockingN1. At the pin's defaults on the GH200, the deterministic-mode head GEMM is DeepGEMM, not Triton (
CodexThere are no Codex comments on af0fa0c yet. |
Under --enable-deterministic-inference SGLang's matmul_persistent runs DeepGEMM's BF16 GEMM at the pin's defaults on this GH200 (one FP32 wgmma accumulator over K, RN BF16 store); its Triton kernel is only the fallback. The README, INTEGRATION.md, the engine README and patch 0006 now say so, and deterministic_head_kernel.py records the kernel names with a profiler.
|
Verdict: APPROVE Re-reviewed head 8dc5e47 (one commit on af0fa0c), base N1 (fixed)
Status of every item
Not blocking. Equality is claimed only at the batch sizes reached (caps 2-16, depending on free memory at start-up). The larger-batch session with |
|
@codex review |
|
Update on 00f305f: both blocking items are fixed. My verdict stays pending until
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 00f305fda7
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
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".
| + stock = stock_seeded_sample_from_logits( | ||
| + next_token_logits[:n], st.seeds[:n], st.positions[:n], st.temps[:n] | ||
| + ) | ||
| + _heads.get("sampled_verify").add_mismatches(ids, stock) |
There was a problem hiding this comment.
Flush sampled mismatches after recording them
In the mtp_sampled_check flow, after_replay calls attach_ids, which dumps the statistics before eagle_sample reaches check_fixed_noise and increments mismatch_rows here. A later replay's pre-replay dump usually captures that increment, but a mismatch on the final sampled replay never reaches certified_stats.json; consequently the check at the end of engine_validate.sh can still report success. Dump again after this comparison or flush all counters during shutdown.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 4c9fc8f with patch 0008 (engine/kernel a28946e0d4). check_fixed_noise writes the counters again after adding its mismatches, so a mismatch on the last sampled replay reaches certified_stats.json. The engine rerun (x9e2) runs on this commit; the earlier attempt (x9e) stopped at its GPU tests and ran no engine arm, so no reported count missed this.
|
Verdict: REQUEST CHANGES (00f305f; 1 blocking: Codex r4159755914, valid) The same class of hole as r4159625134, on the sampled path. In check mode Everything else from my update on 00f305f stands. |
…atches - gumbel_sample ran its two guards after a refused batch too. With no candidates, the small-probability guard compared -inf with a stale ymax and could add its bit to rows already marked refused (x9e's GPU tests caught it: status 576 instead of 64 in test_quantization_data_must_belong_to_the_weight). The guards check a decision, so they now run only after one; a refused batch keeps the single status refused. A CPU test with stale buffers fails without the fix. Outputs never changed (refused rows take the stock chain), and no committed evidence or paper number counts the extra bit: every certified-head evidence file was produced at or before 9f7f369, before the guards (09bf64e, ec46d55, 2c36737), and no other workstream's committed evidence ran the certified head. - Codex on 00f305f: in check mode, the fixed-noise comparison with SGLang's seeded sampler adds its mismatches after attach_ids has written the counters, so a mismatch on the last sampled replay was never recorded. Patch 0008 (engine/kernel a28946e0d4) writes them again after the comparison. - Main now carries #142: the evidence README cites evidence/triton_tma for the first TMA fault (clean only with Triton >= 3.8.0 and ptxas >= 13.3 together, matching triton-lang/triton#9433 by version pattern; the 64-byte refusal stays on Triton 3.7.1).
|
@codex review |
|
Update on 4c9fc8f. The code items are all closed, and my verdict now waits only on
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4c9fc8fd1e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
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".
| + si = forward_batch.sampling_info | ||
| + return ( | ||
| + si is not None | ||
| + and not si.is_all_greedy |
There was a problem hiding this comment.
Reject mixed greedy batches from sampled verification
When continuous batching combines a greedy request with a temperature-sampled request, is_all_greedy is false and the remaining predicates can still pass under deterministic inference with default top-k/top-p/min-p settings. _stage_sampling then stages every request and the sampled graph applies Gumbel sampling to the greedy rows as well, so those requests no longer receive greedy verification. Require that every row is genuinely sampled, rather than merely requiring that the batch is not entirely greedy.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
At the pin a mixed batch was already refused, and f80f7d8 now makes that explicit. The normalisation chain (files unchanged by the kernel series):
python/sglang/srt/sampling/sampling_params.py:217-220: a greedy request (0 <= temperature < _SAMPLING_EPS) becomestemperature = 1.0, top_k = 1.python/sglang/srt/sampling/sampling_batch_info.py:256:need_top_k_sampling = any(top_k != TOP_K_ALL)is therefore true for any batch with a greedy row; on merge it is OR-ed in (:559)._fixed_noise_eligiblerequiresnot need_top_k_sampling, so such a batch took the stock verify.
The contract should not rest on that normalisation, so patch 0009 (engine/kernel 9b5e82258d, in f80f7d8) requires not is_any_greedy instead of not is_all_greedy. A CPU test (tests/test_certified_engine_glue.py) imports the patched glue in a subprocess and checks that a batch with a greedy row is ineligible even with need_top_k_sampling unset. It fails against a28946e0d4. The engine rerun's sampled arm ran 0009 (evidence/certified_head/README.md, x9e2).
| except (OSError, ValueError, KeyError) as exc: | ||
| sys.exit(f'no certified counters: {exc}') | ||
| bad = {p: v['mismatch_rows'] for p, v in paths.items() if v['mismatch_rows']} | ||
| calls = sum(v['calls'] for v in paths.values()) |
There was a problem hiding this comment.
Require calls from every path exercised by each check arm
For multi-path arms such as mtp_draft_check and mtp_all_check, summing calls allows validation to succeed if only one enabled path runs—for example, draft_extend can remain at zero while draft has calls. This defeats the script's per-path validation purpose and can hide a disconnected engine hook; validate an arm-specific set of expected paths and require nonzero calls for each.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in f80f7d8. The check moved to experiments/certified_head/check_arm_stats.py. engine_validate.sh declares the paths each check arm must exercise (expected_paths), and the arm fails if any of them made no certified call. A flag can enable a path the arm's algorithm never runs (DRAFT enables both the MTP and the DFlash draft paths), so such a path is reported, not failed. CPU tests cover the rule. Applied with engine_validate.sh --check-only to x9e2's arms (engine_v2_arm_checks.log, 960ab39), every check arm passes.
|
Verdict: REQUEST CHANGES (4c9fc8f; 1 blocking: Codex r4160186732. Codex r4160186716 needs a reply with its scope, not a code change.)
Everything else on 4c9fc8f stands as in my update. |
Two Codex findings on 4c9fc8f: - engine_validate.sh summed certified calls over all paths, so an arm with several paths (mtp_draft_check, mtp_all_check) passed with one hook idle. The check moves to check_arm_stats.py and fails when any path the arm must exercise made no call; engine_validate.sh declares each check arm's paths (expected_paths). A flag can enable a path the arm's algorithm never runs (DRAFT enables the MTP and DFlash draft paths), so such a path is reported, not failed. --check-only reruns the verdicts on finished arms without a server. CPU tests cover the rule. - A batch mixing greedy and sampled requests: at the pin it was already ineligible for fixed-noise sampled verify, because SGLang normalises a greedy request to top_k = 1 (sampling_params.py), which sets need_top_k_sampling (sampling_batch_info.py, also on merge). Patch 0009 (engine/kernel 9b5e82258d) makes the contract explicit: _fixed_noise_eligible requires not is_any_greedy. A CPU test imports the patched glue in a subprocess and fails against a28946e0d4.
x9e2 ran the merged package's GPU and CPU tests (167 passed), then the eleven engine_v1 arms with the GDN state cache raised (MAMBA_SLOTS=80), so the arms reach 16 plain and 8 speculative requests. Every check arm: 0 rows differing from SGLang's own head, none refused, none probe-tripped; the committed per-path check (f80f7d8) passes all of them. One request at a time, the certified and stock servers' outputs are identical on 64 of 64 prompts for plain decode and for MTP. The README gives each arm's engine commit (patch 0009 reached the engine worktree mid-hold; it changes only the sampled-verify predicate, and the sampled arm ran it), and says that a mid-hold edit of engine_validate.sh made the script fail after its last arm, so the one-request-at-a-time comparison was run afterwards on the saved outputs.
|
@codex review |
|
Verdict: APPROVE (provisional, on 960ab39: Codex has not reviewed this head yet. I will confirm or withdraw once it does.) Code (f80f7d8)
Evidence (960ab39) and the conditions for not rerunning x9e2
The table matches
Checks
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 960ab3964d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
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".
| + if eligible: | ||
| + _stage_sampling(_state[path], forward_batch, rows) |
There was a problem hiding this comment.
Check row capacity before staging sampled verification
When sampled verification receives more than 256 verification rows—for example, 65 MTP requests with four rows each—eligibility can be true and this stages inputs before set_gate() rejects the unsupported size. The staging buffers are fixed at _MAX_ROWS, so st.seeds[:rows] has length 256 while the repeated source has length 260, causing copy_ to raise instead of letting the larger batch use the stock path as intended. Check the row limit before calling _stage_sampling.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 3646242 with patch 0010 (engine/kernel a3a4c8e99a). before_replay now checks the row limit (_fits, the same check set_gate uses) before staging the sampled-verify inputs, so a batch above it takes the stock path instead of failing in the copy. Patches 0001-0010 applied to bd66ce34 reproduce a3a4c8e99a's tree. A CPU test runs the patched glue in a subprocess with 65 requests x 4 rows = 260 rows. It expects the stock path and nothing staged, and it fails against 9b5e82258d with the 256-versus-260 copy error. The engine rerun (x9e2) is unaffected: its sampled batches had at most 32 rows, so the same batches were staged and certified (README).
| tmp = path.with_suffix('.tmp') | ||
| torch.save(qh.__dict__, tmp) | ||
| tmp.replace(path) |
There was a problem hiding this comment.
Use a process-unique temporary cache file
When two engine processes start concurrently with the same uncached head, both write the same digest-specific .tmp path. Their torch.save operations can corrupt each other, and after the first process renames the file, the second process can fail at tmp.replace(path) because that pathname no longer exists, aborting server startup. Use a uniquely named temporary file and coordinate publication of the shared cache entry.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 3646242. quantized_for and load_or_build now write through quantize.publish: a process-unique temporary file, an atomic os.replace onto the cache entry, and removal of the temporary file on failure. Concurrent builders of the same entry write the same data, so the last rename leaves a complete file and none fails. A CPU test completes a second build between the first build's save and rename. With the fixed .tmp name it fails with the race's FileNotFoundError; with the fix both builds succeed and one entry remains.
|
Verdict: REQUEST CHANGES (960ab39; withdraws my provisional approval. Codex's two new comments are valid. Neither affects
|
… atomically Two Codex findings on 960ab39: - Patch 0004 staged the sampled-verify inputs into the head's 256-row buffers before set_gate checked the row limit, so a larger eligible batch (65 MTP requests give 260 verify rows) failed in the copy and killed the server instead of taking the stock path. Patch 0010 (engine/kernel a3a4c8e99a) checks the limit first, with the same check set_gate uses. Patches 0001-0010 applied to bd66ce34 give a3a4c8e99a's tree (9cd14d90). A CPU test runs the patched glue in a subprocess with 260 rows; it fails against 9b5e82258d. - quantized_for and load_or_build wrote the int8 cache entry through a fixed <entry>.tmp, so two engines building the same head at once could corrupt each other's file or fail at the rename. Both now use quantize.publish: a process-unique temporary file, an atomic os.replace onto the entry, and cleanup of the temporary file on failure. A CPU test completes a second build between the first's save and rename; it fails with the fixed name. Neither change alters what x9e2 ran (README): its sampled batches had at most 32 rows, and its servers loaded the existing pinned cache entry.
|
@codex review |
|
Verdict: APPROVE (provisional, on 3646242: Codex has not reviewed this head yet. I will confirm or withdraw once it does.) 3646242 resolves both comments on 960ab39.
Checks. The CPU tests pass (39, with 2 GPU-only tests skipped), pre-commit from main is clean, and the commit has no AI attribution. |
|
Codex Review: Didn't find any major issues. Keep them coming! 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 3646242) This confirms my provisional approval. Codex found no issues on this head. |
…ull; at most five sessions Codex on 84717d2: the certified-head package's fingerprint is now part of the identity the equality hold's preflight records before any run, and build and every later check require it unchanged. The reused stock references must match bench's declared configuration (flags with and without Triton attention, c1 pass, concurrency 1, 256 new tokens, top-5 logprobs, 320 prompts, cold cache, S0's model and prompt set with the same prompt token counts), as must every stack equality run; the prompt file is pinned by hash from preflight to build. analyze.py accepts sessions stack-s1 to stack-s5 only (three and at most two replacements). expected.py's H note and the engine README reflect the merged #45/#52 and #133. Tests for each (98 pass).
…nce (#52) Cold read of 1a22d86, appendix items (triage in the editorial move log): - Register IDs: the notes print N-E21 and N-D24 (\regprefix in the shared register macros and in the notes' \evref/\devref), so an ID never means two things; check_paper_references.py gains check 8, which fails if the paper prints a prefix, the notes print none, or both match. - Each pending marker in the appendices now follows words saying what is not yet done; the capacity item, which supports no paper claim, is stated in words and stays in the notes' pending list. - Table captions go above the table throughout both documents. - Number walls become tables: A.8's speculative positions (adding DFlash's 5.7%/8.6% verification share from selfevidence_dflash4b.json), D.4's divergence rates, E.3's equality rates against stock references; the prose keeps every qualification. - Project-history phrases go or are translated: "kill test", H/P labels, the divergence study's "first/pinned matrix" (now unpinned and pinned runs, defined once), "second panel", the commit wording in A.9 (the commit stays in the register entry). - Appendix E's opening says it holds the serving protocol and the stock baseline, and that no served result for the certified head exists yet. - Glossary: the last "row" used for a position is gone; twelve terms the main text uses now print with the main-text terms; the notes' glossary defines the old project terms its moved text keeps. - E.2 says why the stock chain is 369.0 us in the profile and 370.5 us in the certified head's microbenchmark. #52: register entry kernel-engine (the certified head in SGLang in check mode; 0 of 196,734 certified positions differed from the stock token; engine_v2.json, not the superseded engine_v1.json). The contracts table's greedy and seeded cells cite it, and the seeded pending item narrows to acceptance against the stock rejection-sampling verifier; the notes' status row is updated. Build: paper 53 pages, References on p10, notes 43 pages, 0 warnings in both; checker clean.
Section 4.3 replaces the now-false 'untested on verification positions' with the 64-prompt check inside SGLang (engine_v2.json): no certified position differed from the stock head on any path; under the conservative model with the whole-batch fallback, 1.38% of plain-decode positions fell back (24% of head calls), 1.74% of MTP-4B verify positions (38%), and 3.99% of DFlash-4B verify positions, in 90% of verify head calls. That the per-position fallback would carry DFlash verification is stated as an inference. Section 3.3 adds the in-engine seeded check (21,016 positions at T=0.7); acceptance against stock rejection sampling stays pending. The abstract, the intro's draft-head sentence and Section 7 follow. Every engine number keeps its scope: 64 prompts, conservative model, fallback mode, concurrency, untimed.
What this adds
A small SGLang patch series (
engine/sglang/patches/kernel/0001-0010, against the pinbd66ce34) that routes the LM head through the certified head of PR #45 on four paths. The engine imports thecertified_headpackage; it is not copied into SGLang. #45 is merged; this PR now targetsmainand carries a merge ofmain(8d80119), described below.SGLANG_CERTIFIED_HEAD_DECODESGLANG_CERTIFIED_HEAD_VERIFYSGLANG_CERTIFIED_HEAD_DRAFTSGLANG_CERTIFIED_HEAD_SAMPLED_VERIFYSGLANG_CERTIFIED_HEAD_STATShopper-wgmmais combined with--enable-deterministic-inferenceSGLANG_CERTIFIED_HEAD_MODELSGLANG_CERTIFIED_HEAD_STATSSGLANG_CERTIFIED_HEAD_STATS,_CHECKSGLANG_CERTIFIED_HEAD_SAMPLED_VERIFYSGLANG_CERTIFIED_HEAD_SAMPLED_VERIFYOther flags:
SGLANG_CERTIFIED_HEAD_FALLBACKisbatch(default) orcolumns.columnsapplies only to batch sizes whose bitwise self-test passes, run once per size at graph warm-up.SGLANG_CERTIFIED_HEAD_MODELselects the stock error model:conservative(default) orhopper-wgmma.SGLANG_CERTIFIED_HEAD_MAX_ROWScaps the batch the head serves.SGLANG_CERTIFIED_HEAD_CHECKturns on validation mode.SGLANG_CERTIFIED_HEAD_STATSwrites the counters.SGLANG_CERTIFIED_HEAD_SRCpoints at the package.Merged with #45's final package (8d80119)
This branch was built on 9e3a39a, before #45's TMA-fault fix, per-variant self-test gate, runtime probes, weight digest and sampling guards. 8d80119 merges
mainand resolves:head.py: the device-gated stages keep Certified int8 LM head: exact stock-head decisions, seeded sampling, kernels and evidence #45's self-test gate outside the gated node; bothgumbel_sampleguards (non-positive temperature, winners near small probabilities) run inside the gated stages, so a batch the gate skips sets no fallback flag;enable_column_fallbackkeeps this branch'sextendparameter and Certified int8 LM head: exact stock-head decisions, seeded sampling, kernels and evidence #45's refusal of non-bf16references;sibling()carries the parent'sweight_check, so a refused head cannot yield an accepted sibling. This branch sets no tile, so every Certified int8 LM head: exact stock-head decisions, seeded sampling, kernels and evidence #45 default and refusal stands.engine.py: anunsafehead (runtime probes off) is refused at install; the stats record each path's self-test summary and probe statistics.engine_validate.sh: a check arm fails on refused or probe-tripped rows as well as differing rows.engine_v1.jsonran on the pre-fix package and that the rerun is the evidence for the merged one;evidence/README.mdandexperiments/README.mdgaincertified_headrows.Results on the merged package (x9e2,
engine_v2.json, 960ab39).MAMBA_SLOTS=80, up to 16 plain and 8 speculative requests).engine_validate.shmade the script fail after its last arm, so the one-request-at-a-time comparison ran afterwards on the saved outputs.How it stays exact and graph-safe
LogitsProcessor._get_logits) under its negation. Before each replay the host sets the flag, and the certified ids are copied out after the replay. No conditional node is nested: the certified stages are one node, and each fallback is its own top-level node.SGLANG_SANITIZE_NAN_LOGITSandSGLANG_ENABLE_ASYNC_ASSERT.Contract per path
div_(T), FP32 softmax and log, thenmultinomial_with_seedat the request's seed and the row's position.--enable-deterministic-inference, which is what seeds every request. Its reference is therefore stock SGLang in that mode, a different engine configuration from the default.aten::mmwith SGLang's batch-invariantmatmul_persistent: DeepGEMM's BF16 GEMM at the pin's defaults on this GH200, with a Triton kernel only as its fallback. So the stock head (and the certified fallback, which calls the sametorch.matmul) is that kernel, not cuBLAS. A profiler check of the kernel name is in the second session. The conservative error model covers it. The Hopper model is validated for the cuBLAS head only, and 0006 refuses it there.Validation
Check mode (
SGLANG_CERTIFIED_HEAD_CHECK=1): every certified step also runs SGLang's own head at the same batch shape and counts, on the device, the rows whose token differs; the emitted tokens are the certified ones. For fixed-noise sampled verify the comparison is with SGLang's seeded sampler applied to the same verify logits (its contract above), under--enable-deterministic-inference. Results and commands:evidence/certified_head/README.md("The head inside SGLang") andengine_v1.json.The table below ran on the pre-fix package (repo 8f4f3d7): its W8A16 tiles above 16 rows were the faulty TMA ones, and it had no self-test gate or runtime probes. The arms above 16 rows (DFlash verify at 32, the DFlash draft projection at up to 120, whose 89.6% fallback was that fault, and the sampled verify at 32) ran those tiles, so their 0 differing rows are empirical. The rerun on the merged package (x9e, pending) is the evidence for this PR.
Setup: shared GPU lock,
--mem-fraction-static 0.25, 64 prompts (every fifth ofthe geometry workstream's public prompt set), up to 256 new tokens, greedy except
the sampled arm (seeded, T = 0.7), the conservative stock error model and the
whole-batch fallback except where noted. MTP is NEXTN with 3 steps and top-1 (4
verify rows per request); DFlash uses block size 16. Equality is claimed only at
the batch sizes each arm reached: at this memory fraction SGLang's GDN state cache
capped several arms at 2-4 running requests.
The largest batch is the server's running-request cap where the state cache set
one (plain 3, MTP 4, DFlash 2) and otherwise the largest batch in the server's
decode log; the second session records the exact rows of every certified step. The
fallback columns are rates, not runtime: a fallback reruns the stock head for the
batch (or, in column mode, for the near-tie rows), and its cost is measured in the
head microbenchmark, not here. The DFlash draft projection falls back on 90% of its
rows (the threshold check fails on the flat logits of deep block positions); it is
left off in the proposed bench arm, and its runtime was not measured. #45's final
head microbenchmark has column mode ahead of the stock head through M = 64 on
decode rows (420.5 against 451.6 us under the conservative model); DFlash verify
rows fall back about 2.7 times as often, so its margin at M = 64 is not measured.
One request at a time (batch 1, so a certified server and a stock server see the
same shapes), the two servers' outputs are identical on 64 of 64 prompts for plain
decode (14,995 tokens) and for MTP with certified greedy verify (14,990 tokens,
verify batches of 4 rows). The same run passed
tests/test_certified_engine.py(7)and the W8A8 adversarial-activation and P8 witness tests (3) on the GH200.
The state-cache cap depended on the free GPU memory at server start, not only on the memory fraction:
plain_checkandplain_check_columnshad the same arguments but saw 32 and 68 GB free and caps of 3 and 16. A second session is queued (MAMBA_SLOTS=80, so 16 plain or 8 speculative requests): plain decode, MTP verify and draft together, DFlash verify, sampled verify, the Hopper model, and the bench workstream's tuned flags (buffered GDN verify--enable-linear-replayssm-spec, replay SSM, no radix cache, Triton attention). Patch 0005 records the rows of every certified step for it. Its results will be added here.Bench arms
Proposed for
bench/arms.toml. Run with--sglang-worktreepointing at a worktree with this series applied, and setSGLANG_CERTIFIED_HEAD_SRCto the repo'ssrc:plain_certifiedplainSGLANG_CERTIFIED_HEAD_DECODE=1,FALLBACK=columns,MAX_ROWS=64mtp_certifiedmtpSGLANG_CERTIFIED_HEAD_VERIFY=1,DRAFT=1,FALLBACK=columns,MAX_ROWS=64dflash_certifieddflashSGLANG_CERTIFIED_HEAD_VERIFY=1,FALLBACK=columns,MAX_ROWS=64(noDRAFT: the draft projection falls back on 90% of rows; its runtime was not measured)Each arm returns the same tokens as its base arm at the same batch shapes; only time changes.
MAX_ROWS=64follows #45's final microbenchmark (column mode ahead through M = 64 on decode rows; every mode loses from M = 128); treat it as a knob for DFlash, whose fallback rate is higher. The Hopper error model (SGLANG_CERTIFIED_HEAD_MODEL=hopper-wgmma) is a separate variant, because it rests on a published hardware model.Also in this PR
CertifiedHead.argmaxandgumbel_sampletake an optional devicegate.CertifiedHead.siblingshares the int8 codes across per-path buffers.quantize.quantized_forcaches the int8 copy of any head by SHA-256.certified_head.engineholds the flags, the per-path heads and the device counters.tests/test_certified_engine.pychecks the gated graph shape in both fallback modes.experiments/certified_head/p8_witness_search.pychecks P8 on real rows, and the witnesses it finds become GPU regressions.Engine README
engine/sglang/README.mdhas a kernel section: the worktree commands, one row per patch with its variable and default (unchanged unless set), and the configurations that keep the stock head. The merge withmainplaces it before the repair section.Review comments on the merged head
Flagsbuilt directly by the glue bypassedfrom_env()'s checks (a misspelledFALLBACKran batch mode, a misspelledMODELthe conservative model under the wrong name): fixed in 00f305f.Flagsvalidates in__post_init__; a CPU test fails without it.set_gatebefore the next replay): fixed in 00f305f with patch 0007 (engine/kernel af363a3bee), which writes the counters after each draft graph replay;engine_validate.shpinsSGLANG_CERTIFIED_HEAD_STATS_EVERY=1. x9e had not started and runs on 00f305f.engine.pyrefuses to import unlessSTATUS_BITSis in bit order, which its counter kernel assumes (reviewer).count = 0and a staleymaxcould addsmall_probabilityto rows markedrefused. Fixed in 4c9fc8f: the guards run only after a decision. Outputs never changed (refused rows take the stock chain), and no committed evidence or paper number counts the bit (every certified-head evidence file predates the guards). A CPU test with stale buffers fails without the fix.evidence/triton_tma/and RAW hazard with pipelined wgmma and LHS in register triton-lang/triton#9433 for the first TMA fault.check_arm_stats.pyrequires calls on every path the arm declares (expected_pathsinengine_validate.sh); CPU tests; applied to x9e2's arms with--check-only, all pass.top_k = 1,sampling_params.py:217-220, which setsneed_top_k_sampling,sampling_batch_info.py:256, OR-ed on merge at:559). Patch 0009 makes it explicit (not is_any_greedy); a CPU test against the patched glue fails without it..tmpfile: fixed in 3646242 (quantize.publish: process-unique temporary file, atomic rename; also used byload_or_build). A CPU test that completes a second build between the first's save and rename fails with the fixed name.