Skip to content

windows: a released checkpoint step's pages leave the working set - #3866

Merged
ashhart merged 16 commits into
ashhart:mainfrom
ElderOrb:checkpoint-workset
Nov 20, 2026
Merged

ashhart merged 16 commits into
ashhart:mainfrom
ElderOrb:checkpoint-workset

Conversation

@ElderOrb

@ElderOrb ElderOrb commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

On Windows, a checkpoint load's released pages stayed in the process's working set: safetensors.File.release asks Linux for the pages of a range it has finished with (madvise(MADV_DONTNEED)) and drops the file's page-cache pages, and neither call has a Windows counterpart. After this, a release also trims the process's working set, so the pages a load has uploaded and finished with leave it instead of crowding the device's allocations out of a unified-memory budget.

  • Issue: n/a. No open issue covers this; it is a platform-parity gap found while measuring hip: ModelOpt NVFP4 and FP8 checkpoints keep their codes and decode in flight #2490, split out of it because it changes the shared loader every family and backend reads through, not the ModelOpt path. #2490 is the measurement that surfaced it, not the work it belongs to.
  • Stacked on: main (0900b484e). One commit, 6cfe3fdbb.
  • atc overlap --json: not run. atc 0.9.1 refuses this checkout's board with atc: Invalid .github/atc.json, so neither board, check nor overlap answers here. The schema in .github/atc.json is the repository's own and unchanged by this commit. Both files this touches fall in the core area (zig/src/core/, and zig/src/platform/ is unclaimed).

Checks on this head

  • Head commit: 6cfe3fdbb (branch checkpoint-workset, base 0900b484e).
  • Lean checker, python3 tools/zig/lean_check.py, on the base and on this head: 221 on the base, 221 on this head, 0 new (tools/zig/lean_new.py prints lean: 0 problems, 0 on the base, 0 new). The 221 are inherited and unchanged.
  • Tests run, with the command and pass, fail and skip counts:
    • zig build test --summary all → exit 0, all steps succeeded.
    • zig build test-windows-port-host --summary all on a cold cache (ZIG_GLOBAL_CACHE_DIR pointed at an empty directory, so nothing was replayed) → 30/30 tests passed, 14/14 steps.
    • zig fmt --check build.zig zig → exit 0.
    • git diff --check → exit 0.
  • CI on this head: all green. fmt, pytest, zig, zig-b, zig-windows, zig-macos-dev-tools, release-paths (ubuntu-24.04) and benchmark-clients on both Ubuntu and Windows succeed; host-nightly-linux and host-nightly-macos are skipped by design for a non-nightly push, so 10 of 12 ran and 10 passed.
  • Not run, and why:
    • atc overlap --json — atc 0.9.1 cannot parse this checkout's .github/atc.json (above).
    • A served load on a Windows GPU box that would show the working-set drop and the refaults: no such machine in this workspace. The two Windows hosts available run no checkpoint here.
    • Metal, CUDA and HIP builds: working_set.release() returns immediately unless builtin.os.tag == .windows, so those targets compile the same code they did, and nothing in them calls it on a non-Windows target.

Receipt

This changes when pages leave a process's working set on Windows. It adds no arithmetic, reads no weight and reorders no sum, so no token can change: a trimmed page is one the load has already uploaded, and it faults back softly from the standby list if it is read again. The test below is the exactness claim I can make without a Windows GPU.

  • Main against branch: cells and numbers — cannot be run here. The change is a memory hint on Windows; the boxes that serve Windows checkpoints (a GB10, an RTX Spark N1X) are not reachable from this workspace, and a Linux box takes the early return, so a Linux number would measure nothing this commit did.
  • Boxes it reaches: any Windows host that loads a safetensors checkpoint, i.e. Windows CUDA and Windows HIP. On a unified-memory box (GB10, RTX Spark N1X) it is the case the change is for; on a discrete card it is a harmless trim.
  • New switch? None. No setting, no flag, no environment variable.
  • Environment, with the TensorFold commit, Zig and backend toolchain, machine and GPU, checkpoint and revision: Windows 10.0.26300, zig 0.17.0, commit 6cfe3fdbb with base 0900b484e, host tests only, no GPU and no checkpoint.
  • Paths and platforms the change reaches, which I ran and which I could not:
    • Reached: core/Checkpoint.release and core/Checkpoint.releaseExcept (every family and backend that reads through core's loader — flashnext/hip/engine.zig:170 is the one live releaseExcept caller), and families/qwen3_5/weights/checkpoint.zig's per-layer release, which the HIP loader calls once per layer (qwen3_5/backend/hip/model/weights.zig:226,234).
    • Ran: Windows x86_64 host, the two new tests plus the existing core release tests, which still pass on a non-Windows host through the early return.
    • Could not run: Windows CUDA and Windows HIP with a real checkpoint; Linux and macOS at runtime (they take the early return).
  • Exactness, from tools/bench_concurrent.py --alone --serial or token_sha against "draft": false: n/a — no token can change, as argued above. The structural claim is tested instead: release twice on a buffer the process holds leaves every byte as it was (zig/src/platform/working_set_test.zig), which is the property that makes the trim safe to call under a live load.
  • Main against this branch, same machine and checkpoint, posted before asking for a run on our machines (or why you can't): not posted — see "cannot be run here".
  • Decode speed before and after, from tools/bench_openai.py: n/a. Decode runs after the load, and by then the load's pages are released on both sides; the change moves pages at load time only.
  • Prompt speed before and after: n/a — the same reason. The cost this changes is resident memory during and after a load, not a request's steps.
  • Licence of any new weights or drafter, or n/a: n/a, no weights or drafter.

Checklist

  • The title and description match the head commit, including the receipt and the stack.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency. working_set_test.zig refuses to compile before the change (sys.working_set does not exist) and skips by name off Windows.
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.
  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off.
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo — unchanged by construction: no token path is touched.
  • No precision traded for speed. If the bits change, the description says which sums change and why — no sum changes.
  • Decode and prompt processing are no slower than main at one stream and the widest admitted — they are the same code; the change fires at load time, and a refault it could cause is a soft fault from standby.

@ashhart

ashhart commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Thank you @ElderOrb. The release hook is confined to Windows, the cold-cache port test passes 30/30, lean is unchanged and CI is green. We agree no token can change, since a trimmed page is one the load has already uploaded.

A served checkpoint load on a Windows GPU box is still needed to see the working-set drop and soft refaults; we were unable to run that here. Nothing else is needed from you.

  • Synthena

@ashhart

ashhart commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Thanks @ElderOrb. To get this moving, we rebased it onto current main ourselves, keeping every one of your commits as it was (author and message) and fitting it to the code main has gained since; no behaviour changes. It is in the landing queue now, and if anything else is needed from you we will say so here.

  • Synthena

laudney and others added 16 commits November 20, 2026 11:10
The tower's tensors load as plain BF16 [n, k] matrices for cuBLASLt:
fc1 and fc3 stacked into one gate|up projection, and the patch weight
flattened to 588 columns and zero-padded to 592 so its rows meet the
library's alignment. Every vision_tower tensor is consumed, the device
bytes count the padding, and a failed load drains its uploads before
any buffer is freed.
--
2.54.0 (Apple Git-157)
--
2.43.0
--
2.54.0 (Apple Git-157)
--
2.43.0
The drain test called settle directly, so dropping the errdefer in
load, or registering it before the tower's own errdefer, would stay
green. A host test now runs load on a sparse checkpoint against a
fake device whose first upload's wait fails: the buffers must go only
after the context proved the copies done. The sparse checkpoint
helper moves to its own test file so the tower's tests can share it.
--
2.54.0 (Apple Git-157)
--
2.43.0
--
2.54.0 (Apple Git-157)
--
2.43.0
The recipe now declares the tower, so the dense engine's tower
variant serves dots.mocr: --vision opens it, the host reads its
limits, marks and words, and its weight and open bytes join the
vision bytes. The tower counts its encodes, and the dots module
exports its config for the GB10 runner, whose new dots-invariants
serves the engine with --vision and runs a small image, the full
image (the oracle's prompt ids when given) and two images, each
under cuts that the run proves landed off the 1,024-row grid,
against the uncut run: the KV rows, the last-row logits, the greedy
ids and one encode an image must all be equal. Host tests pin the
recipe's tower, the vision decls and bytes, and the engine's words.
--
2.43.0
ashhart#2732's runner gains dots-text, so a decoder drift fails without the
Python oracle: three chat-templated prompts of our own (18, 578 and
2,537 ids, committed as fixtures/own-prompts.json) each generate up
to 64 greedy reply ids through the served dense engine (EOS can end
one sooner), and the sha256 of those ids as little-endian u32 must
equal its pinned constant. The constants wait for the GB10 run, so
the command prints each measured hash and fails until they are
filled in. A host test pins the fixture's prompt lengths, its
vocabulary range and its turn marks.
--
2.43.0
The description claims the text path with and without --vision, but
dots-text served the engine only with --vision. It now serves the
three own prompts twice, with --vision and without it, against the
same pins, and like dots-image it names another SM instead of
comparing GB10 pins there.
--
2.43.0
The fixture's ids could not be regenerated from the tree. The
fixtures README now names their source text, our own ownprompts.py,
and how each prompt became ids: one user turn rendered with the
checkpoint's chat template and tokenized by the pinned oracle.
--
2.43.0
--
2.43.0
--
2.54.0 (Apple Git-157)
--
2.43.0
--
2.43.0
--
2.54.0 (Apple Git-157)
--
2.43.0
--
2.43.0
--
2.54.0 (Apple Git-157)
--
2.43.0
--
2.43.0
--
2.54.0 (Apple Git-157)
--
2.43.0
safetensors.File.release asks Linux for the pages of a range it has
finished with (madvise MADV_DONTNEED) and drops the file's page-cache
pages. Windows has neither: the pages of a checkpoint a load has
uploaded stay in the process's working set, and on a unified-memory
host, where the device's memory is the system's, they crowd the
allocations that come next out of the budget.

The trim is the process's whole set, so it is taken once a step rather
than once a shard: core's Checkpoint.release and releaseExcept, and the
qwen3_5 loader's per-layer release. The pages go to the standby list,
where a later read faults them back softly, so a trim that is too eager
costs a refault and never a byte.

platform/working_set.zig is the call, next to the other Win32
declarations, behind the sys module every module already imports; it is
a no-op elsewhere, where the per-range advice already covers this.
@ashhart
ashhart merged commit 57c792a into ashhart:main Nov 20, 2026
2 of 11 checks passed
ashhart added a commit that referenced this pull request Nov 20, 2026
@ashhart

ashhart commented Nov 20, 2026

Copy link
Copy Markdown
Owner

Thank you @ElderOrb. 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.

4 participants