Repository navigation
server: build the tokenizer memo on a dense dedicated allocator - #4455
Conversation
|
I trial-merged I added two scratch assertions to the existing Clef Split fixture. Loading with and without a Split override uses The cap still counts live memo entries. Small freed allocations go back to the global allocator's freelists, so that cap should be read separately from process high-water memory. I verified the server wiring on macOS. The GB10 Igor Lessio - AIFLOW LABS |
|
I independently reproduced the memory slope over the real
Two fresh processes per build, run main → PR → PR → main, gave the same numbers. All 1,000 returned token arrays matched across all four runs (SHA-256 To replay on Linux ARM64, build each tree with Igor Lessio - AIFLOW LABS |
As offered in #4389, I ran the Issue's probe on this PR's base and head, serving a GLM-5.3-Flash checkpoint at TP=2 on two GB10s. On rank 0, for messages of 100 and 1,000 bytes, the 64 KiB step per request is gone on both the tokenize and chat routes. For 17.6 KB of new text in each request, the step falls from two units a request to one, and growth still stops where the memo's own count reaches 64 MiB.
In 64 KiB units from With one new 17,599-byte message in each request (tokenize, 1,800 requests), the memo's count reaches 64 MiB at request 1,630 or 1,631:
Base repeats the Issue's tokenize row exactly. On head, rank 0's Setup:
|
|
Thanks both — the description's GB10 result now has independent corroboration on macOS ARM, Linux ARM, and TP=2 CUDA over RoCE, all with the same signature: the fixed 64 KiB-per-request step is gone, growth stops at the memo's own 64 MiB count, and token outputs are unchanged (SHA-equal across builds in AIFlowML's ARM64 runs). @Bizuayeu, on the one unit a request head still adds in the 17.6 KB shape — that reads as the memo filling, not leaking. Your own rows pin it: the memo's count reaches the 64 MiB cap at request ~1,630, which puts ~40 KiB of cap-accounted storage per entry (64 MiB / 1,630), and the allocator serves that entry from one 64 KiB unit — so rank-0 VmData grows one unit per request while the memo fills, then eviction recycles and growth stops exactly where your table stops. On base the same entry took two units, which is the gpa side of this diff. Happy to produce a per-allocation breakdown if that reading is worth confirming. @AIFlowML, agreed on the cap semantics: the cap counts live memo entries, and small freed allocations returning to the global freelists means the cap and process high-water move independently — the description's GB10 VmData rows stay framed as that device's result, not a process-wide claim. Head is unchanged since the reports: one commit, one line in |
Thank you. That reading fits my rows. 64 MiB over about 1,630 entries is about 40 KiB an entry, and head grew by 104,676 kB over the 1,628 requests before the stop, which is 64.3 kB a request. I don't need the breakdown for this PR. The receipts above are all I had to add. |
|
Following up on the per-allocation breakdown — with a correction to my mechanism read in the comment above. Setup: fake_serve on Linux ARM64 (the same method as AIFlowML's second report), real HfText tokenizer files, Zig 0.17.0 ReleaseSafe, one fresh serve per arm, one request at a time over fresh connections. For the breakdown I built a scratch instrument that prints the memo's own
Three findings:
Caveat: this is fake_serve. Your real-server run's VmData stopped at the cap, so the real server's outside component is smaller or absent — if it reproduces on a real serve it may deserve its own issue; happy to keep digging either way. The 100 B row is a third-platform confirmation of the fix (Linux ARM64 numbers align with AIFlowML's). |
Thank you for the breakdown. My reply above checked only the arithmetic. On the real serve, head's one unit a request ended at request 1,628, where the memo's count reaches 64 MiB. The remaining 172 requests added +256 kB in all (four steps of +64 kB, and +0 over the last 100), where 28 to 32 kB a request would have come to about 5 MB. Base stopped the same way (+384 kB over the same 172 requests). The tail is short, so I cannot rule out a smaller component there. If it helps, I can run the 17.6 KB shape to 5,000 requests on the real serve, on both trees. |
I ran your bare 17.6 KB row on the real serve: one bare 17,599-byte user message a request, each with a new nonce line, 5,000 requests to
At 28 to 32 kB a request, the 3,372 requests after head's stop would have added about 92 to 105 MiB. The figures up to the stop are the same as in the 1,800-request runs, to the kB. This covers the native server only. The two runs also differ in the tokenizer files and the text, so mine do not show where the |
The ReleaseSafe serve's process gpa is SafeAllocator over page_allocator, whose minimum bucket is 64 KiB on aarch64. Memo segments land in those buckets among a request's short-lived allocations, so each request that keeps a new segment maps about 64 KiB that stays until the segment evicts (ashhart#4389). Build the memo on std.heap.smp_allocator instead: dense size classes, freed segment space reused by later segments, so VmData tracks the memo's own 64 MiB count. overrideSplit propagates the memo's allocator; the other create call sites (its own tests) are unchanged.
69eb998 to
ed6cfd3
Compare
|
Thank you @bikepresentball. 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. |
Fixes #4389 (direction (a) — the memo gets an allocator of its own).
The change
One line:
zig/src/server/hf_text.zigbuilds the segment memo onstd.heap.smp_allocatorinstead of the server's processgpa.The ReleaseSafe serve's process gpa is
SafeAllocatoroverpage_allocator(
zig/build/cuda.zig;lib/std/start.zig), whose minimum bucket is1 << max(page_size_log2, 13)= 64 KiB on aarch64.Memo.putcopies each newsegment's text and ids with
gpa.dupe(zig/src/core/tokenizer/memo.zig), so akept segment lands in a bucket among that request's short-lived allocations, and
the bucket stays mapped until the segment evicts — the ~64 KiB-per-request
VmDatathe issue measures.std.heap.smp_allocator(Zig 0.17.0,lib/std/heap/SmpAllocator.zig) is aglobal thread-safe singleton with dense size classes; freed segment space is
reused by later segments, so the process's
VmDatanow tracks the memo's ownbyte count instead of one 64 KiB bucket per request.
Tokenizer.overrideSplitreadsconst gpa = m.gpabefore recreating the memo,so the dedicated allocator propagates there;
Memo.create's own unit tests keepstd.testing.allocator. The memo's cap accounting (bytes()+ eviction) isunchanged — the 64 MiB bound still governs what it keeps.
Measured on GB10 (aarch64)
Same instrument as the issue's probes:
tensorfold-native serveofqwen3-embedding-0.6b (same binary and server path as a chat seat), one request at
a time over fresh connections to
/v1/tokenize,VmDatafrom/proc/<pid>/statusaround each arm. Base = main
a4ea27a11, head = this change; both builtzig build native -Dnvcc -Dsm=121on the same box, one fresh serve per build.The base arm reproduces the issue's 0.5–1.1 units/request; the head arm's
1,000-new-segment growth is +676 kB total — the per-request bucket cost is gone.
Gates
zig fmt --checkclean on the touched file.zig test zig/src/core/tokenizer/memo.zig: 7/7 (the memo's cap/recency/eviction suite).both this tree and a pristine
origin/mainworktree (Metal-vision andtiming-sensitive steps on a host without the device); none touch the tokenizer
or server paths, and the CUDA build compiles and serves on the GPU box.
SafeAllocator's per-allocation checks; the memo bounds itself through itsbyte accounting, and every other server allocation keeps the process
allocator's checks.