Skip to content

CUDA: retain pinned peaks and scoped process memory receipts - #865

Merged
ashhart merged 3 commits into
ashhart:mainfrom
jayleaton:shared/cuda-memory-receipts
Oct 18, 2026
Merged

ashhart merged 3 commits into
ashhart:mainfrom
jayleaton:shared/cuda-memory-receipts

Conversation

@jayleaton

@jayleaton jayleaton commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Pinned HostBuffer allocations now retain a high-water mark, and an atomic interval snapshot preserves device and pinned peaks before resetting them. Add an opt-in per-process lifecycle receipt API and a Linux child-process collector so each rank can retain load/reset/cleanup boundaries without an HTTP endpoint.

Evidence Before With this change
Pinned allocations Current bytes only Current and interval peak; freed transients retained
Reset Completed peak discarded Optional atomic capture of completed interval before reset
Per-rank collection HTTP engine endpoint required PID/rank-tagged lifecycle records plus owned-child OS readings
Physical footprint Linux unsupported Explicitly unsupported; RSS/PSS never relabeled as total footprint

The shared API is dormant until a caller opts in and emits boundaries. Family-specific DeepSeek lifecycle wiring is kept on a separate local candidate branch; this PR does not qualify that family or rewrite its cumulative stack. The collector starts only the supplied local command and provides no machine admission, service control or remote access. Use the owner's existing guard for any future device run.

Receipt

  • Environment: Linux x86_64, Zig 0.17.0, base c7137bb. CPU-only tests and probes; no GPU, model or checkpoint loaded.
  • Exactness, decode and prompt speed: unrun. No arithmetic, weight format, scheduling or inference path changed. Host instrumentation results establish counter/collector behavior only.
  • Actual before probe: the pinned base emits {"device":0,"host":0,"peak":0} with no pinned peak. After: seven direct Zig tests pass, covering pinned transient/reset accounting, concurrent reset exclusion, atomic completed-interval capture and both-rank JSON serialization.
  • Six Python checks pass, including actual CPU child memory/exit collection, malformed or missing native evidence, wrong PID/rank, failed child and invalid sampling intervals. Two real CPU-only Zig emitter processes were captured independently as ranks 0 and 1; each retained the matching PID and complete lifecycle while total physical footprint stayed unsupported.
  • Full project gate receipt: committed 6b73325e90eb17685b2825cf4e1bf25555287997, tree 673e573c7bfc000d62f4cdb738b0a2ae382bbe69, clean index. Build 10/10 steps; host test 46/46; frozen goldens 4/4; fuzz 3/3; CUDA-host 27/27; server CPU 3/3. Some test executions are cached; no skipped test was relabeled. Formatting/diff checks pass; lean 527 inherited, zero new by identity.
  • Not run: CUDA/Metal/model memory, full physical footprint, checkpoint/reference precision, token parity and performance. No hardware window was granted. No device qualification claimed.

Additional pinned-allocation accounting uses the existing counter mutex; diagnostic output can affect host timing when enabled. These are owned logical buffer counts, excluding arena reservation/slack, driver, NCCL and other untracked allocations. Linux wait4 RSS includes fork/exec/startup, is lifetime-scoped and cannot establish a unified-memory physical-footprint peak. Raw process logs require publication review.

Checklist

  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off. (Device/model run unrun.)
  • Drafted output equals "draft": false, resumed equals fresh, concurrent equals solo. (Unrun.)
  • No precision traded for speed; no arithmetic or reduction changes.
  • Prompt processing is no slower than the last release. (Unrun.)
  • Platforms and unrun GPU/model gates are stated above.
  • New tests fail before, pass after and skip cleanly. (After checks passed; baseline missing-field probe retained, no claim every new test was run before.)
  • Comments/docstrings are one line; measurements are in this receipt.
  • Publication tree/history inspected; no private identity or tool-attribution additions.

@ashhart

ashhart commented Oct 15, 2026

Copy link
Copy Markdown
Owner

Thanks, @jayleaton. The locked device/pinned interval counters and sampler-before-reap change look right at 6b73325. One shutdown race needs fixing: tools/memory_receipts.py:104 reaps the child before lines 109-110 restore signal handlers. During that gap, forward can send SIGINT or SIGTERM to an unrelated process that reused the PID. Please disarm forwarding before reaping after WNOWAIT confirms exit, or use a pidfd. This is a source-level race finding; no signal reproduction was run here.

@jayleaton

Copy link
Copy Markdown
Contributor Author

Thanks, @ashhart. Fixed in 37828a13. Once WNOWAIT confirms the child has exited and the sampler has stopped, tools/memory_receipts.py now disarms forwarding before wait4 reaps the child. From the reap until the handlers are restored, a SIGINT or SIGTERM is no longer sent to the old PID.

New regression: test_forwarding_is_disarmed_before_child_can_be_reaped sends SIGINT and SIGTERM at that point. It records two forwards before the reap and none after. All 7 tests in tools/test_memory_receipts.py pass at this head. desktop, mobile, zig and fmt pass at 37828a13. Host gate (Linux x86_64, Zig 0.17.0): fmt and diff are clean, and lean_check shows 527 inherited findings and 0 new. No device run was done for this change.

@ashhart ashhart mentioned this pull request Oct 17, 2026
@ashhart
ashhart merged commit 21e8058 into ashhart:main Oct 18, 2026
4 checks passed
ashhart added a commit that referenced this pull request Oct 18, 2026
ashhart added a commit that referenced this pull request Oct 18, 2026
…he 27B's K splits (#887), drafter releases (#893, #894), GLM's split check (#899) and Intel Arc (#802)
@ashhart

ashhart commented Oct 18, 2026

Copy link
Copy Markdown
Owner

Thank you, @jayleaton, for disarming signal forwarding before reaping the child and adding the regression.

We merged your work for 1.1.0 in 21e8058. CUDA keeps pinned-host peaks beside device peaks, and takeUsage returns an interval's peaks as it resets them.

The receipt tool runs a command for each rank and context, keeping RSS and device counts separate. This adds counters and collection tooling; it does not change a family's inference arithmetic.

Posted by Ash's AI Assistant Synthena

Bizuayeu added a commit to Bizuayeu/TensorFold that referenced this pull request Oct 19, 2026
…y_receipts.py reads, and a follower frees what it owns before it leaves

With TF_CUDA_MEMORY_RECEIPTS=1 (ashhart#865) each rank prints load_begin before NCCL and its weights, load_end once every
rank has loaded, and cleanup_begin and cleanup_end around freeing its buffers, so the wrapper records one complete
lifecycle a rank. A follower used to leave without freeing anything; after the end step it now frees its link, image
rows, engine and group as rank 0's close does, so its cleanup receipts measure that. A follower that fails still
leaves with _exit(1).
Bizuayeu added a commit to Bizuayeu/TensorFold that referenced this pull request Oct 19, 2026
…y_receipts.py reads, and a follower frees what it owns before it leaves

With TF_CUDA_MEMORY_RECEIPTS=1 (ashhart#865) each rank prints load_begin before NCCL and its weights, load_end once every
rank has loaded, and cleanup_begin and cleanup_end around freeing its buffers, so the wrapper records one complete
lifecycle a rank. A follower used to leave without freeing anything; after the end step it now frees its link, image
rows, engine and group as rank 0's close does, so its cleanup receipts measure that. A follower that fails still
leaves with _exit(1).
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
goulderb pushed a commit to goulderb/TensorFold that referenced this pull request Oct 21, 2026
…y_receipts.py reads, and a follower frees what it owns before it leaves

With TF_CUDA_MEMORY_RECEIPTS=1 (ashhart#865) each rank prints load_begin before NCCL and its weights, load_end once every
rank has loaded, and cleanup_begin and cleanup_end around freeing its buffers, so the wrapper records one complete
lifecycle a rank. A follower used to leave without freeing anything; after the end step it now frees its link, image
rows, engine and group as rank 0's close does, so its cleanup receipts measure that. A follower that fails still
leaves with _exit(1).

Source-Commit: 80517fc
Port-Changes: source-only; upstream raw receipt files omitted.
Bizuayeu added a commit to Bizuayeu/TensorFold that referenced this pull request Oct 21, 2026
…y_receipts.py reads, and a follower frees what it owns before it leaves

With TF_CUDA_MEMORY_RECEIPTS=1 (ashhart#865) each rank prints load_begin before NCCL and its weights, load_end once every
rank has loaded, and cleanup_begin and cleanup_end around freeing its buffers, so the wrapper records one complete
lifecycle a rank. A follower used to leave without freeing anything; after the end step it now frees its link, image
rows, engine and group as rank 0's close does, so its cleanup receipts measure that. A follower that fails still
leaves with _exit(1).
Bizuayeu added a commit to Bizuayeu/TensorFold that referenced this pull request Oct 22, 2026
…y_receipts.py reads, and a follower frees what it owns before it leaves

With TF_CUDA_MEMORY_RECEIPTS=1 (ashhart#865) each rank prints load_begin before NCCL and its weights, load_end once every
rank has loaded, and cleanup_begin and cleanup_end around freeing its buffers, so the wrapper records one complete
lifecycle a rank. A follower used to leave without freeing anything; after the end step it now frees its link, image
rows, engine and group as rank 0's close does, so its cleanup receipts measure that. A follower that fails still
leaves with _exit(1).
ashhart pushed a commit that referenced this pull request Oct 25, 2026
…y_receipts.py reads, and a follower frees what it owns before it leaves

With TF_CUDA_MEMORY_RECEIPTS=1 (#865) each rank prints load_begin before NCCL and its weights, load_end once every
rank has loaded, and cleanup_begin and cleanup_end around freeing its buffers, so the wrapper records one complete
lifecycle a rank. A follower used to leave without freeing anything; after the end step it now frees its link, image
rows, engine and group as rank 0's close does, so its cleanup receipts measure that. A follower that fails still
leaves with _exit(1).
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.

2 participants