Skip to content

bf16_paths: neither BF16 miss at the served gross positions is shown to be specific to SGLang - #222

Merged
SamMausberg merged 39 commits into
mainfrom
upstream-bf16/hf-bf16-paths
Oct 2, 2026
Merged

SamMausberg merged 39 commits into
mainfrom
upstream-bf16/hf-bf16-paths

Conversation

@SamMausberg

@SamMausberg SamMausberg commented Oct 2, 2026 •

Copy link
Copy Markdown
Owner

The served certified-head benchmark (#190) found two positions where stock SGLang's BF16 prefill and decode paths disagree with each other, and one of them with FP32, by 9 to 15 nats (evidence/certified_head/served/README.md, "Reference paths and FP32"). Sam pre-approved one upstream issue on this, on condition that the error is shown to be specific to SGLang rather than BF16 ill-conditioning any implementation would show. This PR is the investigation; its answer is that neither error is shown to be specific to SGLang, so no issue follows.

Findings (measured; evidence/bf16_paths/README.md)

  • a4db11ff/333 is ill-conditioned in BF16. transformers 5.12.1 in BF16 misses FP32 there by up to 16.7 nats (its torch GDN prefill of the whole output puts FP32's top token at -17.16), and FP32 itself, under relative noise within the BF16 rounding bound (2^-8) on the residual stream or on the GDN inputs, flips its top-1 in 4 of 8 seeds and puts that token as low as -11.65.
  • At 579ae7ce/439 only SGLang misses: transformers BF16 (torch and flash-linear-attention GDN, BF16 or FP32 cached state; 16 readings) keeps FP32's top-1 on top, and in 16 random draws of rounding-sized noise FP32 kept the contested token within 0.52 nats (a probe, not a bound). But on the unpatched pin no single kernel swap removes the miss: one-family swaps (Triton GDN prefill, FlashInfer GDN decode, Triton attention, no CUDA graphs) and the beta-in-FP32 lines of open upstream PRs #38977/#40362 move it between -8.9 and -0.32 without restoring FP32, and the beta change breaks a4db11ff's decode instead.
  • Selection-free comparison: 12 workload prompts x 512 tokens, then 12 prompts whose recorded output ends early x 768 tokens (5,426 positions after the end of text), each scored against FP32 for SGLang's decode and prefill and two transformers configurations on the same text. SGLang's mean logprob error on FP32's top token (0.0039-0.0054 nats) is no larger than transformers' (0.0042-0.0057) in either sample; misses above 0.5 nats at 2 distinct positions for SGLang, both also missed by transformers (2 and 1 positions); the only miss above 2 nats is the same position in all three prefills. The rule declared in rates.py before each run was inconclusive both times (0 vs 0, 1 vs 1; missed positions, each counted once).

So 579ae7ce/439 remains an SGLang outlier at one selected position; the samples cannot separate its rate from transformers' own large misses, and SGLang's typical BF16 accuracy matches transformers'.

Changes

  • experiments/bf16_paths/: hf_paths.py (transformers along the same paths), sglang_variants.py (the unpatched pin under one-family swaps, reusing bench's Server and paths.stock_target), perturb.py (FP32 under BF16-sized noise), rates.py (selection-free comparison and the declared decision), summary.py (readout), hold.sh (shared-lane holds, steps selectable).
  • engine/sglang/patches/upstream-bf16/0001: a diagnostic patch with the two beta lines (variant beta_fp32), and its section in engine/sglang/README.md.
  • evidence/bf16_paths/: README, positions.json, rates.json, rates_eot.json; rows in experiments/README.md and evidence/README.md.
  • tests/test_bf16_paths.py: CPU tests of the readouts and the decision rule.

Validation

  • Five shared-lane holds (correctness only, nothing timed), commits recorded in the README: d8522be (SGLang variants; its transformers step crashed on a trace-range bug fixed in b6abd11 and is void), 4923b0a, aac2264, 43efc79, 94460d6 (perturbations rerun at 2^-8 after Codex's review; the 2^-9 runs are superseded). Evidence files generated by the committed code at 94460d6 (positions.json) and 148847a (rates.json, rates_eot.json).
  • python -m pytest tests/test_bf16_paths.py: 23 passed. pre-commit run --files on every touched file: passed (codespell run by hand on the evidence README, which the hooks exclude).
  • Installed outside the venv: flash-linear-attention and fla-core 0.5.2 (uv pip install --no-deps --target ~/vp-data/upstream/bf16/pydeps, used only through PYTHONPATH in the hold).

Not done

No per-layer localization of the 579ae7ce miss: with no single swap removing it and no rate difference to explain, it would not change the decision. No upstream issue or comment; the beta result shows sensitivity in both directions, not an accuracy gain, so it does not add to #38975.

Review

  • Codex 4169094305 (perturbation bound 2^-9 instead of 2^-8): fixed in 94460d6, both perturbations rerun and regenerated in 41829e3; classifications unchanged.
  • Codex 4169094312 (paired decode/prefill events counted twice): fixed in 94460d6, the decision counts each missed position once; verdicts unchanged.
  • Codex 4169331431 (hold 5's command would hit hold.sh's existing-output guard): the README now lists the archive step taken before hold 5 and notes that a fresh output directory at 94460d6 or later needs no hold 5 (86852c1).
  • Codex 4169374101 (random perturbations are not a rounding bound): the README, the Limits and perturb.py's docstring now call the runs a sensitivity probe and qualify the reading of 579ae7ce/439 (418ad12).
  • Codex 4169426828 ("at least as much as BF16 storage" in perturb.py's docstring): replaced by "of the same order", with the noise stated to bound no particular rounding (8f0021d).
  • Codex 4169463856 (half-nat misses counted per path in the prose): now counted by position, 2 for SGLang, both shared with transformers (b394831).
  • Codex 4169503480 (exact test should pair by position): decide now tests SGLang-only against comparator-only positions (c44ef32); evidence regenerated, verdicts unchanged (c386c13).
  • Codex 4169591661 (swaps are not isolating): the README and this body now say only that no single swap removes the misses (8ee6c4c).
  • Codex 4169629936 and 4169629949 (pre-set readings in perturb.py and sglang_variants.py still drew the unqualified conclusions): each now carries a dated qualification after the original reading, as does hf_paths.py (45b99e7, b78ac73).
  • Codex 4169675362 (tied comparators): the rule is now applied against each transformers run (4f382b7); evidence regenerated, verdicts unchanged (f328125).
  • Codex 4169834582 (first-output guard blocked retries): hold.sh writes done/ on success, refuses only completed steps and resumes failed ones without overwriting (a4c369f).
  • Codex 4169877100 (a completed step aborted mixed reruns): completed steps are skipped, the hold refused only when all requested steps are complete (a41f520).
  • Codex 4169918264 (silent fla fallback could overwrite the torch comparator): --gdn required and checked in both hf entry points, outputs named by the requested kernels (f3e7a7a).
  • Codex 4169956407 (top-token error silently skipped positions outside a path's top-20): the metric now reports outside_top20 and complete (c136288); all positions were inside in the committed data.
  • Self-review pass over the same classes (9b2e717): every rates.py writer refuses an existing output; summary refuses partial traces and an FP32 file that predates a source; the SGLang variants and the rates server are checked to have resolved the requested kernels (GDN dispatcher, attention backend, CUDA graphs); rates.py hf checks the cached state dtype; perturb.py refuses a forward the perturbation did not reach; rates.py's readings keep the pre-run rule and list the post-run refinements.
  • Codex 4170201318 (done markers outliving their outputs): a marker counts only while the step's outputs exist; stale markers are removed (985b762).
  • Codex 4170237673 (shared targets not restored when every step is complete): restored and checked before the completion check (9935ab6).
  • Codex 4170268193 (traces of an old SGLang text could be kept): rows bound to SGLang's text by hash, old traces moved aside on regeneration (029f1a2).
  • Codex 4170298837 and 4170298839 (unhashed rows accepted; manifest regeneration kept old traces): hashes required unless --accept-unhashed (listed in the output), SGLang's text bound to the manifest, downstream files set aside on regeneration (148847a, fa70220).
  • Codex 4170353020 (a rebuilt trace kept the old FP32 scores): FP32 set aside before any trace is rebuilt (dad71b8).

Review round (main, for the reviewer's issuecomment-5962740297)

  • README line 40 and this body: SGLang's mean error "lies within transformers' range" was wrong (0.0039 is below 0.0042); now "is no larger than transformers' in either sample".
  • README line 121: three of sixteen transformers readings exceed 1 nat at 579ae7ce, not two (the torch 576-token prefill counts in both state configurations; checked in positions.json).

… SGLang kernel variants

hf_paths.py reads 579ae7ce/439 and a4db11ff/333 along the prefill and decode
paths in transformers' Qwen3.5 in BF16 (torch or flash-linear-attention GDN
kernels; cached state in BF16 or FP32), and sglang_variants.py reads them on
the unpatched SGLang pin under one-family kernel swaps. Readings set in the
docstrings before the run; hold.sh runs both in one shared hold.
Open upstream issue #38975 and PRs #38977/#40362 report that the packed GDN
decode kernel and the gating kernel round sigmoid(beta) through BF16. The
beta_fp32 variant runs the default flags on the pin with both lines changed
(engine/sglang/patches/upstream-bf16/0001), so the hold can tell whether that
rounding explains the decode/prefill disagreement.
…d steps

The prefill trace stopped one position short when the prefill ended at the
target (KeyError at 439 in the first hold), and the sglang venv has no pip:
install flash-linear-attention 0.5.2 with uv. hold.sh takes a step (all, hf,
sglang) so the transformers runs can be repeated without the server variants.
…readout

perturb.py repeats paths.py's FP32 forward with every decoder layer's output
multiplied by (1 + u), u ~ U[-2^-9, 2^-9], over 8 seeds, to measure how far
rounding of BF16 size moves the two positions by itself (readings set in the
docstring). summary.py tabulates every source and path against FP32. hold.sh
takes several steps (hf, sglang, perturb).
The two positions were found because SGLang erred there, so they cannot
compare error rates between implementations. rates.py decodes and prefills
12 workload prompts on stock SGLang, reads the same text with transformers
BF16 (FP32 and BF16 cached state) and scores every path's top-1 against an
FP32 forward, before and after the first end of text. perturb.py --site gdn
puts the BF16-sized noise on the GDN core's inputs instead of the residual
stream. Readings set in the docstrings.
…ared decision

transformers' torch GDN keeps the recurrence in FP32, so the rate comparison
also reads the same text with flash-linear-attention's kernels (FP32 state),
and rates.decide applies the rule declared before the run against the worse of
the two. CPU tests for the readouts and the rule.
Hold 3's rates sample never reached an end-of-text token, the regime of both
events. rates.py takes the output length and an end-of-text filter on the
benchmark's recorded outputs; hold.sh's rates_eot step decodes 768 tokens of
12 such prompts and compares against both transformers GDN implementations
with an FP32 state. Secondary readouts: finer regret thresholds and the
logprob error on FP32's top-1.
a4db11ff/333 is ill-conditioned in BF16: transformers BF16 misses FP32 there
by up to 16.7 nats and FP32 flips its own top-1 under noise of one BF16
rounding. At 579ae7ce/439 only SGLang misses, but no single kernel family
carries it, and on 15,360 unselected positions per path (5,426 after the end
of text) SGLang is as accurate as transformers; both declared rate rules came
back inconclusive (0 vs 0, 1 vs 1). No upstream issue follows from this.
@SamMausberg

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-02T23:19:07.959130Z 82523e2 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1e8903a4ab

ℹ️ 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".

Comment thread experiments/bf16_paths/perturb.py Outdated
from experiments.benchcert.paths import MODEL, REVISION, TRACE
from experiments.bf16_paths.hf_paths import entry

EPS = 2.0**-9

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Perturb by the full BF16 rounding bound

For normalized BF16 round-to-nearest with eight significant bits, the relative rounding-error bound is approximately 2^-8, not 2^-9; values just above a power of two can incur nearly the larger error. Consequently, the committed perturbation evidence samples only half the advertised range, so the observation that 579ae7ce stays stable does not establish stability under a full BF16-sized rounding perturbation. Increase the bound and regenerate the perturbation evidence before using it to classify that position.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed: round-to-nearest BF16 has a relative error bound of 2^-8, and 2^-9 sampled only half of it. Fixed in 94460d6 (EPS = 2^-8, docstring and README corrected). Both perturbations were rerun at 2^-8 (hold 5) and the evidence regenerated in 41829e3: 579ae7ce's 1756 now stays within 0.52 nats of FP32 (-10.04 to -9.27; 68189 on top in all 8 seeds), and a4db11ff's 18299 falls as low as -11.65 in FP32 itself with the top-1 flipping in 4 of 8 seeds. The classification of both positions is unchanged; the 2^-9 runs are kept outside git as superseded and named so in the README.

Comment thread experiments/bf16_paths/rates.py Outdated
Comment on lines +290 to +293
sglang_events = events_above(counts, 'sglang/decode') + events_above(counts, 'sglang/prefill')
by_comparator = {
name: events_above(counts, f'{name}/decode') + events_above(counts, f'{name}/prefill')
for name in COMPARATORS

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Do not count paired paths as independent events

When a bad position appears in both decode and prefill, these lines count it twice before applying the exact binomial test, even though the two observations share the same prompt, position, weights, and much of the computation. This can manufacture a significant verdict: three affected positions duplicated across both paths become 6-versus-0 events and yield p=0.015625, whereas the three independent positions yield p=0.125. Deduplicate or block events by prompt/position, or use a paired/block-aware test, before deriving the sglang-specific verdict.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed: the two paths share the prompt, position and most of the arithmetic. Fixed in 94460d6: rates.summary records, per source, the positions missed by more than 2 nats on either path, and decide counts each position once (positions_missed_above_2_nats in the JSON; new test test_rates_summary_counts_a_position_missed_on_both_paths_once). Regenerated in 41829e3; neither verdict changes (0 vs 0; then one position, 6af1e245/247, for SGLang and both transformers runs). The README says this correction came after the runs.

… position once

Codex on #222: round-to-nearest BF16 has a relative error bound of 2^-8, not
2^-9, so the perturbation now draws u from [-2^-8, 2^-8] (the 2^-9 runs are
superseded). The rate decision counted a position missed on both the decode
and the prefill path twice; it now counts positions, once each.
…ons counted once

Regenerated at 94460d6: positions.json with the 2^-8 perturbation runs (hold 5;
579ae7ce's 1756 stays within 0.52 nats, a4db11ff's 18299 falls as low as -11.65
in FP32 itself), rates.json and rates_eot.json with the decision on missed
positions counted once (verdicts unchanged: 0 vs 0, 1 vs 1).
@SamMausberg

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 41829e3353

ℹ️ 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".

scripts/gpu_lock.sh -s experiments/bf16_paths/hold.sh rates_eot
# Hold 5 (repo 94460d6): both perturbations again at the full rounding bound, 2^-8 (the runs of
# holds 2 and 3 used 2^-9 and are superseded).
scripts/gpu_lock.sh -s experiments/bf16_paths/hold.sh perturb perturb_gdn

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Make the full-bound rerun command executable

When the documented holds are run in order using the default BF16_PATHS_OUT, holds 2 and 3 create perturb.json and perturb_gdn.json, so this hold-5 command exits with status 65 at hold.sh's existing-output guard before either full-bound run starts. Document the required removal/archive step or use a separate output directory so the listed command actually reproduces the committed perturbation evidence.

AGENTS.md reference: AGENTS.md:L15-L18

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Fixed in 86852c1: the README's command list now shows the step taken before hold 5 (the 2^-9 outputs moved to superseded_eps2m9/, since hold.sh refuses to overwrite an output) and notes that into a fresh output directory at 94460d6 or later holds 2 and 3 already perturb at 2^-8, so hold 5 is not needed for a reproduction.

@SamMausberg

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 86852c1149

ℹ️ 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".

Comment on lines +50 to +51
noise = torch.rand(hidden.shape, generator=generator, dtype=hidden.dtype)
perturbed = hidden * (1 + (2 * noise - 1) * EPS)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Do not treat random perturbations as a rounding bound

When none of the eight random directions happens to expose a sensitive direction, this uniform sampling cannot establish that a position is stable under BF16 rounding: most sampled elements have errors smaller than EPS, and the finite samples do not cover all correlated in-bound rounding patterns. The full EPS fixes the previously reported scale issue, but these lines are fresh evidence that the rerun remains only a positive sensitivity probe, so using its 0.52-nat observed maximum to classify 579ae7ce as “not” ill-conditioned is unsupported; either test actual BF16 round-trips/provide a worst-case bound or qualify the negative conclusion.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed: eight random draws per site are a sensitivity probe, not a bound. Fixed in 418ad12: the README now says 579ae7ce/439 showed no sensitivity in 16 draws (1756 within 0.52 nats), that a random probe cannot bound stability over every correlated in-bound rounding pattern, so this supports rather than proves good conditioning, and that the transformers runs (real BF16 roundings, four configurations) point the same way; the Result item and the Limits bullet are qualified the same way, and perturb.py's docstring states the limit. The verdict does not rest on this probe: it rests on the selection-free rates, which were inconclusive, so no issue follows either way.

…d (Codex on #222)

Eight random draws per site can show that a position is sensitive but cannot
bound its stability over every in-bound rounding pattern; the README and
perturb.py's docstring now say so, and qualify the reading of 579ae7ce/439.
Docstring only: the perturbation evidence (generated at 94460d6) is unchanged.
@SamMausberg

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 418ad12362

ℹ️ 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".

Comment thread experiments/bf16_paths/perturb.py Outdated
Comment on lines +13 to +14
a power of two come close to it), so each run perturbs the residual stream at least as much
as storing it in BF16 after every layer would, at every position of the prefix

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Remove the lower-bound claim for random perturbations

The stated fix still leaves this pointwise lower-bound claim: a uniform draw in [-2^-8, 2^-8] usually has magnitude below the BF16 error bound and can be smaller than the actual rounding error for the fixed activation, so a run does not perturb every element “at least as much” as BF16 storage would. The later random-probe disclaimer addresses directional coverage but does not make this amplitude claim true; retaining it overstates what the residual experiment establishes.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed: a uniform draw within the bound is neither an upper nor a lower bound on a fixed value's rounding error. Fixed in 8f0021d: the docstring now says each run perturbs by relative errors of the same order as BF16 storage and that the draw bounds no particular rounding. The README already describes the noise as uniform within the bound and the runs as a sensitivity probe, not a bound.

…ng (Codex on #222)

Docstring only; the perturbation evidence (generated at 94460d6) is unchanged.
@SamMausberg

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8f0021d1d6

ℹ️ 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".

Comment thread evidence/bf16_paths/README.md Outdated
per path (12 workload prompts decoded for 512 tokens, then 12 prompts decoded for 768 tokens so
that 5,426 positions lie after the end of text), SGLang's mean logprob error on FP32's top token
(0.0039-0.0054 nats per path and sample) lies within transformers' range (0.0042-0.0057), and
SGLang misses FP32's top by more than 0.5 nats at 3 positions against 2 and 1 for the two

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Deduplicate the shared half-nat miss

For the reported rates_eot data, SGLang's decode and prefill entries both exceed 0.5 nats at the same 0ae071b513acf1ae position 551, while only prefill exceeds it at 6af1e245439490c5 position 247. Thus there are two distinct positions, not three; 3 is the number of path-position observations. Since the surrounding result explicitly reports positions and deduplicates paths for its decision, either report 2 against 2 and 1 here or label these as path-position observations.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Fixed in b394831: by position, SGLang misses by more than 0.5 nats at 2 distinct positions (0ae071b5/551 on both paths, 6af1e245/247 on prefill), and transformers' torch GDN run misses at the same 2 (fla at 1 of them); the README now says this, and the per-path table stays labelled per path.

@SamMausberg

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b39483154a

ℹ️ 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".

Comment thread experiments/bf16_paths/rates.py Outdated
comparator = max(by_comparator, key=lambda name: by_comparator[name])
hf_events = by_comparator[comparator]
total = sglang_events + hf_events
p_value = sum(math.comb(total, k) for k in range(sglang_events, total + 1)) / 2**total

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Base the exact test on discordant positions

Because SGLang and transformers are evaluated at the same prompt/position pairs, summing their event counts treats paired observations as independent and counts a position missed by both implementations twice. This already makes the committed rates_eot p-value 0.75 even though its sole event is shared and there are no discordant pairs, for which a paired exact test yields 1.0; in other samples it can change the verdict (for example, six SGLang misses with one shared comparator miss produces 0.0625 here versus 0.03125 from the five SGLang-only discordances). Preserve the position sets through decide and compute the exact test from SGLang-only versus comparator-only positions.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Fixed in c44ef32: summary passes the missed-position sets to decide, which runs the paired exact test on SGLang-only against comparator-only positions (sglang_only, comparator_only, paired_exact_p_one_sided in the JSON) and keeps the declared count thresholds; new test test_decision_pairs_positions_both_miss covers your 6-with-1-shared example (p = 1/32) and the shared-only case (p = 1). Rate evidence regenerated at c44ef32 (b43d550): the rates_eot p is now 1.0 (its one miss is shared), and both verdicts stay inconclusive. README updated (c386c13).

SGLang and transformers are read at the same positions, so the decision now
tests SGLang-only against comparator-only missed positions (McNemar's exact
test) instead of summing the two counts. Neither verdict changes; the rate
evidence is regenerated from this commit.
@SamMausberg

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9935ab68f2

ℹ️ 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".

Comment on lines +187 to +189
for state in $states; do
! missing "$r/hf_bf16_${state}state.jsonl.gz" ||
timeout --foreground 1200 python -m experiments.bf16_paths.rates hf --out "$r" --state-dtype "$state" || fail

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Rebuild dependent traces after regenerating SGLang

When a stale marker is caused by a missing sglang.jsonl.gz, this section regenerates SGLang's greedy text but preserves any existing transformers traces here and the FP32 trace later. If the regenerated decode differs—for example after intentionally moving the file aside to rerun under updated code or dependencies—the preserved files describe the old text, while sources() validates only prompt IDs and trace lengths, so the resulting evidence can silently compare different token contexts. Invalidate the downstream HF/FP32 files whenever SGLang is rebuilt, or record and verify the exact output token IDs before keeping them.

AGENTS.md reference: AGENTS.md:L15-L18

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Fixed in 029f1a2: hf and fp32 rows now record text_sha256 (SHA-256 of the prompt and output ids they were computed on); sources() and summary refuse a row whose hash differs from sglang.jsonl.gz (test test_rates_refuses_traces_of_other_text), and hold.sh moves existing transformers and FP32 traces into a superseded-/ directory before it regenerates the SGLang text. The committed raw rows predate the hash and are not checked; each rates directory was produced once, in order (sglang, then hf, then fp32).

)

hf and fp32 rows record a SHA-256 of the prompt and output ids they were
computed on, sources() and summary refuse a row whose hash differs from
sglang.jsonl.gz, and hold.sh moves existing traces aside before it regenerates
the SGLang text. The committed raw rows predate the hash and are not checked;
each rates directory was produced once, in order.
@SamMausberg

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 029f1a2994

ℹ️ 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".

Comment thread experiments/bf16_paths/rates.py Outdated
Comment on lines +85 to +86
recorded = row.get('text_sha256')
if recorded is not None and recorded != text_sha(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject traces that lack a text hash

When a legacy HF or FP32 row is combined with a regenerated sglang.jsonl.gz having the same prompt and output length but different output tokens, recorded is None, so this check accepts the stale row and summary() compares distributions from different token contexts. Fresh evidence after the prior regeneration fix is this explicit missing-hash bypass; require the hash or otherwise validate the exact token sequence before consuming these raw traces.

AGENTS.md reference: AGENTS.md:L15-L18

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Fixed in 148847a: a transformers or FP32 row without a text hash is refused unless --accept-unhashed, and the output lists every row accepted that way (unhashed_rows_accepted). The README's regeneration commands pass the flag for holds 3 and 4 only, with the reason (each directory produced once, in order: prompts, SGLang, transformers, FP32). Tests: test_rates_refuses_unhashed_traces_unless_accepted. Evidence regenerated (fa70220); verdicts unchanged.

Comment on lines +172 to +174
if missing "$r/prompts.jsonl"; then
python -m experiments.bf16_paths.rates prompts --out "$r" "$@" || { fail; return 0; }
fi

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Invalidate downstream outputs when prompts are regenerated

When prompts.jsonl is moved aside using the supported redo workflow and regenerates to a different sample, these lines replace only the prompt manifest; the following guard keeps the existing SGLang, HF, and FP32 traces and the step can be marked complete. The resulting readout still measures the old prompt sample rather than the newly selected one, so recreating the manifest should also invalidate its dependent outputs or verify that the manifest matches sglang.jsonl.gz.

AGENTS.md reference: AGENTS.md:L15-L18

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Fixed in 148847a: sources() refuses an sglang.jsonl.gz whose prompts and prompt ids differ from the current prompts.jsonl (test_rates_refuses_sglang_text_of_another_manifest), and hold.sh's set_aside moves SGLang's text and every transformers and FP32 trace into superseded-/ when it recreates the manifest (and the traces when it recreates the text).

…alidate on regeneration (Codex on #222)

Rows without a text hash are refused unless --accept-unhashed, which the README
uses for holds 3 and 4 (produced once, in order) and the output lists; sources()
refuses an sglang.jsonl.gz decoded from another prompts.jsonl; hold.sh moves
SGLang's text and every trace aside when it recreates the manifest, and the
traces when it recreates the text.
@SamMausberg

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fa7022026b

ℹ️ 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".

Comment on lines +200 to +202
for state in $states; do
! missing "$r/hf_bf16_${state}state.jsonl.gz" ||
timeout --foreground 1200 python -m experiments.bf16_paths.rates hf --out "$r" --state-dtype "$state" || fail

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Invalidate FP32 when regenerating an HF trace

When the supported redo workflow moves aside one hf_bf16_*.jsonl.gz file, this loop regenerates it but preserves the existing fp32.jsonl.gz. That FP32 file stores logprobs only for tokens present in the BF16 top-20 sets when it was created; if the regenerated HF trace introduces a new top-1 token, rates.summary rejects the supposedly completed hold because FP32 lacks that token's logprob. Set aside FP32 before rebuilding any missing HF trace so the documented evidence command remains reproducible.

AGENTS.md reference: AGENTS.md:L15-L18

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Fixed in dad71b8: before the transformers runs, run_rates sets fp32.jsonl.gz aside whenever any of the step's traces (each state dtype, and fla) is missing and will be rebuilt, so FP32 is recomputed over the new union. With this the rates dependency chain is closed: a new manifest sets aside SGLang's text and all traces, a new text the traces, a new trace FP32. Stub-tested (FP32 kept while every trace exists, moved when one is missing); shellcheck and hold_lint pass.

@SamMausberg

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: dad71b8738

ℹ️ 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".

@SamMausberg

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 5748d8b8c0

ℹ️ 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".

@SamMausberg

Copy link
Copy Markdown
Owner Author

Verdict: REQUEST CHANGES at 5748d8b

This was a full review. The investigation holds up:

  • The decision rule and its minimum count were committed before each run.
  • Both rates samples are selection-free.
  • The verdict is worded within its evidence: row B is BF16 conditioning, and row A is an SGLang outlier at a selected position whose rate the samples cannot separate from transformers'.
  • Nothing suggests an upstream issue was filed.

Two numbers in the README's prose are wrong. Both are one-phrase fixes.

Blocking

  1. evidence/bf16_paths/README.md:40 (and the PR body's "Findings"): "SGLang's mean logprob error on FP32's top token (0.0039-0.0054 nats per path and sample) lies within transformers' range (0.0042-0.0057)". It does not lie within that range. SGLang's decode path in rates_eot has 0.00388, below transformers' lowest value (fla decode, 0.00415). SGLang's path means are at or below transformers' in both samples:

    • ordinary text: 0.0054 / 0.0054 against 0.0056-0.0057;
    • rates_eot: 0.0039 / 0.0045 against 0.0042-0.0049.

    Suggested wording: "is no larger than transformers' in either sample (0.0039-0.0054 against 0.0042-0.0057)".

  2. README:121: "at 579ae7ce two of sixteen readings exceed 1 nat (1.15 on 5715, the torch 576-token prefill; ...)". It is three of sixteen. The torch 576-token prefill is a reading in both torch configurations: hf_bf16_torch/prefill_576 and hf_bf16_torch_fp32state/prefill_576 both have max_abs_diff_from_fp32_tracked 1.1529. A prefill does not read the cached state, so the two are the same computation. Say "three of the sixteen readings (two distinct computations: ...)" or "two of the ten distinct readings".

Optional

  1. README:127: "FP32 gives each a logprob of -0.103 or higher". No committed file holds this figure; positions.json keeps only the largest difference before the target. Add the minimum to summary.py's output, or drop the number.
  2. README:126: "at most 0.047, SGLang's 576-token prefill at 579ae7ce position 437".
    • The 0.0472 maximum belongs to the Triton-attention variant's 514- and 576-token prefills.
    • The default pin's 576-token prefill is 0.0456.
    • Position 437 is not in positions.json.
  3. README:41: "(on 3 paths)". Suggested: "(three path readings: SGLang's decode at one position, its prefill at both)".
  4. README:31: "One BF16 rounding of beta (the lines of ...) moves the decode". The variant removes that rounding. Suggested: "Keeping sigmoid(beta) in FP32 (the lines of ...)".

What I checked

  • The decision rule was set before each run.

    • rates.py at aac2264 (committed 18:09:23 UTC) holds the rule in its docstring and decide: SGLang-specific needs at least 5 SGLang events, at least 3x the worse FP32-state transformers run, and a one-sided binomial p < 0.05; "not specific" needs at least 10 events and at most 1.5x; anything else is inconclusive. Hold 3's log starts at 18:12:03, running at that commit.
    • decide is unchanged at 43efc79 (18:38:58), which adds --eot-before and --output-len. Hold 4 starts at 18:48:55, running at that commit.
  • The refinements made after the runs are labelled as such in the docstring and the README:

    • each missed position counts once;
    • the paired (McNemar) test;
    • the rule applied against each comparator.

    "Against both or comparable to one" is equivalent to the original "worse comparator" thresholds. The original rule also gives inconclusive on the committed counts: 0 against 0, then path-events 1 against 1 with a total of 2.

  • Selection.

    • rates takes the first 12 prompts by hash.
    • rates_eot takes the first 12 by hash whose recorded benchmark output ends before 400, a property of that output and not of any reading.
  • Numbers.

    • Both position tables (96 cells) match positions.json.
    • The swap readings match: 2.75; 0.31/1.18/1.34; 1.06-1.72; 4.60/6.81.
    • The perturbation table matches, including 4 of 8 top-1 flips at both sites, the control at most 0.0219, and 1756 within 0.52.
    • The rates table matches rates.json and rates_eot.json (all 48 cells), as do 15,360 positions per path, 5,426 after the end of text and 3,790 before it.
  • The half-nat correction:

    • SGLang misses at two positions, 0ae071b5/551 (decode and prefill, 0.519) and 6af1e245/247 (prefill, 3.226).
    • The torch FP32-state run misses both, one on each path.
    • fla misses only 247.
    • The only miss above 2 nats is 247, in all three prefills.
  • --accept-unhashed.

    • Without it, check_text refuses unhashed rows. The JSON lists the rows it accepted: 48 in rates.json and 36 in rates_eot.json (fp32 and the transformers runs).
    • The README's justification checks out on disk. In both raw directories the files were written once, in order (prompts, sglang, the transformers runs, fp32), inside each hold's window (18:14-18:35 and 18:48-19:10), and none was modified afterwards.
  • Diagnostic patch. Pin + upstream-bf16/0001 gives tree 01641256, equal to engine head 4608661757. The gating kernel's beta_output buffer is FP32 at the pin, as the engine README says.

  • No upstream filing implied. "issue" appears only as "supports/belongs in an SGLang issue" (the question asked), #38975 as context, and "No upstream issue or comment" in the body.

  • Codex: all 21 threads are answered, and Codex is clean on 5748d8b. The PR merges cleanly with main at 5a125d9.

  • Pending: regenerating the three JSON files at this head, pytest tests/test_bf16_paths.py and pre-commit are queued in the CPU window, which a timed hold is keeping waiting. I will add the result here.

…' (not within its range); three of sixteen readings exceed 1 nat

Reviewer, #222 issuecomment-5962740297: 0.0039 is below transformers' lowest 0.0042, and the torch
576-token prefill exceeds 1 nat in both state configurations (positions.json).
@SamMausberg

Copy link
Copy Markdown
Owner Author

@codex review

@SamMausberg

Copy link
Copy Markdown
Owner Author

Checks at 5748d8b (the pending items from my review above). All pass; the two blocking wording items stand.

  • rates.json, rates_eot.json and positions.json regenerate byte-identical at this head. I ran the README's commands (rates summary ... --accept-unhashed on both raw directories, summary --paths ... --out ...) in the SGLang environment.
  • Without --accept-unhashed, rates summary refuses the same data (exit 1: "hf_bf16_float32state: 0002376d111df4ff carries no text hash"), as the README says.
  • pytest tests/test_bf16_paths.py: 23 passed.
  • pre-commit on the PR's files (against main 5a125d9): every hook passes (ruff, mypy, codespell, shellcheck, host identity).

@SamMausberg

Copy link
Copy Markdown
Owner Author

Verdict: APPROVE at 82523e2 (provisional on Codex, requested 23:14 on this head)

I re-checked only the delta from 5748d8b: one commit, evidence/bf16_paths/README.md only, 5 lines. Both blocking items are fixed.

  1. "is no larger than transformers' (0.0042-0.0057) in either sample". This holds path by path in both samples:

    • SGLang decode 0.0054 and 0.0039 against transformers decodes 0.0056-0.0057 and 0.0042-0.0044;
    • SGLang prefill 0.0054 and 0.0045 against transformers prefills 0.0056 and 0.0047-0.0049.

    The PR body says the same.

  2. "three of sixteen readings exceed 1 nat (1.15 on 5715, the torch 576-token prefill, in both state configurations; ...)" matches positions.json.

My optional items 3-6 were not taken. That is fine; none is blocking.

My earlier checks at 5748d8b still apply, since nothing else changed: the regenerated evidence was byte-identical, rates summary refuses the data without the flag, 23 tests pass and pre-commit is clean. The delta has no trailing whitespace and no hostname. If Codex raises nothing valid on 82523e2, this is final.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 82523e298b

ℹ️ 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".

@SamMausberg
SamMausberg merged commit 7a394a6 into main Oct 2, 2026
SamMausberg added a commit that referenced this pull request Oct 3, 2026
…es and the upstream patches

BF16 (#222, evidence/bf16_paths): the served benchmark read both gross
positions as ill-conditioned in BF16. #222 supports that for a4db11ff/333
only. At 579ae7ce/439, the paper's 8.9-nat position, transformers in BF16
keeps FP32's top token in all 16 readings, FP32 under one-rounding noise
moves 1756 by at most 0.52 nats, and no single SGLang kernel swap removes
the miss: an SGLang outlier at a selected position, whose frequency the
unselected positions cannot compare with transformers'. The abstract and
§4.5 add "unlike transformers'"; App E.5, the served README (two places)
and a new notes subsection give the reading; register entry bf16-paths in
both registers.

Low-concurrency probes (#220, evidence/speed_lowc): one notes paragraph
(split-KV verify dropped by its rule; FA4's head-dim-256 compile failure
and backport; one-session served FA4 probes, exactness not classified;
fused GDN chain passed its rule but not built), H6, "What did not work",
register entry speed-lowc, and the missing index rows.

Upstream (#226): one notes paragraph and register entry upstream-patches
(the FA4 test as a comment on sgl-project/sglang#35757; the sgl-kernel
sm_90a build fix open as sgl-project/sglang#42263). The two FP8 lines say
the CUTLASS GEMM "fails" rather than "aborts", consistent with the engine
README.

Reviewer's optional item from #227: "calls of up to 30-64 positions" in
the abstract and §4.5 (largest certified calls at each point).

Paid for in §4.5's paragraph with no claim dropped; the main text still
ends at the foot of p10.
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