Skip to content

glm cuda dflash2: opt-in measured window prices and cost-derived width - #4573

Open
ashhart wants to merge 2 commits into
mainfrom
lead/glm-priced-windows
Open

ashhart wants to merge 2 commits into
mainfrom
lead/glm-priced-windows

Conversation

@ashhart

@ashhart ashhart commented Nov 22, 2026

Copy link
Copy Markdown
Owner

What this changes

GLM's DFlash2 path verified windows priced by seed formulas (cuda_lane_costs.zig: only MTP published a measured table) and cut each drafted block with a fixed 0.7 probability product after the block was drafted. With TF_GLM_PRICED_WINDOWS=1:

  • Startup times real-text windows for DFlash2 as it does for MTP and publishes the table to the lane core (seed table as the fallback when timing is refused).
  • A generic lane-core option (priced_windows, core/lanes/window_price.zig) calibrates each draft position's chance from observed landings and asks the existing allocator to score every prefix of the drafted block, verifying the width with the best expected kept tokens per measured cost.

Drafting only decides which rows the target verifies, so outputs are unchanged. Off by default; other families are untouched (the option is per family).

Checks

  • Host tests: the measured table is published; steep costs pick narrower widths and flat costs wider; switch off keeps seed prices and the 0.7 cut; environment table and count; compile-cuda-tests (host runner only); fmt, ast-check.

Still to run

Two GB10s, one stream, prose and code with DFlash2, both arms' tokens equal to a draft-off run (kill if either is slower or the gain is under +3%).

@Bizuayeu

Copy link
Copy Markdown
Contributor

Two GB10s, one stream, prose and code with DFlash2, both arms' tokens equal to a draft-off run (kill if either is slower or the gain is under +3%).

#4573

I can run that check on two GB10s at TP=2, if it helps: this head against main, TF_GLM_PRICED_WINDOWS=1 on the head, the two arms taken in turn, and a draft-off run for the tokens, one stream, on the 64 prose and 64 code prompts of our evaluation set at temperature 0. Two things we measured on that pair point at what this changes. A lone DFlash2 round is priced from the seed table shared_costs (76 ms and 4.1 ms a row, cuda_copy_policy.zig), but served rounds there took 41.87 ms and 5.87 ms for each draft verified (fitted to the seconds of 320 replies at five cuts from 0.9 to 0.2, within-request R² 0.979), on the weights below with the expert form fixed by TF_GLM_EXPERT_FORM=factored; the price moves with the weights and the build, which a table timed at startup takes in. And DFlash2's chances run high: replaying the same replies offline, in a counter that matches serving's tokens a round within 0.013, the mean product of chances at a block's first, third and seventh draft is 0.810, 0.491 and 0.172 for prose, while the share of blocks that landed whole to there is 0.672, 0.206 and 0.026 (code: 0.953, 0.865 and 0.690 against 0.947, 0.792 and 0.508).

The head conflicts with main since 1d7cc5f, in the environment table, the build's host list, cuda_env_test.zig and the timing identity in cuda_lane_costs.zig, none of them in the allocator. I would resolve those locally for the run and can push that head to my fork if you want it; if you would rather rebase it yourself first, I will run on yours. The pair serves our 4-bit checkpoint (Bizuayeu/GLM-5.3-Flash-Jammed-XSFP4) with the published DFlash2 at its default 4 bits; say if you want other weights. I would report decode tok/s for prose and code and each arm's tokens against the draft-off run, against your kill line.

Related: the fit and its per-request data, https://github.com/Bizuayeu/Open-DNeo/tree/v0.8.0/receipts/2026-11-23-round-time

@Bizuayeu

Copy link
Copy Markdown
Contributor

Two GB10s, one stream, prose and code with DFlash2, both arms' tokens equal to a draft-off run (kill if either is slower or the gain is under +3%).

#4573

I ran that check on two GB10s at TP=2, on this head as it stands (6ea7cc6a7f) against its base on main (ce0264367e). Tokens equalled the draft-off run in all 512 replies. Prose was 6.2% slower, and code showed no gain (−0.4%, the same size as the 0.2–0.3% between its own launches). By the description's line, that is a kill.

decode tok/s (pooled, mean of two launches) base ce0264367e head, TF_GLM_PRICED_WINDOWS=1 change
prose (64 prompts) 36.50 34.25 −6.2%
code (64 prompts) 61.88 61.63 −0.4%

Setup. Both natives were built with an empty Zig global cache (Zig 0.17.0, nvcc 13.3, sm 121). The head conflicts with current main, so I measured it unrebased against its merge base instead of a local resolution. The checkpoint was Bizuayeu/GLM-5.3-Flash-Jammed-XSFP4 at 0a22bb46ec, with the published DFlash2 (incoai/GLM-5.3-Flash-DFlash2 at 6cc6c481ee, its default 4 bits), at context 1048576 and parallel 4. Every launch pinned TF_GLM_EXPERT_FORM=factored and kept the default cut. Each launch was fresh and sent the 64 prose and 64 code prompts of our evaluation set one at a time, greedy, on /v1/completions. The order was a draft-off run (every request "draft": false), base, head, head, base. No heat wait or heat-cap change fell inside any launch.

Exactness. In each of the four drafting launches, every reply's token_sha256 equalled the draft-off run's for the same prompt: 512 of 512.

Speed. Decode tok/s is the engine's own tokens / decode from its done lines, pooled over a class's 64 replies.

launch prose tok/s prose tokens a round code tok/s code tokens a round
draft-off 25.83 1.004 25.80 1.004
base 1 36.54 2.040 61.83 4.782
head 1 34.38 2.206 61.71 5.128
head 2 34.12 2.204 61.55 5.131
base 2 36.47 2.040 61.94 4.788

The two launches of an arm differed by 0.8% at most. Both head launches started from glm: windows (kept): 38.06 ms at 1 row, 61.03 at 4, 173.15 at 32, a draft 0.67 ms. That table was timed at the start of one earlier head launch, which my own log check stopped before it sent any request.

The head took more tokens a round, and each round took longer by more than that:

per round (both launches of an arm) prose base prose head code base code head
tokens 2.040 2.205 (+8.1%) 4.785 5.130 (+7.2%)
decode ms 55.9 64.4 (+15.2%) 77.3 83.2 (+7.6%)

The median time to the first token was the same in both arms (prose 0.385 s and 0.384 s, code 0.371 s).

What this does not cover. I did not run the head with the switch off, so the difference is the base binary against the head binary with TF_GLM_PRICED_WINDOWS=1, not the switch alone. This is the unrebased head against its own base, not a measurement on current main. It is one checkpoint, one pair of GB10s, one stream, replies of up to 256 tokens, and prose and code only. The window table was timed once and read as kept in both counted launches; I did not check whether timing it again moves the table.

@Bizuayeu

Copy link
Copy Markdown
Contributor

I did not run the head with the switch off, so the difference is the base binary against the head binary with TF_GLM_PRICED_WINDOWS=1, not the switch alone.

#4573 (comment)

I have now run that: two launches of the head with the switch off, with a third base launch between them, on the same pair, setup and prompts. With the switch off, the head matched the base, so the slowdown above comes from the switch.

decode tok/s (pooled) base (3 launches) head, switch off (2) head, switch on (2, above)
prose 36.48 36.55 (+0.2%) 34.25 (−6.1%)
code 61.87 61.93 (+0.1%) 61.63 (−0.4%)

The changes are against the base's three launches. With the switch off, the head took the same tokens a round as the base (prose 2.040 in every launch, code 4.782 to 4.788) and printed no windows line. In all 384 replies of the three new launches, tokens equalled the draft-off run. The third base launch was within 0.2% of the first two.

@kelchm

kelchm commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Adding a complementary 2× GB10 (TP=2) EXL3 4 bpw data point that points in the same direction as @Bizuayeu's XSFP4 receipt across single-stream, 4-stream, and long-context coding turns.

I ported #4573's TF_GLM_PRICED_WINDOWS=1 (b7eae3b7e255, byte-identical window_price.zig + copy_policy.blockChances) onto a downstream TensorFold v1.3.6 build carrying local EXL3/DFlash2 optimizations (GLM-5.3-Flash EXL3 4 bpw 078455ffe6472f9a52fbc1139f58b9db2881b25c, Q4 DFlash2 bf582e4eacc1810f76656d1811693ff6c6737d2a, paged FP8 KV, --parallel 4 --context 1048576) and toggled only TF_GLM_PRICED_WINDOWS on the same binary (all greedy replies bit-identical across arms):

  • Live startup timing on 2× GB10 calibrated at 26.14 ms @ 1 row, 46.48 ms @ 4 rows, 151.11 ms @ 32 rows, 0.56 ms draft.
  • Like @Bizuayeu saw, measured pricing pushed drafts/round up and slowed every workload:
    • 1-stream decode (c1, mean of 3): 66.27 → 63.58 tok/s (−4.1%)
    • 4-stream decode (c4, mean of 3): 103.91 → 101.94 tok/s (−1.9%)
    • 5× warm 40K coding turns: 59.03 → 56.61 tok/s after-first-token / 57.13 → 54.62 tok/s e2e (−4.4%)

(Measured on a downstream v1.3.6 build with the ported switch rather than directly on #4573's head, shared as an additional GB10 EXL3 data point.)

@ashhart
ashhart force-pushed the lead/glm-priced-windows branch 2 times, most recently from 05b0935 to 1f26eb4 Compare November 28, 2026 15:07
@ashhart
ashhart force-pushed the lead/glm-priced-windows branch from 1f26eb4 to 029ff67 Compare November 29, 2026 02:44
@ashhart ashhart added kind:perf Classified by Synthena as performance improvement synthena:needs-receipt Speed PR awaiting verified perf_receipt.py hash run labels Dec 3, 2026
@ashhart

ashhart commented Dec 3, 2026

Copy link
Copy Markdown
Owner Author

Synthena Initial Review — Performance receipt required (kind:perf)

Adds an opt-in TF_GLM_PRICED_WINDOWS mode for GLM DFlash2 that times target windows at startup, publishes a measured cost table, and calibrates per-position draft chances to pick the verify width by expected kept tokens per measured cost. Off by default and outputs unchanged, but the claimed speedup has no benchmark receipt and the CI 'zig' check is failing.

  • Branch currently has merge conflicts against base.
  • Failing CI check(s): zig.
  • Performance claim detected without a verified tf-receipt-v1 receipt.

Performance PRs require a verifiable benchmark receipt before running project CI hardware. See CONTRIBUTING.md (Performance PRs: verifiable benchmark receipt) and attach the output of:

python3 tools/perf_receipt.py run --base-bin /path/to/base-tf --head-bin /path/to/head-tf --model /path/to/model.tfold --out receipt.json

Findings:

  • [BLOCKER] zig/src/families/glm/cuda_lane_costs.zig: When priced timing is refused because the tokenizer text is too short, the code silently falls back to untimed seed prices instead of surfacing the error, so a misconfigured startup gets no signal that measurement never ran. Suggested fix: Log a warning (as the failed-race path does) or return the error so operators can distinguish 'timing refused' from 'timing succeeded'; at minimum document the silent fallback in the PR description.
  • [BLOCKER] zig/src/core/lanes/window_price.zig: probabilities() grows the bin list to raw.len but never shrinks it when a later call passes a shorter raw slice, and observe() indexes s.bins.items[0..n] where n can exceed the calibrated prefix, so stale bins from a longer prior round can be observed as if they were current. Suggested fix: Track the active offered length per round (s.offered is set but observe clamps with @min(offered, s.offered) only after probabilities ran; verify bins beyond the current raw.len are excluded) and reset or truncate stale bins when raw.len shrinks.
  • [WARNING] zig/src/core/lanes/windows.zig: probabilities() allocates from e.arena.allocator() each round and the returned slice replaces probs[0] without any lifetime documentation; if the arena is reset between allocate and use, the calibrated chances are garbage. Suggested fix: Confirm the arena is not reset between windows.allocate and the allocator's use of probs[0], or allocate from e.gpa with an explicit free path.
  • [WARNING] zig/src/families/glm/cuda_copy_policy.zig: When priced is true the cut is hard-coded to 0 and the loop still runs the chain-product logic only for the non-priced branch, but the function signature takes requests/records by anytype and the priced path skips the chain loop entirely via 'continue', leaving l.held_n set but chances untouched; this is correct only if the shared calibrator always consumes raw chances, which is not enforced here. Suggested fix: Add a debug assertion or comment tying the priced path to the window_price.calibrate consumer so a future caller cannot silently get uncut chances with no calibrator.
  • [WARNING] zig/src/core/lanes/allocate.zig: The surplus objective expected - lambda*(cost+overhead) changes the argmax only when timed is true, but the untimed branch still uses expected/(cost+overhead), so a caller passing token_rate with untimed costs silently gets legacy throughput scoring instead of surplus scoring. Suggested fix: Either assert token_rate is null when !timed, or document that token_rate only applies to timed tables.
  • [WARNING] zig/src/families/glm/cuda_lane_cost_measure.zig: The priced block path derives step_ms as fastest(depth 7)/7 but never validates that depth 7 timing succeeded before dividing; a failed or zero timing yields step_ms = 0 or NaN, which then feeds the allocator's surplus objective. Suggested fix: Guard the fastest() result: if it is not finite and positive, fall back to the seed step price or return an error so the caller uses fallback() seeds.
  • Synthena

@ashhart ashhart added synthena:needs-device Initial diff review passed; waiting for device and slowdown check before READY and removed synthena:needs-receipt Speed PR awaiting verified perf_receipt.py hash run labels Dec 5, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind:perf Classified by Synthena as performance improvement synthena:needs-device Initial diff review passed; waiting for device and slowdown check before READY

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants