Skip to content

core lanes: a cut chance tail prices by the rule's rates, not as a measured zero (#2870) - #2979

Merged
ashhart merged 3 commits into
ashhart:mainfrom
devopsfortunato:task/Tensorfold-Contribut+t-mwcrsks6-guta5r
Nov 17, 2026
Merged

ashhart merged 3 commits into
ashhart:mainfrom
devopsfortunato:task/Tensorfold-Contribut+t-mwcrsks6-guta5r

Conversation

@devopsfortunato

@devopsfortunato devopsfortunato commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Shared draft pricing now distinguishes a chain-cut, unmeasured tail from measured zero chances: the measured prefix stays cached and the unknown tail continues at the rule's rates. The cache's cut marker also survives allocation errors; host tests exercise its commit, confidence clamp, retention and clearing through the real allocator and a fake backend probabilities hook.

No family producer is enabled here. GLM's DFlash2 block path still stays off shared draft allocation under #2793. A future producer sets the marker at its first unmeasured chance, whether from a cut chain or a tail past the drafts it holds.

Checks on this head

  • Head commit: 7ac70e226cdc9d2ac9e1abe346ba714dc3052984.
  • Lean checker: pinned base 345 problems, head 345, zero new. The inherited count is not a clean lean-checker exit. python3 tools/pr_check.py --base upstream/main --pr 2979 exits 0, with only the advisory warning for no Unreleased bullet naming this PR. No CHANGELOG changes in the follow-up.
  • Tests run:
    • zig test zig/src/core/lanes/lanes.zig --test-filter 'cached draft cuts:' -lc: 22 passed, 0 failed (10 new tests plus 12 module test stubs).
    • zig test zig/src/core/lanes/lanes.zig --test-filter 'shared draft prices:' -lc: 17 passed, 0 failed.
    • zig build -j2 test-shared-lane-regressions-host --test-timeout 10m --summary all: 3/3 steps succeeded; 371 passed, 1 skipped, 0 failed out of 372 tests. This build step supplies the repository modules needed by the complete lane suite; a bare unfiltered zig test lacks the sys import.
    • zig fmt --check build.zig zig and git diff --check: exit 0.
  • Failing controls: before errdefer, the error tests fail with prior marker 1 becoming 3 or null. Ten independently restored mutations make the commit, clamp, replace-cache, copy/context-copy clear, non-head/empty-prefix retention, success restore and error restore checks fail on assertions. The final source contains no mutations or debug prints.
  • Review: Reviewed by GLM-5.3. Both review rounds approve with no blocking findings; final review checked the actual worktree, including the context-copy test.
  • CI: green on this head — all lanes pass (run https://github.com/ashhart/TensorFold/actions/runs/43894137063): zig, zig-b, zig-windows, pytest, fmt, release-paths, both benchmark-clients, zig-macos-dev-tools.
  • Not run locally: the complete zig build test suite on the loaded four-core host; the PR's CI runs the full host/platform checks. No GPU/model benchmark was run.

Receipt

  • Main against branch: the original host pricing control fails under main's rule and passes with the marker. The follow-up's error regressions fail before the one-line restoration and pass after; lifecycle controls are mutation-tested as above.
  • Boxes it reaches: shared host lane allocation and the backend probabilities contract. No family sets the marker in production yet, so serving remains unchanged, as confirmed in the maintainer review.
  • New switch: n/a; no setting added.
  • Environment: Linux/aarch64, Zig 0.17.0, pinned merge base and head above; CPU-only host checks. No checkpoint, drafter or backend toolchain needed for these tests.
  • Paths and platforms: host core used by all backends. Linux/aarch64 run locally; Linux, Windows and macOS CI results will be recorded on this head. No GPU execution performed.
  • Exactness: no token selection, precision, kernel or family implementation changes. No new model-token receipt claimed; the marker has no production producer in this PR.
  • Main against branch device measurements, decode speed and cold-prefill speed: waived for this PR by the maintainer in core lanes: a cut chance tail prices by the rule's rates, not as a measured zero (#2870) #2979 (comment). The four-stream DFlash2 comparison belongs with the follow-up that wires a producer.
  • Licence of new weights or drafter: n/a; none added.

Review requests addressed

  1. Ten host tests call windows.allocate through a fake backend hook, including head commit/clamp, forced/no-draft/fill/empty-prefix retention, copy/context-copy clearing, and both error paths. Each relevant assertion has a failing mutation control.
  2. An iteration-scoped errdefer restores the prior marker if the hook fails or NoDraftProbabilities is raised.
  3. The one-line comment on Backend.VTable.probabilities says the hook marks s.draft_chances_cut at the first unmeasured chance.

Checklist

  • Title, description, head and receipt match the pushed change.
  • Error regressions fail before the fix and pass after; lifecycle assertions have failing mutation controls.
  • Comments and docstrings are single lines; touched source files stay below 600 lines.
  • No private data, local paths, machine names or AI attribution in the code or outgoing commits; author and committer use the GitHub noreply address.
  • Full CI passes on the new head (zig, zig-b, zig-windows, pytest, fmt, release-paths, both benchmark-clients, zig-macos-dev-tools; run https://github.com/ashhart/TensorFold/actions/runs/43894137063).

@ashhart

ashhart commented Nov 12, 2026

Copy link
Copy Markdown
Owner

Thanks @devopsfortunato for picking up #2870, and for writing down both of GLM's zero sources for whoever wires the first family.

The pricing rule is right. With no marker, known at zig/src/core/lanes/shared_drafts.zig:41 is the old @min(cached.len, most), so every path prices as before. With a marker, the cut tail continues from the last measured chance at the rule's rates. A cut at 0 drops to the uncached branch, as an empty cache does. We ran the new test both ways on f1bc2c62f: it fails with main's rule and passes with yours. CI is green, and the branch merges cleanly with today's main. No family sets the marker yet, and GLM's block path still stays off shared rounds (zig/src/families/glm/cuda_lanes.zig:103), so serving can't change here. We won't ask for the four-stream DFlash2 run on this PR; it belongs with the follow-up that wires a producer.

Three small things before it lands:

  1. A test for the allocate side. Only budgets is tested, with a marker set by hand. Removing the commit at zig/src/core/lanes/windows.zig:278 or the clear at :272 would fail no test. Could you add a host test that gives the fake backend a probabilities hook that writes chances and sets s.draft_chances_cut, runs allocate with allocate_shared_drafts on, and checks these three cases?

    • A head plan commits the marker with its cache. With draft_confidence set, the marker is capped at the prefix kept.
    • A plan with no chances (forced, or no drafts) keeps the previous cache and marker.
    • A copy plan clears both.

    Each check should fail when its line is removed.

  2. The error path. windows.zig:251 clears the marker before planChances, and :267 puts it back only when that call returns. If the hook fails (or NoDraftProbabilities is raised), the stream keeps its old chances without their marker, and that's the zero-as-measured reading this PR removes. An errdefer p.stream.draft_chances_cut = prior; after :251 keeps the marker with its cache on that path too.

  3. Say it where a family author will look. The only place a producer can set the marker is inside its probabilities hook. Could the doc comment on that field (zig/src/core/lanes/backend.zig:121) say that the hook sets s.draft_chances_cut to the first chance it could not measure? That covers both a cut chain and chances past what it holds. Keep it to one line, per the repo's comment rule.

Once these are in and CI is green, it can go on the landing queue.

  • Synthena (Ash's Agent)

@devopsfortunato

Copy link
Copy Markdown
Contributor Author

Addressed the three requests in 7ac70e226cdc9d2ac9e1abe346ba714dc3052984.

  1. Allocator coverage: the ten host tests install a probabilities hook on the fake backend and call the real allocate with shared draft allocation enabled. They pin the cached values and marker for head commit, confidence clamp, forced/no-draft/fill/empty-prefix retention, copy/context-copy clearing, and both failure paths.
  2. Error restoration: the per-iteration errdefer restores the prior marker when the hook errors or a false hook result raises NoDraftProbabilities. Before this line, the two tests fail with expected 1, found 3 and expected 1, found null; with it they pass and retain the original cached values.
  3. Producer contract: the one-line hook comment tells a producer to mark s.draft_chances_cut at the first unmeasured chance.

Each lifecycle assertion was also checked against an independently restored mutation: null marker commit, removed clamp, missing head cache replacement, missing copy cache/marker clears, either retention guard clause, the context-copy clause, the normal prior restore, and the error restore all fail their corresponding assertions. No mutation or debug print remains.

Independent checks on this head:

  • New filter: 22/22 passed (10 new tests plus 12 module stubs); original pricing filter: 17/17 passed.
  • zig build -j2 test-shared-lane-regressions-host --test-timeout 10m --summary all: 3/3 steps succeeded, 371 passed, 1 skipped, 0 failed.
  • Formatting and whitespace checks pass; PR preflight reports base/head lean 345/345, zero new findings. The missing changelog bullet is advisory; no CHANGELOG or other docs changed.
  • Reviewed by GLM-5.3: final review approved with no blocking findings.

The new-head full CI is being checked separately; the old head's green checks are not being counted for this revision. No family producer or GPU benchmark is added, per your scope decision.

ashhart added a commit that referenced this pull request Nov 17, 2026
ashhart added a commit that referenced this pull request Nov 17, 2026
…inted commit

Eight are for PRs that haven't landed (#3457, #3560, #2979, #3588, #2824, #3233, #2000, #3038); they return when those PRs land. The ninth repeated #2878's line, which is already in its release.
@ashhart
ashhart force-pushed the task/Tensorfold-Contribut+t-mwcrsks6-guta5r branch from 7ac70e2 to 933cf1e Compare November 17, 2026 09:31
@ashhart
ashhart merged commit c0557ef into ashhart:main Nov 17, 2026
2 of 11 checks passed
@ashhart

ashhart commented Nov 17, 2026

Copy link
Copy Markdown
Owner

Thank you @devopsfortunato. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes.

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.

core lanes: shared rounds can't tell a cut draft tail from a measured zero chance

2 participants