Repository navigation
Conversation
The prompt's n-gram gather copied each id's rows one at a time on the host. Rows now locate the shard by division when the shard sizes allow it and split the ids across up to eight threads into disjoint staging rows, same bytes. After every weight is on the device the checkpoint's pages are dropped from the mapping and the page cache, except the n-gram table spans a gather still reads. Fixes ashhart#1606
A prompt's n-gram gather reads one 100-byte row per id at random rows, but the table shards were mapped without advice, so each faulted page pulled a readahead window: about 1.4 GB read from disk for a first short request. The table tensors' spans now get MADV_RANDOM after mapping. Fixes ashhart#1602
9 tasks done
Owner
|
Thanks — the random-access advice makes sense for scattered n-gram rows. This PR contains all of #1611 plus the madvise change; could you say whether it replaces 1611 or should be rebased on top of it once 1611 lands? Either works, but we'll only land one copy. Please also add a short description with before/after numbers (page faults, or gather / first-prefill time) so we can see what the advice buys. |
Contributor
Author
|
It stacks on #1611 rather than replacing it: after #1611 lands I'll rebase this so it holds only the advice commit. What the advice buys, on the same machine and checkpoint (
I also pushed a |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this changes
The HIP Flash Next engine advises
MADV_RANDOMover the n-gram table tensors' spans after mapping (File.adviseRandom,Checkpoint.adviseRandom), so a gather's random single-row reads fault only their pages instead of whole readahead windows. Fixes #1602. Stacked on #1611 (same files:safetensors.zig,checkpoint.zig,hip/tables.zig); the second commit is this change.The issue guessed at first-use graph capture; measuring showed otherwise: with graphs off the first request was equally slow, the engine replays 4,563 of 4,571 rounds, and the first request read 1,419,132 KiB from disk with 11,262 major faults while the identical repeat read 0. The slowdown follows new prompt content (new n-gram rows), not server start. The CUDA path already advises its tables this way.
Receipt
7c068895plus hip flashnext: parallel n-gram gather, release weight pages after upload #1611 and this change,tensorfold-native 1.1.8built withzig build native-hip -Dhip-arch=gfx1151, Ubuntu archive HIP 7.1 (clang 21), AMD Ryzen AI MAX+ 395 with Radeon 8060Sgfx1151(128 GB unified memory), page cache dropped before each server start. CheckpointTensorFold/Qwen3.8-Flash-Next-MLX-4bit-MTPrevision2b170fa6, MTP 3 drafts,--parallel 1 --context 131072 --prompt-cache-gib 0, fresh process per run, base and candidate on the same machine.token_sha256oftools/bench_openai.py,tools/bench_concurrent.pyand bothtools/bench_cache.pyprompts identical to the base build;bench_concurrent --alone --serialevery cellalone3/3 and 12/12 equal,serialequal, 0 failed.tools/bench_openai.py --tokens 256 --reps 3 --temperatures 0: first request after start (14-token prompt) 24.4 tok/s on the base, 35.8 / 35.9 / 34.9 tok/s with this change alone over three fresh processes, 35.5 tok/s stacked on hip flashnext: parallel n-gram gather, release weight pages after upload #1611; later requests unchanged (base 50.03 / 43.93, stacked 50.13 / 44.09 median code / chat).tools/bench_cache.py --require-coldon public 7,377- and 29,364-token arrays, first cold requestttft_s: base 48.44 / 108.97 s; this change alone 28.9 s at 7,377; stacked on hip flashnext: parallel n-gram gather, release weight pages after upload #1611 25.30 / 102.22 s.zig build test -Dhip=true --summary all466/466 steps, 0 failed, on the stacked tree; a new host test checks thatadviseRandommarks the tensor's pages random in/proc/self/smaps(fails with the advice disabled: 25 passed, 1 failed).python3 tools/zig/lean_check.py425 on base and change.git diff --checkclean.hip-kernel-testand the kernel contract (no kernel change). The residual cold cost is random-read latency (about 4 s for 5,888 rows on this disk); parallel reads could cut it further and are left out. Metal and CUDA (Linux HIP path only; the advice is a no-op elsewhere and on heap-copied files).Checklist
"draft": false, a resumed prompt equals a fresh one, and concurrent equals solo.SUMMARYline is in the receipt. (No kernel change.)